From 86e395595a4acdd496cdc8b72824820bd981548e Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Mon, 1 May 2023 16:52:00 -0400 Subject: android: Use navigation bar shade view --- .../java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt | 59 ++++++++++++---------- .../java/org/yuzu/yuzu_emu/utils/ThemeHelper.kt | 22 -------- .../src/main/res/layout-w600dp/activity_main.xml | 11 ++++ .../app/src/main/res/layout/activity_main.xml | 11 ++++ 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 { window.statusBarColor = ContextCompat.getColor(applicationContext, android.R.color.transparent) - ThemeHelper.setNavigationBarColor( - this, - ElevationOverlayProvider(binding.navigationView.context).compositeOverlay( - MaterialColors.getColor(binding.navigationView, R.attr.colorSurface), - binding.navigationView.elevation + window.navigationBarColor = + ContextCompat.getColor(applicationContext, android.R.color.transparent) + + binding.statusBarShade.setBackgroundColor( + ThemeHelper.getColorWithOpacity( + MaterialColors.getColor( + binding.root, + R.attr.colorSurface + ), + ThemeHelper.SYSTEM_BAR_ALPHA ) ) + if (InsetsHelper.getSystemGestureType(applicationContext) != InsetsHelper.GESTURE_NAVIGATION) { + binding.navigationBarShade.setBackgroundColor( + ThemeHelper.getColorWithOpacity( + MaterialColors.getColor( + binding.root, + R.attr.colorSurface + ), + ThemeHelper.SYSTEM_BAR_ALPHA + ) + ) + } val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment @@ -83,16 +99,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider { } } - binding.statusBarShade.setBackgroundColor( - ThemeHelper.getColorWithOpacity( - MaterialColors.getColor( - binding.root, - R.attr.colorSurface - ), - ThemeHelper.SYSTEM_BAR_ALPHA - ) - ) - // Prevents navigation from being drawn for a short time on recreation if set to hidden if (!homeViewModel.navigationVisible.value?.first!!) { binding.navigationView.visibility = View.INVISIBLE @@ -116,14 +122,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider { navController.navigate(R.id.action_firstTimeSetupFragment_to_gamesFragment) (binding.navigationView as NavigationBarView).setupWithNavController(navController) showNavigation(visible = true, animated = true) - - ThemeHelper.setNavigationBarColor( - this, - ElevationOverlayProvider(binding.navigationView.context).compositeOverlay( - MaterialColors.getColor(binding.navigationView, R.attr.colorSurface), - binding.navigationView.elevation - ) - ) } private fun setUpNavigation(navController: NavController) { @@ -210,11 +208,18 @@ class MainActivity : AppCompatActivity(), ThemeProvider { } private fun setInsets() = - ViewCompat.setOnApplyWindowInsetsListener(binding.statusBarShade) { view: View, windowInsets: WindowInsetsCompat -> + ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _: View, windowInsets: WindowInsetsCompat -> val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) - val mlpShade = view.layoutParams as MarginLayoutParams - mlpShade.height = insets.top - binding.statusBarShade.layoutParams = mlpShade + val mlpStatusShade = binding.statusBarShade.layoutParams as MarginLayoutParams + mlpStatusShade.height = insets.top + binding.statusBarShade.layoutParams = mlpStatusShade + + // The only situation where we care to have a nav bar shade is when it's at the bottom + // of the screen where scrolling list elements can go behind it. + val mlpNavShade = binding.navigationBarShade.layoutParams as MarginLayoutParams + mlpNavShade.height = insets.bottom + binding.navigationBarShade.layoutParams = mlpNavShade + windowInsets } 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 { } } - @JvmStatic - fun setNavigationBarColor(activity: Activity, @ColorInt color: Int) { - val gestureType = InsetsHelper.getSystemGestureType(activity.applicationContext) - val orientation = activity.resources.configuration.orientation - - if ((gestureType == InsetsHelper.THREE_BUTTON_NAVIGATION || - gestureType == InsetsHelper.TWO_BUTTON_NAVIGATION) && - orientation == Configuration.ORIENTATION_LANDSCAPE - ) { - activity.window.navigationBarColor = color - } else if (gestureType == InsetsHelper.THREE_BUTTON_NAVIGATION || - gestureType == InsetsHelper.TWO_BUTTON_NAVIGATION - ) { - activity.window.navigationBarColor = getColorWithOpacity(color, SYSTEM_BAR_ALPHA) - } else { - activity.window.navigationBarColor = ContextCompat.getColor( - activity.applicationContext, - android.R.color.transparent - ) - } - } - @ColorInt fun getColorWithOpacity(@ColorInt color: Int, alphaFactor: Float): Int { 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 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> + + 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 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> + + -- cgit v1.2.3