From 32e3e5b2edbaedba284b229fdc511d78a7e40105 Mon Sep 17 00:00:00 2001 From: Candice Lo Date: Fri, 24 Mar 2023 10:37:55 +0000 Subject: [PATCH 1/3] Change the font size after interacting with SeekBar Since it will lead to lags on the screen if we set the font scale to system everytime the progress changes when we drag through the seekbar, we change the behavior to be only changing the system font scale when users release their finger from the seekbar. Bug: 274395502 Test: Manually - attach videos to the bug Test: atest FontScalingDialogTest Change-Id: I3b4168414c93d847f10ce081d1617010f62c2e21 --- .../fontscaling/FontScalingDialog.kt | 32 ++++++++---- .../fontscaling/FontScalingDialogTest.kt | 52 +++++++++++++++++-- 2 files changed, 69 insertions(+), 15 deletions(-) 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 1836ce8577835..1cdd5801b57dc 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt @@ -84,31 +84,41 @@ class FontScalingDialog( seekBarWithIconButtonsView.setOnSeekBarChangeListener( object : OnSeekBarChangeListener { + var isTrackingTouch = false + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { - if (progress != lastProgress) { - if (!fontSizeHasBeenChangedFromTile) { - backgroundExecutor.execute { updateSecureSettingsIfNeeded() } - fontSizeHasBeenChangedFromTile = true - } - - backgroundExecutor.execute { updateFontScale(strEntryValues[progress]) } - - lastProgress = progress + if (!isTrackingTouch) { + // The seekbar progress is changed by icon buttons + changeFontSize(progress) } } override fun onStartTrackingTouch(seekBar: SeekBar) { - // Do nothing + isTrackingTouch = true } override fun onStopTrackingTouch(seekBar: SeekBar) { - // Do nothing + isTrackingTouch = false + changeFontSize(seekBar.progress) } } ) doneButton.setOnClickListener { dismiss() } } + private fun changeFontSize(progress: Int) { + if (progress != lastProgress) { + if (!fontSizeHasBeenChangedFromTile) { + backgroundExecutor.execute { updateSecureSettingsIfNeeded() } + fontSizeHasBeenChangedFromTile = true + } + + backgroundExecutor.execute { updateFontScale(strEntryValues[progress]) } + + lastProgress = progress + } + } + private fun fontSizeValueToIndex(value: Float): Int { var lastValue = strEntryValues[0].toFloat() for (i in 1 until strEntryValues.size) { 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 eb8295653199e..a6dcd24371d56 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 @@ -26,6 +26,8 @@ import com.android.systemui.R import com.android.systemui.SysuiTestCase import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView import com.android.systemui.util.concurrency.FakeExecutor +import com.android.systemui.util.mockito.capture +import com.android.systemui.util.mockito.whenever import com.android.systemui.util.settings.FakeSettings import com.android.systemui.util.settings.SecureSettings import com.android.systemui.util.settings.SystemSettings @@ -34,6 +36,10 @@ import com.google.common.truth.Truth.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito.spy +import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations private const val ON: Int = 1 @@ -53,6 +59,9 @@ class FontScalingDialogTest : SysuiTestCase() { .getResources() .getStringArray(com.android.settingslib.R.array.entryvalues_font_size) + @Captor + private lateinit var seekBarChangeCaptor: ArgumentCaptor + @Before fun setUp() { MockitoAnnotations.initMocks(this) @@ -61,7 +70,7 @@ class FontScalingDialogTest : SysuiTestCase() { secureSettings = FakeSettings() backgroundExecutor = FakeExecutor(FakeSystemClock()) fontScalingDialog = - FontScalingDialog(mContext, systemSettings, secureSettings, backgroundExecutor) + spy(FontScalingDialog(mContext, systemSettings, secureSettings, backgroundExecutor)) } @Test @@ -70,7 +79,7 @@ class FontScalingDialogTest : SysuiTestCase() { val seekBar: SeekBar = fontScalingDialog.findViewById(R.id.seekbar)!! val progress: Int = seekBar.getProgress() - val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f) + val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def= */ 1.0f) assertThat(currentScale).isEqualTo(fontSizeValueArray[progress].toFloat()) @@ -91,7 +100,7 @@ class FontScalingDialogTest : SysuiTestCase() { iconEndFrame.performClick() backgroundExecutor.runAllReady() - val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f) + val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def= */ 1.0f) assertThat(seekBar.getProgress()).isEqualTo(1) assertThat(currentScale).isEqualTo(fontSizeValueArray[1].toFloat()) @@ -112,7 +121,7 @@ class FontScalingDialogTest : SysuiTestCase() { iconStartFrame.performClick() backgroundExecutor.runAllReady() - val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f) + val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def= */ 1.0f) assertThat(seekBar.getProgress()).isEqualTo(fontSizeValueArray.size - 2) assertThat(currentScale) .isEqualTo(fontSizeValueArray[fontSizeValueArray.size - 2].toFloat()) @@ -141,4 +150,39 @@ class FontScalingDialogTest : SysuiTestCase() { fontScalingDialog.dismiss() } + + @Test + fun dragSeekbar_systemFontSizeSettingsDoesNotChange() { + val slider: SeekBarWithIconButtonsView = spy(SeekBarWithIconButtonsView(mContext)) + whenever( + fontScalingDialog.findViewById(R.id.font_scaling_slider) + ) + .thenReturn(slider) + fontScalingDialog.show() + verify(slider).setOnSeekBarChangeListener(capture(seekBarChangeCaptor)) + val seekBar: SeekBar = slider.findViewById(R.id.seekbar)!! + + // Default seekbar progress for font size is 1, simulate dragging to 0 without + // releasing the finger. + seekBarChangeCaptor.value.onStartTrackingTouch(seekBar) + // Update seekbar progress. This will trigger onProgressChanged in the + // OnSeekBarChangeListener and the seekbar could get updated progress value + // in onStopTrackingTouch. + seekBar.progress = 0 + backgroundExecutor.runAllReady() + + // Verify that the scale of font size remains the default value 1.0f. + var systemScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def= */ 1.0f) + assertThat(systemScale).isEqualTo(1.0f) + + // Simulate releasing the finger from the seekbar. + seekBarChangeCaptor.value.onStopTrackingTouch(seekBar) + backgroundExecutor.runAllReady() + + // Verify that the scale of font size has been updated. + systemScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def= */ 1.0f) + assertThat(systemScale).isEqualTo(fontSizeValueArray[0].toFloat()) + + fontScalingDialog.dismiss() + } } From 45af47c2fe69dc77e6d1ff05b56517754da700bc Mon Sep 17 00:00:00 2001 From: Candice Lo Date: Tue, 28 Mar 2023 10:38:16 +0000 Subject: [PATCH 2/3] Enable text preview in dialog when dragging through seekbar We use the heading of font scaling dialog to provide font size preview when users are dragging through the seekbar and before they release their fingers from the seekbar. Bug: 274395502 Test: Manually - attach viideos to the bug Test: atest FontScalingDialogTest Change-Id: I3290d8c3560fea86453674bfb1f935ba6f709609 --- packages/SystemUI/res/values/dimens.xml | 3 +++ packages/SystemUI/res/values/styles.xml | 2 +- .../fontscaling/FontScalingDialog.kt | 22 ++++++++++++++-- .../fontscaling/FontScalingDialogTest.kt | 25 +++++++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 0c0defadd8b0b..7fb978aa1631d 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1553,6 +1553,9 @@ 12dp 12sp + + 24sp + 662dp diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml index a3655c31fde9a..8a86fd560655a 100644 --- a/packages/SystemUI/res/values/styles.xml +++ b/packages/SystemUI/res/values/styles.xml @@ -1041,7 +1041,7 @@