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

Commit 49e62507 authored by Shaowei Shen's avatar Shaowei Shen Committed by Android (Google) Code Review
Browse files

Merge "[Physical Keyboard] Update seekbar to slider" into main

parents 9a462738 d10028d6
Loading
Loading
Loading
Loading
+22 −33
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/input_keys_dialog_scroll_view"
    android:gravity="center_horizontal"
    android:layout_width="match_parent"
@@ -122,6 +122,8 @@
                        android:layout_gravity="center_vertical"
                        android:layout_marginTop="8dp"
                        android:visibility="gone"/>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout
                android:id="@+id/input_setting_keys_custom_seekbar_layout"
                android:orientation="horizontal"
@@ -130,31 +132,18 @@
                android:layout_gravity="center_horizontal"
                android:gravity="center_vertical"
                android:paddingEnd="36dp">
                        <ImageView
                            android:layout_marginTop="8dp"
                            android:layout_width="16dp"
                            android:layout_height="16dp"
                            android:tint="@androidprv:color/materialColorPrimary"
                            android:importantForAccessibility="no"
                            android:src="@drawable/ic_remove_24dp" />
                        <SeekBar
                <com.google.android.material.slider.Slider
                    android:id="@+id/input_setting_keys_value_custom_slider"
                            style="@android:style/Widget.Material.SeekBar"
                            android:min="1"
                            android:max="50"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:valueFrom="0.1"
                    android:valueTo="5"
                    android:stepSize="0.1"
                    android:layout_gravity="center_vertical"
                            android:layout_marginTop="8dp" />
                        <ImageView
                            android:layout_marginTop="8dp"
                            android:layout_width="16dp"
                            android:layout_height="16dp"
                            android:tint="@androidprv:color/materialColorPrimary"
                            android:importantForAccessibility="no"
                            android:src="@drawable/ic_add_24dp" />
                    </LinearLayout>
                </LinearLayout>
                    android:theme="@style/Theme.Material3.DynamicColors.DayNight"
                    app:tickVisible="false"
                    app:labelBehavior="gone"
                    />
            </LinearLayout>
        </RadioGroup>

+27 −38
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.settings.inputmethod;
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -28,22 +27,23 @@ import android.view.Window;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;

import com.google.android.material.slider.Slider;

import org.jspecify.annotations.Nullable;

import java.util.Locale;
import java.util.concurrent.TimeUnit;

public abstract class KeyboardAccessibilityKeysDialogFragment extends DialogFragment {
    private static final int CUSTOM_PROGRESS_INTERVAL = 100;
    private static final long MILLISECOND_IN_SECONDS = TimeUnit.SECONDS.toMillis(1);
    protected static final String EXTRA_TITLE_RES = "extra_title_res";
    protected static final String EXTRA_SUBTITLE_RES = "extra_subtitle_res";
@@ -74,23 +74,23 @@ public abstract class KeyboardAccessibilityKeysDialogFragment extends DialogFrag
        int seekbarContentDescriptionRes = getArguments().getInt(EXTRA_SEEKBAR_CONTENT_DESCRIPTION);

