Wish Full-screen Immersive mode android 4.4

NeoTechni

Well-Known Member
Licensed User
Longtime User
The old style is too convenient. It keeps the button out of usable space. It was stupid of google to ever remove that button
 

appie21

Active Member
Licensed User
Longtime User
Yes Sorry you are right! If i touch the schreen the fun is over :(

Now i must update my screen (HP Slate21) to Android 4.4
 

walterf25

Expert
Licensed User
Longtime User
Yes Sorry you are right! If i touch the schreen the fun is over :(

Now i must update my screen (HP Slate21) to Android 4.4
What is the conclusion?
Is There a cleaner solution to this issue, i've tried the code Informatix provided here but it doesn't work properly i keep getting this error when the immersive mode is forced.
java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1

Has anyone come up with a better way to fix this issue?

Thanks,
Walter
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
At what point does it throw the error? I've started to use immersive mode without issues but I'm running my app in fixed landscape mode and so I don't need to set the listener which is the part I'm guessing is causing you the error?
 

walterf25

Expert
Licensed User
Longtime User
At what point does it throw the error? I've started to use immersive mode without issues but I'm running my app in fixed landscape mode and so I don't need to set the listener which is the part I'm guessing is causing you the error?
Hi RandomCoder, the error actually comes up as soon as i slide down from the top to make the soft menu appear, and yes i'm too using the fixed landscape mode.
Have you been able to resize your layout to fit the screen, if so can you share how have you done this?
there's always a gap left where the soft menu is when using the immersive mode.
Has anyone else had any luck with this?
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Hi @walterf25 please find attached a sample project demonstrating how I set and use ImmersiveMode. It's pieced together from posts I've found here on the forum, I'm not sure if the way I save the calling Activity is correct? Basically I wanted to store the code to set ImmersiveMode in a separate Code Module then as I choose to add new Activities I can just call the function and if I ever make changes there's only one place I need to make those changes. I like to try and keep things neat and reduce duplicate code as much as possible :)

The reason for loading my layout and setting ImmersiveMode in Activity_Resume instead of Activity_Create is because when using the back button to move to an Activity that has already been loaded, the Activity_Create sub is not triggered and so you end up with the NavigationBar showing again. Using Activity_Resume prevents this from happening.

You also don't need to use all the constant declarations in my "Set_ImmersiveMode" subroutine. I've only done this for clarity in case I need to add more flags in the future. These values can all be combined into one value as normally used elsewhere here on the forum.

Since creating this sample I've noticed that the NavigationBar does momentarily shows when first loading the Activity. I've not noticed this in my own App because I typically only use one Activity with tabbed views on it after the initial Splash and login screen. Therefore I don't see this effect as I'm not changing Activities. Hopefully it's minor enough not to cause you a problem.

If you need further help I can try but this is about the extent of my knowledge on the subject :(
 

Attachments

  • ImmersiveSample1.zip
    12.6 KB · Views: 460

RandomCoder

Well-Known Member
Licensed User
Longtime User
To reduce the impact of the black NavigationBar briefly showing when changing Activities you can change the Manifest file to use this theme instead...
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light.NoActionBar.TranslucentDecor")
There may be other better themes that can be used? I'm actually using an AppCompat Theme because I'm using a ToolBar in my project.
 

walterf25

Expert
Licensed User
Longtime User
Hi @walterf25 please find attached a sample project demonstrating how I set and use ImmersiveMode. It's pieced together from posts I've found here on the forum, I'm not sure if the way I save the calling Activity is correct? Basically I wanted to store the code to set ImmersiveMode in a separate Code Module then as I choose to add new Activities I can just call the function and if I ever make changes there's only one place I need to make those changes. I like to try and keep things neat and reduce duplicate code as much as possible :)

The reason for loading my layout and setting ImmersiveMode in Activity_Resume instead of Activity_Create is because when using the back button to move to an Activity that has already been loaded, the Activity_Create sub is not triggered and so you end up with the NavigationBar showing again. Using Activity_Resume prevents this from happening.

You also don't need to use all the constant declarations in my "Set_ImmersiveMode" subroutine. I've only done this for clarity in case I need to add more flags in the future. These values can all be combined into one value as normally used elsewhere here on the forum.

Since creating this sample I've noticed that the NavigationBar does momentarily shows when first loading the Activity. I've not noticed this in my own App because I typically only use one Activity with tabbed views on it after the initial Splash and login screen. Therefore I don't see this effect as I'm not changing Activities. Hopefully it's minor enough not to cause you a problem.

If you need further help I can try but this is about the extent of my knowledge on the subject :(
Hi RandomCoder, thanks so much for the code, i haven't had time to try it out yet, I will as soon as i get some free time, again, thank you!

Walter
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I'm trying it again and I get errors like:

main_forceimmersivemode (java line: 4488)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
at anywheresoftware.b4a.agraham.reflection.Reflection.GetActivity(Reflection.java:661)
at com.omnicorp.lcarui.test.main._forceimmersivemode(main.java:4488)
at com.omnicorp.lcarui.test.main._activity_windowfocuschanged(main.java:1630)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at com.omnicorp.lcarui.test.main.onWindowFocusChanged(main.java:183)
at com.android.internal.policy.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:3237)
at android.view.View.dispatchWindowFocusChanged(View.java:9534)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1200)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3378)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
mainonWindowFocusChanged (java line: 183)
java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:206)
at com.omnicorp.lcarui.test.main.onWindowFocusChanged(main.java:183)
at com.android.internal.policy.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:3237)
at android.view.View.dispatchWindowFocusChanged(View.java:9534)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1200)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3378)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
at anywheresoftware.b4a.agraham.reflection.Reflection.GetActivity(Reflection.java:661)
at com.omnicorp.lcarui.test.main._forceimmersivemode(main.java:4488)
at com.omnicorp.lcarui.test.main._activity_windowfocuschanged(main.java:1630)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
... 11 more
--------- beginning of crash
** Activity (main) Resume **
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
and
main_forceimmersivemode (java line: 4480)
java.lang.NullPointerException: Attempt to read from field 'com.omnicorp.lcarui.test.api com.omnicorp.lcarui.test.main._api' on a null object reference
at com.omnicorp.lcarui.test.main._forceimmersivemode(main.java:4480)
at com.omnicorp.lcarui.test.main._activity_windowfocuschanged(main.java:1626)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at com.omnicorp.lcarui.test.main.onWindowFocusChanged(main.java:183)
at com.android.internal.policy.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:3237)
at android.view.View.dispatchWindowFocusChanged(View.java:9534)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1200)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3378)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
java.lang.NullPointerException: Attempt to read from field 'com.omnicorp.lcarui.test.api com.omnicorp.lcarui.test.main._api' on a null object reference
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
How do we turn immersive mode off if someone disables it in my app's setting?
 
Top