From 1f62c34a131decd2b3fc55e9b496eb6f47c59aa4 Mon Sep 17 00:00:00 2001 From: torrentcome Date: Tue, 16 May 2017 10:10:37 +0200 Subject: [PATCH] (edit text typed) add onPast listener on the view --- .../tusky/view/EditTextTyped.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/src/main/java/com/keylesspalace/tusky/view/EditTextTyped.java b/app/src/main/java/com/keylesspalace/tusky/view/EditTextTyped.java index 2c8f85219..4693ee35c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/view/EditTextTyped.java +++ b/app/src/main/java/com/keylesspalace/tusky/view/EditTextTyped.java @@ -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(); + } }