From 76be5e352a92495805c42894fd2ee9860fcd2b30 Mon Sep 17 00:00:00 2001 From: Toni Barzic Date: Tue, 18 Aug 2015 10:30:08 -0700 Subject: [PATCH] Add a11y setting for Automatically click after pointer stops Adds new preference screen for the feature, where the feature can be enabled/disabled, and delay before click can be specified (implemented as seek bar preference, enabled iff the feature is enabled). Preference is added to Accessibility setting. The preference summary is set to string describing the delay after pointer stops moving before click is scheduled (the string also contains numerical value of the delay). BUG=20049245 Change-Id: Ib7b2f5c24efbd08e3200143c069bcdbc9b5a327a --- res/layout/preference_iconless_slider.xml | 55 ++++++ res/values/strings.xml | 25 +++ res/xml/accessibility_autoclick_settings.xml | 26 +++ res/xml/accessibility_settings.xml | 5 + .../settings/InstrumentedFragment.java | 2 + .../accessibility/AccessibilitySettings.java | 23 +++ .../ToggleAutoclickPreferenceFragment.java | 179 ++++++++++++++++++ 7 files changed, 315 insertions(+) create mode 100644 res/layout/preference_iconless_slider.xml create mode 100644 res/xml/accessibility_autoclick_settings.xml create mode 100644 src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java diff --git a/res/layout/preference_iconless_slider.xml b/res/layout/preference_iconless_slider.xml new file mode 100644 index 00000000000..8e2b8f37d85 --- /dev/null +++ b/res/layout/preference_iconless_slider.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 143792ff07b..90b39f67613 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3816,6 +3816,10 @@ Color correction This feature is experimental and may affect performance. + + Click after pointer stops moving + + Delay before click Show in Quick Settings @@ -3835,6 +3839,27 @@ Tritanomaly (blue-yellow) + + + Extremely short delay (%1$d ms) + + + + Very short delay (%1$d ms) + + + + Short delay (%1$d ms) + + + + Long delay (%1$d ms) + + + + Very long delay (%1$d ms) + + Settings diff --git a/res/xml/accessibility_autoclick_settings.xml b/res/xml/accessibility_autoclick_settings.xml new file mode 100644 index 00000000000..1eb4dc190de --- /dev/null +++ b/res/xml/accessibility_autoclick_settings.xml @@ -0,0 +1,26 @@ + + + + + + + + + diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml index cd9d471fe5c..881037d7747 100644 --- a/res/xml/accessibility_settings.xml +++ b/res/xml/accessibility_settings.xml @@ -37,6 +37,11 @@ android:key="screen_magnification_preference_screen" android:title="@string/accessibility_screen_magnification_title"/> + + = MAX_AUTOCLICK_DELAY) { + 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); + } + + @Override + protected int getMetricsCategory() { + return InstrumentedFragment.ACCESSIBILITY_TOGGLE_AUTOCLICK; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.accessibility_autoclick_settings); + + 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); + } + + @Override + protected void onInstallSwitchBarToggleSwitch() { + super.onInstallSwitchBarToggleSwitch(); + + int value = Settings.Secure.getInt(getContentResolver(), + Settings.Secure.ACCESSIBILITY_AUTOCLICK_ENABLED, 0); + mSwitchBar.setCheckedInternal(value == 1); + mSwitchBar.addOnSwitchChangeListener(this); + mDelay.setEnabled(value == 1); + } + + @Override + protected void onRemoveSwitchBarToggleSwitch() { + super.onRemoveSwitchBarToggleSwitch(); + mSwitchBar.removeOnSwitchChangeListener(this); + } + + @Override + public void onSwitchChanged(Switch switchView, boolean isChecked) { + onPreferenceToggled(Settings.Secure.ACCESSIBILITY_AUTOCLICK_ENABLED, isChecked); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + setTitle(getString(R.string.accessibility_autoclick_preference_title)); + } + + @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; + } + + /** + * 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; + } + + /** + * 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; + } +}