Skip to content

Commit

Permalink
Support right click to copy text as well
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Oct 4, 2024
1 parent fdbb573 commit eaa5a8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Version 2024.4
* 🔧 Calendar: add discoverable more options button on items, does the same thing as touch and hold.
* 🔧 Display more options of list items on touch and hold and right click (for example in Samsung
Dex) as well.
* 🔧 Where touch and hold copies text, support right click to copy as well.

### 2024.4.3 🧪
*2024-09-13*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,20 @@ private val onLongClickListener = View.OnLongClickListener {
return@OnLongClickListener it is TextView && copyTextToClipboard(it.context, it.text)
}

private val onContextClickListener = View.OnContextClickListener {
return@OnContextClickListener it is TextView && copyTextToClipboard(it.context, it.text)
}

/**
* Sets a long click listener and on Android 6 or newer a context click listener that enables
* right clicks with a mouse.
*/
fun TextView.copyTextToClipboardOnLongClick() {
// globally shared click listener instance
// globally shared click listener instances
setOnLongClickListener(onLongClickListener)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
setOnContextClickListener(onContextClickListener)
}
}

fun View.copyTextToClipboardOnLongClick(text: CharSequence) {
Expand Down

0 comments on commit eaa5a8d

Please sign in to comment.