本文整理汇总了Java中android.support.v7.preference.SwitchPreferenceCompat类的典型用法代码示例。如果您正苦于以下问题:Java SwitchPreferenceCompat类的具体用法?Java SwitchPreferenceCompat怎么用?Java SwitchPreferenceCompat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SwitchPreferenceCompat类属于android.support.v7.preference包,在下文中一共展示了SwitchPreferenceCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
protected void save() {
preferences.activateAccelerometer(true);
preferences.activateCamera(true);
preferences.activateMicrophone(true);
setPhoneNumber();
boolean remoteAccessActive = ((SwitchPreferenceCompat) findPreference(PreferenceManager.REMOTE_ACCESS_ACTIVE)).isChecked();
preferences.activateRemoteAccess(remoteAccessActive);
String password = ((EditTextPreference) findPreference(PreferenceManager.REMOTE_ACCESS_CRED)).getText();
if (checkValidStrings(password, preferences.getRemoteAccessCredential()) && (TextUtils.isEmpty(preferences.getRemoteAccessCredential()) || !password.trim().equals(preferences.getRemoteAccessCredential().trim()))) {
preferences.setRemoteAccessCredential(password.trim());
app.stopServer();
app.startServer();
}
mActivity.setResult(Activity.RESULT_OK);
mActivity.finish();
}
示例2: setPhoneNumber
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
private void setPhoneNumber() {
boolean smsActive = ((SwitchPreferenceCompat) findPreference(PreferenceManager.SMS_ACTIVE)).isChecked();
String phoneNumber = ((EditTextPreference) findPreference(PreferenceManager.SMS_NUMBER)).getText();
if (smsActive && checkValidString(phoneNumber)) {
preferences.activateSms(true);
} else {
preferences.activateSms(false);
}
if (checkValidString(phoneNumber)) {
preferences.setSmsNumber(phoneNumber.trim());
findPreference(PreferenceManager.SMS_NUMBER).setSummary(phoneNumber.trim());
} else {
preferences.setSmsNumber("");
findPreference(PreferenceManager.SMS_NUMBER).setSummary(R.string.sms_dialog_message);
}
}
示例3: onViewCreated
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
app = (App) getContext().getApplicationContext();
view.setBackgroundColor(Color.parseColor("#FFFFFF"));
SwitchPreferenceCompat preference = (SwitchPreferenceCompat)findPreference("enableNotifications");
preference.setOnPreferenceChangeListener(onSetAlarm);
ListPreference delay = (ListPreference)findPreference("delayNotifications");
delay.setOnPreferenceChangeListener(onDelayChange);
CheckBoxPreference display = (CheckBoxPreference)findPreference("displaySilNotification");
display.setOnPreferenceChangeListener(onDisplayChange);
if (app.getPublicPreferenceB(Common.GLOBAL_SETTING_ISNOTIFON)) {
preference.setChecked(true);
delay.setEnabled(true);
delay.setValueIndex(getIdByTime(app.account.getNotificationTime()));
display.setEnabled(true);
display.setChecked(app.getPublicPreferenceB(Common.GLOBAL_SETTING_NOTIFICATIONDISPLAY));
} else {
preference.setChecked(false);
delay.setEnabled(false);
display.setEnabled(false);
display.setChecked(false);
}
}
示例4: updatePrefDefaultValue
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
private static void updatePrefDefaultValue(Preference pref) {
String realPrefKey = pref.getKey();
pref.setPersistent(false);
if (pref instanceof CheckBoxPreference) {
pref.setKey("tmpKeyBool");
CheckBoxPreference checkBoxPref = (CheckBoxPreference) pref;
checkBoxPref.setChecked(PrefsManager.getBool(realPrefKey));
} else if (pref instanceof SwitchPreferenceCompat) {
pref.setKey("tmpKeyBool");
SwitchPreferenceCompat switchPref = (SwitchPreferenceCompat) pref;
switchPref.setChecked(PrefsManager.getBool(realPrefKey));
} else if (pref instanceof EditTextPreference) {
pref.setKey("tmpKeyString");
EditTextPreference editTextPref = (EditTextPreference) pref;
editTextPref.setText(PrefsManager.getString(realPrefKey));
} else if (pref instanceof ListPreference) {
pref.setKey("tmpKeyString");
ListPreference listPref = (ListPreference) pref;
listPref.setValue(PrefsManager.getString(realPrefKey));
}
pref.setPersistent(true);
pref.setKey(realPrefKey);
}
示例5: onCreatePreferences
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.preferences);
mPrefLocation = (CheckBoxPreference)findPreference(FlavordexApp.PREF_DETECT_LOCATION);
mPrefAccount = (SwitchPreferenceCompat)findPreference(FlavordexApp.PREF_ACCOUNT);
mPrefEditAccount = findPreference(PREF_EDIT_ACCOUNT);
mPrefSyncData = (CheckBoxPreference)findPreference(FlavordexApp.PREF_SYNC_DATA);
mPrefSyncPhotos = (CheckBoxPreference)findPreference(FlavordexApp.PREF_SYNC_PHOTOS);
setupEditCatsPref();
setupLocationPref();
setupAccountPref();
setupEditAccountPref();
setupSyncDataPref();
setupSyncPhotosPref();
PreferenceManager.getDefaultSharedPreferences(getContext())
.registerOnSharedPreferenceChangeListener(this);
mAuth = FirebaseAuth.getInstance();
}
示例6: enableOrDisablePreferences
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
private void enableOrDisablePreferences(boolean enable)
{
String keyAddress = getString(R.string.pref_key_proxy_address);
EditTextPreference address = (EditTextPreference) findPreference(keyAddress);
address.setEnabled(enable);
String keyPort = getString(R.string.pref_key_proxy_port);
EditTextPreference port = (EditTextPreference) findPreference(keyPort);
port.setEnabled(enable);
String keyProxyPeersToo = getString(R.string.pref_key_proxy_peers_too);
SwitchPreferenceCompat proxyPeersToo = (SwitchPreferenceCompat) findPreference(keyProxyPeersToo);
proxyPeersToo.setEnabled(enable);
String keyForceProxy = getString(R.string.pref_key_force_proxy);
SwitchPreferenceCompat forceProxy = (SwitchPreferenceCompat) findPreference(keyForceProxy);
forceProxy.setEnabled(enable);
String keyRequiresAuth = getString(R.string.pref_key_proxy_requires_auth);
SwitchPreferenceCompat requiresAuth = (SwitchPreferenceCompat) findPreference(keyRequiresAuth);
requiresAuth.setEnabled(enable);
}
示例7: onCreatePreferencesFix
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
@Override
public void onCreatePreferencesFix(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.app_preferences);
PreferenceScreen mainPreferenceScreen = (PreferenceScreen) findPreference("mainPreferenceScreen");
pushPreferenceCat = findPreference("pushCat");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
Preference downloadNotificationCat = findPreference("downloadNotificationCat");
mainPreferenceScreen.removePreference(downloadNotificationCat);
}
crashlyticsAlwaysSendPreference = (SwitchPreferenceCompat) findPreference(getString(R.string.pref_key_crashlytics_always_send));
crashlyticsAlwaysSendPreference.setChecked(TazSettings.getInstance(getContext())
.getCrashlyticsAlwaysSend());
crashlyticsAlwaysSendPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
TazSettings.getInstance(preference.getContext())
.setCrashlyticsAlwaysSend((Boolean) newValue);
return true;
}
});
setPushPrefState(!TextUtils.isEmpty(TazSettings.getInstance(getContext())
.getFirebaseToken()));
}
示例8: onCreatePreferences
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.pref_discogs);
SwitchPreferenceCompat sw = (SwitchPreferenceCompat) findPreference("enable_discogs");
Discogs discogs = Discogs.getInstance(getContext());
boolean loggedin = discogs.isLoggedIn();
sw.setChecked(loggedin);
if(loggedin) {
sw.setSummaryOn("Signed in as " + discogs.getUser());
}
Preference preloadButton = findPreference("discogs_preload_collection");
preloadButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
Discogs.getInstance(getActivity()).preloadCollection();
return true;
}
});
}
示例9: onPreferenceChange
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
@Override public boolean onPreferenceChange(final Preference preference, Object newValue) {
if (newValue == Boolean.TRUE) {
((SwitchPreferenceCompat) preference).setChecked(true);
Prefs.setReadingListSyncEnabled(true);
Prefs.setReadingListsRemoteSetupPending(true);
Prefs.setReadingListsRemoteDeletePending(false);
ReadingListSyncAdapter.manualSync();
} else {
new AlertDialog.Builder(getActivity())
.setMessage(R.string.reading_lists_confirm_remote_delete)
.setPositiveButton(R.string.reading_lists_confirm_remote_delete_yes, new DeleteRemoteListsYesListener(preference))
.setNegativeButton(R.string.reading_lists_confirm_remote_delete_no, new DeleteRemoteListsNoListener(preference))
.show();
}
// clicks are handled and preferences updated accordingly; don't pass the result through
return false;
}
示例10: onCreatePreferences
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.settings);
activity = this.getActivity();
enableFloatWindowPreference = (SwitchPreferenceCompat) findPreference(ENABLE_FLOAT_WINDOW);
bootCompletedPreference = (SwitchPreferenceCompat) findPreference(BOOT_COMPLETED);
openMainActivityWhenQuickStartOrQuickStopPreference = (SwitchPreferenceCompat) findPreference(OPEN_MAIN_ACTIVITY_WHEN_QUICK_START_OR_QUICK_STOP);
gestureClickPreference = (ListPreference) findPreference(GESTURE_CLICK);
gestureLongPressPreference = (ListPreference) findPreference(GESTURE_LONG_PRESS);
workingModePreference = (ListPreference) findPreference(WORKING_MODE);
initFloatViewBroadcastReceiverHelper();
}
示例11: onCreatePreferences
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.app_preference);
suggestions = (SwitchPreferenceCompat) findPreference("suggestions");
suggestions.setOnPreferenceChangeListener(this);
}
示例12: onCreatePreferences
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.pref_global);
mSnoozeDuration = (ListPreference)findPreference(getString(R.string.pref_snooze_duration_key));
mRingDuration = (ListPreference)findPreference(getString(R.string.pref_ring_duration_key));
mAlarmVolume = (VolumeSliderPreference)findPreference(getString(R.string.pref_ring_volume_key));
mEnableNotifications = (SwitchPreferenceCompat)findPreference(getString(R.string.pref_enable_notifications_key));
mEnableReliability = (SwitchPreferenceCompat)findPreference(getString(R.string.pref_enable_reliability_key));
mEnableReliability.setEnabled(mEnableNotifications.isChecked());
setDefaultSummaryValues();
}
示例13: activateBackup
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
private void activateBackup() {
final SwitchPreferenceCompat backupActivePref = (SwitchPreferenceCompat) findPreference(KEY_BACKUP_ACTIVE_BOOL);
if (!backupActivePref.isChecked()) {
backupActivePref.setChecked(true);
}
changeProgressBarVisibility(false);
}
示例14: onPreferenceChange
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());
if (preference instanceof SwitchPreferenceCompat) {
pref.put(preference.getKey(), (boolean) newValue);
} else if (preference.getKey().equals(getString(R.string.pref_key_port))) {
int value = TorrentEngine.Settings.DEFAULT_PORT;
if (!TextUtils.isEmpty((String) newValue)) {
value = Integer.parseInt((String) newValue);
}
pref.put(preference.getKey(), value);
preference.setSummary(Integer.toString(value));
} else if (preference.getKey().equals(getString(R.string.pref_key_enc_mode))) {
int type = Integer.parseInt((String) newValue);
pref.put(preference.getKey(), type);
String typesName[] = getResources().getStringArray(R.array.pref_enc_mode_entries);
preference.setSummary(typesName[type]);
boolean enableAdvancedEncryptSettings = type != Integer.parseInt(getString(R.string.pref_enc_mode_disable_value));
String keyEncryptInConnections = getString(R.string.pref_key_enc_in_connections);
SwitchPreferenceCompat encryptInConnections =
(SwitchPreferenceCompat) findPreference(keyEncryptInConnections);
encryptInConnections.setEnabled(enableAdvancedEncryptSettings);
encryptInConnections.setChecked(enableAdvancedEncryptSettings);
String keyEncryptOutConnections = getString(R.string.pref_key_enc_out_connections);
SwitchPreferenceCompat encryptOutConnections =
(SwitchPreferenceCompat) findPreference(keyEncryptOutConnections);
encryptOutConnections.setEnabled(enableAdvancedEncryptSettings);
encryptOutConnections.setChecked(enableAdvancedEncryptSettings);
}
return true;
}
示例15: onPreferenceChange
import android.support.v7.preference.SwitchPreferenceCompat; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
if (preference instanceof SwitchPreferenceCompat) {
SettingsManager pref = new SettingsManager(getActivity().getApplicationContext());
pref.put(preference.getKey(), (boolean) newValue);
}
return true;
}