Immersive mode broken?


#1

Hi

Just upgrade my phone from 7.1 to 8.1 and seem to have lost immersive mode … bottom menu bar is permanently visible, I recall that immersive was set to be default behaviour for Android mode a year or so ago
… or maybe even longer than that… but does this need updating for the latest android versions?

Or… can some one provide a code snippet that would let me set immersive mode myself?

Many thanks

Mark

EDIT:

Just managed to get it working in Android Studio by pasting the code below into the Main Activity, but how can I get it to work in Processing? The errors I get are

1. ERROR in C:\Users\MArk\AppData\Local\Temp\android4180019193616482448sketch\app\src\main\java\com\softwarecreative\sessionsheddemo\SessionShed.java (at line 751)
	public void onWindowFocusChanged(boolean hasFocus) {
	            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The method onWindowFocusChanged(boolean) of type SessionShed must override or implement a supertype method
----------
2. ERROR in C:\Users\MArk\AppData\Local\Temp\android4180019193616482448sketch\app\src\main\java\com\softwarecreative\sessionsheddemo\SessionShed.java (at line 752)
	super.onWindowFocusChanged(hasFocus);
	      ^^^^^^^^^^^^^^^^^^^^
The method onWindowFocusChanged(boolean) is undefined for the type PApplet
----------
2 problems (2 errors)

 @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        hideSystemUI();
    }
}

private void hideSystemUI() {
    // 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
            // 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);
}

// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

#2

@shedMusic===
the error (with P5) is probably (i have to get a look at that to morrow) because you are in a fragment and not in an activity…


#3

@akenaton thanks for replying …

maybe … but it was already a fragment for me (has been for a long time)… changing OS from 7.1 to 8.1 made the difference? Immersive mode was default behaviour for Android Mode but now seems broken. No worries though as I tend to port my sketches to AS now for finishing, as I can generate my apks with existing keys etc, and it was easy to get the immersive mode working there.


#4

@shedMusic===
i was only speaking about the 2 error code, not about the immersive mode…


#5

@akenaton

OK I understand. Thanks


#6

@shedMusic===

try this code (some modifs for fragment); of course it could be useful (for testing) to add somme toggle button with a listener for calling the other method( show…)…

import android.view.View;
void setup(){
  size(800,1000);
}

void draw(){
  
}
 //@Override
public void onWindowFocusChanged(boolean hasFocus) {
   this.getActivity().onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        hideSystemUI();
    }
}

private void hideSystemUI() {
    // 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 = getActivity().getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE
            // 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);
}

// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

#7

@akenaton
Thanks … will give that a try :slight_smile:


#8

@akenaton
Yes that worked fine
Many thanks :slight_smile: