Support autoclick secondary action (1/n)
Added radio button preference and control to handle user update value. Bug: 146019277 Test: Manual Change-Id: Ie9136f942eec43fc378e7f39d8c2eb7534c531c9
This commit is contained in:
@@ -702,6 +702,24 @@
|
||||
<item>Accessibility volume</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Keys for the list of accessibility auto click xml. -->
|
||||
<string-array name="accessibility_autoclick_control_selector_keys" translatable="false">
|
||||
<item>accessibility_control_autoclick_default</item>
|
||||
<item>accessibility_control_autoclick_200ms</item>
|
||||
<item>accessibility_control_autoclick_600ms</item>
|
||||
<item>accessibility_control_autoclick_1sec</item>
|
||||
<item>accessibility_control_autoclick_custom</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Values for the list of accessibility auto click, pairs to Keys . -->
|
||||
<integer-array name="accessibility_autoclick_selector_values" translatable="false">
|
||||
<item>0</item>
|
||||
<item>200</item>
|
||||
<item>600</item>
|
||||
<item>1000</item>
|
||||
<item>2000</item>
|
||||
</integer-array>
|
||||
|
||||
<!-- Keys for the list of accessibility timeouts xml. -->
|
||||
<string-array name="accessibility_timeout_control_selector_keys" translatable="false">
|
||||
<item>accessibility_control_timeout_default</item>
|
||||
|
@@ -4919,11 +4919,25 @@
|
||||
<!-- Subtitle for the accessibility preference to configure display color inversion. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_display_inversion_preference_subtitle">Turn light screens dark so people who are sensitive to bright light can have a better viewing experience.\n\nNote: dark colors will turn light. Images will also be inverted.</string>
|
||||
<!-- Title for accessibility preference for configuring feature that performs click action soon after mouse/trackpad pointer stops moving. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_autoclick_preference_title">Dwell timing</string>
|
||||
<string name="accessibility_autoclick_preference_title">Auto click (dwell timing)</string>
|
||||
<!-- Footer text to explain what autoclick does -->
|
||||
<string name="accessibility_autoclick_description">If you are using a mouse, you can set the cursor to take action automatically when it stops moving for a certain amount of time.</string>
|
||||
<!-- Title for accessibility preference for configuring amount of time that has to pass after pointer stops moving before click action can be performed (if automatic click after pointer stops moving feature is enabled). [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_autoclick_delay_preference_title">Delay before click</string>
|
||||
<!-- Option heading to leave the auto click requirement for accessibility users at its default level. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_autoclick_default_title">None</string>
|
||||
<!-- Option heading to leave the auto click requirement for accessibility users at its short level. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_autoclick_short_title">Short</string>
|
||||
<!-- Option summary text for the auto click delay 0.2 seconds radio button. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_autoclick_short_summary">0.2 seconds</string>
|
||||
<!-- Option heading to leave the auto click requirement for accessibility users at its medium level. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_autoclick_medium_title">Medium</string>
|
||||
<!-- Option summary text for the auto click delay 0.6 seconds radio button. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_autoclick_medium_summary">0.6 seconds</string>
|
||||
<!-- Option heading to leave the auto click requirement for accessibility users at its long level. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_autoclick_long_title">Long</string>
|
||||
<!-- Option summary text for the auto click delay 1 second radio button. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_autoclick_long_summary">1 second</string>
|
||||
<!-- Option heading to leave the auto click requirement for accessibility users at its custom level. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_autoclick_custom_title">Custom</string>
|
||||
<!-- Title for accessibility preference screen for configuring vibrations. -->
|
||||
<string name="accessibility_vibration_settings_title">Vibration & haptic strength</string>
|
||||
<!-- Title for accessibility preference for configuring notification vibrations. -->
|
||||
|
@@ -20,14 +20,37 @@
|
||||
android:key="autoclick_preference_screen"
|
||||
android:title="@string/accessibility_autoclick_preference_title">
|
||||
|
||||
<com.android.settingslib.widget.RadioButtonPreference
|
||||
android:key="accessibility_control_autoclick_default"
|
||||
android:title="@string/accessibility_autoclick_default_title"
|
||||
settings:allowDividerAbove="true" />
|
||||
|
||||
<com.android.settingslib.widget.RadioButtonPreference
|
||||
android:key="accessibility_control_autoclick_200ms"
|
||||
android:title="@string/accessibility_autoclick_short_title"
|
||||
android:summary="@string/accessibility_autoclick_short_summary" />
|
||||
|
||||
<com.android.settingslib.widget.RadioButtonPreference
|
||||
android:key="accessibility_control_autoclick_600ms"
|
||||
android:title="@string/accessibility_autoclick_medium_title"
|
||||
android:summary="@string/accessibility_autoclick_medium_summary" />
|
||||
|
||||
<com.android.settingslib.widget.RadioButtonPreference
|
||||
android:key="accessibility_control_autoclick_1sec"
|
||||
android:title="@string/accessibility_autoclick_long_title"
|
||||
android:summary="@string/accessibility_autoclick_long_summary" />
|
||||
|
||||
<com.android.settingslib.widget.RadioButtonPreference
|
||||
android:key="accessibility_control_autoclick_custom"
|
||||
android:title="@string/accessibility_autoclick_custom_title" />
|
||||
|
||||
<com.android.settings.widget.SeekBarPreference
|
||||
android:key="autoclick_delay"
|
||||
android:title="@string/accessibility_autoclick_delay_preference_title" />
|
||||
android:key="autoclick_delay" />
|
||||
|
||||
<com.android.settingslib.widget.FooterPreference
|
||||
android:key="autoclick_footer"
|
||||
android:title="@string/accessibility_autoclick_description"
|
||||
android:selectable="false"
|
||||
settings:searchable="false"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
import android.util.ArrayMap;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.widget.SeekBarPreference;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.widget.RadioButtonPreference;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Controller class that controls accessibility autoclick settings.
|
||||
*/
|
||||
public class ToggleAutoclickPreferenceController extends BasePreferenceController implements
|
||||
LifecycleObserver, RadioButtonPreference.OnClickListener, PreferenceControllerMixin,
|
||||
Preference.OnPreferenceChangeListener {
|
||||
// Min allowed autoclick delay value.
|
||||
static final int MIN_AUTOCLICK_DELAY_MS = 200;
|
||||
|
||||
// Max allowed autoclick delay value.
|
||||
static final int MAX_AUTOCLICK_DELAY_MS = 1000;
|
||||
|
||||
private static final String CONTROL_AUTOCLICK_DELAY_SECURE =
|
||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY;
|
||||
private static final String KEY_AUTOCLICK_DELA = "autoclick_delay";
|
||||
private static final String KEY_CUSTOM_DELAY_VALUE = "custom_delay_value";
|
||||
private static final String KEY_DELAY_MODE = "delay_mode";
|
||||
|
||||
// Allowed autoclick delay values are discrete.
|
||||
// This is the difference between two allowed values.
|
||||
private static final int AUTOCLICK_DELAY_STEP = 100;
|
||||
private static final int AUTOCLICK_OFF_MODE = 0;
|
||||
private static final int AUTOCLICK_CUSTOM_MODE = 2000;
|
||||
|
||||
// Pair the preference key and autoclick mode value.
|
||||
private final Map<String, Integer> mAccessibilityAutoclickKeyToValueMap = new ArrayMap<>();
|
||||
|
||||
private SharedPreferences mSharedPreferences;
|
||||
private final ContentResolver mContentResolver;
|
||||
private final Resources mResources;
|
||||
private OnChangeListener mOnChangeListener;
|
||||
private RadioButtonPreference mDelayModePref;
|
||||
|
||||
/**
|
||||
* Seek bar preference for autoclick delay value. The seek bar has values between 0 and
|
||||
* number of possible discrete autoclick delay values. These will have to be converted to actual
|
||||
* delay values before saving them in settings.
|
||||
*/
|
||||
private SeekBarPreference mCustomDelayPref;
|
||||
private int mCurrentUiAutoClickMode;
|
||||
|
||||
public ToggleAutoclickPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
|
||||
mSharedPreferences = context.getSharedPreferences(context.getPackageName(), MODE_PRIVATE);
|
||||
mContentResolver = context.getContentResolver();
|
||||
mResources = context.getResources();
|
||||
|
||||
setAutoclickModeToKeyMap();
|
||||
}
|
||||
|
||||
public ToggleAutoclickPreferenceController(Context context, Lifecycle lifecycle,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
|
||||
mSharedPreferences = context.getSharedPreferences(context.getPackageName(), MODE_PRIVATE);
|
||||
mContentResolver = context.getContentResolver();
|
||||
mResources = context.getResources();
|
||||
|
||||
setAutoclickModeToKeyMap();
|
||||
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnChangeListener(OnChangeListener listener) {
|
||||
mOnChangeListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mDelayModePref = (RadioButtonPreference)
|
||||
screen.findPreference(getPreferenceKey());
|
||||
mDelayModePref.setOnClickListener(this);
|
||||
|
||||
int delay = getSharedPreferenceForDelayValue();
|
||||
|
||||
// Initialize seek bar preference. Sets seek bar size to the number of possible delay
|
||||
// values.
|
||||
mCustomDelayPref = (SeekBarPreference) screen.findPreference(KEY_AUTOCLICK_DELA);
|
||||
mCustomDelayPref.setMax(delayToSeekBarProgress(MAX_AUTOCLICK_DELAY_MS));
|
||||
mCustomDelayPref.setProgress(delayToSeekBarProgress(delay));
|
||||
mCustomDelayPref.setOnPreferenceChangeListener(this);
|
||||
|
||||
updateState((Preference) mDelayModePref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRadioButtonClicked(RadioButtonPreference preference) {
|
||||
int value = mAccessibilityAutoclickKeyToValueMap.get(mPreferenceKey);
|
||||
handleRadioButtonPreferenceChange(value);
|
||||
if (mOnChangeListener != null) {
|
||||
mOnChangeListener.onCheckedChanged(mDelayModePref);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePreferenceCheckedState(int mode) {
|
||||
if (mCurrentUiAutoClickMode == mode) {
|
||||
mDelayModePref.setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePreferenceVisibleState(int mode) {
|
||||
mCustomDelayPref.setVisible(mCurrentUiAutoClickMode == mode);
|
||||
}
|
||||
|
||||
private void updateSeekBarProgressState() {
|
||||
if (mCurrentUiAutoClickMode == AUTOCLICK_CUSTOM_MODE) {
|
||||
int delay = getSharedPreferenceForDelayValue();
|
||||
mCustomDelayPref.setProgress(delayToSeekBarProgress(delay));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
mCurrentUiAutoClickMode = getSharedPreferenceForAutoClickMode();
|
||||
|
||||
// Reset RadioButton.
|
||||
mDelayModePref.setChecked(false);
|
||||
int mode = mAccessibilityAutoclickKeyToValueMap.get(mDelayModePref.getKey());
|
||||
updateSeekBarProgressState();
|
||||
updatePreferenceCheckedState(mode);
|
||||
updatePreferenceVisibleState(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (preference == mCustomDelayPref && newValue instanceof Integer) {
|
||||
putSecureInt(CONTROL_AUTOCLICK_DELAY_SECURE, seekBarProgressToDelay((int) newValue));
|
||||
mSharedPreferences.edit().putInt(KEY_CUSTOM_DELAY_VALUE,
|
||||
seekBarProgressToDelay((int) newValue)).apply();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Listener interface handles checked event. */
|
||||
public interface OnChangeListener {
|
||||
/**
|
||||
* A hook that is called when preference checked.
|
||||
*/
|
||||
void onCheckedChanged(Preference preference);
|
||||
}
|
||||
|
||||
private void setAutoclickModeToKeyMap() {
|
||||
String[] autoclickKeys = mResources.getStringArray(
|
||||
R.array.accessibility_autoclick_control_selector_keys);
|
||||
|
||||
int[] autoclickValues = mResources.getIntArray(
|
||||
R.array.accessibility_autoclick_selector_values);
|
||||
|
||||
final int autoclickValueCount = autoclickValues.length;
|
||||
for (int i = 0; i < autoclickValueCount; i++) {
|
||||
mAccessibilityAutoclickKeyToValueMap.put(autoclickKeys[i], autoclickValues[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRadioButtonPreferenceChange(int preference) {
|
||||
if (preference == AUTOCLICK_OFF_MODE) {
|
||||
putSecureInt(Settings.Secure.ACCESSIBILITY_AUTOCLICK_ENABLED, /*value= */ 0);
|
||||
} else {
|
||||
putSecureInt(Settings.Secure.ACCESSIBILITY_AUTOCLICK_ENABLED, /*value= */ 1);
|
||||
}
|
||||
|
||||
mSharedPreferences.edit().putInt(KEY_DELAY_MODE, preference).apply();
|
||||
|
||||
if (preference == AUTOCLICK_CUSTOM_MODE) {
|
||||
putSecureInt(CONTROL_AUTOCLICK_DELAY_SECURE, getSharedPreferenceForDelayValue());
|
||||
} else {
|
||||
putSecureInt(CONTROL_AUTOCLICK_DELAY_SECURE, preference);
|
||||
}
|
||||
}
|
||||
|
||||
/** Converts seek bar preference progress value to autoclick delay associated with it. */
|
||||
private int seekBarProgressToDelay(int progress) {
|
||||
return progress * AUTOCLICK_DELAY_STEP + MIN_AUTOCLICK_DELAY_MS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts autoclick delay value to seek bar preference progress values that represents said
|
||||
* delay.
|
||||
*/
|
||||
private int delayToSeekBarProgress(int delay) {
|
||||
return (delay - MIN_AUTOCLICK_DELAY_MS) / AUTOCLICK_DELAY_STEP;
|
||||
}
|
||||
|
||||
private void putSecureInt(String name, int value) {
|
||||
Settings.Secure.putInt(mContentResolver, name, value);
|
||||
}
|
||||
|
||||
private int getSharedPreferenceForDelayValue() {
|
||||
int mode = mSharedPreferences.getInt(KEY_DELAY_MODE, AUTOCLICK_OFF_MODE);
|
||||
int delay = mSharedPreferences.getInt(KEY_CUSTOM_DELAY_VALUE,
|
||||
AccessibilityManager.AUTOCLICK_DELAY_DEFAULT);
|
||||
|
||||
return mode == AUTOCLICK_CUSTOM_MODE ? delay : mode;
|
||||
}
|
||||
|
||||
private int getSharedPreferenceForAutoClickMode() {
|
||||
return mSharedPreferences.getInt(KEY_DELAY_MODE, AUTOCLICK_OFF_MODE);
|
||||
}
|
||||
}
|
@@ -16,22 +16,20 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.ToggleAutoclickPreferenceController.MAX_AUTOCLICK_DELAY_MS;
|
||||
import static com.android.settings.accessibility.ToggleAutoclickPreferenceController.MIN_AUTOCLICK_DELAY_MS;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
import android.widget.Switch;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settings.widget.SeekBarPreference;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -42,18 +40,11 @@ import java.util.List;
|
||||
* feature.
|
||||
*/
|
||||
@SearchIndexable
|
||||
public class ToggleAutoclickPreferenceFragment extends ToggleFeaturePreferenceFragment
|
||||
implements SwitchBar.OnSwitchChangeListener, Preference.OnPreferenceChangeListener {
|
||||
public class ToggleAutoclickPreferenceFragment extends DashboardFragment
|
||||
implements ToggleAutoclickPreferenceController.OnChangeListener {
|
||||
|
||||
/** Min allowed autoclick delay value. */
|
||||
private static final int MIN_AUTOCLICK_DELAY = 200;
|
||||
/** Max allowed autoclick delay value. */
|
||||
private static final int MAX_AUTOCLICK_DELAY = 1000;
|
||||
/**
|
||||
* Allowed autoclick delay values are discrete. This is the difference between two allowed
|
||||
* values.
|
||||
*/
|
||||
private static final int AUTOCLICK_DELAY_STEP = 100;
|
||||
private static final String TAG = "AutoclickPrefFragment";
|
||||
private static final List<AbstractPreferenceController> sControllers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Resource ids from which autoclick preference summaries should be derived. The strings have
|
||||
@@ -67,13 +58,6 @@ public class ToggleAutoclickPreferenceFragment extends ToggleFeaturePreferenceFr
|
||||
R.plurals.accessibilty_autoclick_preference_subtitle_very_long_delay
|
||||
};
|
||||
|
||||
/**
|
||||
* Seek bar preference for autoclick delay value. The seek bar has values between 0 and
|
||||
* number of possible discrete autoclick delay values. These will have to be converted to actual
|
||||
* delay values before saving them in settings.
|
||||
*/
|
||||
private SeekBarPreference mDelay;
|
||||
|
||||
/**
|
||||
* Gets string that should be used as a autoclick preference summary for provided autoclick
|
||||
* delay.
|
||||
@@ -91,21 +75,15 @@ public class ToggleAutoclickPreferenceFragment extends ToggleFeaturePreferenceFr
|
||||
* Finds index of the summary that should be used for the provided autoclick delay.
|
||||
*/
|
||||
private static int getAutoclickPreferenceSummaryIndex(int delay) {
|
||||
if (delay <= MIN_AUTOCLICK_DELAY) {
|
||||
if (delay <= MIN_AUTOCLICK_DELAY_MS) {
|
||||
return 0;
|
||||
}
|
||||
if (delay >= MAX_AUTOCLICK_DELAY) {
|
||||
if (delay >= MAX_AUTOCLICK_DELAY_MS) {
|
||||
return mAutoclickPreferenceSummaries.length - 1;
|
||||
}
|
||||
int rangeSize = (MAX_AUTOCLICK_DELAY - MIN_AUTOCLICK_DELAY) /
|
||||
(mAutoclickPreferenceSummaries.length - 1);
|
||||
return (delay - MIN_AUTOCLICK_DELAY) / rangeSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||
Settings.Secure.putInt(getContentResolver(), preferenceKey, enabled ? 1 : 0);
|
||||
mDelay.setEnabled(enabled);
|
||||
int delayRange = MAX_AUTOCLICK_DELAY_MS - MIN_AUTOCLICK_DELAY_MS;
|
||||
int rangeSize = (delayRange) / (mAutoclickPreferenceSummaries.length - 1);
|
||||
return (delay - MIN_AUTOCLICK_DELAY_MS) / rangeSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,82 +96,68 @@ public class ToggleAutoclickPreferenceFragment extends ToggleFeaturePreferenceFr
|
||||
return R.string.help_url_autoclick;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.accessibility_autoclick_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
int delay = Settings.Secure.getInt(
|
||||
getContentResolver(), Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY,
|
||||
AccessibilityManager.AUTOCLICK_DELAY_DEFAULT);
|
||||
|
||||
// Initialize seek bar preference. Sets seek bar size to the number of possible delay
|
||||
// values.
|
||||
mDelay = (SeekBarPreference) findPreference("autoclick_delay");
|
||||
mDelay.setMax(delayToSeekBarProgress(MAX_AUTOCLICK_DELAY));
|
||||
mDelay.setProgress(delayToSeekBarProgress(delay));
|
||||
mDelay.setOnPreferenceChangeListener(this);
|
||||
for (AbstractPreferenceController controller : sControllers) {
|
||||
((ToggleAutoclickPreferenceController) controller).setOnChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInstallSwitchBarToggleSwitch() {
|
||||
super.onInstallSwitchBarToggleSwitch();
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
int value = Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_ENABLED, 0);
|
||||
mSwitchBar.setCheckedInternal(value == 1);
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mDelay.setEnabled(value == 1);
|
||||
for (AbstractPreferenceController controller : sControllers) {
|
||||
((ToggleAutoclickPreferenceController) controller).setOnChangeListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRemoveSwitchBarToggleSwitch() {
|
||||
super.onRemoveSwitchBarToggleSwitch();
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
public void onCheckedChanged(Preference preference) {
|
||||
for (AbstractPreferenceController controller : sControllers) {
|
||||
controller.updateState(preference);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
onPreferenceToggled(Settings.Secure.ACCESSIBILITY_AUTOCLICK_ENABLED, isChecked);
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context, getSettingsLifecycle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (preference == mDelay && newValue instanceof Integer) {
|
||||
Settings.Secure.putInt(getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY,
|
||||
seekBarProgressToDelay((int) newValue));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
Resources resources = context.getResources();
|
||||
|
||||
@Override
|
||||
protected void updateSwitchBarText(SwitchBar switchBar) {
|
||||
final String switchBarText = getString(R.string.accessibility_service_master_switch_title,
|
||||
getString(R.string.accessibility_autoclick_preference_title));
|
||||
switchBar.setSwitchBarText(switchBarText, switchBarText);
|
||||
}
|
||||
String[] autoclickKeys = resources.getStringArray(
|
||||
R.array.accessibility_autoclick_control_selector_keys);
|
||||
|
||||
/**
|
||||
* Converts seek bar preference progress value to autoclick delay associated with it.
|
||||
*/
|
||||
private int seekBarProgressToDelay(int progress) {
|
||||
return progress * AUTOCLICK_DELAY_STEP + MIN_AUTOCLICK_DELAY;
|
||||
final int length = autoclickKeys.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
sControllers.add(new ToggleAutoclickPreferenceController(
|
||||
context, lifecycle, autoclickKeys[i]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts autoclick delay value to seek bar preference progress values that represents said
|
||||
* delay.
|
||||
*/
|
||||
private int delayToSeekBarProgress(int delay) {
|
||||
return (delay - MIN_AUTOCLICK_DELAY) / AUTOCLICK_DELAY_STEP;
|
||||
return sControllers;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.accessibility_autoclick_settings);
|
||||
new BaseSearchIndexProvider(R.xml.accessibility_autoclick_settings) {
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||
Context context) {
|
||||
return buildPreferenceControllers(context, null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user