diff options
4 files changed, 70 insertions, 0 deletions
diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml index b92b3d665675..8e7d36edb05a 100644 --- a/packages/SettingsLib/res/values/strings.xml +++ b/packages/SettingsLib/res/values/strings.xml @@ -1648,4 +1648,7 @@ <item>Move right</item> <item>Move up</item> </string-array> + + <!-- Formatting states for the scale of font size, in percent. Double "%" is required to represent the symbol "%". [CHAR LIMIT=20] --> + <string name="font_scale_percentage"> <xliff:g id="percentage">%1$d</xliff:g> %%</string> </resources> 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 54f933ae6d09..53a421d9eccc 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/accessibility/fontscaling/FontScalingDialog.kt @@ -29,6 +29,7 @@ import com.android.systemui.R import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView import com.android.systemui.statusbar.phone.SystemUIDialog import com.android.systemui.util.settings.SystemSettings +import kotlin.math.roundToInt /** The Dialog that contains a seekbar for changing the font size. */ class FontScalingDialog(context: Context, private val systemSettings: SystemSettings) : @@ -56,6 +57,16 @@ class FontScalingDialog(context: Context, private val systemSettings: SystemSett doneButton = requireViewById(com.android.internal.R.id.button1) seekBarWithIconButtonsView = requireViewById(R.id.font_scaling_slider) + val labelArray = arrayOfNulls<String>(strEntryValues.size) + for (i in strEntryValues.indices) { + labelArray[i] = + context.resources.getString( + com.android.settingslib.R.string.font_scale_percentage, + (strEntryValues[i].toFloat() * 100).roundToInt() + ) + } + seekBarWithIconButtonsView.setProgressStateLabels(labelArray) + seekBarWithIconButtonsView.setMax((strEntryValues).size - 1) val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, 1.0f) diff --git a/packages/SystemUI/src/com/android/systemui/common/ui/view/SeekBarWithIconButtonsView.java b/packages/SystemUI/src/com/android/systemui/common/ui/view/SeekBarWithIconButtonsView.java index 24f6296de122..de3a9901b8c4 100644 --- a/packages/SystemUI/src/com/android/systemui/common/ui/view/SeekBarWithIconButtonsView.java +++ b/packages/SystemUI/src/com/android/systemui/common/ui/view/SeekBarWithIconButtonsView.java @@ -45,6 +45,7 @@ public class SeekBarWithIconButtonsView extends LinearLayout { private SeekBar mSeekbar; private SeekBarChangeListener mSeekBarListener = new SeekBarChangeListener(); + private String[] mStateLabels = null; public SeekBarWithIconButtonsView(Context context) { this(context, null); @@ -132,6 +133,30 @@ public class SeekBarWithIconButtonsView extends LinearLayout { } /** + * Stores the String array we would like to use for describing the state of seekbar progress + * and updates the state description with current progress. + * + * @param labels The state descriptions to be announced for each progress. + */ + public void setProgressStateLabels(String[] labels) { + mStateLabels = labels; + if (mStateLabels != null) { + setSeekbarStateDescription(); + } + } + + /** + * Sets the state of seekbar based on current progress. The progress of seekbar is + * corresponding to the index of the string array. If the progress is larger than or equals + * to the length of the array, the state description is set to an empty string. + */ + private void setSeekbarStateDescription() { + mSeekbar.setStateDescription( + (mSeekbar.getProgress() < mStateLabels.length) + ? mStateLabels[mSeekbar.getProgress()] : ""); + } + + /** * Sets a onSeekbarChangeListener to the seekbar in the layout. * We update the Start Icon and End Icon if needed when the seekbar progress is changed. */ @@ -173,6 +198,9 @@ public class SeekBarWithIconButtonsView extends LinearLayout { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (mStateLabels != null) { + setSeekbarStateDescription(); + } if (mOnSeekBarChangeListener != null) { mOnSeekBarChangeListener.onProgressChanged(seekBar, progress, fromUser); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/common/ui/view/SeekBarWithIconButtonsViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/common/ui/view/SeekBarWithIconButtonsViewTest.java index eafe727ee7dc..afd9be5787c9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/common/ui/view/SeekBarWithIconButtonsViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/common/ui/view/SeekBarWithIconButtonsViewTest.java @@ -107,4 +107,32 @@ public class SeekBarWithIconButtonsViewTest extends SysuiTestCase { assertThat(mSeekbar.getProgress()).isEqualTo(0); } + + @Test + public void setProgressStateLabels_getExpectedStateDescriptionOnInitialization() { + String[] stateLabels = new String[]{"1", "2", "3", "4", "5"}; + mIconDiscreteSliderLinearLayout.setMax(stateLabels.length); + mIconDiscreteSliderLinearLayout.setProgress(1); + mIconDiscreteSliderLinearLayout.setProgressStateLabels(stateLabels); + + final int currentProgress = mSeekbar.getProgress(); + final CharSequence stateDescription = mSeekbar.getStateDescription(); + + assertThat(currentProgress).isEqualTo(1); + assertThat(stateDescription).isEqualTo(stateLabels[currentProgress]); + } + + @Test + public void setProgressStateLabels_progressChanged_getExpectedStateDescription() { + String[] stateLabels = new String[]{"1", "2", "3", "4", "5"}; + mIconDiscreteSliderLinearLayout.setMax(stateLabels.length); + mIconDiscreteSliderLinearLayout.setProgressStateLabels(stateLabels); + mIconDiscreteSliderLinearLayout.setProgress(1); + + final int currentProgress = mSeekbar.getProgress(); + final CharSequence stateDescription = mSeekbar.getStateDescription(); + + assertThat(currentProgress).isEqualTo(1); + assertThat(stateDescription).isEqualTo(stateLabels[currentProgress]); + } } |