本文整理汇总了Java中android.preference.SwitchPreference.setChecked方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchPreference.setChecked方法的具体用法?Java SwitchPreference.setChecked怎么用?Java SwitchPreference.setChecked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.SwitchPreference
的用法示例。
在下文中一共展示了SwitchPreference.setChecked方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.document_mode_preferences);
getActivity().setTitle(R.string.tabs_and_apps_title);
mDocumentModeManager = DocumentModeManager.getInstance(getActivity());
mDocumentModeSwitch = (SwitchPreference) findPreference(PREF_DOCUMENT_MODE_SWITCH);
boolean isdocumentModeEnabled = !mDocumentModeManager.isOptedOutOfDocumentMode();
mDocumentModeSwitch.setChecked(isdocumentModeEnabled);
mDocumentModeSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if ((boolean) newValue == !mDocumentModeManager.isOptedOutOfDocumentMode()) {
return true;
}
createOptOutAlertDialog((boolean) newValue).show();
return true;
}
});
}
示例2: updateShowTouchesOptions
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void updateShowTouchesOptions() {
final SwitchPreference showTouchesPref = (SwitchPreference) findPreference("show_touches");
int enable = 0;
try {
enable = Settings.System.getInt(getContentResolver(), Constants.SETTINGS_SYSTEM_SHOW_TOUCHES);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
showTouchesPref.setChecked(enable == 1);
showTouchesPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Settings.System.putInt(getContentResolver(),
Constants.SETTINGS_SYSTEM_SHOW_TOUCHES,
newValue == Boolean.TRUE ? 1 : 0);
return true;
}
});
}
示例3: addSwitchPreferenceBasedOnCheckBoxPreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox,
final PreferenceGroup group) {
final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext());
switchPref.setTitle(checkBox.getTitle());
switchPref.setKey(checkBox.getKey());
switchPref.setOrder(checkBox.getOrder());
switchPref.setPersistent(checkBox.isPersistent());
switchPref.setEnabled(checkBox.isEnabled());
switchPref.setChecked(checkBox.isChecked());
switchPref.setSummary(checkBox.getSummary());
switchPref.setSummaryOn(checkBox.getSummaryOn());
switchPref.setSummaryOff(checkBox.getSummaryOff());
switchPref.setSwitchTextOn(EMPTY_TEXT);
switchPref.setSwitchTextOff(EMPTY_TEXT);
group.addPreference(switchPref);
switchPref.setDependency(checkBox.getDependency());
}
示例4: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
cacheWithWifi = (SwitchPreference) findPreference("cache_with_wifi");
cacheWithWifi.setOnPreferenceChangeListener(this);
boolean checked = PreferenceManager.getBooleanValue(context, CACHE_KEY, true);
cacheWithWifi.setChecked(checked);
clearVideoCache = findPreference("clear_video_cache");
clearVideoCache.setOnPreferenceClickListener(this);
float videoFileSize = calculateCacheFileSize("video-cache", true);
clearVideoCache.setSummary(String.format(Locale.CHINESE, "%.2fMb", videoFileSize));
clearPhotoCache = findPreference("clear_photo_cache");
clearPhotoCache.setOnPreferenceClickListener(this);
float photoFileSize = calculateCacheFileSize("image_manager_disk_cache", false);
photoFileSize += calculateCacheFileSize("picasso-cache", false);
clearPhotoCache.setSummary(String.format(Locale.CHINESE, "%.2fMb", photoFileSize));
}
示例5: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.setting);
mSharedPreferenceUtil = SharedPreferenceUtil.getInstance();
mACache = ACache.get(getActivity());
mChangeIcons = findPreference(SharedPreferenceUtil.CHANGE_ICONS);
mChangeUpdate = findPreference(SharedPreferenceUtil.AUTO_UPDATE);
mClearCache = findPreference(SharedPreferenceUtil.CLEAR_CACHE);
mNotificationType = (SwitchPreference) findPreference(SharedPreferenceUtil.NOTIFICATION_MODEL);
mNotificationType.setChecked(true);
mChangeIcons.setSummary(getResources().getStringArray(R.array.icons)[mSharedPreferenceUtil.getIconType()]);
mChangeUpdate.setSummary(
mSharedPreferenceUtil.getAutoUpdate() == 0 ? "禁止刷新" : "每" + mSharedPreferenceUtil.getAutoUpdate() + "小时更新");
mClearCache.setSummary(FileSizeUtil.getAutoFileOrFilesSize(BaseApplication.cacheDir + "/NetCache"));
mChangeIcons.setOnPreferenceClickListener(this);
mChangeUpdate.setOnPreferenceClickListener(this);
mClearCache.setOnPreferenceClickListener(this);
mNotificationType.setOnPreferenceClickListener(this);
}
示例6: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.launcher_preferences);
SwitchPreference pref = (SwitchPreference) findPreference(
Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
pref.setPersistent(false);
Bundle extras = new Bundle();
extras.putBoolean(LauncherSettings.Settings.EXTRA_DEFAULT_VALUE, false);
Bundle value = getActivity().getContentResolver().call(
LauncherSettings.Settings.CONTENT_URI,
LauncherSettings.Settings.METHOD_GET_BOOLEAN,
Utilities.ALLOW_ROTATION_PREFERENCE_KEY, extras);
pref.setChecked(value.getBoolean(LauncherSettings.Settings.EXTRA_VALUE));
pref.setOnPreferenceChangeListener(this);
}
示例7: updatePreferenceScreen
import android.preference.SwitchPreference; //导入方法依赖的package包/类
void updatePreferenceScreen() {
PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("dataSourceType");
PhoneSensorDataSource phoneSensorDataSource;
for (int i = 0; i < phoneSensorDataSources.getPhoneSensorDataSources().size(); i++) {
phoneSensorDataSource = phoneSensorDataSources.getPhoneSensorDataSources().get(i);
SwitchPreference switchPreference = (SwitchPreference) preferenceCategory.findPreference(phoneSensorDataSource.getDataSourceType());
switchPreference.setChecked(phoneSensorDataSource.isEnabled());
if (!isSensorSupported(phoneSensorDataSource.getDataSourceType()))
switchPreference.setSummary("Not Supported");
else {
try {
switchPreference.setSummary(phoneSensorDataSource.getFrequency() + " Hz");
} catch (NumberFormatException nfe) {
switchPreference.setSummary(phoneSensorDataSource.getFrequency());
}
}
}
}
示例8: build
import android.preference.SwitchPreference; //导入方法依赖的package包/类
/**
* Builds a SwitchPreference object
*/
@Override
public Preference build() {
SwitchPreference preference = null;
preference = build(SwitchPreference.class, true);
preference.setChecked((boolean) mDefaultValue);
preference.setSummaryOn((String)
getOptionalAttribute(TweakableBoolean.BUNDLE_ON_SUMMARY_KEY));
preference.setSummaryOff((String)
getOptionalAttribute(TweakableBoolean.BUNDLE_OFF_SUMMARY_KEY));
preference.setSwitchTextOn((String)
getOptionalAttribute(TweakableBoolean.BUNDLE_ON_LABEL_KEY));
preference.setSwitchTextOff((String)
getOptionalAttribute(TweakableBoolean.BUNDLE_OFF_LABEL_KEY));
return preference;
}
示例9: updatePreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void updatePreference(int i) {
AppServiceManager appServiceManager= (AppServiceManager) ModelManager.getInstance(getActivity()).getModel(ModelFactory.MODEL_APP_SERVICE);
SwitchPreference switchPreference = (SwitchPreference) findPreference(String.valueOf(i));
Status status = appServiceManager.appServiceList.get(i).getStatus();
if(status.getStatus()== Status.APP_NOT_INSTALLED) {
switchPreference.setEnabled(false);
switchPreference.setChecked(false);
switchPreference.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_error_red_50dp));
switchPreference.setSummary(status.getMessage());
}else if(status.getStatus()== Status.APP_NOT_RUNNING) {
switchPreference.setEnabled(true);
switchPreference.setChecked(false);
switchPreference.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_error_red_50dp));
switchPreference.setSummary(status.getMessage());
}else{
switchPreference.setEnabled(true);
switchPreference.setChecked(true);
switchPreference.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_ok_teal_50dp));
switchPreference.setSummary(status.getMessage());
}
}
示例10: startOrStopService
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void startOrStopService(final SharedPreferences preferences) {
boolean userDidStart = preferences.getBoolean(PBConstants.PREF_SERVICE_RUNNING, false);
Log.i(LOG_TAG, "PREF_SERVICE_RUNNING = " + userDidStart);
if (userDidStart) {
if (validatePreferences()) {
checkPermissions(PBConstants.PERM_ORIGIN_SERVICE);
} else {
final SwitchPreference switchPreference = (SwitchPreference) findPreference(PBConstants.PREF_SERVICE_RUNNING);
switchPreference.setChecked(false);
}
} else if (isPhotoBackupServiceRunning() && currentService != null) {
Log.i(LOG_TAG, "stop PhotoBackup service");
getActivity().unbindService(serviceConnection);
getActivity().invalidateOptionsMenu();
isBoundToService = false;
currentService.stopSelf();
currentService = null;
updatePreferences();
}
}
示例11: startOrStopService
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void startOrStopService(final SharedPreferences preferences) {
boolean userDidStart = preferences.getBoolean(PREF_SERVICE_RUNNING, false);
Log.i(LOG_TAG, "PREF_SERVICE_RUNNING = " + userDidStart);
if (userDidStart) {
if (validatePreferences()) {
Log.i(LOG_TAG, "start PhotoBackup service");
testMediaSender();
} else {
final SwitchPreference switchPreference = (SwitchPreference) findPreference(PREF_SERVICE_RUNNING);
switchPreference.setChecked(false);
}
} else if (isPhotoBackupServiceRunning() && currentService != null) {
Log.i(LOG_TAG, "stop PhotoBackup service");
getActivity().unbindService(serviceConnection);
isBoundToService = false;
currentService.stopSelf();
currentService = null;
updateUploadJournalPreference();
}
}
示例12: initInLineAction
import android.preference.SwitchPreference; //导入方法依赖的package包/类
public void initInLineAction(SwitchPreference switchPref) {
switchPref.setChecked(true);
mActionOn = switchPref.isChecked();
switchPref.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mActionOn = (Boolean) newValue;
return true;
}
});
}
示例13: initAvatar
import android.preference.SwitchPreference; //导入方法依赖的package包/类
public void initAvatar(SwitchPreference switchPref) {
switchPref.setChecked(true);
mAvatarOn = switchPref.isChecked();
switchPref.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mAvatarOn = (Boolean) newValue;
return true;
}
});
}
示例14: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.prefs_in_line_progress);
mDeterminantSwitchPref =
(SwitchPreference)
findPreference(getString(R.string.key_pref_determinant_switch));
mDeterminantSwitchPref.setChecked(true);
mCircledImageViewPref =
(CircledImageViewPreference)
findPreference(getString(R.string.key_pref_circled_image_view));
mPreferenceScreen =
(PreferenceScreen) findPreference(getString(R.string.key_pref_progress_screen));
mProgressBarPreference = new ProgressBarPreference(getContext());
mProgressBarPreference.setTitle("@string/indeterminant_progress");
mDeterminantSwitchPref.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mDeterminantSwitchPref.setChecked(!mDeterminantSwitchPref.isChecked());
if (mDeterminantSwitchPref.isChecked()) {
mCircledImageViewPref.cancelCountDownTimer();
mCircledImageViewPref.setStartCircledImageView();
mPreferenceScreen.removePreference(mProgressBarPreference);
mPreferenceScreen.addPreference(mCircledImageViewPref);
} else {
mPreferenceScreen.removePreference(mCircledImageViewPref);
mPreferenceScreen.addPreference(mProgressBarPreference);
}
return true;
}
});
}
示例15: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BrowserApp.getAppComponent().inject(this);
addPreferencesFromResource(R.xml.preference_debug);
mSwitchLeakCanary = (SwitchPreference) findPreference(LEAK_CANARY);
mSwitchLeakCanary.setChecked(mPreferenceManager.getUseLeakCanary());
mSwitchLeakCanary.setOnPreferenceChangeListener(this);
}