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

Commit b5888bb6 authored by Candice's avatar Candice
Browse files

Notify interaction finalized when users are changing the seekbar progress without touching

With accessibility services, users are able to change the seekbar
progress without touching the it. In this case, we would like to notify
the interaction with seekbar has finished and set the font size.

Bug: 379216747
Test: atest FontScalingDialogDelegateTest
Test: atest SeekBaeWithIconButtonsViewTest
Test: atest WindowMagnificationSettingsTest
Test: Manually. Add videos to the bug
Flag: EXEMPT bugfix
Change-Id: Ibabb2c70ed5df82cc2ed4057ad7264f47c5e17bc
parent d6c5bcb1
Loading
Loading
Loading
Loading
+3 −13
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.DialogTransitionAnimator
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView.OnSeekBarWithIconButtonsChangeListener
import com.android.systemui.model.SysUiState
import com.android.systemui.res.R
import com.android.systemui.settings.UserTracker
@@ -236,13 +235,13 @@ class FontScalingDialogDelegateTest : SysuiTestCase() {
        dialog.show()

        val slider = dialog.findViewById<SeekBarWithIconButtonsView>(R.id.font_scaling_slider)!!
        val changeListener = slider.onSeekBarWithIconButtonsChangeListener
        val seekBarListener = slider.getSeekBarChangeListener()

        val seekBar: SeekBar = slider.findViewById(R.id.seekbar)!!

        // Default seekbar progress for font size is 1, simulate dragging to 0 without
        // releasing the finger.
        changeListener.onStartTrackingTouch(seekBar)
        seekBarListener.onStartTrackingTouch(seekBar)
        // Update seekbar progress. This will trigger onProgressChanged in the
        // OnSeekBarChangeListener and the seekbar could get updated progress value
        // in onStopTrackingTouch.
@@ -261,16 +260,7 @@ class FontScalingDialogDelegateTest : SysuiTestCase() {
        assertThat(systemScale).isEqualTo(1.0f)

        // Simulate releasing the finger from the seekbar.
        changeListener.onStopTrackingTouch(seekBar)
        backgroundDelayableExecutor.runAllReady()
        backgroundDelayableExecutor.advanceClockToNext()
        backgroundDelayableExecutor.runAllReady()

        // SeekBar interaction is finalized.
        changeListener.onUserInteractionFinalized(
            seekBar,
            OnSeekBarWithIconButtonsChangeListener.ControlUnitType.SLIDER,
        )
        seekBarListener.onStopTrackingTouch(seekBar)
        backgroundDelayableExecutor.runAllReady()
        backgroundDelayableExecutor.advanceClockToNext()
        backgroundDelayableExecutor.runAllReady()
+29 −3
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.common.ui.view;
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
@@ -129,16 +128,43 @@ public class SeekBarWithIconButtonsViewTest extends SysuiTestCase {
    }

    @Test
    public void setProgress_onlyOnProgressChangedTriggeredWithFromUserFalse() {
    public void setProgress_onProgressChangedAndOnUserInteractionFinalized() {
        reset(mOnSeekBarChangeListener);
        mIconDiscreteSliderLinearLayout.setProgress(1);

        // If users are changing seekbar progress without touching the seekbar or clicking the
        // buttons, trigger onUserInteractionFinalized.
        verify(mOnSeekBarChangeListener).onProgressChanged(
                eq(mSeekbar), /* progress= */ eq(1), /* fromUser= */ eq(false));
        verify(mOnSeekBarChangeListener, never()).onStartTrackingTouch(/* seekBar= */ any());
        verify(mOnSeekBarChangeListener, never()).onStopTrackingTouch(/* seekBar= */ any());
        verify(mOnSeekBarChangeListener).onUserInteractionFinalized(
                /* seekBar= */ any(),
                eq(OnSeekBarWithIconButtonsChangeListener.ControlUnitType.SLIDER));
    }

    @Test
    public void setProgressToSeekBarByTouch_onUserInteractionFinalizedAfterTouchEnds() {
        reset(mOnSeekBarChangeListener);
        final SeekBarWithIconButtonsView.SeekBarChangeListener seekBarChangeListener =
                mIconDiscreteSliderLinearLayout.getSeekBarChangeListener();
        final SeekBar seekBar = mIconDiscreteSliderLinearLayout.findViewById(R.id.seekbar);

        // Simulate changing seekbar progress by touch
        seekBarChangeListener.onStartTrackingTouch(seekBar);
        mIconDiscreteSliderLinearLayout.setProgress(1);

        verify(mOnSeekBarChangeListener).onProgressChanged(
                eq(mSeekbar), /* progress= */ eq(1), /* fromUser= */ eq(false));
        verify(mOnSeekBarChangeListener, never()).onUserInteractionFinalized(
                /* seekBar= */any(), /* control= */ anyInt());
                /* seekBar= */ any(),
                eq(OnSeekBarWithIconButtonsChangeListener.ControlUnitType.SLIDER));

        // Notify onUserInteractionFinalized after touch ends
        seekBarChangeListener.onStopTrackingTouch(seekBar);
        verify(mOnSeekBarChangeListener).onUserInteractionFinalized(
                /* seekBar= */ any(),
                eq(OnSeekBarWithIconButtonsChangeListener.ControlUnitType.SLIDER));
    }

    @Test
+21 −1
Original line number Diff line number Diff line
@@ -178,6 +178,14 @@ public class SeekBarWithIconButtonsView extends LinearLayout {
        return mSeekBarListener.mOnSeekBarChangeListener;
    }

    /**
     * Only for testing. Get mSeekBarListener to the seekbar.
     */
    @VisibleForTesting
    public SeekBarChangeListener getSeekBarChangeListener() {
        return mSeekBarListener;
    }

    /**
     * Only for testing. Get {@link #mSeekbar} in the layout.
     */
@@ -289,8 +297,10 @@ public class SeekBarWithIconButtonsView extends LinearLayout {
        void onUserInteractionFinalized(SeekBar seekBar, @ControlUnitType int control);
    }

    private class SeekBarChangeListener implements SeekBar.OnSeekBarChangeListener {
    @VisibleForTesting
    public class SeekBarChangeListener implements SeekBar.OnSeekBarChangeListener {
        private OnSeekBarWithIconButtonsChangeListener mOnSeekBarChangeListener = null;
        private boolean mSeekByTouch = false;

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@@ -308,6 +318,14 @@ public class SeekBarWithIconButtonsView extends LinearLayout {
                            seekBar, OnSeekBarWithIconButtonsChangeListener.ControlUnitType.BUTTON);
                } else {
                    mOnSeekBarChangeListener.onProgressChanged(seekBar, progress, fromUser);
                    if (!mSeekByTouch) {
                        // Accessibility users could change the progress of the seekbar without
                        // touching the seekbar or clicking the buttons. We will consider the
                        // interaction has finished in this case.
                        mOnSeekBarChangeListener.onUserInteractionFinalized(
                                seekBar,
                                OnSeekBarWithIconButtonsChangeListener.ControlUnitType.SLIDER);
                    }
                }
            }
            updateIconViewIfNeeded(progress);
@@ -315,6 +333,7 @@ public class SeekBarWithIconButtonsView extends LinearLayout {

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            mSeekByTouch = true;
            if (mOnSeekBarChangeListener != null) {
                mOnSeekBarChangeListener.onStartTrackingTouch(seekBar);
            }
@@ -322,6 +341,7 @@ public class SeekBarWithIconButtonsView extends LinearLayout {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            mSeekByTouch = false;
            if (mOnSeekBarChangeListener != null) {
                mOnSeekBarChangeListener.onStopTrackingTouch(seekBar);
                mOnSeekBarChangeListener.onUserInteractionFinalized(
+5 −2
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.view.accessibility.AccessibilityManager;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.SeekBar;

import androidx.test.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -81,6 +82,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

@SmallTest
@@ -544,9 +546,10 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
        OnSeekBarWithIconButtonsChangeListener onChangeListener =
                mZoomSeekbar.getOnSeekBarWithIconButtonsChangeListener();

        mZoomSeekbar.setProgress(30);
        SeekBar mockSeekBar = Mockito.mock(SeekBar.class);
        when(mockSeekBar.getProgress()).thenReturn(30);
        onChangeListener.onUserInteractionFinalized(
                mZoomSeekbar.getSeekbar(),
                mockSeekBar,
                OnSeekBarWithIconButtonsChangeListener.ControlUnitType.SLIDER);

        // should trigger callback to update magnifier scale and persist the scale