Merge "[Physical Keyboard][A11y Page] Add custom slider" into main
This commit is contained in:
@@ -56,28 +56,79 @@
|
|||||||
android:id="@+id/bounce_key_value_200"
|
android:id="@+id/bounce_key_value_200"
|
||||||
android:text="@string/bounce_keys_dialog_option_200"
|
android:text="@string/bounce_keys_dialog_option_200"
|
||||||
android:paddingStart="12dp"
|
android:paddingStart="12dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="start|center_vertical"
|
||||||
android:background="@null"/>
|
android:background="@null"/>
|
||||||
<RadioButton
|
<RadioButton
|
||||||
android:id="@+id/bounce_key_value_400"
|
android:id="@+id/bounce_key_value_400"
|
||||||
android:text="@string/bounce_keys_dialog_option_400"
|
android:text="@string/bounce_keys_dialog_option_400"
|
||||||
android:paddingStart="12dp"
|
android:paddingStart="12dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="start|center_vertical"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="12dp"
|
||||||
android:background="@null"/>
|
android:background="@null"/>
|
||||||
<RadioButton
|
<RadioButton
|
||||||
android:id="@+id/bounce_key_value_600"
|
android:id="@+id/bounce_key_value_600"
|
||||||
android:text="@string/bounce_keys_dialog_option_600"
|
android:text="@string/bounce_keys_dialog_option_600"
|
||||||
android:paddingStart="12dp"
|
android:paddingStart="12dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="start|center_vertical"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="12dp"
|
||||||
android:background="@null"/>
|
android:background="@null"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginVertical="12dp">
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/bounce_key_value_custom"
|
||||||
|
android:paddingStart="12dp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:background="@null"/>
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/custom_value_option"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingEnd="16dp">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/bounce_key_value_custom_title"
|
||||||
|
android:text="Custom"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/bounce_key_value_custom_value"
|
||||||
|
android:text="custom value"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/bounce_key_value_custom_slider"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingEnd="36dp"
|
||||||
|
android:min="1"
|
||||||
|
android:max="50"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:background="@null"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@@ -21,7 +21,11 @@ import android.hardware.input.InputSettings;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -33,9 +37,13 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.PrimarySwitchPreference;
|
import com.android.settingslib.PrimarySwitchPreference;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class KeyboardAccessibilityBounceKeysController extends
|
public class KeyboardAccessibilityBounceKeysController extends
|
||||||
InputSettingPreferenceController implements
|
InputSettingPreferenceController implements
|
||||||
LifecycleObserver {
|
LifecycleObserver {
|
||||||
|
private static final int CUSTOM_PROGRESS_INTERVAL = 100;
|
||||||
|
private static final long MILLISECOND_IN_SECONDS = TimeUnit.SECONDS.toMillis(1);
|
||||||
public static final int BOUNCE_KEYS_THRESHOLD = 500;
|
public static final int BOUNCE_KEYS_THRESHOLD = 500;
|
||||||
|
|
||||||
private AlertDialog mAlertDialog;
|
private AlertDialog mAlertDialog;
|
||||||
@@ -62,7 +70,7 @@ public class KeyboardAccessibilityBounceKeysController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
|
||||||
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -105,23 +113,87 @@ public class KeyboardAccessibilityBounceKeysController extends
|
|||||||
(dialog, which) -> {
|
(dialog, which) -> {
|
||||||
RadioGroup radioGroup =
|
RadioGroup radioGroup =
|
||||||
mAlertDialog.findViewById(R.id.bounce_key_value_group);
|
mAlertDialog.findViewById(R.id.bounce_key_value_group);
|
||||||
int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
|
SeekBar seekbar = mAlertDialog.findViewById(
|
||||||
int threshold = checkedRadioButtonId == R.id.bounce_key_value_600 ? 600
|
R.id.bounce_key_value_custom_slider);
|
||||||
: checkedRadioButtonId == R.id.bounce_key_value_400 ? 400
|
RadioButton customRadioButton = mAlertDialog.findViewById(
|
||||||
: checkedRadioButtonId == R.id.bounce_key_value_200
|
R.id.bounce_key_value_custom);
|
||||||
? 200 : 0;
|
int threshold;
|
||||||
|
if (customRadioButton.isChecked()) {
|
||||||
|
threshold = seekbar.getProgress() * CUSTOM_PROGRESS_INTERVAL;
|
||||||
|
} else {
|
||||||
|
int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
|
||||||
|
threshold = checkedRadioButtonId == R.id.bounce_key_value_600 ? 600
|
||||||
|
: checkedRadioButtonId == R.id.bounce_key_value_400 ? 400
|
||||||
|
: checkedRadioButtonId == R.id.bounce_key_value_200
|
||||||
|
? 200 : 0;
|
||||||
|
}
|
||||||
InputSettings.setAccessibilityBounceKeysThreshold(context, threshold);
|
InputSettings.setAccessibilityBounceKeysThreshold(context, threshold);
|
||||||
})
|
})
|
||||||
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
|
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
|
||||||
.create();
|
.create();
|
||||||
mAlertDialog.setOnShowListener(dialog -> {
|
mAlertDialog.setOnShowListener(dialog -> {
|
||||||
RadioGroup radioGroup = mAlertDialog.findViewById(R.id.bounce_key_value_group);
|
RadioGroup cannedValueRadioGroup = mAlertDialog.findViewById(
|
||||||
int bounceKeysThreshold = InputSettings.getAccessibilityBounceKeysThreshold(context);
|
R.id.bounce_key_value_group);
|
||||||
switch (bounceKeysThreshold) {
|
RadioButton customRadioButton = mAlertDialog.findViewById(R.id.bounce_key_value_custom);
|
||||||
case 600 -> radioGroup.check(R.id.bounce_key_value_600);
|
TextView customValueTextView = mAlertDialog.findViewById(
|
||||||
case 400 -> radioGroup.check(R.id.bounce_key_value_400);
|
R.id.bounce_key_value_custom_value);
|
||||||
default -> radioGroup.check(R.id.bounce_key_value_200);
|
SeekBar customProgressBar = mAlertDialog.findViewById(
|
||||||
}
|
R.id.bounce_key_value_custom_slider);
|
||||||
|
customProgressBar.incrementProgressBy(CUSTOM_PROGRESS_INTERVAL);
|
||||||
|
customProgressBar.setProgress(1);
|
||||||
|
View customValueView = mAlertDialog.findViewById(R.id.custom_value_option);
|
||||||
|
customValueView.setOnClickListener(l -> customRadioButton.performClick());
|
||||||
|
customRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
if (isChecked) {
|
||||||
|
cannedValueRadioGroup.clearCheck();
|
||||||
|
}
|
||||||
|
customValueTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||||
|
customValueTextView.setText(
|
||||||
|
progressToThresholdInSecond(customProgressBar.getProgress()));
|
||||||
|
customProgressBar.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) {
|
||||||
|
customValueTextView.setText(progressToThresholdInSecond(progress));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
initStateBasedOnThreshold(cannedValueRadioGroup, customRadioButton, customValueTextView,
|
||||||
|
customProgressBar);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String progressToThresholdInSecond(int progress) {
|
||||||
|
return String.valueOf((double) progress * CUSTOM_PROGRESS_INTERVAL
|
||||||
|
/ MILLISECOND_IN_SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initStateBasedOnThreshold(RadioGroup cannedValueRadioGroup,
|
||||||
|
RadioButton customRadioButton, TextView customValueTextView,
|
||||||
|
SeekBar customProgressBar) {
|
||||||
|
int bounceKeysThreshold = InputSettings.getAccessibilityBounceKeysThreshold(mContext);
|
||||||
|
switch (bounceKeysThreshold) {
|
||||||
|
case 600 -> cannedValueRadioGroup.check(R.id.bounce_key_value_600);
|
||||||
|
case 400 -> cannedValueRadioGroup.check(R.id.bounce_key_value_400);
|
||||||
|
case 0, 200 -> cannedValueRadioGroup.check(R.id.bounce_key_value_200);
|
||||||
|
default -> {
|
||||||
|
customValueTextView.setText(
|
||||||
|
String.valueOf(
|
||||||
|
(double) bounceKeysThreshold / MILLISECOND_IN_SECONDS));
|
||||||
|
customProgressBar.setProgress(bounceKeysThreshold / CUSTOM_PROGRESS_INTERVAL);
|
||||||
|
customRadioButton.setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user