Skip to content

Commit db56cb0

Browse files
Feature: Added Navigation hiding.
1 parent 9ac1c29 commit db56cb0

File tree

10 files changed

+100
-17
lines changed

10 files changed

+100
-17
lines changed

app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,34 @@ class AppHelper @Inject constructor() {
213213
}
214214
}
215215

216+
fun showNavigationBar(window: Window) {
217+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
218+
// For Android 11 (API 30) and above, use WindowInsetsController to show the navigation bar
219+
window.insetsController?.show(WindowInsets.Type.navigationBars())
220+
} else {
221+
@Suppress("DEPRECATION", "InlinedApi")
222+
// For older versions, show the navigation bar using systemUiVisibility
223+
window.decorView.apply {
224+
systemUiVisibility =
225+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
226+
}
227+
}
228+
}
229+
230+
fun hideNavigationBar(window: Window) {
231+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
232+
// For Android 11 (API 30) and above, use WindowInsetsController to hide the navigation bar
233+
window.insetsController?.hide(WindowInsets.Type.navigationBars())
234+
} else {
235+
@Suppress("DEPRECATION")
236+
// For older versions, hide the navigation bar using systemUiVisibility
237+
window.decorView.apply {
238+
systemUiVisibility =
239+
View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN
240+
}
241+
}
242+
}
243+
216244
fun wordOfTheDay(resources: Resources): String {
217245
val dailyWordsArray =
218246
resources.getStringArray(R.array.settings_appearance_daily_word_default)

app/src/main/java/com/github/droidworksstudio/launcher/helper/PreferenceHelper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
2727
get() = prefs.getBoolean(Constants.SHOW_STATUS_BAR, true)
2828
set(value) = prefs.edit().putBoolean(Constants.SHOW_STATUS_BAR, value).apply()
2929

30+
var showNavigationBar: Boolean
31+
get() = prefs.getBoolean(Constants.SHOW_NAVIGATION_BAR, true)
32+
set(value) = prefs.edit().putBoolean(Constants.SHOW_NAVIGATION_BAR, value).apply()
33+
3034
var showTime: Boolean
3135
get() = prefs.getBoolean(Constants.SHOW_TIME, true)
3236
set(value) = prefs.edit().putBoolean(Constants.SHOW_TIME, value).apply()

app/src/main/java/com/github/droidworksstudio/launcher/ui/activities/MainActivity.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class MainActivity : AppCompatActivity() {
9696
setupNavController()
9797
setupOrientation()
9898
setupLocationManager()
99-
setLanguage()
10099
}
101100

102101
@Suppress("DEPRECATION")
@@ -110,6 +109,7 @@ class MainActivity : AppCompatActivity() {
110109
private fun initializeDependencies() {
111110
setLocationPermissionDenied(false)
112111
preferenceViewModel.setShowStatusBar(preferenceHelper.showStatusBar)
112+
preferenceViewModel.setShowNavigationBar(preferenceHelper.showNavigationBar)
113113
preferenceViewModel.setFirstLaunch(preferenceHelper.firstLaunch)
114114

115115
window.addFlags(FLAG_LAYOUT_NO_LIMITS)
@@ -214,6 +214,12 @@ class MainActivity : AppCompatActivity() {
214214
if (it) appHelper.showStatusBar(this.window)
215215
else appHelper.hideStatusBar(this.window)
216216
}
217+
218+
preferenceViewModel.setShowNavigationBar(preferenceHelper.showNavigationBar)
219+
preferenceViewModel.showNavigationBarLiveData.observe(this) {
220+
if (it) appHelper.showNavigationBar(this.window)
221+
else appHelper.hideNavigationBar(this.window)
222+
}
217223
}
218224

219225
private fun setupNavController() {
@@ -288,9 +294,11 @@ class MainActivity : AppCompatActivity() {
288294
when (navController.currentDestination?.id) {
289295
R.id.SettingsFeaturesFragment,
290296
R.id.SettingsLookFeelFragment,
297+
R.id.SettingsWidgetFragment,
291298
R.id.SettingsAdvancedFragment,
292299
R.id.FavoriteFragment,
293-
R.id.HiddenFragment -> {
300+
R.id.HiddenFragment,
301+
-> {
294302
val actionTypeNavOptions: NavOptions? =
295303
if (preferenceHelper.disableAnimations) null
296304
else appHelper.getActionType(Constants.Swipe.Up)
@@ -338,7 +346,7 @@ class MainActivity : AppCompatActivity() {
338346
override fun onRequestPermissionsResult(
339347
requestCode: Int,
340348
permissions: Array<out String>,
341-
grantResults: IntArray
349+
grantResults: IntArray,
342350
) {
343351
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
344352
when (requestCode) {

app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeFragment.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ class HomeFragment : Fragment(),
537537
}
538538

539539
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
540-
val actionTypeNavOptions: NavOptions =
541-
appHelper.getActionType(Constants.Swipe.DoubleTap)
540+
val actionTypeNavOptions: NavOptions? =
541+
if (preferenceHelper.disableAnimations) null
542+
else appHelper.getActionType(Constants.Swipe.DoubleTap)
542543
findNavController().navigate(
543544
R.id.SettingsFragment,
544545
null,
@@ -554,8 +555,9 @@ class HomeFragment : Fragment(),
554555
if (preferenceHelper.settingsLock) {
555556
fingerHelper.startBiometricSettingsAuth(R.id.SettingsFragment)
556557
} else {
557-
val actionTypeNavOptions: NavOptions =
558-
appHelper.getActionType(Constants.Swipe.DoubleTap)
558+
val actionTypeNavOptions: NavOptions? =
559+
if (preferenceHelper.disableAnimations) null
560+
else appHelper.getActionType(Constants.Swipe.DoubleTap)
559561
findNavController().navigate(
560562
R.id.SettingsFragment,
561563
null,

app/src/main/java/com/github/droidworksstudio/launcher/ui/settings/SettingsLookFeelFragment.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ class SettingsLookFeelFragment : Fragment(),
8989
private fun initializeInjectedDependencies() {
9090
// Set initial values and listeners for switches
9191
binding.apply {
92-
statueBarSwitchCompat.isChecked = preferenceHelper.showStatusBar
92+
statusBarSwitchCompat.isChecked = preferenceHelper.showStatusBar
93+
navBarSwitchCompat.isChecked = preferenceHelper.showNavigationBar
9394
timeSwitchCompat.isChecked = preferenceHelper.showTime
9495
dateSwitchCompat.isChecked = preferenceHelper.showDate
9596
batterySwitchCompat.isChecked = preferenceHelper.showBattery
@@ -142,12 +143,18 @@ class SettingsLookFeelFragment : Fragment(),
142143
@RequiresApi(Build.VERSION_CODES.Q)
143144
private fun setupSwitchListeners() {
144145
binding.apply {
145-
statueBarSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
146+
statusBarSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
146147
preferenceViewModel.setShowStatusBar(isChecked)
147148
val feedbackType = if (isChecked) "on" else "off"
148149
appHelper.triggerHapticFeedback(context, feedbackType)
149150
}
150151

152+
navBarSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
153+
preferenceViewModel.setShowNavigationBar(isChecked)
154+
val feedbackType = if (isChecked) "on" else "off"
155+
appHelper.triggerHapticFeedback(context, feedbackType)
156+
}
157+
151158
dateSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
152159
preferenceViewModel.setShowDate(isChecked)
153160
val feedbackType = if (isChecked) "on" else "off"

app/src/main/java/com/github/droidworksstudio/launcher/utils/Constants.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ object Constants {
3232
const val SHOW_ALARM_CLOCK = "SHOW_ALARM_CLOCK"
3333
const val SHOW_BATTERY = "SHOW_BATTERY"
3434
const val SHOW_STATUS_BAR = "SHOW_STATUS_BAR"
35+
const val SHOW_NAVIGATION_BAR = "SHOW_NAVIGATION_BAR"
36+
3537

3638
const val SHOW_WEATHER_WIDGET = "SHOW_WEATHER_WIDGET"
3739
const val SHOW_WEATHER_WIDGET_SUN_SET_RISE = "SHOW_WEATHER_WIDGET_SUN_SET_RISE"

app/src/main/java/com/github/droidworksstudio/launcher/viewmodel/PreferenceViewModel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class PreferenceViewModel @Inject constructor(
1414

1515
private val firstLaunchLiveData: MutableLiveData<Boolean> = MutableLiveData()
1616
val showStatusBarLiveData: MutableLiveData<Boolean> = MutableLiveData()
17+
val showNavigationBarLiveData: MutableLiveData<Boolean> = MutableLiveData()
1718
val showTimeLiveData: MutableLiveData<Boolean> = MutableLiveData()
1819
val showDateLiveData: MutableLiveData<Boolean> = MutableLiveData()
1920
val showDailyWordLiveData: MutableLiveData<Boolean> = MutableLiveData()
@@ -76,6 +77,11 @@ class PreferenceViewModel @Inject constructor(
7677
showStatusBarLiveData.postValue(preferenceHelper.showStatusBar)
7778
}
7879

80+
fun setShowNavigationBar(showNavigationBar: Boolean) {
81+
preferenceHelper.showNavigationBar = showNavigationBar
82+
showNavigationBarLiveData.postValue(preferenceHelper.showNavigationBar)
83+
}
84+
7985
fun setShowTime(showTime: Boolean) {
8086
preferenceHelper.showTime = showTime
8187
showTimeLiveData.postValue(preferenceHelper.showTime)

app/src/main/res/layout/fragment_settings_look_feel.xml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
tools:ignore="MissingConstraints">
6161

6262
<androidx.appcompat.widget.AppCompatTextView
63-
android:id="@+id/statue_bar_text"
63+
android:id="@+id/status_bar_text"
6464
style="@style/TextDefaultStyle"
6565
android:layout_width="0dp"
6666
android:layout_height="wrap_content"
@@ -73,7 +73,38 @@
7373
tools:ignore="RtlHardcoded" />
7474

7575
<androidx.appcompat.widget.SwitchCompat
76-
android:id="@+id/statue_bar_switchCompat"
76+
android:id="@+id/status_bar_switchCompat"
77+
android:layout_width="wrap_content"
78+
android:layout_height="wrap_content"
79+
android:scaleX="0.7"
80+
android:scaleY="0.8"
81+
android:thumb="@drawable/shape_switch_thumb"
82+
app:track="@drawable/selector_switch"
83+
tools:ignore="DuplicateSpeakableTextCheck,TouchTargetSizeCheck" />
84+
85+
</androidx.appcompat.widget.LinearLayoutCompat>
86+
87+
<androidx.appcompat.widget.LinearLayoutCompat
88+
android:layout_width="match_parent"
89+
android:layout_height="wrap_content"
90+
android:orientation="horizontal"
91+
tools:ignore="MissingConstraints">
92+
93+
<androidx.appcompat.widget.AppCompatTextView
94+
android:id="@+id/nav_bar_text"
95+
style="@style/TextDefaultStyle"
96+
android:layout_width="0dp"
97+
android:layout_height="wrap_content"
98+
android:layout_weight="1"
99+
android:gravity="left|center"
100+
android:text="@string/settings_display_nav_bar"
101+
android:textSize="@dimen/text_large"
102+
app:layout_constraintStart_toStartOf="parent"
103+
app:layout_constraintTop_toTopOf="parent"
104+
tools:ignore="RtlHardcoded" />
105+
106+
<androidx.appcompat.widget.SwitchCompat
107+
android:id="@+id/nav_bar_switchCompat"
77108
android:layout_width="wrap_content"
78109
android:layout_height="wrap_content"
79110
android:scaleX="0.7"

app/src/main/res/layout/fragment_widgets.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
android:orientation="vertical"
99
tools:context=".ui.widgets.WidgetFragment">
1010

11-
<FrameLayout
12-
android:id="@+id/touchArea"
13-
android:layout_width="match_parent"
14-
android:layout_height="match_parent"
15-
android:layout_marginVertical="20dp" />
16-
1711
<androidx.core.widget.NestedScrollView
1812
android:id="@+id/nestedScrollView"
1913
android:layout_width="match_parent"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<string name="settings_title_others">Others</string>
9696

9797
<string name="settings_display_status_bar">Show Status Bar</string>
98+
<string name="settings_display_nav_bar">Show Navigation Bar</string>
9899
<string name="settings_display_date">Show Date</string>
99100
<string name="settings_display_time">Show Time</string>
100101
<string name="settings_display_battery">Show Battery</string>

0 commit comments

Comments
 (0)