本文整理汇总了Java中android.support.v14.preference.SwitchPreference.setOnPreferenceChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchPreference.setOnPreferenceChangeListener方法的具体用法?Java SwitchPreference.setOnPreferenceChangeListener怎么用?Java SwitchPreference.setOnPreferenceChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v14.preference.SwitchPreference
的用法示例。
在下文中一共展示了SwitchPreference.setOnPreferenceChangeListener方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreatePreferences
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.settings_preferences);
if(getActivity()!=null) {
Activity mActivity = getActivity();
final SharedPreferences sharedPref = mActivity.getPreferences(Context.MODE_PRIVATE);
final String currentServer = sharedPref.getString(getString(R.string.saved_server_ip), "https://github.com/jboss-outreach");
final EditTextPreference mPreference = (EditTextPreference) findPreference("server_location");
final SwitchPreference mToggleMode = (SwitchPreference) findPreference("dark_theme");
mToggleMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mActivity.startActivity(new Intent(mActivity, MainActivity.class));
mActivity.finish();
return true;
}
});
mPreference.setSummary(currentServer);
mPreference.setText(currentServer);
}
}
示例2: onCreatePreferences
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setSharedPreferencesName(Constants.PREF_NAME);
addPreferencesFromResource(R.xml.monitor);
suVersion = Tools.SuVersion(getActivity());
isCMSU = Tools.SuVersionBool(suVersion);
mMonitor = (PreferenceCategory) findPreference("monitor_su");
mPerAppDontCare = (Preference) findPreference("per_app_dontcare");
mPerAppActive = (Preference) findPreference("per_app_active");
mAutoRestartSU = (SwitchPreference) findPreference("auto_restart_su");
mAutoRestartISU = (SwitchPreference) findPreference("auto_restart_isu");
mPerAppDeactive = (Preference) findPreference("per_app_deactive");
mMonitorView = (Preference) findPreference("per_app_view");
mMonitorWarning = (Preference) findPreference("per_app_warning");
mAutoRestartSU.setOnPreferenceChangeListener(this);
mAutoRestartISU.setOnPreferenceChangeListener(this);
}
示例3: initUi
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
private void initUi() {
mUiNavBarPreference =
(SwitchPreference) findPreference("preference_switch_ui_transparent_nav_bar");
mUiNavBarPreference.setChecked(mPrefs.enableTransparentNavBar().get());
mUiNavBarPreference.setOnPreferenceChangeListener((preference, newValue) -> {
mPrefs.enableTransparentNavBar().set((Boolean) newValue);
return true;
});
mUiLessAnimPreference = (SwitchPreference) findPreference("preference_ui_less_anim");
mUiLessAnimPreference.setChecked(mPrefs.lessAnim().get());
mUiLessAnimPreference.setOnPreferenceChangeListener((preference, newValue) -> {
mPrefs.lessAnim().set((Boolean) newValue);
return true;
});
}
示例4: initDevOps
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
private void initDevOps() {
SwitchPreference hideItselfPreference =
(SwitchPreference) findPreference("preference_switch_hide_itself");
hideItselfPreference.setChecked(mPrefs.hideItself().getValue());
hideItselfPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PackageManager pm = getContext().getPackageManager();
ComponentName componentName =
new ComponentName(getContext(), MainActivity.class);
if ((Boolean) newValue) {
mPrefs.hideItself().setValue(true);
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
} else {
mPrefs.hideItself().setValue(false);
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
return true;
}
});
}
示例5: onCreatePreferences
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
((RingApplication) getActivity().getApplication()).getRingInjectionComponent().inject(this);
super.onCreatePreferences(bundle, rootKey);
addPreferencesFromResource(R.xml.account_media_prefs);
audioCodecsPref = (CodecPreference) findPreference("Account.audioCodecs");
videoCodecsPref = (CodecPreference) findPreference("Account.videoCodecs");
mRingtoneCustom = (SwitchPreference) findPreference("Account.ringtoneCustom");
presenter.init(getArguments().getString(AccountEditionActivity.ACCOUNT_ID_KEY));
addPreferenceListener(ConfigKey.VIDEO_ENABLED, changeVideoPreferenceListener);
mRingtoneCustom.setOnPreferenceChangeListener(changeAudioPreferenceListener);
}
示例6: invalidateSettings
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
public void invalidateSettings() {
SwitchPreference dark = (SwitchPreference) findPreference("dark_theme");
ExcludeFolderPreference exclude = (ExcludeFolderPreference) findPreference("excluded_folders_listener_key");
ColorPickerPreference primary = (ColorPickerPreference) findPreference("primary");
ColorPickerPreference accent = (ColorPickerPreference) findPreference("accent");
Preference security = findPreference("security_placeholder");
Preference animations = findPreference("animations");
Preference staggered = findPreference("staggered");
Preference cache = findPreference("clear_cache_placeholder");
Preference sdcard = findPreference("externalsd_placeholder");
Preference removesd = findPreference("removesd_placeholder");
sdcard.setSummary(ExtSdHelper.getSdPath()==null ? getContext().getResources().getString(R.string.no_sd) : ExtSdHelper.getSdPath().substring(ExtSdHelper.getSdPath().lastIndexOf("/")+1));
if (Build.VERSION.SDK_INT < 21) {
sdcard.setEnabled(false);
}
removesd.setOnPreferenceClickListener(this);
sdcard.setOnPreferenceClickListener(this);
security.setOnPreferenceClickListener(this);
exclude.setOnPreferenceClickListener(this);
cache.setOnPreferenceClickListener(this);
staggered.setOnPreferenceChangeListener(this);
animations.setOnPreferenceChangeListener(this);
dark.setOnPreferenceChangeListener(this);
primary.setOnPreferenceChangeListener(this);
accent.setOnPreferenceChangeListener(this);
}
示例7: addThemeChangeListener
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
private void addThemeChangeListener() {
SwitchPreference pref = (SwitchPreference) getPreferenceScreen().findPreference("selectTheme");
pref.setOnPreferenceChangeListener((prev, val) -> {
getActivity().recreate();
return true;
});
}
示例8: addOnEnableNotificationsChangeListener
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
private void addOnEnableNotificationsChangeListener() {
SwitchPreference enableNotifications = (SwitchPreference) getPreferenceScreen().findPreference("enable_notifications");
Preference notificationTypes = getPreferenceScreen().findPreference("enabled_notification_types");
enableNotifications.setOnPreferenceChangeListener((preference, newValue) -> {
notificationTypes.setEnabled((Boolean) newValue);
return true;
});
}
示例9: onCreate
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IconFlag[] flags = IconFlag.values();
for (int i = 0; i < flags.length; i++) {
SwitchPreference switchPreference =
new SwitchPreference(mPreferenceScreen.getContext());
switchPreference.setKey("switchPreference_" + flags[i].name());
mPrefs.isTabShow(flags[i].name().toLowerCase())
.asObservable().subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(switchPreference::setChecked);
switchPreference.setTitle(ResourceUtil
.getStringFromResString(getContext(), "tab_" + flags[i].name().toLowerCase()));
if (i == flags.length - 1) {
switchPreference.setLayoutResource(R.layout.layout_preference_card_last);
} else {
switchPreference.setLayoutResource(R.layout.layout_preference_card);
}
int index = i;
switchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
mPrefs.isTabShow(flags[index].name().toLowerCase()).set((Boolean) newValue);
return true;
});
mPreferenceScreen.addPreference(switchPreference);
}
}
示例10: initSwitchPreferences
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
private void initSwitchPreferences() {
mDisableBluetoothContactSharingSwitchPreference = (SwitchPreference) findPreference(
DISABLE_BLUETOOTH_CONTACT_SHARING_KEY);
mDisableCrossProfileCallerIdSwitchPreference = (SwitchPreference) findPreference(
DISABLE_CROSS_PROFILE_CALLER_ID_KEY);
mDisableCrossProfileContactsSearchSwitchPreference = (SwitchPreference) findPreference(
DISABLE_CROSS_PROFILE_CONTACTS_SEARCH_KEY);
mDisableBluetoothContactSharingSwitchPreference.setOnPreferenceChangeListener(this);
mDisableCrossProfileCallerIdSwitchPreference.setOnPreferenceChangeListener(this);
mDisableCrossProfileContactsSearchSwitchPreference.setOnPreferenceChangeListener(this);
reloadBluetoothContactSharing();
reloadCrossProfileCallerIdDisableUi();
}
示例11: onCreatePreferences
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setSharedPreferencesName(Constants.PREF_NAME);
addPreferencesFromResource(R.xml.controls);
suVersion = Tools.SuVersion(getActivity());
isCMSU = Tools.SuVersionBool(suVersion);
rootAccess = Tools.rootAccess(getActivity());
mControls = (PreferenceCategory) findPreference("controls_su");
mSuSwitch = (SwitchPreference) findPreference("su_switch");
mSuSwitch.setOnPreferenceChangeListener(this);
mSelSwitch = (SwitchPreference) findPreference("selinux_switch");
mSelSwitch.setOnPreferenceChangeListener(this);
mFakeSelSwitch = (SwitchPreference) findPreference("fake_selinux_switch");
mFakeSelSwitch.setOnPreferenceChangeListener(this);
mDebug = (SwitchPreference) findPreference("android_debug");
mDebug.setOnPreferenceChangeListener(this);
mDebugRoot = (SwitchPreference) findPreference("android_debug_root");
mDebugRoot.setOnPreferenceChangeListener(this);
mControlsView = (Preference) findPreference("controls_view");
mTasker = (Preference) findPreference("tasker");
mTasker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String options = Constants.TASKER_SU_ON + "\n" + Constants.TASKER_SU_OFF + "\n" + Constants.TASKER_SU_INV + "\n\n" +
Constants.TASKER_SELINUX_ON + "\n" + Constants.TASKER_SELINUX_OFF + "\n" + Constants.TASKER_SELINUX_INV + "\n\n" +
Constants.TASKER_DEBUG_ON + "\n" + Constants.TASKER_DEBUG_OFF + "\n" + Constants.TASKER_DEBUG_INV + "\n\n" +
getString(R.string.tasker_help_extra_description) +
"su = " + getString(R.string.su_switch) + "\n" +
"selinux = " + getString(R.string.selinux_switch) + "\n" +
"debug = " + getString(R.string.anddebug_change) + "\n\n" +
"on = " + String.format(getString(R.string.tasker_help_extra_state), getString(R.string.activated)) +
"off = " + String.format(getString(R.string.tasker_help_extra_state), getString(R.string.deactivated)) +
"inverse = " + getString(R.string.tasker_help_inv);
Tools.SimpleDialog(String.format(getString(R.string.tasker_help), options), getActivity());
return true;
}
});
}
示例12: onCreatePreferences
import android.support.v14.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setSharedPreferencesName(Constants.PREF_NAME);
addPreferencesFromResource(R.xml.settings);
mSettingsPref = (PreferenceCategory) findPreference("settings_pref");
mSettingsView = (Preference) findPreference("settings_view");
mSettingsForceEnglish = (SwitchPreference) findPreference("forceenglish");
mSettingsForceEnglish.setOnPreferenceChangeListener(this);
mSettingsSU = (PreferenceCategory) findPreference("su_settings_pref");
mSettingsMonitor = (PreferenceCategory) findPreference("monitor_settings");
mSettingsNotifications = (PreferenceCategory) findPreference("notifications_settings_pref");
mSettingsSelinux = (PreferenceCategory) findPreference("selinux_settings_pref");
mSettingsDebug = (PreferenceCategory) findPreference("anddebug_settings_pref");
mSettingsProps = (PreferenceCategory) findPreference("props_settings_pref");
mApplySuDelay = (ListPreference) findPreference("apply_su_delay");
mApplyMonitorDelay = (ListPreference) findPreference("allow_delay");
CharSequence[] entriesSuDelay = new CharSequence[6];
CharSequence[] entryValuesSuDelay = new CharSequence[6];
for (int i = 0; i < 6; i++) {
entriesSuDelay[i] = (String.format(getString(R.string.apply_su_delay_summary), ((i + 1) * 10)));
entryValuesSuDelay[i] = String.valueOf((i + 1) * 10000);
}
mApplySuDelay.setEntries(entriesSuDelay);
mApplySuDelay.setEntryValues(entryValuesSuDelay);
CharSequence[] entriesMonitorDelay = new CharSequence[7];
CharSequence[] entryValuesMonitorDelay = new CharSequence[7];
for (int i = 0; i < 7; i++) {
if (i == 0) {
entriesMonitorDelay[i] = getString(R.string.disable);
entryValuesMonitorDelay[i] = String.valueOf(i);
} else {
entriesMonitorDelay[i] = (String.format(getString(R.string.apply_su_delay_summary), ((i) * 5)));
entryValuesMonitorDelay[i] = String.valueOf((i) * 5000);
}
}
mApplyMonitorDelay.setEntries(entriesMonitorDelay);
mApplyMonitorDelay.setEntryValues(entryValuesMonitorDelay);
suVersion = Tools.SuVersion(getActivity());
isCMSU = Tools.SuVersionBool(suVersion);
if (!isCMSU) {
mSettingsSU.setEnabled(false);
mSettingsMonitor.setEnabled(false);
mSettingsNotifications.setEnabled(false);
mSettingsSelinux.setEnabled(false);
mSettingsDebug.setEnabled(false);
if (!Tools.rootAccess(getActivity())) {
mSettingsView.setSummary(getString(R.string.device_not_root));
mSettingsProps.setEnabled(false);
}
} else
mSettingsPref.removePreference(mSettingsView);
}