summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorGravatar Charles Lombardo2023-05-01 16:52:00 -0400
committerGravatar bunnei2023-06-03 00:05:58 -0700
commit86e395595a4acdd496cdc8b72824820bd981548e (patch)
tree621faaf1b1b2ae94c1e8850318507c19359c26a9 /src/android
parentandroid: About fragment (diff)
downloadyuzu-86e395595a4acdd496cdc8b72824820bd981548e.tar.gz
yuzu-86e395595a4acdd496cdc8b72824820bd981548e.tar.xz
yuzu-86e395595a4acdd496cdc8b72824820bd981548e.zip
android: Use navigation bar shade view
Diffstat (limited to 'src/android')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt59
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt22
-rw-r--r--src/android/app/src/main/res/layout-w600dp/activity_main.xml11
-rw-r--r--src/android/app/src/main/res/layout/activity_main.xml11
4 files changed, 54 insertions, 49 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
index 5fafc2d2d..8edf01fea 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
@@ -65,13 +65,29 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
65 65
66 window.statusBarColor = 66 window.statusBarColor =
67 ContextCompat.getColor(applicationContext, android.R.color.transparent) 67 ContextCompat.getColor(applicationContext, android.R.color.transparent)
68 ThemeHelper.setNavigationBarColor( 68 window.navigationBarColor =
69 this, 69 ContextCompat.getColor(applicationContext, android.R.color.transparent)
70 ElevationOverlayProvider(binding.navigationView.context).compositeOverlay( 70
71 MaterialColors.getColor(binding.navigationView, R.attr.colorSurface), 71 binding.statusBarShade.setBackgroundColor(
72 binding.navigationView.elevation 72 ThemeHelper.getColorWithOpacity(
73 MaterialColors.getColor(
74 binding.root,
75 R.attr.colorSurface
76 ),
77 ThemeHelper.SYSTEM_BAR_ALPHA
73 ) 78 )
74 ) 79 )
80 if (InsetsHelper.getSystemGestureType(applicationContext) != InsetsHelper.GESTURE_NAVIGATION) {
81 binding.navigationBarShade.setBackgroundColor(
82 ThemeHelper.getColorWithOpacity(
83 MaterialColors.getColor(
84 binding.root,
85 R.attr.colorSurface
86 ),
87 ThemeHelper.SYSTEM_BAR_ALPHA
88 )
89 )
90 }
75 91
76 val navHostFragment = 92 val navHostFragment =
77 supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment 93 supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment
@@ -83,16 +99,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
83 } 99 }
84 } 100 }
85 101
86 binding.statusBarShade.setBackgroundColor(
87 ThemeHelper.getColorWithOpacity(
88 MaterialColors.getColor(
89 binding.root,
90 R.attr.colorSurface
91 ),
92 ThemeHelper.SYSTEM_BAR_ALPHA
93 )
94 )
95
96 // Prevents navigation from being drawn for a short time on recreation if set to hidden 102 // Prevents navigation from being drawn for a short time on recreation if set to hidden
97 if (!homeViewModel.navigationVisible.value?.first!!) { 103 if (!homeViewModel.navigationVisible.value?.first!!) {
98 binding.navigationView.visibility = View.INVISIBLE 104 binding.navigationView.visibility = View.INVISIBLE
@@ -116,14 +122,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
116 navController.navigate(R.id.action_firstTimeSetupFragment_to_gamesFragment) 122 navController.navigate(R.id.action_firstTimeSetupFragment_to_gamesFragment)
117 (binding.navigationView as NavigationBarView).setupWithNavController(navController) 123 (binding.navigationView as NavigationBarView).setupWithNavController(navController)
118 showNavigation(visible = true, animated = true) 124 showNavigation(visible = true, animated = true)
119
120 ThemeHelper.setNavigationBarColor(
121 this,
122 ElevationOverlayProvider(binding.navigationView.context).compositeOverlay(
123 MaterialColors.getColor(binding.navigationView, R.attr.colorSurface),
124 binding.navigationView.elevation
125 )
126 )
127 } 125 }
128 126
129 private fun setUpNavigation(navController: NavController) { 127 private fun setUpNavigation(navController: NavController) {
@@ -210,11 +208,18 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
210 } 208 }
211 209
212 private fun setInsets() = 210 private fun setInsets() =
213 ViewCompat.setOnApplyWindowInsetsListener(binding.statusBarShade) { view: View, windowInsets: WindowInsetsCompat -> 211 ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _: View, windowInsets: WindowInsetsCompat ->
214 val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) 212 val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
215 val mlpShade = view.layoutParams as MarginLayoutParams 213 val mlpStatusShade = binding.statusBarShade.layoutParams as MarginLayoutParams
216 mlpShade.height = insets.top 214 mlpStatusShade.height = insets.top
217 binding.statusBarShade.layoutParams = mlpShade 215 binding.statusBarShade.layoutParams = mlpStatusShade
216
217 // The only situation where we care to have a nav bar shade is when it's at the bottom
218 // of the screen where scrolling list elements can go behind it.
219 val mlpNavShade = binding.navigationBarShade.layoutParams as MarginLayoutParams
220 mlpNavShade.height = insets.bottom
221 binding.navigationBarShade.layoutParams = mlpNavShade
222
218 windowInsets 223 windowInsets
219 } 224 }
220 225
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt
index 1295b4257..1a9495ea7 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt
@@ -44,28 +44,6 @@ object ThemeHelper {
44 } 44 }
45 } 45 }
46 46
47 @JvmStatic
48 fun setNavigationBarColor(activity: Activity, @ColorInt color: Int) {
49 val gestureType = InsetsHelper.getSystemGestureType(activity.applicationContext)
50 val orientation = activity.resources.configuration.orientation
51
52 if ((gestureType == InsetsHelper.THREE_BUTTON_NAVIGATION ||
53 gestureType == InsetsHelper.TWO_BUTTON_NAVIGATION) &&
54 orientation == Configuration.ORIENTATION_LANDSCAPE
55 ) {
56 activity.window.navigationBarColor = color
57 } else if (gestureType == InsetsHelper.THREE_BUTTON_NAVIGATION ||
58 gestureType == InsetsHelper.TWO_BUTTON_NAVIGATION
59 ) {
60 activity.window.navigationBarColor = getColorWithOpacity(color, SYSTEM_BAR_ALPHA)
61 } else {
62 activity.window.navigationBarColor = ContextCompat.getColor(
63 activity.applicationContext,
64 android.R.color.transparent
65 )
66 }
67 }
68
69 @ColorInt 47 @ColorInt
70 fun getColorWithOpacity(@ColorInt color: Int, alphaFactor: Float): Int { 48 fun getColorWithOpacity(@ColorInt color: Int, alphaFactor: Float): Int {
71 return Color.argb( 49 return Color.argb(
diff --git a/src/android/app/src/main/res/layout-w600dp/activity_main.xml b/src/android/app/src/main/res/layout-w600dp/activity_main.xml
index 39b61a13e..8a4f46bef 100644
--- a/src/android/app/src/main/res/layout-w600dp/activity_main.xml
+++ b/src/android/app/src/main/res/layout-w600dp/activity_main.xml
@@ -43,4 +43,15 @@
43 app:layout_constraintEnd_toEndOf="parent" 43 app:layout_constraintEnd_toEndOf="parent"
44 app:layout_constraintStart_toStartOf="parent" /> 44 app:layout_constraintStart_toStartOf="parent" />
45 45
46 <View
47 android:id="@+id/navigation_bar_shade"
48 android:layout_width="0dp"
49 android:layout_height="1px"
50 android:background="@android:color/transparent"
51 android:clickable="false"
52 android:focusable="false"
53 app:layout_constraintBottom_toBottomOf="parent"
54 app:layout_constraintEnd_toEndOf="parent"
55 app:layout_constraintStart_toStartOf="parent" />
56
46</androidx.constraintlayout.widget.ConstraintLayout> 57</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/src/android/app/src/main/res/layout/activity_main.xml b/src/android/app/src/main/res/layout/activity_main.xml
index 214acb041..7db1a409e 100644
--- a/src/android/app/src/main/res/layout/activity_main.xml
+++ b/src/android/app/src/main/res/layout/activity_main.xml
@@ -43,4 +43,15 @@
43 app:layout_constraintEnd_toEndOf="parent" 43 app:layout_constraintEnd_toEndOf="parent"
44 app:layout_constraintStart_toStartOf="parent" /> 44 app:layout_constraintStart_toStartOf="parent" />
45 45
46 <View
47 android:id="@+id/navigation_bar_shade"
48 android:layout_width="0dp"
49 android:layout_height="1px"
50 android:background="@android:color/transparent"
51 android:clickable="false"
52 android:focusable="false"
53 app:layout_constraintBottom_toBottomOf="parent"
54 app:layout_constraintEnd_toEndOf="parent"
55 app:layout_constraintStart_toStartOf="parent" />
56
46</androidx.constraintlayout.widget.ConstraintLayout> 57</androidx.constraintlayout.widget.ConstraintLayout>