From 02239be06edaf85269de347506a6bff6927d1e56 Mon Sep 17 00:00:00 2001 From: Beth Thibodeau Date: Wed, 1 Jun 2022 22:45:35 -0500 Subject: [PATCH] Improve long press menu readability When media cannot be dismissed, hide the "Hide" button completely and make the "Cancel" button solid. Also update the top text to be medium weight so it is more readable on busy backgrounds. Fixes: 231397561 Test: manual - video in bug Test: atest com.android.systemui.media Change-Id: I1f9341d84102aaf6634745c42cf23ce572136954 --- .../res/layout/media_long_press_menu.xml | 4 +-- .../systemui/media/ColorSchemeTransition.kt | 1 + .../android/systemui/media/GutsViewHolder.kt | 29 +++++++++++++++---- .../systemui/media/MediaControlPanel.java | 9 +++++- .../systemui/media/MediaViewController.kt | 7 +++-- .../media/ColorSchemeTransitionTest.kt | 3 ++ 6 files changed, 42 insertions(+), 11 deletions(-) diff --git a/packages/SystemUI/res/layout/media_long_press_menu.xml b/packages/SystemUI/res/layout/media_long_press_menu.xml index 99c5e47073383..a8ddd4cb93ef4 100644 --- a/packages/SystemUI/res/layout/media_long_press_menu.xml +++ b/packages/SystemUI/res/layout/media_long_press_menu.xml @@ -26,7 +26,7 @@ android:layout_marginStart="@dimen/qs_media_padding" android:layout_marginEnd="@dimen/qs_media_padding" android:id="@+id/remove_text" - android:fontFamily="@*android:string/config_headlineFontFamily" + android:fontFamily="@*android:string/config_headlineFontFamilyMedium" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" @@ -62,7 +62,6 @@ android:layout_marginEnd="@dimen/qs_media_action_spacing" android:layout_marginBottom="@dimen/qs_media_padding" app:layout_constrainedWidth="true" - app:layout_constraintWidth_min="@dimen/min_clickable_item_size" app:layout_constraintHeight_min="@dimen/min_clickable_item_size" app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintStart_toStartOf="parent" @@ -73,6 +72,7 @@ android:id="@+id/dismiss_text" android:layout_width="wrap_content" android:layout_height="wrap_content" + app:layout_constraintWidth_min="@dimen/min_clickable_item_size" android:layout_gravity="center|top" style="@style/MediaPlayer.SolidButton" android:background="@drawable/qs_media_solid_button" diff --git a/packages/SystemUI/src/com/android/systemui/media/ColorSchemeTransition.kt b/packages/SystemUI/src/com/android/systemui/media/ColorSchemeTransition.kt index 9b0d43272fd3c..f1d5e94bfbf3a 100644 --- a/packages/SystemUI/src/com/android/systemui/media/ColorSchemeTransition.kt +++ b/packages/SystemUI/src/com/android/systemui/media/ColorSchemeTransition.kt @@ -238,5 +238,6 @@ class ColorSchemeTransition internal constructor( fun updateColorScheme(colorScheme: ColorScheme?, enableGradient: Boolean) { isGradientEnabled = enableGradient colorTransitions.forEach { it.updateColorScheme(colorScheme) } + colorScheme?.let { mediaViewHolder.gutsViewHolder.colorScheme = colorScheme } } } diff --git a/packages/SystemUI/src/com/android/systemui/media/GutsViewHolder.kt b/packages/SystemUI/src/com/android/systemui/media/GutsViewHolder.kt index 1a48a84aff23b..73240b54a27a5 100644 --- a/packages/SystemUI/src/com/android/systemui/media/GutsViewHolder.kt +++ b/packages/SystemUI/src/com/android/systemui/media/GutsViewHolder.kt @@ -40,6 +40,9 @@ class GutsViewHolder constructor(itemView: View) { val dismissText: TextView = itemView.requireViewById(R.id.dismiss_text) val settings: ImageButton = itemView.requireViewById(R.id.settings) + private var isDismissible: Boolean = true + var colorScheme: ColorScheme? = null + /** Marquees the main text of the guts menu. */ fun marquee(start: Boolean, delay: Long, tag: String) { val gutsTextHandler = gutsText.handler @@ -47,19 +50,31 @@ class GutsViewHolder constructor(itemView: View) { Log.d(tag, "marquee while longPressText.getHandler() is null", Exception()) return } - gutsTextHandler.postDelayed( { gutsText.isSelected = start }, delay) + gutsTextHandler.postDelayed({ gutsText.isSelected = start }, delay) + } + + /** Set whether this control can be dismissed, and update appearance to match */ + fun setDismissible(dismissible: Boolean) { + if (isDismissible == dismissible) return + + isDismissible = dismissible + colorScheme?.let { setColors(it) } } /** Sets the right colors on all the guts views based on the given [ColorScheme]. */ - fun setColors(colorScheme: ColorScheme) { - setSurfaceColor(surfaceFromScheme(colorScheme)) - setTextPrimaryColor(textPrimaryFromScheme(colorScheme)) - setAccentPrimaryColor(accentPrimaryFromScheme(colorScheme)) + fun setColors(scheme: ColorScheme) { + colorScheme = scheme + setSurfaceColor(surfaceFromScheme(scheme)) + setTextPrimaryColor(textPrimaryFromScheme(scheme)) + setAccentPrimaryColor(accentPrimaryFromScheme(scheme)) } /** Sets the surface color on all guts views that use it. */ fun setSurfaceColor(surfaceColor: Int) { dismissText.setTextColor(surfaceColor) + if (!isDismissible) { + cancelText.setTextColor(surfaceColor) + } } /** Sets the primary accent color on all guts views that use it. */ @@ -74,7 +89,9 @@ class GutsViewHolder constructor(itemView: View) { fun setTextPrimaryColor(textPrimary: Int) { val textColorList = ColorStateList.valueOf(textPrimary) gutsText.setTextColor(textColorList) - cancelText.setTextColor(textColorList) + if (isDismissible) { + cancelText.setTextColor(textColorList) + } } companion object { diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java index 972e93b886b84..dea13251e100d 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java @@ -1183,7 +1183,7 @@ public class MediaControlPanel { gutsViewHolder.getGutsText().setText(text); // Dismiss button - gutsViewHolder.getDismissText().setAlpha(isDismissible ? 1 : DISABLED_ALPHA); + gutsViewHolder.getDismissText().setVisibility(isDismissible ? View.VISIBLE : View.GONE); gutsViewHolder.getDismiss().setEnabled(isDismissible); gutsViewHolder.getDismiss().setOnClickListener(v -> { if (mFalsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) return; @@ -1194,11 +1194,18 @@ public class MediaControlPanel { }); // Cancel button + TextView cancelText = gutsViewHolder.getCancelText(); + if (isDismissible) { + cancelText.setBackground(mContext.getDrawable(R.drawable.qs_media_outline_button)); + } else { + cancelText.setBackground(mContext.getDrawable(R.drawable.qs_media_solid_button)); + } gutsViewHolder.getCancel().setOnClickListener(v -> { if (!mFalsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) { closeGuts(); } }); + gutsViewHolder.setDismissible(isDismissible); // Settings button gutsViewHolder.getSettings().setOnClickListener(v -> { diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt b/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt index deb5cbafccc4a..27cd1ce2b440b 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt @@ -270,8 +270,11 @@ class MediaViewController @Inject constructor( } } gutsIds.forEach { id -> - viewState.widgetStates.get(id)?.alpha = if (isGutsVisible) 1f else 0f - viewState.widgetStates.get(id)?.gone = !isGutsVisible + viewState.widgetStates.get(id)?.let { state -> + // Make sure to use the unmodified state if guts are visible + state.alpha = if (isGutsVisible) state.alpha else 0f + state.gone = if (isGutsVisible) state.gone else true + } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/ColorSchemeTransitionTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/ColorSchemeTransitionTest.kt index 8fd2d2f81dcea..b979241073228 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/ColorSchemeTransitionTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/ColorSchemeTransitionTest.kt @@ -57,11 +57,13 @@ class ColorSchemeTransitionTest : SysuiTestCase() { private lateinit var animatingColorTransitionFactory: AnimatingColorTransitionFactory @Mock private lateinit var mediaViewHolder: MediaViewHolder + @Mock private lateinit var gutsViewHolder: GutsViewHolder @JvmField @Rule val mockitoRule = MockitoJUnit.rule() @Before fun setUp() { + whenever(mediaViewHolder.gutsViewHolder).thenReturn(gutsViewHolder) animatingColorTransitionFactory = { _, _, _ -> mockAnimatingTransition } whenever(extractColor.invoke(colorScheme)).thenReturn(TARGET_COLOR) @@ -147,5 +149,6 @@ class ColorSchemeTransitionTest : SysuiTestCase() { fun testColorSchemeTransition_update() { colorSchemeTransition.updateColorScheme(colorScheme, true) verify(mockAnimatingTransition, times(10)).updateColorScheme(colorScheme) + verify(gutsViewHolder).colorScheme = colorScheme } }