|
|
|
@ -189,7 +189,7 @@ public class NoteEditText extends EditText {
|
|
|
|
|
mOnTextViewChangeListener.onTextChange(mIndex, false);
|
|
|
|
|
} else {
|
|
|
|
|
mOnTextViewChangeListener.onTextChange(mIndex, true);
|
|
|
|
|
}
|
|
|
|
|
}9
|
|
|
|
|
}
|
|
|
|
|
super.onFocusChanged(focused, direction, previouslyFocusedRect);
|
|
|
|
|
}
|
|
|
|
@ -197,37 +197,43 @@ public class NoteEditText extends EditText {
|
|
|
|
|
//上下文菜单创建时的处理,可以在编辑框中添加特定行为的菜单项,例如打电话、打开网页或发送邮箱
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreateContextMenu(ContextMenu menu) {
|
|
|
|
|
//检查文本内容是否为Spanned类型
|
|
|
|
|
if (getText() instanceof Spanned) {
|
|
|
|
|
int selStart = getSelectionStart();
|
|
|
|
|
int selEnd = getSelectionEnd();
|
|
|
|
|
int selStart = getSelectionStart();//获取选择文本起始位置
|
|
|
|
|
int selEnd = getSelectionEnd();// 结束位置
|
|
|
|
|
|
|
|
|
|
int min = Math.min(selStart, selEnd);
|
|
|
|
|
int max = Math.max(selStart, selEnd);
|
|
|
|
|
|
|
|
|
|
//从选择文本中获取URLSpan对象数组
|
|
|
|
|
final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class);
|
|
|
|
|
//如果只有一个URLSpan存在
|
|
|
|
|
if (urls.length == 1) {
|
|
|
|
|
int defaultResId = 0;
|
|
|
|
|
//遍历所有已定义的模式(schema)
|
|
|
|
|
for(String schema: sSchemaActionResMap.keySet()) {
|
|
|
|
|
//如果URLSpan的URL中包含该模式
|
|
|
|
|
if(urls[0].getURL().indexOf(schema) >= 0) {
|
|
|
|
|
//获取该模式对应的资源ID
|
|
|
|
|
defaultResId = sSchemaActionResMap.get(schema);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果没有找到匹配的模式对应的资源ID,则使用R.string.note_link_other作为默认资源ID
|
|
|
|
|
if (defaultResId == 0) {
|
|
|
|
|
defaultResId = R.string.note_link_other;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//像上下文菜单中添加菜单项,并设置点击事件
|
|
|
|
|
menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
|
|
|
|
|
new OnMenuItemClickListener() {
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
// goto a new intent
|
|
|
|
|
// goto a new intent 执行URLSpan中定义的点击操作
|
|
|
|
|
urls[0].onClick(NoteEditText.this);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
super.onCreateContextMenu(menu);
|
|
|
|
|
super.onCreateContextMenu(menu); //调用父类的方法创建上下文菜单
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|