Created
October 9, 2019 23:10
-
-
Save robsenshuu/a772b55035ef79e1f6713ac18c0c92ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CutCopyPasteEditText @JvmOverloads constructor( | |
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 | |
) : EditText(context, attrs, defStyleAttr) { | |
interface OnCutCopyPasteListener { | |
fun onCut() | |
fun onCopy() | |
fun onPaste() | |
} | |
private var cutCopyPasteListener: OnCutCopyPasteListener? = null | |
fun setOnCutCopyPasteListener(listener: OnCutCopyPasteListener) { | |
cutCopyPasteListener = listener | |
} | |
override fun onTextContextMenuItem(id: Int): Boolean { | |
val consumed = super.onTextContextMenuItem(id) | |
when(id) { | |
android.R.id.cut -> { | |
cutCopyPasteListener?.onCut() | |
} | |
android.R.id.copy -> { | |
cutCopyPasteListener?.onCopy() | |
} | |
android.R.id.paste -> { | |
cutCopyPasteListener?.onPaste() | |
} | |
} | |
return consumed | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment