Status bar can now be hidden or shown as desired

This commit is contained in:
ottoptj 2024-08-06 04:15:59 +03:00
commit c145eec220
3 changed files with 38 additions and 6 deletions

View file

@ -98,6 +98,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private lateinit var leftSwipeActivity: Pair<LauncherActivityInfo?, Int?> private lateinit var leftSwipeActivity: Pair<LauncherActivityInfo?, Int?>
private lateinit var rightSwipeActivity: Pair<LauncherActivityInfo?, Int?> private lateinit var rightSwipeActivity: Pair<LauncherActivityInfo?, Int?>
private var windowInsetsController: WindowInsetsController? = null
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -113,13 +115,18 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
Color.parseColor(preferences.getString("bgColor", "#00000000")) Color.parseColor(preferences.getString("bgColor", "#00000000"))
) )
val windowInsetsController = window.insetsController windowInsetsController = window.insetsController
windowInsetsController?.let { windowInsetsController?.let {
it.hide(WindowInsets.Type.statusBars()) // Hide system bars if (preferences.getBoolean("barVisibility", false)) {
it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE // Set behavior it.show(WindowInsets.Type.statusBars())
}
else {
it.hide(WindowInsets.Type.statusBars())
it.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} }
searchView = findViewById(R.id.searchView) searchView = findViewById(R.id.searchView)
@ -274,6 +281,19 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
"rightSwipeApp" -> { "rightSwipeApp" -> {
rightSwipeActivity = getSwipeInfo("right") rightSwipeActivity = getSwipeInfo("right")
} }
"barVisibility" -> {
windowInsetsController?.let {
if (preferences?.getBoolean("barVisibility", false) == true) {
it.show(WindowInsets.Type.statusBars())
}
else {
it.hide(WindowInsets.Type.statusBars())
it.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
}
} }
} }

View file

@ -90,7 +90,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="32dp" android:layout_marginHorizontal="32dp"
android:layout_marginTop="40dp" android:layout_marginTop="45dp"
android:layout_marginBottom="27dp" android:layout_marginBottom="27dp"
android:fontFamily="@null" android:fontFamily="@null"
android:format12Hour="hh:mm a" android:format12Hour="hh:mm a"

View file

@ -115,6 +115,18 @@
app:title="Search Size" app:title="Search Size"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:allowDividerAbove="false"
app:title="System bars">
<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="false"
android:title="Show Status Bar"
app:key="barVisibility" />
</PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"