|
|
|
@ -39,18 +39,18 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class NoteEditText extends EditText {
|
|
|
|
|
private static final String TAG = "NoteEditText";
|
|
|
|
|
private int mIndex;
|
|
|
|
|
private int mSelectionStartBeforeDelete;
|
|
|
|
|
private int mIndex; // 当前索引
|
|
|
|
|
private int mSelectionStartBeforeDelete; // 删除前的光标位置
|
|
|
|
|
|
|
|
|
|
private static final String SCHEME_TEL = "tel:" ;
|
|
|
|
|
private static final String SCHEME_HTTP = "http:" ;
|
|
|
|
|
private static final String SCHEME_EMAIL = "mailto:" ;
|
|
|
|
|
private static final String SCHEME_TEL = "tel:"; // 电话号码链接的Scheme
|
|
|
|
|
private static final String SCHEME_HTTP = "http:"; // 网页链接的Scheme
|
|
|
|
|
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 {
|
|
|
|
|
sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel);
|
|
|
|
|
sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web);
|
|
|
|
|
sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email);
|
|
|
|
|
sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel); // 将电话号码链接的Scheme和对应的操作资源ID放入映射中
|
|
|
|
|
sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web); // 将网页链接的Scheme和对应的操作资源ID放入映射中
|
|
|
|
|
sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email); // 将邮件链接的Scheme和对应的操作资源ID放入映射中
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -58,44 +58,51 @@ public class NoteEditText extends EditText {
|
|
|
|
|
*/
|
|
|
|
|
public interface OnTextViewChangeListener {
|
|
|
|
|
/**
|
|
|
|
|
* Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens
|
|
|
|
|
* and the text is null
|
|
|
|
|
* 当按下删除键{@link KeyEvent#KEYCODE_DEL}并且文本为空时,删除当前编辑文本
|
|
|
|
|
*
|
|
|
|
|
* @param index 当前编辑文本的索引
|
|
|
|
|
* @param text 当前编辑文本的内容
|
|
|
|
|
*/
|
|
|
|
|
void onEditTextDelete(int index, String text);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER}
|
|
|
|
|
* happen
|
|
|
|
|
* 当按下回车键{@link KeyEvent#KEYCODE_ENTER}时,在当前编辑文本后添加一个新的编辑文本
|
|
|
|
|
*
|
|
|
|
|
* @param index 当前编辑文本的索引
|
|
|
|
|
* @param 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private OnTextViewChangeListener mOnTextViewChangeListener;
|
|
|
|
|
private OnTextViewChangeListener mOnTextViewChangeListener; // 文本视图变化的监听器
|
|
|
|
|
|
|
|
|
|
public NoteEditText(Context context) {
|
|
|
|
|
super(context, null);
|
|
|
|
|
mIndex = 0;
|
|
|
|
|
mIndex = 0; // 初始化当前索引为0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setIndex(int index) {
|
|
|
|
|
mIndex = index;
|
|
|
|
|
mIndex = index; // 设置当前索引
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
|
|
|
|
|
mOnTextViewChangeListener = listener;
|
|
|
|
|
mOnTextViewChangeListener = listener; // 设置文本视图变化的监听器
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
super(context, attrs, defStyle); // 调用父类构造方法
|
|
|
|
|
// TODO Auto-generated constructor stub
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|