diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml index b92b3d665675a..8e7d36edb05ae 100644 --- a/packages/SettingsLib/res/values/strings.xml +++ b/packages/SettingsLib/res/values/strings.xml @@ -1648,4 +1648,7 @@ Move right Move up + + + %1$d %% 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 54f933ae6d09c..53a421d9eccc0 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(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 24f6296de1228..de3a9901b8c41 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); @@ -131,6 +132,30 @@ public class SeekBarWithIconButtonsView extends LinearLayout { iconFrame.setEnabled(enabled); } + /** + * 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 eafe727ee7dc3..afd9be5787c94 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]); + } }