summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/res/values/dimens.xml3
-rw-r--r--packages/SystemUI/res/values/styles.xml2
-rw-r--r--packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt54
-rw-r--r--packages/SystemUI/src/com/android/systemui/flags/Flags.kt2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/accessibility/fontscaling/FontScalingDialogTest.kt77
5 files changed, 119 insertions, 19 deletions
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 082ede382c36..2663ffb1fed9 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -1553,6 +1553,9 @@
<dimen name="status_bar_user_chip_end_margin">12dp</dimen>
<dimen name="status_bar_user_chip_text_size">12sp</dimen>
+ <!-- System UI Dialog -->
+ <dimen name="dialog_title_text_size">24sp</dimen>
+
<!-- Internet panel related dimensions -->
<dimen name="internet_dialog_list_max_height">662dp</dimen>
<!-- The height of the WiFi network in Internet panel. -->
diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml
index a3655c31fde9..8a86fd560655 100644
--- a/packages/SystemUI/res/values/styles.xml
+++ b/packages/SystemUI/res/values/styles.xml
@@ -1041,7 +1041,7 @@
<style name="TextAppearance.Dialog.Title" parent="@android:style/TextAppearance.DeviceDefault.Large">
<item name="android:textColor">?android:attr/textColorPrimary</item>
- <item name="android:textSize">24sp</item>
+ <item name="android:textSize">@dimen/dialog_title_text_size</item>
<item name="android:fontFamily">@*android:string/config_headlineFontFamily</item>
<item name="android:lineHeight">32sp</item>
<item name="android:gravity">center</item>
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 1836ce857783..c9579d5e1356 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt
@@ -21,6 +21,7 @@ import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.os.Bundle
import android.provider.Settings
+import android.util.TypedValue
import android.view.LayoutInflater
import android.widget.Button
import android.widget.SeekBar
@@ -49,8 +50,7 @@ class FontScalingDialog(
private lateinit var seekBarWithIconButtonsView: SeekBarWithIconButtonsView
private var lastProgress: Int = -1
- private val configuration: Configuration =
- Configuration(context.getResources().getConfiguration())
+ private val configuration: Configuration = Configuration(context.resources.configuration)
override fun onCreate(savedInstanceState: Bundle?) {
setTitle(R.string.font_scaling_dialog_title)
@@ -84,31 +84,45 @@ class FontScalingDialog(
seekBarWithIconButtonsView.setOnSeekBarChangeListener(
object : OnSeekBarChangeListener {
- override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
- if (progress != lastProgress) {
- if (!fontSizeHasBeenChangedFromTile) {
- backgroundExecutor.execute { updateSecureSettingsIfNeeded() }
- fontSizeHasBeenChangedFromTile = true
- }
-
- backgroundExecutor.execute { updateFontScale(strEntryValues[progress]) }
+ var isTrackingTouch = false
- lastProgress = progress
+ override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
+ if (!isTrackingTouch) {
+ // The seekbar progress is changed by icon buttons
+ changeFontSize(progress)
+ } else {
+ // Provide preview configuration for text instead of changing the system
+ // font scale before users release their finger from the seekbar.
+ createTextPreview(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) {
@@ -153,6 +167,20 @@ class FontScalingDialog(
}
}
+ /** Provides font size preview for text before putting the final settings to the system. */
+ fun createTextPreview(index: Int) {
+ val previewConfig = Configuration(configuration)
+ previewConfig.fontScale = strEntryValues[index].toFloat()
+
+ val previewConfigContext = context.createConfigurationContext(previewConfig)
+ previewConfigContext.theme.setTo(context.theme)
+
+ title.setTextSize(
+ TypedValue.COMPLEX_UNIT_PX,
+ previewConfigContext.resources.getDimension(R.dimen.dialog_title_text_size)
+ )
+ }
+
companion object {
private const val ON = "1"
private const val OFF = "0"
diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
index ff4a2528fcde..27f35db056e9 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
@@ -285,7 +285,7 @@ object Flags {
/** Enables Font Scaling Quick Settings tile */
// TODO(b/269341316): Tracking Bug
@JvmField
- val ENABLE_FONT_SCALING_TILE = unreleasedFlag(509, "enable_font_scaling_tile", teamfood = false)
+ val ENABLE_FONT_SCALING_TILE = unreleasedFlag(509, "enable_font_scaling_tile", teamfood = true)
/** Enables new QS Edit Mode visual refresh */
// TODO(b/269787742): Tracking Bug
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 eb8295653199..353a7c370ab6 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<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,64 @@ 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()
+ }
+
+ @Test
+ fun dragSeekBar_createTextPreview() {
+ 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)
+ seekBarChangeCaptor.value.onProgressChanged(
+ seekBar,
+ /* progress= */ 0,
+ /* fromUser= */ false
+ )
+ backgroundExecutor.runAllReady()
+
+ verify(fontScalingDialog).createTextPreview(/* index= */ 0)
+ fontScalingDialog.dismiss()
+ }
}