Merge "Announce scaled value for font scaling seekbar in Talkback" into udc-dev
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user