Signed-off-by: rtc <rtc@qq.com>

pull/35/head
rtc 2 years ago
parent 3364c862eb
commit 1519ad030c

@ -39,18 +39,18 @@ import java.util.Map;
public class NoteEditText extends EditText { public class NoteEditText extends EditText {
private static final String TAG = "NoteEditText"; private static final String TAG = "NoteEditText";
private int mIndex; private int mIndex; // 当前索引
private int mSelectionStartBeforeDelete; private int mSelectionStartBeforeDelete; // 删除前的光标位置
private static final String SCHEME_TEL = "tel:" ; private static final String SCHEME_TEL = "tel:"; // 电话号码链接的Scheme
private static final String SCHEME_HTTP = "http:" ; private static final String SCHEME_HTTP = "http:"; // 网页链接的Scheme
private static final String SCHEME_EMAIL = "mailto:" ; private static final String SCHEME_EMAIL = "mailto:"; // 邮件链接的Scheme
private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>(); private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>(); // 存储链接Scheme和对应操作资源的映射
static { static {
sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel); sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel); // 将电话号码链接的Scheme和对应的操作资源ID放入映射中
sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web); sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web); // 将网页链接的Scheme和对应的操作资源ID放入映射中
sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email); sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email); // 将邮件链接的Scheme和对应的操作资源ID放入映射中
} }
/** /**
@ -58,44 +58,51 @@ public class NoteEditText extends EditText {
*/ */
public interface OnTextViewChangeListener { public interface OnTextViewChangeListener {
/** /**
* Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens * {@link KeyEvent#KEYCODE_DEL}
* and the text is null *
* @param index
* @param text
*/ */
void onEditTextDelete(int index, String text); void onEditTextDelete(int index, String text);
/** /**
* Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER} * {@link KeyEvent#KEYCODE_ENTER}
* happen *
* @param index
* @param text
*/ */
void onEditTextEnter(int index, String text); void onEditTextEnter(int index, String text);
/** /**
* Hide or show item option when text change *
*
* @param index
* @param hasText
*/ */
void onTextChange(int index, boolean hasText); void onTextChange(int index, boolean hasText);
} }
private OnTextViewChangeListener mOnTextViewChangeListener; private OnTextViewChangeListener mOnTextViewChangeListener; // 文本视图变化的监听器
public NoteEditText(Context context) { public NoteEditText(Context context) {
super(context, null); super(context, null);
mIndex = 0; mIndex = 0; // 初始化当前索引为0
} }
public void setIndex(int index) { public void setIndex(int index) {
mIndex = index; mIndex = index; // 设置当前索引
} }
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) { public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
mOnTextViewChangeListener = listener; mOnTextViewChangeListener = listener; // 设置文本视图变化的监听器
} }
public NoteEditText(Context context, AttributeSet attrs) { public NoteEditText(Context context, AttributeSet attrs) {
super(context, attrs, android.R.attr.editTextStyle); super(context, attrs, android.R.attr.editTextStyle); // 调用父类构造方法
} }
public NoteEditText(Context context, AttributeSet attrs, int defStyle) { public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle); // 调用父类构造方法
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }

Loading…
Cancel
Save