Android InputMethodService Inconsistent State in Fullscreen Mode - android

I am developing a soft keyboard. I have a class MyIME that extends InputMethodService.
I override onKey(int, int) to handle keypresses. My keyboard is able to insert and delete text the way I defined it just fine in portrait modes, I am just running into a problem in landscape when the keyboard is set to full screen.
In full screen mode, the framework's default ExtractEditLayout is used which contains an ExtractEditText instance. As I type in full screen mode, the following weird behavior happens:
I can type normal characters just fine. I insert these using getCurrentInputConnection().commitText(String.valueOf(code), 1);
When I press backspace to delete a character, the cursor moves back and the preceding character is removed. This behaves fine. Subsequent key strokes from this point on are no longer functioning as they are supposed to:
If I press backspace after the first one, the cursor moves backwards however the character does not get deleted. When backspace is pressed, getCurrentInputConnection().deleteSurroundingText(1, 0); is executed.
Similarly, if I add more characters after pressing backspace once, the cursor will move forward but the characters will not appear on the screen.
When I exit full screen mode by rotating my device back into portrait orientation, all of the characters that I typed or deleted are there. It appears as if the ExtractEditLayout used for composing fullscreen messages becomes out of sync with my InputMethodService subclass and it appears that they only become out of sync after I initially attempt to delete a character.

The bug was related to an expensive ExtractedTextRequest I was making each time I pressed backspace. The request was being used to determine if the text field was empty so I could determine whether or not to set the keyboard into a shifted state.
I got rid of the ExtractedTextRequest and now determine if the textfield is empty by a two (largish) calls to InputConnection's getTextBeforeCursor() and getTextAfterCursor() and the undesired behavior I described in the question component of this post no longer occurs.

Related

.NET MAUI Entry keyboard does not hide

I have a very simple UI that has one entry control to enter phone number and a button. The entry control has a handler for removing border around it. When the entry control got focus, keyboard pops up. But when I try to tap outside the entry control such as on the screen empty area, the keyboard does not dismiss and the entry control does not lose focus. Also since the button is at the bottom of the screen, therefore, the soft keyboard hides it and there is no way to tap the button. The button can only be tapped if I press the Android device back button.
At present, I have not checked this behavior on an iOS device.
This was not a problem in Xamarin Forms though. I searched a lot on Internet and found that it is currently a bug in MAUI.
I tried to attach a tap gesture on the parent layout control and invoked platform-specific code to hide the keyboard but it seems the entry does not lose focus and in turn the tap gesture event is never called.
However, the entry control should lose focus automatically when I tap outside the entry control (such as on the screen) and the soft keyboard should automatically dismiss.
Please provide a workaround if there is any.
Known bug. Removing the focus sometimes helps. Sometimes you need to do Disable/Enable in sequence. (I go with the second).
If you want, you can read this for example:
https://github.com/dotnet/maui/issues/12002
(Most disturbing part, considering this is know bug for half year+)
We can leave the behavior how this is for now in NET7 and provide an
API in NET8 that lets users toggle this behavior on/off for iOS and
Android

Hiding android soft keyboard interrupts value assigning

I made a small app that should visualize a priority queue by using a heap structure(Kotlin, Android Studio API23).
It has an array that displays numbers, a grid view where elements are shown or hidden, an edittext as input field, an enqueue, dequeue and help button.
Everything works find, BUT:
If I want to enqueue a number I have to click on the edittext field, this automatically opens the soft keyboard. I can confirm by clicking on soft keyboard's enter or on UI's enqueue button, confirming automatically closes the keyboard- everything fine.
But if I select the edittext, enter a number and close the keyboard manually with it's button and then want to confirm with the enqueue button in UI, the tree and array are not showing the new number instead showing the previous entered number. Then clicking on edittext the keyboard shows again and without entering anything the numbers are getting updated. This only happens to numbers where an action have to take place.
(To be mentioned: tree works with max-heap, numbers getting enqueued on last place if parents are smaller children are swapped so always the largest number is on top as root
I want to know how I can fix that if I made an input, then close the keyboard manually and confirm with enqueue button, the numbers immediately are getting updated.
Thanks, see the picture for further understanding by link.

How to disable longtouch, copy and past and cursor when the screen is rotated on Android?

I tried everything that I could to remove the copy and past, long touch and the blue selectors.
I followed the all suggestion on this thread:
EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event
However, it only works when my phone screen is in portraid mode.. if I rotate the screen in landscape mode then I still see the text selections, long press, etc.. I wanna rid of these blue cursors and copy and past functionality.
I notice in landscape, the onTouch methods are not called.. seems to be an independent object and does not respect the layout and class definitions.
Any idea is very welcome.

PhoneGap + Android page doesn't refresh after soft keyboard closes

Most of the time (but not always), when I finish typing in a or and the soft keyboard hides, the view area is left raised with a black space on the bottom. Clicking, tilting or otherwise engaging the phone corrects the screen. However, user's first motion is usually pressing , but if you click submit it jumps down and you actually just click on the text area again. How do you stop this and get the screen to reset after the keyboard closes.
Take a look at you AndroidManifest.xml
http://developer.android.com/guide/topics/manifest/activity-element.html
I think you need to change android:configChanges.
I have the exact same problem what i did was handle hidekeyboard even in javascript and do something like window.scrollTo(0,0) or $("input[type=text],textarea").blur();
This will cause the the screen to get back to normal position
But there is just one problem when click from input field of type = text to a input field password it internally hide the keyboard which causes the hidekeyboard event to fire and scrolls the screen to top. This is the only side effect of this
Let me know if you find the solution for this

EditText.getLocationOnScreen() returns same result for 2 different positions

I have a dialog with an EditText, and when the user clicks on it, the soft keyboard appears and pushes the dialog up (so as not to hide it). When the keyboard is dismissed, the EditText resumes its original position. This is standard behavior. The EditText has clearly moved, but calling getLocationOnScreen(), getBottom(), etc return the same result for both positions. Am I missing something here or is this a bug in Android?
By the way, the reason why I ask is because this behavior is causing some of our Robotium tests to fail, because Robotium relies on getLocationOnScreen() to calculate where to click.

Categories

Resources