@Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference instanceof ListPreference && newValue instanceof String) { final ListPreference listPreference = (ListPreference) preference; final int index = listPreference.findIndexOfValue((String) newValue); final CharSequence[] entries = listPreference.getEntries(); if (index >= 0 && index < entries.length) { preference.setSummary(entries[index].toString().replaceAll("%", "%%")); } else { preference.setSummary(""); } } final String key = preference.getKey(); if (getString(R.string.pref_resume_talkback_key).equals(key)) { final String oldValue = SharedPreferencesUtils.getStringPref( mPrefs, getResources(), R.string.pref_resume_talkback_key, R.string.pref_resume_talkback_default); if (!newValue.equals(oldValue)) { // Reset the suspend warning dialog when the resume // preference changes. SharedPreferencesUtils.putBooleanPref( mPrefs, getResources(), R.string.pref_show_suspension_confirmation_dialog, true); } } return true; }
/** * Updates the preference that controls whether TalkBack will attempt to request Explore by Touch. * * @param requestedState The state requested by the user. * @return Whether to update the reflected state. */ private boolean setTouchExplorationRequested(boolean requestedState) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(TalkBackPreferencesActivity.this); // Update the "requested" state. This will trigger a listener in // TalkBack that changes the "actual" state. SharedPreferencesUtils.putBooleanPref( prefs, getResources(), R.string.pref_explore_by_touch_key, requestedState); // If TalkBack is inactive, we should immediately reflect the change in // "requested" state. if (!MyAccessibilityService.isServiceActive()) { return true; } if (requestedState && MyAccessibilityService.getInstance() != null) { // TODO // MyAccessibilityService.getInstance().showTutorial(); } // If accessibility is on, we should wait for the "actual" state to // change, then reflect that change. If the user declines the system's // touch exploration dialog, the "actual" state will not change and // nothing needs to happen. LogUtils.log(this, Log.DEBUG, "TalkBack active, waiting for EBT request to take effect"); return false; }
/** * Updates the preferences state to match the actual state of touch exploration. This is called * once when the preferences activity launches and again whenever the actual state of touch * exploration changes. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void updateTouchExplorationState() { final CheckBoxPreference prefTouchExploration = (CheckBoxPreference) findPreferenceByResId(R.string.pref_explore_by_touch_reflect_key); if (prefTouchExploration == null) { return; } final ContentResolver resolver = getContentResolver(); final Resources res = getResources(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final boolean requestedState = SharedPreferencesUtils.getBooleanPref( prefs, res, R.string.pref_explore_by_touch_key, R.bool.pref_explore_by_touch_default); final boolean reflectedState = prefTouchExploration.isChecked(); final boolean actualState; // If accessibility is disabled then touch exploration is always // disabled, so the "actual" state should just be the requested state. if (MyAccessibilityService.isServiceActive()) { actualState = isTouchExplorationEnabled(resolver); } else { actualState = requestedState; } // If touch exploration is actually off and we requested it on, the user // must have declined the "Enable touch exploration" dialog. Update the // requested value to reflect this. if (requestedState != actualState) { LogUtils.log( this, Log.DEBUG, "Set touch exploration preference to reflect actual state %b", actualState); SharedPreferencesUtils.putBooleanPref( prefs, res, R.string.pref_explore_by_touch_key, actualState); } // Ensure that the check box preference reflects the requested state, // which was just synchronized to match the actual state. if (reflectedState != actualState) { prefTouchExploration.setChecked(actualState); } }
/** @return the current auto scan time delay that is selected in the preferences */ private int getAutoScanDelay() { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); return (int) (MILLISECONDS_PER_SECOND * SharedPreferencesUtils.getFloatFromStringPref( prefs, mContext.getResources(), R.string.pref_key_auto_scan_time_delay, R.string.pref_auto_scan_time_delay_default_value)); }