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

Commit 7514ac15 authored by Candice Lo's avatar Candice Lo Committed by Automerger Merge Worker
Browse files

Merge "Announce scaled value for font scaling seekbar in Talkback" into...

Merge "Announce scaled value for font scaling seekbar in Talkback" into udc-dev am: 80d1f08c am: 17fd989f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21647983



Change-Id: If507164e0affb2b8ff5610ae3f2315c11d6c42e1
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a4c0bf71 17fd989f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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>
+11 −0
Original line number 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.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)
+28 −0
Original line number Diff line number Diff line
@@ -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);
            }
+28 −0
Original line number Diff line number Diff line
@@ -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]);
    }
}