本文整理汇总了Java中android.preference.TwoStatePreference.setOnPreferenceChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java TwoStatePreference.setOnPreferenceChangeListener方法的具体用法?Java TwoStatePreference.setOnPreferenceChangeListener怎么用?Java TwoStatePreference.setOnPreferenceChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.TwoStatePreference
的用法示例。
在下文中一共展示了TwoStatePreference.setOnPreferenceChangeListener方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initVibrateWhenRinging
import android.preference.TwoStatePreference; //导入方法依赖的package包/类
private void initVibrateWhenRinging(PreferenceCategory root) {
mVibrateWhenRinging = (TwoStatePreference) root.findPreference(KEY_VIBRATE_WHEN_RINGING);
if (mVibrateWhenRinging == null) {
Log.i(TAG, "Preference not found: " + KEY_VIBRATE_WHEN_RINGING);
return;
}
if (!mVoiceCapable || !Utils.isUserOwner()) {
root.removePreference(mVibrateWhenRinging);
mVibrateWhenRinging = null;
return;
}
mVibrateWhenRinging.setPersistent(false);
updateVibrateWhenRinging();
mVibrateWhenRinging.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean val = (Boolean) newValue;
return Settings.System.putInt(getContentResolver(),
Settings.System.VIBRATE_WHEN_RINGING,
val ? 1 : 0);
}
});
}
示例2: checkTouchExplorationSupportInner
import android.preference.TwoStatePreference; //导入方法依赖的package包/类
/**
* Touch exploration preference management code
*
* @param category The touch exploration category.
*/
private void checkTouchExplorationSupportInner(PreferenceGroup category) {
final TwoStatePreference prefTouchExploration =
(TwoStatePreference) findPreferenceByResId(
R.string.pref_explore_by_touch_reflect_key);
if (prefTouchExploration == null) {
return;
}
// Remove single-tap preference if it's not supported on this device.
final TwoStatePreference prefSingleTap = (TwoStatePreference) findPreferenceByResId(
R.string.pref_single_tap_key);
if ((prefSingleTap != null)
&& (Build.VERSION.SDK_INT <
ProcessorFocusAndSingleTap.MIN_API_LEVEL_SINGLE_TAP)) {
category.removePreference(prefSingleTap);
}
// Ensure that changes to the reflected preference's checked state never
// trigger content observers.
prefTouchExploration.setPersistent(false);
// Synchronize the reflected state.
updateTouchExplorationState();
// Set up listeners that will keep the state synchronized.
prefTouchExploration.setOnPreferenceChangeListener(mTouchExplorationChangeListener);
// Hook in the external PreferenceActivity for gesture management
final Preference shortcutsScreen = findPreferenceByResId(
R.string.pref_category_manage_gestures_key);
Activity activity = getActivity();
if (activity != null) {
final Intent shortcutsIntent = new Intent(
activity, TalkBackShortcutPreferencesActivity.class);
shortcutsScreen.setIntent(shortcutsIntent);
}
}
示例3: updateInfoPref
import android.preference.TwoStatePreference; //导入方法依赖的package包/类
private void updateInfoPref(PreferenceCategory category, int index, int helpId, boolean isOn) {
TwoStatePreference pref = (TwoStatePreference) category.getPreference(index);
pref.setChecked(isOn);
pref.setOnPreferenceChangeListener(this);
pref.setIntent(getHelpIntent(helpId));
}
示例4: onCreate
import android.preference.TwoStatePreference; //导入方法依赖的package包/类
/**
* Loads the preferences from the XML preference definition and defines an
* onPreferenceChangeListener
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Activity activity = getActivity();
if (activity == null) {
return;
}
// Set preferences to use device-protected storage.
if (BuildCompat.isAtLeastN()) {
getPreferenceManager().setStorageDeviceProtected();
}
mPrefs = SharedPreferencesUtils.getSharedPreferences(activity);
addPreferencesFromResource(R.xml.preferences);
final TwoStatePreference prefTreeDebug = (TwoStatePreference) findPreferenceByResId(
R.string.pref_tree_debug_reflect_key);
prefTreeDebug.setOnPreferenceChangeListener(mTreeDebugChangeListener);
fixListSummaries(getPreferenceScreen());
assignTtsSettingsIntent();
assignTutorialIntent();
assignLabelManagerIntent();
assignKeyboardShortcutIntent();
assignDumpA11yEventIntent();
checkTelevision();
checkTouchExplorationSupport();
checkWebScriptsSupport();
checkTelephonySupport();
checkVibrationSupport();
checkProximitySupport();
checkAccelerometerSupport();
checkInstalledBacks();
showTalkBackVersion();
updateTalkBackShortcutStatus();
// We should never try to open the play store in WebActivity.
assignPlayStoreIntentToPreference(R.string.pref_play_store_key,
"https://play.google.com/store/apps/details" +
"?id=com.google.android.marvin.talkback");
assignWebIntentToPreference(R.string.pref_policy_key,
"http://www.google.com/policies/privacy/");
assignWebIntentToPreference(R.string.pref_show_tos_key,
"http://www.google.com/mobile/toscountry");
assignFeedbackIntentToPreference(R.string.pref_help_and_feedback_key);
if (TalkBackService.isInArc()) {
hidePreferencesForArc();
}
}
示例5: updateDimingPreferenceStatus
import android.preference.TwoStatePreference; //导入方法依赖的package包/类
private void updateDimingPreferenceStatus() {
final TwoStatePreference dimPreference = (TwoStatePreference) findPreferenceByResId(
R.string.pref_dim_when_talkback_enabled_key);
final TwoStatePreference dimShortcutPreference =
(TwoStatePreference) findPreferenceByResId(
R.string.pref_dim_volume_three_clicks_key);
if (dimPreference == null || dimShortcutPreference == null) {
return;
}
final TalkBackService talkBack = TalkBackService.getInstance();
if (!DimScreenControllerApp.IS_SUPPORTED_PLATFORM) {
final PreferenceGroup category = (PreferenceGroup) findPreferenceByResId(
R.string.pref_category_miscellaneous_key);
if (category == null) {
return;
}
category.removePreference(dimPreference);
category.removePreference(dimShortcutPreference);
return;
}
// Make sure that we have the latest value of the dim preference before continuing.
boolean dimEnabled = SharedPreferencesUtils.getBooleanPref(mPrefs, getResources(),
R.string.pref_dim_when_talkback_enabled_key,
R.bool.pref_dim_when_talkback_enabled_default);
dimPreference.setChecked(dimEnabled);
dimPreference.setEnabled(
TalkBackService.isServiceActive() || dimPreference.isChecked());
dimPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue == null || !(newValue instanceof Boolean)) {
return true;
}
boolean dimPreferenceOn = (Boolean) newValue;
if (dimPreferenceOn) {
if (talkBack != null) {
// A TalkBack instance should be available if you can check the box,
// but let's err on the side of safety here.
talkBack.getDimScreenController().showDimScreenDialog();
}
return false; // The DimScreenController will take care of any pref changes.
} else {
if (talkBack != null) {
// We allow turning off screen dimming when TalkBack is off, so we
// definitely do need to check if a TalkBack instance is available.
talkBack.getDimScreenController().disableDimming();
}
if (!TalkBackService.isServiceActive()) {
dimPreference.setEnabled(false);
}
return true; // Let the preferences system turn the preference off.
}
}
});
}