Android immersive mode possible?

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
With regard to the previous post about mac fullscreen, I kind of got the opposite problem with Android?
How do I get rid of the softbuttons to get a true fullscreen?

Is there a way to get 50% transparency softbuttons or to shut them off completely?


,
Softbuttons.jpeg
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
That's awesome, thank you! Will try to integrate this into Cerberus.
 

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
70
You can use the code on https://developer.android.com/training/system-ui/immersive#EnableFullscreen

I used SYSTEM_UI_FLAG_IMMERSIVE_STICKY instead of SYSTEM_UI_FLAG_IMMERSIVE, else it doesn't auto hide after swiping.

Add it to /targets/android-original/modules/native/androidgame.java inside the AndroidGame class.

Code:
private void hideSystemUI() {
        if (Build.VERSION.SDK_INT >= 19) {
            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);
        }
    }

Call hideSystemUI from onWindowFocusChanged when hasFocus is true.
Code:
public void onWindowFocusChanged( boolean hasFocus ){
        if( hasFocus ){
            hideSystemUI();
            _view.onResume();
            _game.ResumeGame();
        }else{
            _game.SuspendGame();
            _view.onPause();
        }
    }

I tried making it a third party module, but it crashes and says the views can't be messed with from a different thread. I don't know how to make this into a config.cxs setting... Although it could be nice to be able to change it at run time as well.

Edit: On my testing device that has a display cutout it just shows a black bar there, so you don't need to worry about safe areas.
 
Last edited:

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
Wow thank you so much, is there a reason to not make this permanent? I guess it's possible to just comment hideSystemUI() whenever you want to go back to normal. Gonna try it right away.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
Hmm I got the same graphics, the only thing that changed was that the softbuttonarea is now black, isn't there a way to use the full screen?

It reacts to touch like the screen now but it seems that deviceheight() & devicewidth() reported the same resolution still as when there where buttons? Or maybe there is something else to consider to make use of the full screen area?
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
I wonder if android:fitsSystemWindows="true" is needed, could that be it?
 

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
70
My game project seems to report the correct size when using deviceheight()/devicewidth(), but not when I tested DisplayMode. I printed the output to the console and also the game is displaying correctly. Are you updating your game size on OnUpdate?

is there a reason to not make this permanent?

It may be nice to able change it while it's is running, because someone may want to change it at different sections of their game or app. I have a few games released that don't use immersive mode, but I haven't made any that change between both yet.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
I also get the correct native resolution of the device which is 1920.

Still there's clearly x pixels used for the softbuttons. Very strange..

I'm avoiding all kinds of graphic-commands inside OnUpdate, I communicate graphical information to other parts using variables that are read-and-written-to from inside OnRender. DisplayMode command is new to me so I can't say anything about what it says.
android:fitsSystemWindows="true" did not work btw. (https://michiganlabs.com/android/design/development/2018/03/20/a-more-immersive-android-navbar)

If you allow rotation of the device, you'll see that the black area will get smudged with graphics. It's an unmanaged area, which is kind of interesting.
 
Last edited:

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
70
Oh yes, OnRender and not OnUpdate. I hadn't thought of the distinction. What I had meant to ask was is your game adjusting it's size when the window size changes after it first starts? My project is calling SetProjection2d when ever DeviceWidth() or DeviceHeight() change.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
Sadly I do that already every frame whenever the width or height changes, so there's nothing that I can improve there.

Code:
canvas.SetViewport 0,0,awidth,aheight
canvas.SetScissor 0,0,awidth,aheight
canvas.SetProjection2d 0,awidth,0,aheight
 

grant

Member
CX Code Contributor
3rd Party Module Dev
Joined
Nov 19, 2019
Messages
70
Sadly I do that already every frame whenever the width or height changes, so there's nothing that I can improve there.

Code:
canvas.SetViewport 0,0,awidth,aheight
canvas.SetScissor 0,0,awidth,aheight
canvas.SetProjection2d 0,awidth,0,aheight
Did you ever figure this out? Are you recreating the canvas when the screen size changes? myCanvas = New Canvas(); is what I'm doing, but I'm not sure if there is a better way to resize the canvas.

I feel like this would be a really nice feature to put in Cerberus X.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
Sadly no It's not solved yet but I hope to solve it soon. I'm learning Android more as we speak!

To change the size of the canvas I think you only need to do SetDisplay together with those commands mentioned above.
The canvas has no actual size and can be any size. It behaves more like a pointer to something. I might be wrong though but this is the impression I have because I never needed to change the size of the canvas.
 
Top Bottom