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

Commit f9599ebd authored by Yuhan Yang's avatar Yuhan Yang Committed by Android (Google) Code Review
Browse files

Merge "Update seek bar when clicking decrease and increase button" into main

parents e4f202d9 3c24d286
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
@@ -80,6 +81,10 @@ public class AutoclickDelayDialogFragment extends InstrumentedDialogFragment {
        TextView customValueTextView = dialogView.findViewById(
                R.id.accessibility_autoclick_custom_value);
        Group sliderContainer = dialogView.findViewById(R.id.sliderContainer);
        ImageView decreaseButton = dialogView.findViewById(
                R.id.accessibility_autoclick_custom_value_decrease);
        ImageView increaseButton = dialogView.findViewById(
                R.id.accessibility_autoclick_custom_value_increase);

        AlertDialog alertDialog = new AlertDialog.Builder(getContext())
                .setView(dialogView)
@@ -125,6 +130,9 @@ public class AutoclickDelayDialogFragment extends InstrumentedDialogFragment {
                }
            });

        decreaseButton.setOnClickListener(v -> decreaseDelayByImageView(customProgressBar));
        increaseButton.setOnClickListener(v -> increaseDelayByImageView(customProgressBar));

        if (savedInstanceState == null) {
            initStateBasedOnDelay(radioGroup, customValueTextView, customProgressBar);
        }
@@ -149,6 +157,22 @@ public class AutoclickDelayDialogFragment extends InstrumentedDialogFragment {
        }
    }

    private void decreaseDelayByImageView(@NonNull SeekBar customProgressBar) {
        int delay = customProgressBar.getProgress();
        if (delay > customProgressBar.getMin()) {
            delay--;
        }
        customProgressBar.setProgress(delay);
    }

    private void increaseDelayByImageView(@NonNull SeekBar customProgressBar) {
        int delay = customProgressBar.getProgress();
        if (delay < customProgressBar.getMax()) {
            delay++;
        }
        customProgressBar.setProgress(delay);
    }

    private boolean isCustomButtonChecked(int checkedId) {
        return checkedId == R.id.accessibility_autoclick_dialog_custom;
    }
+41 −8
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.SeekBar;

@@ -95,12 +96,7 @@ public class AutoclickDelayDialogFragmentTest {
        mDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
        ShadowLooper.idleMainLooper();

        final int autoclickDelay = Settings.Secure.getInt(
                ApplicationProvider.getApplicationContext().getContentResolver(),
                Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY,
                AUTOCLICK_DELAY_WITH_INDICATOR_DEFAULT);

        assertThat(autoclickDelay).isEqualTo(800);
        assertDelayUpdatedInSettings(800);
    }

    @Test
@@ -134,13 +130,50 @@ public class AutoclickDelayDialogFragmentTest {

        mDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
        ShadowLooper.idleMainLooper();
        assertDelayUpdatedInSettings(TEST_SEEK_BAR_PROGRESS * AUTOCLICK_DELAY_STEP);
    }

    @Test
    public void clickIncreaseAndDecreaseImageView_updatesAutoclickDelay() {
        assertThat(mDialog.isShowing()).isTrue();
        RadioGroup radioGroup = mDialog.findViewById(
                R.id.autoclick_delay_before_click_value_group);
        radioGroup.check(R.id.accessibility_autoclick_dialog_custom);

        SeekBar customProgressBar = mDialog.findViewById(
                R.id.accessibility_autoclick_custom_slider);
        assertThat(customProgressBar.getVisibility()).isEqualTo(View.VISIBLE);
        customProgressBar.setProgress(TEST_SEEK_BAR_PROGRESS);
        ShadowLooper.idleMainLooper();

        ImageView decreaseButton = mDialog.findViewById(
                R.id.accessibility_autoclick_custom_value_decrease);
        decreaseButton.callOnClick();
        decreaseButton.callOnClick();
        assertThat(customProgressBar.getProgress()).isEqualTo(TEST_SEEK_BAR_PROGRESS - 2);

        ImageView increaseButton = mDialog.findViewById(
                R.id.accessibility_autoclick_custom_value_increase);
        increaseButton.callOnClick();
        assertThat(customProgressBar.getProgress()).isEqualTo(TEST_SEEK_BAR_PROGRESS - 1);

        mDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
        ShadowLooper.idleMainLooper();

        final int autoclickDelay = Settings.Secure.getInt(
                ApplicationProvider.getApplicationContext().getContentResolver(),
                Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY,
                AUTOCLICK_DELAY_WITH_INDICATOR_DEFAULT);

        assertDelayUpdatedInSettings((TEST_SEEK_BAR_PROGRESS - 1) * AUTOCLICK_DELAY_STEP);
    }

    private void assertDelayUpdatedInSettings(int expectedDelay) {
        final int autoclickDelay = Settings.Secure.getInt(
                ApplicationProvider.getApplicationContext().getContentResolver(),
                Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY,
                AUTOCLICK_DELAY_WITH_INDICATOR_DEFAULT);

        assertThat(autoclickDelay).isEqualTo(
                TEST_SEEK_BAR_PROGRESS * AUTOCLICK_DELAY_STEP);
        assertThat(autoclickDelay).isEqualTo(expectedDelay);
    }
}