(edit text typed) add onPast listener on the view

This commit is contained in:
torrentcome 2017-05-16 10:10:37 +02:00
parent 864bad819a
commit 1f62c34a13
1 changed files with 28 additions and 0 deletions

View File

@ -26,8 +26,10 @@ import android.view.inputmethod.InputConnection;
import com.keylesspalace.tusky.util.Assert;
public class EditTextTyped extends AppCompatEditText {
InputConnectionCompat.OnCommitContentListener onCommitContentListener;
String[] mimeTypes;
private OnPasteListener mOnPasteListener;
public EditTextTyped(Context context) {
super(context);
@ -37,6 +39,10 @@ public class EditTextTyped extends AppCompatEditText {
super(context, attributeSet);
}
public void addOnPasteListener(OnPasteListener mOnPasteListener) {
this.mOnPasteListener = mOnPasteListener;
}
public void setMimeTypes(String[] types,
InputConnectionCompat.OnCommitContentListener listener) {
mimeTypes = types;
@ -55,4 +61,26 @@ public class EditTextTyped extends AppCompatEditText {
return connection;
}
}
@Override
public boolean onTextContextMenuItem(int id) {
boolean consumed = super.onTextContextMenuItem(id);
switch (id) {
case android.R.id.paste:
onPaste();
}
return consumed;
}
/**
* Text was pasted into the EditText.
*/
public void onPaste() {
if (mOnPasteListener != null)
mOnPasteListener.onPaste();
}
public interface OnPasteListener {
void onPaste();
}
}