From 27d77690001df3aec1eb6dace1a1de5b57299a93 Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Wed, 4 Oct 2023 20:13:24 -0700 Subject: [PATCH] Fix task bar crash in gesture nav mode with task bar / nav bar unification on a11yButton is reserved for 3-button mode so it can be null. Also TaskbarNavLayoutter is used for large screen both in gesture nav and 3-button mode, so need to check isContextualButtonShowing to add contextual buttons Fixes: 300849078 Test: Make sure that it doesn't crash in large screen gesture nav mode Change-Id: I9d0694b7f4c95461f24efb2af1af905e68e3cd8d --- .../navbutton/AbstractNavButtonLayoutter.kt | 2 +- .../taskbar/navbutton/KidsNavLayoutter.kt | 6 ++- .../navbutton/NavButtonLayoutFactory.kt | 2 +- .../navbutton/PhoneGestureLayoutter.kt | 2 +- .../navbutton/PhoneLandscapeNavLayoutter.kt | 6 ++- .../navbutton/PhonePortraitNavLayoutter.kt | 6 ++- .../navbutton/PhoneSeascapeNavLayoutter.kt | 6 ++- .../taskbar/navbutton/SetupNavLayoutter.kt | 6 ++- .../taskbar/navbutton/TaskbarNavLayoutter.kt | 43 +++++++++++-------- 9 files changed, 48 insertions(+), 31 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/AbstractNavButtonLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/AbstractNavButtonLayoutter.kt index 9758d44679..75295089c7 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/AbstractNavButtonLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/AbstractNavButtonLayoutter.kt @@ -46,7 +46,7 @@ abstract class AbstractNavButtonLayoutter( protected val startContextualContainer: ViewGroup, protected val imeSwitcher: ImageView?, protected val rotationButton: RotationButton?, - protected val a11yButton: ImageView + protected val a11yButton: ImageView? ) : NavButtonLayoutter { protected val homeButton: ImageView? = navButtonContainer.findViewById(R.id.home) protected val recentsButton: ImageView? = navButtonContainer.findViewById(R.id.recent_apps) diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt index f254ee8d4f..e7847f3448 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/KidsNavLayoutter.kt @@ -35,7 +35,7 @@ class KidsNavLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView + a11yButton: ImageView? ) : AbstractNavButtonLayoutter( resources, @@ -114,7 +114,9 @@ class KidsNavLayoutter( startContextualContainer.addView(imeSwitcher) imeSwitcher.layoutParams = getParamsToCenterView() } - endContextualContainer.addView(a11yButton) + if (a11yButton != null) { + endContextualContainer.addView(a11yButton) + } if (rotationButton != null) { endContextualContainer.addView(rotationButton.currentView) rotationButton.currentView.layoutParams = getParamsToCenterView() diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactory.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactory.kt index 7db1a374d3..c502cdb235 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactory.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/NavButtonLayoutFactory.kt @@ -58,7 +58,7 @@ class NavButtonLayoutFactory { navButtonsView: FrameLayout, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView, + a11yButton: ImageView?, resources: Resources, isKidsMode: Boolean, isInSetup: Boolean, diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneGestureLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneGestureLayoutter.kt index c1dae403c5..d6ea7f0c2a 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneGestureLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneGestureLayoutter.kt @@ -31,7 +31,7 @@ class PhoneGestureLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView + a11yButton: ImageView? ) : AbstractNavButtonLayoutter( resources, diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt index efe9d4b6e3..54edd2110c 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneLandscapeNavLayoutter.kt @@ -36,7 +36,7 @@ open class PhoneLandscapeNavLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView, + a11yButton: ImageView?, ) : AbstractNavButtonLayoutter( resources, @@ -113,7 +113,9 @@ open class PhoneLandscapeNavLayoutter( startContextualContainer.addView(imeSwitcher) imeSwitcher.layoutParams = getParamsToCenterView() } - startContextualContainer.addView(a11yButton) + if (a11yButton != null) { + startContextualContainer.addView(a11yButton) + } if (rotationButton != null) { startContextualContainer.addView(rotationButton.currentView) rotationButton.currentView.layoutParams = getParamsToCenterView() diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt index ad03e5b7b7..34df282ba1 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhonePortraitNavLayoutter.kt @@ -35,7 +35,7 @@ class PhonePortraitNavLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView, + a11yButton: ImageView?, ) : AbstractNavButtonLayoutter( resources, @@ -111,7 +111,9 @@ class PhonePortraitNavLayoutter( endContextualContainer.addView(imeSwitcher) imeSwitcher.layoutParams = getParamsToCenterView() } - endContextualContainer.addView(a11yButton) + if (a11yButton != null) { + endContextualContainer.addView(a11yButton) + } if (rotationButton != null) { endContextualContainer.addView(rotationButton.currentView) rotationButton.currentView.layoutParams = getParamsToCenterView() diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt index fd6e9917bc..cfe1276ac6 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/PhoneSeascapeNavLayoutter.kt @@ -31,7 +31,7 @@ class PhoneSeascapeNavLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView + a11yButton: ImageView? ) : PhoneLandscapeNavLayoutter( resources, @@ -63,7 +63,9 @@ class PhoneSeascapeNavLayoutter( endContextualContainer.addView(imeSwitcher) imeSwitcher.layoutParams = getParamsToCenterView() } - endContextualContainer.addView(a11yButton) + if (a11yButton != null) { + endContextualContainer.addView(a11yButton) + } if (rotationButton != null) { endContextualContainer.addView(rotationButton.currentView) rotationButton.currentView.layoutParams = getParamsToCenterView() diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt index db245b8922..36f5150650 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/SetupNavLayoutter.kt @@ -32,7 +32,7 @@ class SetupNavLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView + a11yButton: ImageView? ) : AbstractNavButtonLayoutter( resources, @@ -72,7 +72,9 @@ class SetupNavLayoutter( startContextualContainer.addView(imeSwitcher) imeSwitcher.layoutParams = getParamsToCenterView() } - endContextualContainer.addView(a11yButton) + if (a11yButton != null) { + endContextualContainer.addView(a11yButton) + } if (rotationButton != null) { endContextualContainer.addView(rotationButton.currentView) rotationButton.currentView.layoutParams = getParamsToCenterView() diff --git a/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt b/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt index 56e55bbc1a..58dce69fea 100644 --- a/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/navbutton/TaskbarNavLayoutter.kt @@ -26,7 +26,10 @@ import com.android.launcher3.DeviceProfile import com.android.launcher3.R import com.android.systemui.shared.rotation.RotationButton -/** Layoutter for showing 3 button navigation on large screen */ +/** + * Layoutter for rendering task bar in large screen. {@param isContextualButtonShowing} is true in + * 3-button mode. + */ class TaskbarNavLayoutter( resources: Resources, navBarContainer: LinearLayout, @@ -34,7 +37,7 @@ class TaskbarNavLayoutter( startContextualContainer: ViewGroup, imeSwitcher: ImageView?, rotationButton: RotationButton?, - a11yButton: ImageView + a11yButton: ImageView? ) : AbstractNavButtonLayoutter( resources, @@ -89,24 +92,28 @@ class TaskbarNavLayoutter( endContextualContainer.removeAllViews() startContextualContainer.removeAllViews() - val endContextualContainerParams = FrameLayout.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT) - endContextualContainerParams.gravity = Gravity.END or Gravity.CENTER_VERTICAL - endContextualContainer.layoutParams = endContextualContainerParams + if (isContextualButtonShowing) { + val endContextualContainerParams = FrameLayout.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT) + endContextualContainerParams.gravity = Gravity.END or Gravity.CENTER_VERTICAL + endContextualContainer.layoutParams = endContextualContainerParams - val startContextualContainerParams = FrameLayout.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT) - startContextualContainerParams.gravity = Gravity.START or Gravity.CENTER_VERTICAL - startContextualContainer.layoutParams = startContextualContainerParams + val startContextualContainerParams = FrameLayout.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT) + startContextualContainerParams.gravity = Gravity.START or Gravity.CENTER_VERTICAL + startContextualContainer.layoutParams = startContextualContainerParams - if (imeSwitcher != null) { - startContextualContainer.addView(imeSwitcher) - imeSwitcher.layoutParams = getParamsToCenterView() - } - endContextualContainer.addView(a11yButton) - if (rotationButton != null) { - endContextualContainer.addView(rotationButton.currentView) - rotationButton.currentView.layoutParams = getParamsToCenterView() + if (imeSwitcher != null) { + startContextualContainer.addView(imeSwitcher) + imeSwitcher.layoutParams = getParamsToCenterView() + } + if (a11yButton != null) { + endContextualContainer.addView(a11yButton) + } + if (rotationButton != null) { + endContextualContainer.addView(rotationButton.currentView) + rotationButton.currentView.layoutParams = getParamsToCenterView() + } } } }