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
This commit is contained in:
Candice Lo
2023-03-28 10:38:16 +00:00
parent 32e3e5b2ed
commit 45af47c2fe
4 changed files with 49 additions and 3 deletions

View File

@@ -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. -->

View File

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

View File

@@ -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)
@@ -90,6 +90,10 @@ class FontScalingDialog(
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)
}
}
@@ -163,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"

View File

@@ -185,4 +185,29 @@ class FontScalingDialogTest : SysuiTestCase() {
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()
}
}