HeliBoard icon indicating copy to clipboard operation
HeliBoard copied to clipboard

toast notifications

Open codokie opened this issue 1 year ago • 7 comments

This PR adds toast notifications.

In Android 12L and below, there is no need for notification permission (which Heliboard currently does not have), so the toasts will be displayed natively.

For newer Android versions, a "fake" toast will be shown instead. Here's how it would look (inspired by OneUI): Light theme: toast Dark theme: dark toast

It has a 300ms fade in/out animation to make the transition smoother. The view does not prevent pressing the keys it covers.

In Android versions older than 13, a toast notification will now be shown for 2 seconds when content is copied to the clipboard (can be triggered by pressing the copy/cut toolbar keys). In Android 13+, most devices already show some kind of notification whenever the clipboard is set, so there is no need to display another one.

However, it will be possible to use it for other purposes like indicating an image URI could not be pasted to an input field (#722), or that the clipboard history has been cleared (#679). If you have any other ideas please let me know.

Fixes #545

codokie avatar Apr 24 '24 22:04 codokie

Not sure whether it works, but having the fake toast in default device style is worth trying. Could you try making a Toast without showing it on Android 13+ and extract the background drawable and text color? According to https://stackoverflow.com/a/9432923 Toast.getView() should contain a TextView accessible via TextView v = (TextView) toast.getView().findViewById(android.R.id.message); Then you could get background and text color using v.getBackground() and v.getCurrentTextColor().

Helium314 avatar May 02 '24 16:05 Helium314

Shouldn't this notification be a little lower? 🤔 Most often I saw them just above the spacebar.

maruuk avatar May 05 '24 20:05 maruuk

It looks better than on the keyboard, but I think that for some people such a notification in the middle of the screen can be annoying. Maybe it's better to place it just above the keyboard?

maruuk avatar May 06 '24 09:05 maruuk

I find the position somewhat awkward comparing to normal toast messages, but showing some amount above the keyboard definitely is a good idea, as this is a. not covering the text field (assuming it's a single line), and b. not at a place that might be covered with fingers.

The inability to copy the system toast style is unfortunate. Though maybe we could derive toast colors from the keyboard colors...

Helium314 avatar May 06 '24 19:05 Helium314

@codokie do you plan to move the notification to the place above the input field, or do you consider this PR done?

Helium314 avatar May 27 '24 03:05 Helium314

I think it might work when you do it in input_view.xml. But this might also end up increasing size of the input view, which would be bad. If that doesn't work out, I'll have a look later.

Helium314 avatar May 27 '24 17:05 Helium314

You could try something like android:drawableLeft="@drawable/ic_launcher_round" in the TextView.

Helium314 avatar May 27 '24 18:05 Helium314

like in a real toast

This is highly dependent on the Android version though, device manufacturers may style the toast, and some custom roms also do this, or let the user tune the toast. I just want to say that sticking to specific style is not necessary, as it cannot fit with toast style of all devices.

Helium314 avatar May 27 '24 20:05 Helium314

Having the message centered may be a (minor) issue in some cases. E.g. in landscape mode it will be on the keyboard, or when height scale is very low it will be far above the keyboard. But handling the window insets is probably too much, at least in scope of this PR.

Helium314 avatar May 28 '24 18:05 Helium314

I don't really like the way how some parts of the toast are being handled though.

  1. When showToast is called, it should really show a toast; the fallback thing is out of place. When it should actually not show the toast_msg_clipboard_copy toast, then just don't call showToast (have that logic in copyText)
  2. I don't think showToast should be in LatinIME, KeyboardSwitcher already has a relevant part of that code. Then you could also call it using KeyboardSwitcher.getInstance().showToast

Helium314 avatar May 28 '24 19:05 Helium314