        Activity activity = getActivity();
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
        View dialoglayout =
                LayoutInflater.from(activity).inflate(
                LayoutInflater.from(/*dialogBuilder.getContext()*/activity).inflate(
                        R.layout.dialog_keyboard_a11y_input_setting_keys, null);
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
        dialogBuilder.setView(dialoglayout);
        Button doneButton = dialoglayout.findViewById(R.id.done_button);
        doneButton.setOnClickListener(v -> {
            RadioGroup radioGroup =
                    dialoglayout.findViewById(
                            R.id.input_setting_keys_value_group);
            SeekBar seekbar = dialoglayout.findViewById(
            Slider slider = dialoglayout.findViewById(
                    R.id.input_setting_keys_value_custom_slider);
            RadioButton customRadioButton = dialoglayout.findViewById(
                    R.id.input_setting_keys_value_custom);
            int threshold;
            if (customRadioButton.isChecked()) {
                threshold = seekbar.getProgress() * CUSTOM_PROGRESS_INTERVAL;
                threshold = (int) (slider.getValue() * MILLISECOND_IN_SECONDS);
            } else {
                int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
                if (checkedRadioButtonId == R.id.input_setting_keys_value_600) {
@@ -124,7 +124,7 @@ public abstract class KeyboardAccessibilityKeysDialogFragment extends DialogFrag
                    R.id.input_setting_keys_value_custom_value);
            View seekbarView = accessibilityKeyDialog.findViewById(
                    R.id.input_setting_keys_custom_seekbar_layout);
            SeekBar customProgressBar = accessibilityKeyDialog.findViewById(
            Slider customProgressSlider = accessibilityKeyDialog.findViewById(
                    R.id.input_setting_keys_value_custom_slider);
            TextView titleTextView = accessibilityKeyDialog.findViewById(
                    R.id.input_setting_keys_dialog_title);
@@ -134,11 +134,9 @@ public abstract class KeyboardAccessibilityKeysDialogFragment extends DialogFrag
            subTitleTextView.setText(subtitleRes);

            if (seekbarContentDescriptionRes != 0) {
                customProgressBar.setContentDescription(
                        getContext().getString(seekbarContentDescriptionRes));
                customProgressSlider.setContentDescription(
                        activity.getString(seekbarContentDescriptionRes));
            }
            customProgressBar.incrementProgressBy(CUSTOM_PROGRESS_INTERVAL);
            customProgressBar.setProgress(1);
            View customValueView = accessibilityKeyDialog.findViewById(
                    R.id.input_setting_keys_custom_value_option);
            customValueView.setOnClickListener(l -> customRadioButton.performClick());
@@ -148,27 +146,17 @@ public abstract class KeyboardAccessibilityKeysDialogFragment extends DialogFrag
                }
                customValueTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
                customValueTextView.setText(
                        progressToThresholdInSecond(customProgressBar.getProgress()));
                        progressToThresholdInSecond(customProgressSlider.getValue()));
                seekbarView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
                buttonView.setChecked(isChecked);
            });
            cannedValueRadioGroup.setOnCheckedChangeListener(
                    (group, checkedId) -> customRadioButton.setChecked(false));
            customProgressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    String threshold = progressToThresholdInSecond(progress);
                    customValueTextView.setText(threshold);
                    customProgressBar.setContentDescription(threshold);
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            customProgressSlider.clearOnChangeListeners();
            customProgressSlider.addOnChangeListener((slider, v, b) -> {
                String thresholdInSecond = progressToThresholdInSecond(v);
                customValueTextView.setText(thresholdInSecond);
                customProgressSlider.setContentDescription(thresholdInSecond);
            });
            if (cannedValueRadioGroup.getCheckedRadioButtonId() == -1
                    && !customRadioButton.isChecked()) {
@@ -176,13 +164,13 @@ public abstract class KeyboardAccessibilityKeysDialogFragment extends DialogFrag
                // setting
                initStateBasedOnThreshold(cannedValueRadioGroup, customRadioButton,
                        customValueTextView,
                        customProgressBar, seekbarView);
                        customProgressSlider, seekbarView);
            } else if (customRadioButton.isChecked()) {
                cannedValueRadioGroup.clearCheck();
                customRadioButton.setChecked(true);
                customValueTextView.setVisibility(View.VISIBLE);
                customValueTextView.setText(
                        progressToThresholdInSecond(customProgressBar.getProgress()));
                        progressToThresholdInSecond(customProgressSlider.getValue()));
                seekbarView.setVisibility(View.VISIBLE);
            }
        });
@@ -193,25 +181,26 @@ public abstract class KeyboardAccessibilityKeysDialogFragment extends DialogFrag
        return accessibilityKeyDialog;
    }

    private String progressToThresholdInSecond(int progress) {
        return (double) progress * CUSTOM_PROGRESS_INTERVAL
                / MILLISECOND_IN_SECONDS + " " + TimeUnit.SECONDS.name().toLowerCase(
                Locale.getDefault());
    private String progressToThresholdInSecond(float progress) {
        return String.format(Locale.getDefault(), "%.1f %s", progress,
                TimeUnit.SECONDS.name().toLowerCase(
                        Locale.getDefault()));
    }

    private void initStateBasedOnThreshold(RadioGroup cannedValueRadioGroup,
            RadioButton customRadioButton, TextView customValueTextView,
            SeekBar customProgressBar, View seekbarView) {
            Slider customProgressSlider, View seekbarView) {
        int inputSettingKeysThreshold = getInputSettingKeysValue();
        switch (inputSettingKeysThreshold) {
            case 600 -> cannedValueRadioGroup.check(R.id.input_setting_keys_value_600);
            case 400 -> cannedValueRadioGroup.check(R.id.input_setting_keys_value_400);
            case 0, 200 -> cannedValueRadioGroup.check(R.id.input_setting_keys_value_200);
            default -> {
                float thresholdInSecond =
                        (float) inputSettingKeysThreshold / MILLISECOND_IN_SECONDS;
                customValueTextView.setText(
                        String.valueOf(
                                (double) inputSettingKeysThreshold / MILLISECOND_IN_SECONDS));
                customProgressBar.setProgress(inputSettingKeysThreshold / CUSTOM_PROGRESS_INTERVAL);
                        progressToThresholdInSecond(thresholdInSecond));
                customProgressSlider.setValue(thresholdInSecond);
                customRadioButton.setChecked(true);
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -21,12 +21,12 @@ import static com.android.settings.inputmethod.KeyboardAccessibilityKeysDialogFr

import static com.google.common.truth.Truth.assertThat;

import android.app.AlertDialog;
import android.hardware.input.InputSettings;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RadioGroup;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.testing.FragmentScenario;
import androidx.lifecycle.Lifecycle;
import androidx.test.core.app.ApplicationProvider;
+1 −1
Original line number Diff line number Diff line
@@ -21,12 +21,12 @@ import static com.android.settings.inputmethod.KeyboardAccessibilityKeysDialogFr

import static com.google.common.truth.Truth.assertThat;

import android.app.AlertDialog;
import android.hardware.input.InputSettings;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RadioGroup;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.testing.FragmentScenario;
import androidx.lifecycle.Lifecycle;
import androidx.test.core.app.ApplicationProvider;