Update NoteEditText.java

main
p6zpjanrb 10 months ago
parent 859c84ee76
commit 093d309b8d

@ -36,18 +36,29 @@ import net.micode.notes.R;
import java.util.HashMap;
import java.util.Map;
/*NoteEditTextEditTextEditText
mIndexmSelectionStartBeforeDelete
Scheme
MapSchemeID便SchemeID
*/
public class NoteEditText extends EditText {
private static final String TAG = "NoteEditText";
private int mIndex;
private int mSelectionStartBeforeDelete;
// 定义了几种Scheme的常量值
private static final String SCHEME_TEL = "tel:" ;
private static final String SCHEME_HTTP = "http:" ;
private static final String SCHEME_EMAIL = "mailto:" ;
// 定义了一个Map用于存储Scheme和对应的资源ID的映射关系
private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>();
static {
// 将不同Scheme和对应的资源ID放入Map中
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);
@ -58,47 +69,57 @@ 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}
*/
void onEditTextDelete(int index, String text);
/**
* Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER}
* happen
* {@link KeyEvent#KEYCODE_ENTER}
*/
void onEditTextEnter(int index, String text);
/**
* Hide or show item option when text change
*
*/
void onTextChange(int index, boolean hasText);
}
/*NoteEditTextEditText
*/
private OnTextViewChangeListener mOnTextViewChangeListener;
/*
NoteEditTextContextEditText(Context context, AttributeSet attrs)mIndex0
*/
public NoteEditText(Context context) {
super(context, null);
mIndex = 0;
}
/*
mIndex
*/
public void setIndex(int index) {
mIndex = index;
}
/*
OnTextViewChangeListener
*/
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
mOnTextViewChangeListener = listener;
}
/*
NoteEditTextContextAttributeSetEditText(Context context, AttributeSet attrs, int defStyle)
*/
public NoteEditText(Context context, AttributeSet attrs) {
super(context, attrs, android.R.attr.editTextStyle);
}
public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
/*
onTouchEvent
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
@ -120,7 +141,9 @@ public class NoteEditText extends EditText {
return super.onTouchEvent(event);
}
/*
onKeyDown
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
@ -137,7 +160,9 @@ public class NoteEditText extends EditText {
}
return super.onKeyDown(keyCode, event);
}
/*
onKeyUp
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch(keyCode) {
@ -166,7 +191,9 @@ public class NoteEditText extends EditText {
}
return super.onKeyUp(keyCode, event);
}
/*
onFocusChanged
*/
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (mOnTextViewChangeListener != null) {
@ -178,7 +205,11 @@ public class NoteEditText extends EditText {
}
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
/*
onCreateContextMenuURL
OnTextViewChangeListener
*/
@Override
protected void onCreateContextMenu(ContextMenu menu) {
if (getText() instanceof Spanned) {

Loading…
Cancel
Save