From 8b9e973834673bd3319711f2d9838608d7e034af Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Sat, 18 Jan 2025 15:50:46 +0100 Subject: [PATCH] hotfix(fullscreen handling): Fix animations not refreshing --- .../main/java/net/kdt/pojavlaunch/Tools.java | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index a599bb3ef7..0167492123 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -654,37 +654,27 @@ public static DisplayMetrics getDisplayMetrics(Activity activity) { } public static void setFullscreen(Activity activity, boolean fullscreen) { - WindowInsetsControllerCompat windowInsetsController = - WindowCompat.getInsetsController(activity.getWindow(), activity.getWindow().getDecorView()); - if (windowInsetsController == null) { - Log.w(APP_NAME, "WindowInsetsController is null, cannot set fullscreen"); - return; - } - - // Configure the behavior of the hidden system bars. - windowInsetsController.setSystemBarsBehavior( - WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE - ); - - ViewCompat.setOnApplyWindowInsetsListener( - activity.getWindow().getDecorView(), - (view, windowInsets) -> { - boolean fullscreenImpl = fullscreen; - if (SDK_INT >= Build.VERSION_CODES.N && activity.isInMultiWindowMode()) - fullscreenImpl = false; - - if (fullscreenImpl) { - windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()); - } else { - windowInsetsController.show(WindowInsetsCompat.Type.systemBars()); - } - - if(SDK_INT >= Build.VERSION_CODES.R) - activity.getWindow().setDecorFitsSystemWindows(!fullscreenImpl); - - return ViewCompat.onApplyWindowInsets(view, windowInsets); - }); + final View decorView = activity.getWindow().getDecorView(); + View.OnSystemUiVisibilityChangeListener visibilityChangeListener = visibility -> { + boolean multiWindowMode = SDK_INT >= 24 && activity.isInMultiWindowMode(); + // When in multi-window mode, asking for fullscreen makes no sense (cause the launcher runs in a window) + // So, ignore the fullscreen setting when activity is in multi window mode + if(fullscreen && !multiWindowMode){ + if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } + }else{ + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); + } + }; + decorView.setOnSystemUiVisibilityChangeListener(visibilityChangeListener); + visibilityChangeListener.onSystemUiVisibilityChange(decorView.getSystemUiVisibility()); //call it once since the UI state may not change after the call, so the activity wont become fullscreen } public static DisplayMetrics currentDisplayMetrics;