Get soft keyboard height in fullscreen mode - android

I have a fullscreen activity in which I have some editing area. For Android 4.3 and before, I set fullscreen mode with
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
In the editing view, I use the method described here to get notified when the soft keyboard visibility changes and also to get its height. Everything works fine.
From 4.4, in order to profit immersive mode, the normal mode is set (when status bar is visible) with:
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
But apparently, the method mentioned above to get soft keyboard height is no longer working with getWindowVisibleFrame() returns always the same rectangle whether the keyboard is visible or not.
Here my question: is there any other way to get soft keyboard state and its height on 4.4 that works with SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN?
Thanks in advance.

Related

Android soft input behavior for KEYBOARD_12KEY, KEYBOARD_QWERTY, and KEYBOARD_NOKEYS

I was wondering if anybody here knows in what scenarios will Android show the user an on-screen soft keyboard, and how Android takes into account the different types of hardware keyboards available (KEYBOARD_12KEY, KEYBOARD_QWERTY, and KEYBOARD_NOKEYS).
https://developer.android.com/reference/android/content/res/Configuration#keyboard
Question (PART 1) - Could someone please fill out the following
Note that ??? = [show | hide | do nothing | other]
Scenario 1)
User clicks on a AppCompatEditText and has KEYBOARD_NOKEYS, Android will ??? soft input
Scenario 2)
User clicks on a AppCompatEditText and has KEYBOARD_12KEY, Android will ??? soft input
Scenario 3)
User clicks on a AppCompatEditText and has KEYBOARD_QWERTY, Android will ??? soft input
Question (PART 2) - Is it possible to disable this built-in behavior
Now that you have filled in all the blanks of ??? = [show | hide | do nothing | other], is it possible to disable these built-in Android behaviors? And instead replace them all with custom versions by manually detecting the hardware keyboard type on the device and showing/hiding the soft keyboard inside a View.OnFocusChangeListener?
Whether to display the soft keyboard is actually decided by the soft keyboard. The soft keyboard has a function InputMethodService.onEvaluateInputViewShown(). This function is called when there's a chance to show the soft keyboard. If it returns true, the keyboard will be shown. The default implementation is to look and see if a hardware keyboard exists, and to not display if so. But the soft keyboard can override that to display anyway.
All of this is totally up to the soft keyboard app- whichever keyboard they're using (so behavior can change based on which keyboard the user prefers). There's no way for anything else to override it.

Xamarin.Forms Android immersive mode with soft keyboard or Alert

I am trying to get my Xamarin.Forms application to use Android's immersive mode, since I am using a device with small screen, so soft keys and navigation bar is stealing my precious screen real estate.
Since the device I am using features hardware keyboard, I wanted to hide the soft keyboard. Currently I solved this by installing a "Null Input Method" keyboard. The keyboard is still there however, so every time focus is requested on Entry element, the keyboard is "shown". This causes application to exit immersive mode. The same is true when I show an Alert from my forms application.
Ideally I would want my application to stay in immersive mode all the time, at least when focus on Entry is requested (soft keyboard is not "shown" at all or immersive mode is not disabled when keyboard is "shown"). For Alerts I would like the application to reenter immersive mode when Alert is hidden. Currently I solved this by extending the Page class with custom DisplayAlert methos, which toggles immersive mode after DisplayAlert Task is completed.
I did some research and found the following articles:
Immersive mode while using keyboard
Appereantly user managed to solve the issue, so there could be a solution?
https://forums.xamarin.com/discussion/33034/prevent-entry-soft-keyboard-from-showing-on-android
But this solution does not work on Entry elements, and I would like to avoid writing custom renderers for elements.
Is there someone that faced a similiar issue before and managed to solve it?
It's not the best solution but defiantly the most simple for me.
Try this:
final Handler forceImmersive = new Handler();
Runnable runnable = new Runnable() {
#Override
public void run() {
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
forceImmersive.postDelayed(this, 1000);
}
};
forceImmersive.postDelayed(runnable, 1000);

Push up the layout when Keypad is enabled

I am using Collapsing ToolBar and Tab to make this layout. When the EditText cursor is enabled the entire activity has to be pushed up. Even here I used the same working code which is working good in an another app without Collapsing ToolBar. But here it is missed to work. Please help me.
This is the code that I used in another activity which is working good.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN |
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
From the WindowManager documentation:
SOFT_INPUT_ADJUST_PAN
Adjustment option for softInputMode: set to have a window pan when an input method is shown, so it doesn't need to deal with resizing but just panned by the framework to ensure the current input focus is visible.
Try setting the soft input mode to only WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE and see if that fixes your problem.

Android detect keyboard hide in landscape mode

Using the method shown in this thread - How to check visibility of software keyboard in Android?
I am able to detect keyboard hide when in portrait mode or in landscape mode where the keyboard is not in fullscreen. If keyboard in landscape mode is fullscreen then, the layout changes are not triggered and hence i cannot detect it in the OnGlobalLayoutListener !
Please help me with this? Is there no simple way to detect keyboard hide?
NOTE: I cannot afford to change anything in the manifest file. It should all be done through code dynamically!
Thanks!

Disable touchs and UI in VideoView in fullscreen kiosk mode?

I need to run VideoView in splash kiosk mode.
So I set it to fullscreen (all UI hidden, LOW_PROFILE etc). Mediacontroller not set and not exists. videoview set to not clickable in xml. VideoView OnTouch method overrided. Zorder set to -1. I tried all methods...
but!
Any touch of running VideoView shows me bottom navigation bar (back, home etc) on tablet.
System hides it automatically at 3 seconds. I can not override it :(
How to make VideoView in fullscreen - fully untouchable?
I found a solution, never seen it here.
this totally disables bottom UI on tablet (but leave upper bar on phone)
videoView.setSystemUiVisibility(View.GONE);
to hide status on phone just set in activity onCreate as usual:
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_fullscreen);
Have been fighting with this for a while, and it turns out nothing happens if you set the flags on the VideoView, but works when you do it on the mediaController:
mediaController.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
A remaining problem is that the video now doesn't seem to respond to touch at all, so the media controls are also gone.

Categories

Resources