From b68b8465bb36ed06dbae5e9245e9e138999bf120 Mon Sep 17 00:00:00 2001 From: Candice Lo Date: Mon, 10 Jul 2023 07:54:42 +0000 Subject: [PATCH] Disabling the Done button when system applying new font size Since we are not able to interact with the whole screen when the system is applying the new font size, we disable the Done button before updating the font scale and enable it again after the change finishes. The Done button is turned into gray when disabled to let users understand that we are not able to interact with the button at that time. Bug: 288699753 Test: atest FontScalingDialogTest Test: manually - attach video to the bug. Manually check that the button is disabled when the system is updating font size and the button is enabled again after the font size change finishes. Change-Id: Id56bb41290e44ea922031f3515c484ef7dc1c1b5 --- .../color/qs_dialog_btn_filled_background.xml | 23 +++++++++++++++ .../color/qs_dialog_btn_filled_text_color.xml | 23 +++++++++++++++ .../res/drawable/qs_dialog_btn_filled.xml | 3 +- packages/SystemUI/res/values/styles.xml | 2 +- .../fontscaling/FontScalingDialog.kt | 17 +++++++---- .../fontscaling/FontScalingDialogTest.kt | 28 ++++++++++++++++++- 6 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 packages/SystemUI/res/color/qs_dialog_btn_filled_background.xml create mode 100644 packages/SystemUI/res/color/qs_dialog_btn_filled_text_color.xml diff --git a/packages/SystemUI/res/color/qs_dialog_btn_filled_background.xml b/packages/SystemUI/res/color/qs_dialog_btn_filled_background.xml new file mode 100644 index 0000000000000..40bab5ed08f25 --- /dev/null +++ b/packages/SystemUI/res/color/qs_dialog_btn_filled_background.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/res/color/qs_dialog_btn_filled_text_color.xml b/packages/SystemUI/res/color/qs_dialog_btn_filled_text_color.xml new file mode 100644 index 0000000000000..e76ad991a92c5 --- /dev/null +++ b/packages/SystemUI/res/color/qs_dialog_btn_filled_text_color.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/res/drawable/qs_dialog_btn_filled.xml b/packages/SystemUI/res/drawable/qs_dialog_btn_filled.xml index c4e45bf2c2237..9bc8b53b308eb 100644 --- a/packages/SystemUI/res/drawable/qs_dialog_btn_filled.xml +++ b/packages/SystemUI/res/drawable/qs_dialog_btn_filled.xml @@ -15,7 +15,6 @@ ~ limitations under the License. --> @@ -28,7 +27,7 @@ - + 28dp @drawable/qs_dialog_btn_filled - ?androidprv:attr/materialColorOnPrimary + @color/qs_dialog_btn_filled_text_color 14sp 20sp @*android:string/config_bodyFontFamilyMedium diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt b/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt index 783460c325fad..0ef256d411578 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt @@ -145,6 +145,8 @@ class FontScalingDialog( */ @MainThread fun updateFontScaleDelayed(delayMsFromSource: Long) { + doneButton.isEnabled = false + var delayMs = delayMsFromSource if (systemClock.elapsedRealtime() - lastUpdateTime < MIN_UPDATE_INTERVAL_MS) { delayMs += MIN_UPDATE_INTERVAL_MS @@ -197,17 +199,22 @@ class FontScalingDialog( title.post { title.setTextAppearance(R.style.TextAppearance_Dialog_Title) doneButton.setTextAppearance(R.style.Widget_Dialog_Button) + doneButton.isEnabled = true } } } @WorkerThread fun updateFontScale() { - systemSettings.putStringForUser( - Settings.System.FONT_SCALE, - strEntryValues[lastProgress.get()], - userTracker.userId - ) + if ( + !systemSettings.putStringForUser( + Settings.System.FONT_SCALE, + strEntryValues[lastProgress.get()], + userTracker.userId + ) + ) { + title.post { doneButton.isEnabled = true } + } } @WorkerThread diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt b/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt index d5e6881500bca..7b99314692b4a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt @@ -15,11 +15,13 @@ */ package com.android.systemui.accessibility.fontscaling +import android.content.res.Configuration import android.os.Handler import android.provider.Settings import android.testing.AndroidTestingRunner import android.testing.TestableLooper import android.view.ViewGroup +import android.widget.Button import android.widget.SeekBar import androidx.test.filters.SmallTest import com.android.systemui.R @@ -61,6 +63,7 @@ class FontScalingDialogTest : SysuiTestCase() { private lateinit var secureSettings: SecureSettings private lateinit var systemClock: FakeSystemClock private lateinit var backgroundDelayableExecutor: FakeExecutor + private lateinit var testableLooper: TestableLooper private val fontSizeValueArray: Array = mContext .getResources() @@ -73,7 +76,8 @@ class FontScalingDialogTest : SysuiTestCase() { @Before fun setUp() { MockitoAnnotations.initMocks(this) - val mainHandler = Handler(TestableLooper.get(this).getLooper()) + testableLooper = TestableLooper.get(this) + val mainHandler = Handler(testableLooper.looper) systemSettings = FakeSettings() // Guarantee that the systemSettings always starts with the default font scale. systemSettings.putFloatForUser(Settings.System.FONT_SCALE, 1.0f, userTracker.userId) @@ -286,4 +290,26 @@ class FontScalingDialogTest : SysuiTestCase() { verify(fontScalingDialog).createTextPreview(/* index= */ 0) fontScalingDialog.dismiss() } + + @Test + fun changeFontSize_buttonIsDisabledBeforeFontSizeChangeFinishes() { + fontScalingDialog.show() + + val iconEndFrame: ViewGroup = fontScalingDialog.findViewById(R.id.icon_end_frame)!! + val doneButton: Button = fontScalingDialog.findViewById(com.android.internal.R.id.button1)!! + + iconEndFrame.performClick() + backgroundDelayableExecutor.runAllReady() + backgroundDelayableExecutor.advanceClockToNext() + backgroundDelayableExecutor.runAllReady() + + // Verify that the button is disabled before receiving onConfigurationChanged + assertThat(doneButton.isEnabled).isFalse() + + val config = Configuration() + config.fontScale = 1.15f + fontScalingDialog.onConfigurationChanged(config) + testableLooper.processAllMessages() + assertThat(doneButton.isEnabled).isTrue() + } }