Skip to content
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

[Android AOSP Keyboard] Backspace key is not working #1941

Closed
nekrondev opened this issue Feb 11, 2021 · 7 comments
Closed

[Android AOSP Keyboard] Backspace key is not working #1941

nekrondev opened this issue Feb 11, 2021 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed question A question has been asked

Comments

@nekrondev
Copy link

nekrondev commented Feb 11, 2021

Describe the bug:

  • Entry widget on Android 8, 9 AOSP is not processing invisible keys events like backspace or enter / return send by Android on-screen keyboard.
  • It is impossible to submit (OnSubmit event is not fired)

To Reproduce:

Steps to reproduce the behaviour:

  • Bug could be reproduced on two different Android devices (ASOP 8.1, 9)
  • Compile the below given source code using NDK version R21E on Win10 host.
  • Build Android package like so:
fyne package -os android -appID de.company.support -name POC -icon icon.png

Screenshots:

none

Example code:

main.go:

package main

import (
	"os"

	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.NewWithID("de.company.support")
	window := a.NewWindow("Support App")
	a.Settings().SetTheme(theme.DarkTheme())
	window.SetOnClosed(func() {
		os.Exit(1)
	})
	title := widget.NewLabel("Entry Android Bug")
	/* The Entry widget on Android 8, 9 ASOP is not working with the on-screen keyboard.
	However visible keys are printed inside the widget but invisible keys like backspace or return fail.
	You can enter text but editing or submitting is not possible due to this bug.
	*/
	tbCode := widget.NewEntry()
	tbCode.SetPlaceHolder("Enter text here ...")
	tbCode.OnSubmitted = func(text string) {
		title.SetText("Enter key is working")
	}
	// set V-layout
	window.SetContent(container.NewVBox(
		title,
		tbCode,
	))
	window.ShowAndRun()
}

go.mod:

module poc

go 1.15

require (
	fyne.io/fyne/v2 v2.0.0
)

Device (please complete the following information):

  • OS: Android
  • Version: 8, 9 both AOSP
  • Go version: 1.15
  • Fyne version: 2.0
@nekrondev nekrondev added the bug Something isn't working label Feb 11, 2021
@Jacalz
Copy link
Member

Jacalz commented Feb 11, 2021

Thanks for the bug report. I have a few things that I would like to see improved with the bug report to make it easier to understand the issue.

  • The description currently describes the application, not the bug that you found. Could you please explain and describe the bug instead?
  • The reproduction steps explain how to compile the program. Can you please change it specifically explain how to reproduce the bug?
  • The code example is very long and seems to contain code unrelated to the issue. Can you please put together a clear and concise code example used for replicating the issue?

Once these issues are resolved, we can see to hopefully get this fixed 🙂

@nekrondev
Copy link
Author

Hi @Jacalz,

thanks for the pointers!
I reviewed my bug report and hopefully things become clearer now :).

Cheers and keep up the "fyne" work!
Nek

@andydotxyz
Copy link
Member

andydotxyz commented Feb 13, 2021

Can you please share information about the Android devices and they keyboard that is loaded?
I am not able to replicate on my Galaxy S10 or HTC Desire X

@andydotxyz andydotxyz added the question A question has been asked label Feb 13, 2021
@nekrondev
Copy link
Author

Hello Andy,

I think the issue is receiving the KEY_BACKSPACE event when using an Android AOSP keyboard which is the default on e.g. Lineage OS or other AOSP ROM flavours.

Our customer is using a custom build ROM based on Android AOSP 9 on their devices which I am unfortunately unable to share.
However two additional public devices can be used to reproduce the issue.

Device 1: Sailfish OS on Sony Xperia XA2, 10 I (the Android emulation layer is based on AOSP 8.1 or newer)

  • SailfishOS will show it's stock keyboard but backspace key events will not be send to Entry widget like using a stock AOSP keyboard

Device 2: Sony Xperia 10 Mark II (or any Android 8, 9 or 10 based device so S10 and Desire X should work, too)

On the latter device which is stock Sony ROM I observe two behaviours:

  1. using the pre-installed Google keyboard (Gboard) backspace works fine. The return key is switched to accept key and not enter key layout (indeed this should be the case if using a single line Entry so maybe enter key works ok after all)
  2. if I install an AOSP-based keyboard like e.g. https://github.com/Hardslog/platform_packages_inputmethods_EnhancedIME/releases/download/1.0.4/EnhancedIME_1.0.4.apk and set it as default backspace for the Entry widget will not work

HTH to analyse the issue any further.

@nekrondev nekrondev changed the title [Android] Backspace and Return keys not working [Android AOSP Keyboard] Backspace key is not working Feb 15, 2021
@nekrondev
Copy link
Author

nekrondev commented Feb 16, 2021

Small update on the issue.

I analysed Fyne Android bindings and the culprit seems to be here GoNativeActivity.java.
As a POC I added the keyboardDelete() Fyne runtime call when a backspace event was detected via onTextChanged.

               mTextEdit.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        String logline = String.format("s.len() = %d, old.len() = %d, start = %d, before = %d, count = %d, s = '%s'", s.length(), oldState.length(), start, before, count, s.toString());
                        Log.e("Fyne", logline);
                        if (s.length() > oldState.length()) {
                            keyboardTyped(s.subSequence(oldState.length(), s.length()).toString());
                        } else if (s.length() < oldState.length()) {
                                // backspace key seems to be sent even for soft content (nope, it doesn't do on default AOSP keyboard)
                                Log.e("Fyne", "keyboardDelete() called");
                                keyboardDelete();
                            }
                            oldState = s.toString();
                    }

Basically if you enter a single continous text without whitespace the backspace button works as expected. However if you enter whitespace Android AOSP keyboard is doing weird things calling the onTextChanged() method. This results in duplicated text fragments and text that can't be edited.

The second issue I found was moving the cursor in the Entry widget via touchscreen causes an "doShowKeyboard()" call that resets the Android EditText but previously entered text is still visible in the Fyne Entry widget, i.e. Fyne runtime still displays the previously entered text but Android runtime uses a new empty string. The effect is that you can paste fresh characters into the Entry widget but you can't edit the Fyne managed text as keyboardDelete() calls will not submitted to Fyne runtime because of empty Android EditText strings.

@andydotxyz
Copy link
Member

Thanks this is really helpful.
If I understand correctly both could be addressed if we set the hidden entry content to the Fyne entry content each time it is reset?

@andydotxyz andydotxyz added the help wanted Extra attention is needed label Apr 16, 2021
@andydotxyz
Copy link
Member

On develop for testing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed question A question has been asked
Projects
None yet
Development

No branches or pull requests

3 participants