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
This commit is contained in:
Candice Lo
2023-03-24 10:37:55 +00:00
parent 87f7979d46
commit 32e3e5b2ed
2 changed files with 69 additions and 15 deletions

View File

@@ -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) {

View File

@@ -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<SeekBar.OnSeekBarChangeListener>
@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<SeekBar>(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<SeekBarWithIconButtonsView>(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()
}
}