SpEditTool

Additional

Language
Java
Version
N/A
Created
Jan 16, 2018
Updated
May 30, 2018
Owner
sunhapper
Contributor
sunhapper
1
Activity
Badge
Generate
Download
Source code
APK file

Announcement

Description

  • SpEditText--An EditText for mentioning user and showing topic with highlight and overall deleting
  • GifTextUtil--A tool for show gif on graph-text mixed TextView/EditText efficiently

ScreenShot

Usage

Gradle

  • root build.gradle
 allprojects {
  repositories {
   ...
   maven { url 'https://jitpack.io' }
  }
 }
  • dependency

dependencies {
         compile 'com.github.sunhapper:SpEditTool:{last version}'
 }

xml

<com.sunhapper.spedittool.view.SpEditText
    android:id="@+id/spEdt"
    app:react_keys="#*%@"
    app:sp_mode="breakable"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
  • app:react_keys--characters will be reacted
  • app:sp_mode
    • "integrated"means overall deleting
    • "breakable"means normal deleting,data and style will be removed when integrity break

java

SpEditText

  • react the character input
spEditText.setReactKeys("@#%*");
spEditText.setKeyReactListener(new KeyReactListener() {
      @Override
      public void onKeyReact(String key) {

      }
    });
  • insert special content
spEditText.insertSpecialStr(" @sunhapper ", true, 0, new ForegroundColorSpan(Color.RED));
  /**
   *
   * @param showContent special text content
   * @param rollBack true is need to delete on char forward
   * @param customData special text`s extra data
   * @param customSpan special text`s style
   */
  public void insertSpecialStr(String showContent, boolean rollBack, Object customData,
      Object customSpan)
  • get data from SpEditText
SpData[] spDatas = spEditText.getSpDatas(); 
  public class SpData {

    /**
     * special text content
     */
    private String showContent;
    /**
     * special text`s extra data
     */
    private Object customData;
    /**
     * special text`s start on EditText
     */
    private int start;
    /**
     * special text`s end on EditText
     */
    private int end;
  }

GifTextUtil

define a custom gifDrawable extend Drawable and implements RefreshableDrawable

public interface RefreshableDrawable {

  boolean canRefresh();

  int getInterval();

  void addCallback(Drawable.Callback callback);

  void removeCallback(Drawable.Callback callback);

}

bind spannable with gifDrawable to textView

GifTextUtil.setTextWithReuseDrawable(textView, charSequence, false);

proguard

-keep class com.sunhapper.spedittool.**{*;}

more detail info and guidance,please see the demo

中文文档

welcome to star,PR and issue