Difference between InputMethodManager SHOW_FORCED and SHOW_IMPLICIT in Android - android

I would like to know the behavioral difference of the constants SHOW_FORCED andSHOW_IMPLICIT. I tried both and couldn't see any difference in the first look.

SHOW_FORCED and SHOW_IMPLICIT work in tandem with the hiding methods HIDE_IMPLICIT_ONLY and HIDE_NOT_ALWAYS.
Using SHOW_FORCED indicates that the user has explicitly requested that the keyboard be shown (such as by pressing an "open keyboard" button), and thus the system should force it to open. In this case, any existing request to hide the keyboard using the above flags will be ignored (thus the keyboard is "forced" open).
Using SHOW_IMPLICIT means that your app thinks the user wants the keyboard open, but hasn't explicitly requested it. In this case, requests to hide the keyboard with HIDE_IMPLICIT_ONLY or HIDE_NOT_ALWAYS will still be respected.

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

How to get the Window of InputMethod on Android

In order to collect user's keystroke features on our App, I have to collect the touchevent(or just the click timestamp) on the input method view(soft keyboard).
1)As far as I know, the window of the soft keyboard is distinct from the window of the Activity
2)As long as I could get the window of a view, I can intercept the touch event of this window.
So is there a way to get the window of the soft keyboard?
As far as I know, the keyboard window belongs to system UI, like status bar or notification window; a common app has no access to such system windows in Android framework.
However you may try something tricky to to see if it would achieve your purpose: When the soft keyboard is launched, you can calculate its height and then create a new transparent window, like PopupWindow, with the same height covering the keyboard. This way you may be able to intercept the touch events on the keyboard without blocking them.
=== Updated 21/12/2018 ===
Please note that all windows in Android are actually implemented the similar way in ui framework. i.e. Your app's application window, InputMethod, Status Bar, Notification Bar... are all windows each with a flag to indicate the window type (read here). In short, window type will decide the window z-index when being rendered on the screen. They are categorised as Application Window, Sub-Window and System Window.
With that being said, PopupWindow is just one of them, a handy helper window provided by Android system (with a smaller z-index against the InputMethod window's). Just try to create your own window using WindowManager.addView() with some window type flag greater than the InputMethod window (which might be carrying a flag of TYPE_INPUT_METHOD).

Android custom keyboard popup

I have a custom android keyboard. On long press popup keyboard is shown how it should. The problem is, when it pops up, the keyboard behind is darkenes.
How can i disable this, except overriding the default KeyboardView onDraw?
One more thing: how can I make the poped up keyboard buttons selected without pressing on them? In Google keyboard, when you press on a "." key, you just keep moving your finger and it selects the key on the popup. But on the default implementation of KeyboardView, you have to press on the key.
This has been bugging me for a month, hope you can help!
Solution: don't use KeyboardView. Its meant for quick prototyping, when you need a basic keyboard and are working on other things like autocorrect algorithms. No serious keyboard actually uses it, and it isn't required (you can return any view from onCreateInputView). As you ramp up UI complexity, it just quickly becomes unable to deal

InputMethodManager showSoftInput method

What is the purpose of the method showSoftInput in class InputMethodManager? I am new to android, and well for me the documentation is not very clear :
Explicitly request that the current input method's soft input area be shown to the user, if needed. Call this if the user interacts with your view in such a way that they have expressed they would like to start performing input into it.
From what I have understood it opens the keyboard, am I am right? Why should we use this method, doesn't touching an EditText open automatically the keyboard??
No, touching an edit text doesn't automatically open a soft keyboard. That's just the default behavior. Under the hood, when you touch the edit text a series of events occurs. Eventually the Android framework will call showSoftInput on the IMS of the keyboard. This is the keyboard's chance to decide it doesn't want to show for some reason and return false if it is not shown. For example, I believe at Swype we overrode this not to show the keyboard if there was a hardware keyboard on the device already slid out, on the theory they then wanted to use the hardware keyboard.
Most of the time you're just going to either use the default implementation here, or do a few minor checks then fall back to the default implementation.

Android keyboard issue when switching layouts with "?123" button

In Android if we press ?123 key (or similar) on software keyboard it shows us digits/symbols layout. And it will automatically turns back to alphabetical layout when whitespace pressed or EditText cleared by app from code.
Is there any option to turn off this "auto reset" behavior? Maybe some flag for EditText, InputConnection, InputType, etc.
Note that numeric keyboard is not suitable. It must be common keyboard (InputType.TYPE_CLASS_TEXT) which just allows only manual switching between layouts.

Categories

Resources