refactor hide navigation bar

* move code to UIObject
* remove listener
* rename 'full screen' to 'hide status bar'
This commit is contained in:
Josia Pietsch 2025-03-13 16:28:01 +01:00
parent 941b06b258
commit d7dd1aa71a
Signed by: jrpie
GPG key ID: E70B571D66986A2D
7 changed files with 45 additions and 44 deletions

View file

@ -59,9 +59,9 @@ import eu.jonahbauer.android.preference.annotations.Preferences;
}), }),
@PreferenceGroup(name = "display", prefix = "settings_display_", suffix = "_key", value = { @PreferenceGroup(name = "display", prefix = "settings_display_", suffix = "_key", value = {
@Preference(name = "screen_timeout_disabled", type = boolean.class, defaultValue = "false"), @Preference(name = "screen_timeout_disabled", type = boolean.class, defaultValue = "false"),
@Preference(name = "full_screen", type = boolean.class, defaultValue = "true"), @Preference(name = "hide_status_bar", type = boolean.class, defaultValue = "true"),
@Preference(name = "rotate_screen", type = boolean.class, defaultValue = "true"),
@Preference(name = "hide_navigation_bar", type = boolean.class, defaultValue = "false"), @Preference(name = "hide_navigation_bar", type = boolean.class, defaultValue = "false"),
@Preference(name = "rotate_screen", type = boolean.class, defaultValue = "true"),
}), }),
@PreferenceGroup(name = "functionality", prefix = "settings_functionality_", suffix = "_key", value = { @PreferenceGroup(name = "functionality", prefix = "settings_functionality_", suffix = "_key", value = {
@Preference(name = "search_auto_launch", type = boolean.class, defaultValue = "true"), @Preference(name = "search_auto_launch", type = boolean.class, defaultValue = "true"),

View file

@ -110,33 +110,6 @@ class HomeActivity : UIObject, AppCompatActivity() {
} }
} }
@Suppress("DEPRECATION")
private fun hideNavigationBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.apply {
hide(WindowInsets.Type.navigationBars())
systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
val decorView = window.decorView
val uiOptions = (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
// Try to hide the navigation bar but do not hide the status bar
decorView.systemUiVisibility = uiOptions
// Add listener to hide the navigation bar
decorView.setOnSystemUiVisibilityChangeListener { visibility ->
if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
decorView.systemUiVisibility = uiOptions
}
}
}
}
private fun updateSettingsFallbackButtonVisibility() { private fun updateSettingsFallbackButtonVisibility() {
// If µLauncher settings can not be reached from any action bound to an enabled gesture, // If µLauncher settings can not be reached from any action bound to an enabled gesture,

View file

@ -3,7 +3,11 @@ package de.jrpie.android.launcher.ui
import android.app.Activity import android.app.Activity
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.content.res.Resources import android.content.res.Resources
import android.os.Build
import android.view.View
import android.view.Window import android.view.Window
import android.view.WindowInsets
import android.view.WindowInsetsController
import android.view.WindowManager import android.view.WindowManager
import de.jrpie.android.launcher.preferences.LauncherPreferences import de.jrpie.android.launcher.preferences.LauncherPreferences
@ -14,7 +18,7 @@ import de.jrpie.android.launcher.preferences.LauncherPreferences
fun setWindowFlags(window: Window, homeScreen: Boolean) { fun setWindowFlags(window: Window, homeScreen: Boolean) {
window.setFlags(0, 0) // clear flags window.setFlags(0, 0) // clear flags
// Display notification bar // Display notification bar
if (LauncherPreferences.display().fullScreen()) if (LauncherPreferences.display().hideStatusBar())
window.setFlags( window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN WindowManager.LayoutParams.FLAG_FULLSCREEN
@ -36,17 +40,19 @@ fun setWindowFlags(window: Window, homeScreen: Boolean) {
} }
interface UIObject { interface UIObject {
fun onCreate() { fun onCreate() {
if (this is Activity) { if (this !is Activity) {
setWindowFlags(window, isHomeScreen()) return
}
if (!LauncherPreferences.display().rotateScreen()) { setWindowFlags(window, isHomeScreen())
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR
}
if (!LauncherPreferences.display().rotateScreen()) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR
} }
} }
fun onStart() { fun onStart() {
setOnClicks() setOnClicks()
adjustLayout() adjustLayout()
@ -70,4 +76,26 @@ interface UIObject {
fun isHomeScreen(): Boolean { fun isHomeScreen(): Boolean {
return false return false
} }
@Suppress("DEPRECATION")
fun hideNavigationBar() {
if (this !is Activity) {
return
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.apply {
hide(WindowInsets.Type.navigationBars())
systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
// Try to hide the navigation bar but do not hide the status bar
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
}
}
} }

View file

@ -155,7 +155,7 @@ class ListActivity : AppCompatActivity(), UIObject {
binding.listContainer.context.resources.displayMetrics.heightPixels binding.listContainer.context.resources.displayMetrics.heightPixels
val diff = height - r.bottom val diff = height - r.bottom
if (diff != 0 && if (diff != 0 &&
LauncherPreferences.display().fullScreen() LauncherPreferences.display().hideStatusBar()
) { ) {
if (binding.listContainer.paddingBottom != diff) { if (binding.listContainer.paddingBottom != diff) {
binding.listContainer.setPadding(0, 0, 0, diff) binding.listContainer.setPadding(0, 0, 0, diff)

View file

@ -135,8 +135,8 @@
- -
--> -->
<string name="settings_display_screen_timeout_disabled_key" translatable="false">display.disable_timeout</string> <string name="settings_display_screen_timeout_disabled_key" translatable="false">display.disable_timeout</string>
<string name="settings_display_full_screen_key" translatable="false">display.use_full_screen</string>
<string name="settings_display_rotate_screen_key" translatable="false">display.rotate_screen</string> <string name="settings_display_rotate_screen_key" translatable="false">display.rotate_screen</string>
<string name="settings_display_hide_status_bar_key" translatable="false">display.use_full_screen</string>
<string name="settings_display_hide_navigation_bar_key" translatable="false">display.hide_navigation</string> <string name="settings_display_hide_navigation_bar_key" translatable="false">display.hide_navigation</string>
<string name="settings_enabled_gestures_double_swipe_key" translatable="false">enabled_gestures.double_actions</string> <string name="settings_enabled_gestures_double_swipe_key" translatable="false">enabled_gestures.double_actions</string>

View file

@ -153,9 +153,9 @@
<string name="settings_launcher_section_display">Display</string> <string name="settings_launcher_section_display">Display</string>
<string name="settings_display_screen_timeout_disabled">Keep screen on</string> <string name="settings_display_screen_timeout_disabled">Keep screen on</string>
<string name="settings_display_full_screen">Use full screen</string> <string name="settings_display_hide_status_bar">Hide status bar</string>
<string name="settings_display_rotate_screen">Rotate screen</string>
<string name="settings_display_hide_navigation_bar">Hide navigation bar</string> <string name="settings_display_hide_navigation_bar">Hide navigation bar</string>
<string name="settings_display_rotate_screen">Rotate screen</string>
<string name="settings_launcher_section_functionality">Functionality</string> <string name="settings_launcher_section_functionality">Functionality</string>

View file

@ -168,10 +168,6 @@
<PreferenceCategory <PreferenceCategory
android:title="@string/settings_launcher_section_display" android:title="@string/settings_launcher_section_display"
app:allowDividerAbove="false"> app:allowDividerAbove="false">
<SwitchPreference
android:key="@string/settings_display_full_screen_key"
android:defaultValue="true"
android:title="@string/settings_display_full_screen"/>
<SwitchPreference <SwitchPreference
android:key="@string/settings_display_rotate_screen_key" android:key="@string/settings_display_rotate_screen_key"
android:defaultValue="true" android:defaultValue="true"
@ -180,6 +176,10 @@
android:key="@string/settings_display_screen_timeout_disabled_key" android:key="@string/settings_display_screen_timeout_disabled_key"
android:defaultValue="false" android:defaultValue="false"
android:title="@string/settings_display_screen_timeout_disabled"/> android:title="@string/settings_display_screen_timeout_disabled"/>
<SwitchPreference
android:key="@string/settings_display_hide_status_bar_key"
android:defaultValue="true"
android:title="@string/settings_display_hide_status_bar"/>
<SwitchPreference <SwitchPreference
android:key="@string/settings_display_hide_navigation_bar_key" android:key="@string/settings_display_hide_navigation_bar_key"
android:defaultValue="false" android:defaultValue="false"