Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc0f07ca authored by Candice Lo's avatar Candice Lo
Browse files

Announce scaled value for font scaling seekbar in Talkback

1. Keep state descriptions in the SeekBarWithIconButtonsView.
2. Set the scaled values to be the state descriptions for the font
   scaling seekbar.

Bug: 269680636
Test: manually - attach videos to the bug
Test: atest SeekBarWithIconButtonsViewTest
Change-Id: I12951446a4cd81838b8d5f875037874118fb1dd5
parent aeba6853
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -1648,4 +1648,7 @@
        <item>Move right</item>
        <item>Move right</item>
        <item>Move up</item>
        <item>Move up</item>
    </string-array>
    </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>
</resources>
+11 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.R
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView
import com.android.systemui.statusbar.phone.SystemUIDialog
import com.android.systemui.statusbar.phone.SystemUIDialog
import com.android.systemui.util.settings.SystemSettings
import com.android.systemui.util.settings.SystemSettings
import kotlin.math.roundToInt


/** The Dialog that contains a seekbar for changing the font size. */
/** The Dialog that contains a seekbar for changing the font size. */
class FontScalingDialog(context: Context, private val systemSettings: SystemSettings) :
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)
        doneButton = requireViewById(com.android.internal.R.id.button1)
        seekBarWithIconButtonsView = requireViewById(R.id.font_scaling_slider)
        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)
        seekBarWithIconButtonsView.setMax((strEntryValues).size - 1)


        val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, 1.0f)
        val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, 1.0f)
+28 −0
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ public class SeekBarWithIconButtonsView extends LinearLayout {
    private SeekBar mSeekbar;
    private SeekBar mSeekbar;


    private SeekBarChangeListener mSeekBarListener = new SeekBarChangeListener();
    private SeekBarChangeListener mSeekBarListener = new SeekBarChangeListener();
    private String[] mStateLabels = null;


    public SeekBarWithIconButtonsView(Context context) {
    public SeekBarWithIconButtonsView(Context context) {
        this(context, null);
        this(context, null);
@@ -131,6 +132,30 @@ public class SeekBarWithIconButtonsView extends LinearLayout {
        iconFrame.setEnabled(enabled);
        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.
     * 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.
     * 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
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (mStateLabels != null) {
                setSeekbarStateDescription();
            }
            if (mOnSeekBarChangeListener != null) {
            if (mOnSeekBarChangeListener != null) {
                mOnSeekBarChangeListener.onProgressChanged(seekBar, progress, fromUser);
                mOnSeekBarChangeListener.onProgressChanged(seekBar, progress, fromUser);
            }
            }
+28 −0
Original line number Original line Diff line number Diff line
@@ -107,4 +107,32 @@ public class SeekBarWithIconButtonsViewTest extends SysuiTestCase {


        assertThat(mSeekbar.getProgress()).isEqualTo(0);
        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]);
    }
}
}