-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Add Clipboard Paste Functionality #11
base: master
Are you sure you want to change the base?
Feature: Add Clipboard Paste Functionality #11
Conversation
@@ -90,6 +93,15 @@ class SmsConfirmationView @JvmOverloads constructor( | |||
else SmsConfirmationViewStyleUtils.getFromAttributes(attrs, context) | |||
updateState() | |||
|
|||
// Conditionally allow pasting with long-press to the component | |||
if (allowCodePaste) { | |||
this.rootView.setOnLongClickListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can simplify this a little bit to something lile
rootView.setOnLongClickListener {
initPasteMenu().show()
true
}
?
// Used to inflate and return the popup paste menu | ||
private fun initPasteMenu() : PopupMenu { | ||
val clipboard = getSystemService(context, ClipboardManager::class.java) | ||
val pasteMenu = PopupMenu(this.context, this).apply { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny: we can probably omit this
like you did in the previous line
val item = clipboard?.primaryClip?.getItemAt(0) | ||
|
||
// Get the clipboard item text. | ||
val pasteData = item?.text?.toString() ?: "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can let appendPaste
to work with CharSequence
and avoid toString
conversion? I think appendPaste
can handle this type without any additional changes
|
||
// If the clipboard doesn't contain data, disable the paste menu item. | ||
// If it does contain data, decide whether you can handle the data. | ||
pasteItem.isEnabled = when { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idea: how about not showing the popup menu at all if there is nothing we can do from there? I think the default OS popup menu just doesn't show "Paste" if the Clibpobar is empty, we can probably follow this here as well
@@ -202,7 +279,8 @@ class SmsConfirmationView @JvmOverloads constructor( | |||
|
|||
@SuppressLint("ClickableViewAccessibility") | |||
override fun onTouchEvent(event: MotionEvent): Boolean { | |||
if (event.action == MotionEvent.ACTION_DOWN && requestFocus()) { | |||
if (event.action == MotionEvent.ACTION_DOWN && !this.isFocused) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this change breaks the keyboard: open demo app -> dismiss keyboard -> try opening it again by clicking on the view-> woops...
val pasteData = item?.text?.toString() ?: "" | ||
|
||
// Paste the text into the component | ||
appendPaste(pasteData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add some filtering for the pasted content: it is now possible to paste text and not just digits. I guess we can just extend appendSymbol
a little bit to skip non-digit symbols
private fun handleKeyEvent(keyCode: Int, event: KeyEvent): Boolean = when { | ||
event.action == KeyEvent.ACTION_MULTIPLE && event.keyCode == KeyEvent.KEYCODE_UNKNOWN && allowCodePaste -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haven't checked it by myself yet, but wondering if we can somehow use any of those functions instead:
Hey @BAbbottKlover, thanks for your work, the view is indeed missing this functionality and it would be really nice to support it. I've left some comments for you, please take a look and let me know what you think. |
* TODO: Look into `View::onReceiveContent`
Hi @fraggjkee! Thanks for the quick response, sorry I'm late to getting back to this, I just came back from a vacation. Working now to resolve these issues |
Drafting PR until I can figure out how to properly handle auto-fill payloads |
Hey @BAbbottKlover I've added basic support for the copy-pasting functionality in 1.8.0 release. It is still missing handling for the hints panel that is rendered above the soft keyboard though, it's just a pop-up menu that is now shown in response to long click events. But I see that it is supported in your PR, hopefully, this part of your work can be reused for future releases. |
Why?
Functionality for pasting codes was not available, so I added it as well as an
attr
to enable/disable, enabled by default. Also added the ability to long-click and paste from the clipboard via menu item.Known Issues
Deprecation warning for KeyEvent.ACTION_MULTIPLE and its event.characters, there doesn't seem to be a great explanation let alone an alternative. See here.
Videos
device-2023-05-18-151130.mp4
device-2023-05-18-151336.mp4
device-2023-05-18-163626.webm