本文整理汇总了Java中android.support.v14.preference.SwitchPreference类的典型用法代码示例。如果您正苦于以下问题:Java SwitchPreference类的具体用法?Java SwitchPreference怎么用?Java SwitchPreference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SwitchPreference类属于android.support.v14.preference包,在下文中一共展示了SwitchPreference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onViewCreated
import android.support.v14.preference.SwitchPreference; //导入依赖的package包/类
@Override public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setDivider(ActivityCompat.getDrawable(getActivity(), R.drawable.list_divider));
setDividerHeight(1);
PreferenceGroupAdapter adapter = (PreferenceGroupAdapter) getListView().getAdapter();
for (int i = 0; i < getListView().getAdapter().getItemCount(); i++) {//lazy global setOnPreferenceClickListener
Preference preference = adapter.getItem(i);
if (preference != null && !InputHelper.isEmpty(preference.getKey())) {
if (preference.getKey().equalsIgnoreCase("version")) {
preference.setSummary(BuildConfig.VERSION_NAME);
} else if (!(preference instanceof SwitchPreference) && !(preference instanceof ListPreference)) {
preference.setOnPreferenceClickListener(this);
}
}
}
}
示例6: 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);
}
示例7: 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);
}
示例8: onRequestPermissionsResult
import android.support.v14.preference.SwitchPreference; //导入依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (permissions.length > 0 && grantResults.length > 0) {
if (permissions[0].equals(Manifest.permission.ACCESS_FINE_LOCATION) && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
((SwitchPreference) findPreference(Common.PREF_ENABLE_LOCATION_TRACKING)).setChecked(true);
}
}
}
示例9: 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;
});
}
示例10: 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;
});
}
示例11: createTwoStatePreference
import android.support.v14.preference.SwitchPreference; //导入依赖的package包/类
@DexAdd
private TwoStatePreference createTwoStatePreference(Context context) {
if (useSwitchPreference()) {
return new SwitchPreference(context);
} else {
return new CheckBoxPreference(context);
}
}
示例12: mResetTwoStatePrefsAdd
import android.support.v14.preference.SwitchPreference; //导入依赖的package包/类
@DexAdd
private boolean mResetTwoStatePrefsAdd(TwoStatePreference preference) {
if (useSwitchPreference()) {
return mResetSwitchPrefs.add((SwitchPreference) preference);
} else {
return mResetCbPrefs.add((CheckBoxPreference) preference);
}
}
示例13: updateTwoStatePreference
import android.support.v14.preference.SwitchPreference; //导入依赖的package包/类
@DexAdd
private void updateTwoStatePreference(TwoStatePreference preference, boolean value) {
if (useSwitchPreference()) {
updateSwitchPreference((SwitchPreference) preference, value);
} else {
updateCheckBox((CheckBoxPreference) preference, value);
}
}
示例14: 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);
}
}
示例15: 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();
}