本文整理汇总了Java中android.preference.SwitchPreference.isChecked方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchPreference.isChecked方法的具体用法?Java SwitchPreference.isChecked怎么用?Java SwitchPreference.isChecked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.SwitchPreference
的用法示例。
在下文中一共展示了SwitchPreference.isChecked方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
});
}
示例2: 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;
}
});
}
示例3: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
SwitchPreference switchPref = (SwitchPreference) findPreference(getString(R.string.key_auto_day_night));
mDayTimePref = findPreference(getString(R.string.key_day_mode_time));
mNightTimePref = findPreference(getString(R.string.key_night_mode_time));
mCachePreference = findPreference(getString(R.string.key_cache));
if (!switchPref.isChecked()) {
mDayTimePref.setEnabled(false);
mNightTimePref.setEnabled(false);
}
String cache = getCacheSizeString();
mCachePreference.setSummary(cache.equals("0.0B") ? "无缓存" : cache);
int[] time = PrefUtil.getDayNightModeStartTime(true);
int h = time[0];
int m = time[1];
mDayTimePref.setSummary(getString(R.string.format_hour_min2, formatTime(h), formatTime(m)));
time = PrefUtil.getDayNightModeStartTime(false);
h = time[0];
m = time[1];
mNightTimePref.setSummary(getString(R.string.format_hour_min2, formatTime(h), formatTime(m)));
switchPref.setOnPreferenceChangeListener(this);
mDayTimePref.setOnPreferenceClickListener(this);
mNightTimePref.setOnPreferenceClickListener(this);
findPreference(getString(R.string.key_theme)).setOnPreferenceClickListener(this);
mCachePreference.setOnPreferenceClickListener(this);
findPreference(getString(R.string.key_feedback)).setOnPreferenceClickListener(this);
}
示例4: updateCheckBoxSyncCalendarEnabled
import android.preference.SwitchPreference; //导入方法依赖的package包/类
void updateCheckBoxSyncCalendarEnabled() {
final SwitchPreference prefCalendar = (SwitchPreference) findPreference(AppSettings.Notifications.ENABLE_CALENDAR);
final SwitchPreference prefNotifications = (SwitchPreference) findPreference(AppSettings.Notifications.ENABLE_CALENDAR);
final Preference prefSyncCalendar = findPreference(AppSettings.Notifications.CHECKBOX_SYNC_CALENDAR);
if (prefCalendar.isChecked() && prefNotifications.isChecked())
prefSyncCalendar.setEnabled(true);
else
prefSyncCalendar.setEnabled(false);
}
示例5: onResume
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
SwitchPreference switchPreference = (SwitchPreference) findPreference("show_advanced_setting");
if (switchPreference.isChecked()) {
addPreferencesFromResource(R.xml.preference_advanced_setting);
}
}
示例6: initUseDeviceLockPreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void initUseDeviceLockPreference() {
SwitchPreference pref = (SwitchPreference) findPreference("useDeviceLock");
DevicePolicyManager mgr = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName cn = new ComponentName(mContext, AdminReceiver.class);
if (pref.isChecked() && !mgr.isAdminActive(cn) ) {
pref.setChecked(false);
}
}
示例7: toggleOver18Dependants
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void toggleOver18Dependants(boolean flag){
SwitchPreference labelPref = (SwitchPreference) getPreferenceManager().findPreference(SettingsActivity.general_label_nsfw);
if(labelPref.isChecked() != flag){
labelPref.setChecked(flag);
}
SwitchPreference prevPref = (SwitchPreference) getPreferenceManager().findPreference(SettingsActivity.general_preview_nsfw);
if(prevPref.isChecked() != flag){
prevPref.setChecked(flag);
}
}
示例8: setupPreference
import android.preference.SwitchPreference; //导入方法依赖的package包/类
private void setupPreference() {
SwitchPreference calendarSyncState = (SwitchPreference) findPreference("calendar_sync_state");
PreferenceCategory calendarCategory = (PreferenceCategory) findPreference("calendar_category");
if (!SupporterHelper.isSupporter()) {
calendarSyncState.setChecked(false);
calendarSyncState.setEnabled(false);
calendarCategory.setTitle(calendarCategory.getTitle() + " (Supporter Feature)");
} else {
if (calendarSyncState.isChecked() && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED) {
setCalendarPreference();
} else if (calendarSyncState.isChecked() && ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(context, "Calendar permission denied, try re-selecting or go to Android Settings -> Apps to enable.", Toast.LENGTH_LONG).show();
}
}
}
示例9: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
notificationSwitch =
(SwitchPreference)findPreference(
getString(R.string.notifications_switch_key) );
notificationSwitch.setTitle(R.string.notifications_switch_title);
if ( notificationSwitch.isChecked() ) {
notificationSwitch.setSummary( alarmNextDueString() );
} else {
notificationSwitch.setSummary(
R.string.notifications_switched_off_confirmation);
}
notificationSwitch.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
boolean switchValue = (Boolean)newValue;
Log.d(LOG_TAG, "New value for notification switch will be "
+ switchValue);
if (switchValue == false) {
Log.d(LOG_TAG, "Disabling notifications... ");
Alarms.getInstance().cancel();
SettingsFragment.this.notificationSwitch.setSummary(
R.string.notifications_switched_off_confirmation);
showToast(R.string.notifications_switched_off_confirmation);
} else {
Log.d(LOG_TAG, "Enabling notifications... ");
AlarmTimeInterval interval = getAlarmInterval();
Alarms.getInstance().set(interval);
SettingsFragment.this.notificationSwitch.setSummary(
alarmNextDueString() );
showToast(R.string.notifications_switched_on_confirmation,
interval.getDays(),
interval.getHours(),
interval.getMinutes() );
}
return true;
}
}
);
preferenceListener = new NextAlarmPreferenceListener();
getActivity().getSharedPreferences(LOG_TAG, Context.MODE_PRIVATE)
.registerOnSharedPreferenceChangeListener(preferenceListener);
}
示例10: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.internal_sensor__confix);
enabledSensorNr = 0;
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
String[] internalSensorArrayList = getResources().getStringArray(
R.array.internal_sensor_config);
for (String s : internalSensorArrayList) {
final SwitchPreference swp = (SwitchPreference) getPreferenceManager()
.findPreference(s);
if (swp.isChecked())
enabledSensorNr++;
if (!availableSensor(swp.getKey())) {
swp.setSummary("not available");
swp.setEnabled(false);
} else {
swp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(
Preference preference, Object newValue) {
if ((Boolean) newValue) {
if (enabledSensorNr >= 2) {
openPopupDialog("Warning",
"More than 2 sensors can't be enabled at once!");
return false;
} else {
enabledSensorNr++;
return true;
}
} else {
enabledSensorNr--;
return true;
}
}
});
}
}
}
示例11: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.stats_widget_settings);
int defaultAppsNo = WIDGET_3X3_DEFAULT_APPSNO;
int defaultAppsNoLs = WIDGET_3X3_DEFAULT_APPSNO_LS;
SharedPreferences mPrefs = prefs.prefsGet();
divider_preference = (CheckBoxPreference)findPreference(Settings.DIVIDER_PREFERENCE);
divider_preference.setChecked(mPrefs.getBoolean(Settings.DIVIDER_PREFERENCE, Settings.DIVIDER_DEFAULT));
divider_preference.setOnPreferenceChangeListener(changeListener);
rounded_corners_preference = (CheckBoxPreference)findPreference(Settings.ROUNDED_CORNERS_PREFERENCE);
rounded_corners_preference.setChecked(mPrefs.getBoolean(Settings.ROUNDED_CORNERS_PREFERENCE, Settings.ROUNDED_CORNERS_DEFAULT));
rounded_corners_preference.setOnPreferenceChangeListener(changeListener);
apps_by_widget_size_preference = (SwitchPreference)findPreference(Settings.APPS_BY_WIDGET_SIZE_PREFERENCE);
apps_by_widget_size_preference.setChecked(mPrefs.getBoolean(Settings.APPS_BY_WIDGET_SIZE_PREFERENCE, Settings.APPS_BY_WIDGET_SIZE_DEFAULT));
apps_by_widget_size_preference.setOnPreferenceChangeListener(changeListener);
background_color_preference = (ColorPickerPreference) findPreference(Settings.BACKGROUND_COLOR_PREFERENCE);
int intColor = mPrefs.getInt(Settings.BACKGROUND_COLOR_PREFERENCE, Settings.BACKGROUND_COLOR_DEFAULT);
String hexColor = String.format("#%08x", (intColor));
background_color_preference.setSummary(hexColor);
background_color_preference.setOnPreferenceChangeListener(changeListener);
appnos_preference = (UpdatingListPreference)findPreference(Settings.STATS_WIDGET_APPSNO_PREFERENCE);
appnos_preference.setValue(mPrefs.getString(extras == null ? Settings.STATS_WIDGET_APPSNO_PREFERENCE : Integer.toString(defaultAppsNo),
Integer.toString(defaultAppsNo)));
appnos_preference.setOnPreferenceChangeListener(changeListener);
if (apps_by_widget_size_preference.isChecked()) {
appnos_preference.setSummary(R.string.automatic_appsno);
}
appnos_ls_preference = (UpdatingListPreference)findPreference(Settings.STATS_WIDGET_APPSNO_LS_PREFERENCE);
appnos_ls_preference.setValue(mPrefs.getString(extras == null ? Settings.STATS_WIDGET_APPSNO_LS_PREFERENCE : Integer.toString(defaultAppsNoLs),
Integer.toString(defaultAppsNoLs)));
appnos_ls_preference.setOnPreferenceChangeListener(changeListener);
if (apps_by_widget_size_preference.isChecked()) {
appnos_ls_preference.setSummary(R.string.automatic_appsno);
}
alignment_preference = (UpdatingListPreference)findPreference(Settings.ALIGNMENT_PREFERENCE);
alignment_preference.setValue(mPrefs.getString(Settings.ALIGNMENT_PREFERENCE,
Integer.toString(Settings.ALIGNMENT_DEFAULT)));
alignment_preference.setOnPreferenceChangeListener(changeListener);
}
示例12: onCreate
import android.preference.SwitchPreference; //导入方法依赖的package包/类
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.apps_widget_settings);
int defaultAppsNo = APPS_WIDGET_DEFAULT_APPSNO;
int defaultAppsNoLs = APPS_WIDGET_DEFAULT_APPSNO_LS;
SharedPreferences mPrefs = prefs.prefsGet();
apps_by_widget_size_preference = (SwitchPreference)findPreference(Settings.APPS_BY_WIDGET_SIZE_PREFERENCE);
apps_by_widget_size_preference.setChecked(mPrefs.getBoolean(Settings.APPS_BY_WIDGET_SIZE_PREFERENCE, Settings.APPS_BY_WIDGET_SIZE_DEFAULT));
apps_by_widget_size_preference.setOnPreferenceChangeListener(changeListener);
background_color_preference = (ColorPickerPreference) findPreference(Settings.BACKGROUND_COLOR_PREFERENCE);
int intColor = mPrefs.getInt(Settings.BACKGROUND_COLOR_PREFERENCE, Settings.BACKGROUND_COLOR_DEFAULT);
String hexColor = String.format("#%08x", (intColor));
background_color_preference.setSummary(hexColor);
background_color_preference.setOnPreferenceChangeListener(changeListener);
appnos_preference = (UpdatingListPreference)findPreference(Settings.STATS_WIDGET_APPSNO_PREFERENCE);
appnos_preference.setValue(mPrefs.getString(extras == null ? Settings.STATS_WIDGET_APPSNO_PREFERENCE : Integer.toString(defaultAppsNo),
Integer.toString(defaultAppsNo)));
appnos_preference.setOnPreferenceChangeListener(changeListener);
if (apps_by_widget_size_preference.isChecked()) {
appnos_preference.setSummary(R.string.automatic_appsno);
}
appnos_ls_preference = (UpdatingListPreference)findPreference(Settings.STATS_WIDGET_APPSNO_LS_PREFERENCE);
appnos_ls_preference.setValue(mPrefs.getString(extras == null ? Settings.STATS_WIDGET_APPSNO_LS_PREFERENCE : Integer.toString(defaultAppsNoLs),
Integer.toString(defaultAppsNoLs)));
appnos_ls_preference.setOnPreferenceChangeListener(changeListener);
if (apps_by_widget_size_preference.isChecked()) {
appnos_ls_preference.setSummary(R.string.automatic_appsno);
}
weighted_recents_preference = (CheckBoxPreference)findPreference(Settings.WEIGHTED_RECENTS_PREFERENCE);
weighted_recents_preference.setChecked(mPrefs.getBoolean(Settings.WEIGHTED_RECENTS_PREFERENCE, Settings.WEIGHTED_RECENTS_DEFAULT));
weighted_recents_preference.setOnPreferenceChangeListener(changeListener);
weight_priority_preference = (UpdatingListPreference)findPreference(Settings.WEIGHT_PRIORITY_PREFERENCE);
weight_priority_preference.setValue(mPrefs.getString(Settings.WEIGHT_PRIORITY_PREFERENCE, Integer.toString(Settings.WEIGHT_PRIORITY_DEFAULT)));
weight_priority_preference.setOnPreferenceChangeListener(changeListener);
colorize_preference = (CheckBoxPreference)findPreference(Settings.COLORIZE_PREFERENCE);
colorize_preference.setChecked(mPrefs.getBoolean(Settings.COLORIZE_PREFERENCE, Settings.COLORIZE_DEFAULT));
colorize_preference.setOnPreferenceChangeListener(changeListener);
ignore_pinned_preference = (CheckBoxPreference)findPreference(Settings.IGNORE_PINNED_PREFERENCE);
ignore_pinned_preference.setChecked(mPrefs.getBoolean(Settings.IGNORE_PINNED_PREFERENCE, Settings.IGNORE_PINNED_DEFAULT));
ignore_pinned_preference.setOnPreferenceChangeListener(changeListener);
icon_color_preference = (ColorPickerPreference) findPreference(Settings.ICON_COLOR_PREFERENCE);
int intColor2 = mPrefs.getInt(Settings.ICON_COLOR_PREFERENCE, Settings.ICON_COLOR_DEFAULT);
String hexColor2 = String.format("#%08x", (intColor2));
icon_color_preference.setSummary(hexColor2);
icon_color_preference.setOnPreferenceChangeListener(changeListener);
rounded_corners_preference = (CheckBoxPreference)findPreference(Settings.ROUNDED_CORNERS_PREFERENCE);
rounded_corners_preference.setChecked(mPrefs.getBoolean(Settings.ROUNDED_CORNERS_PREFERENCE, Settings.ROUNDED_CORNERS_DEFAULT));
rounded_corners_preference.setOnPreferenceChangeListener(changeListener);
icon_size_preference = (UpdatingListPreference)findPreference(Settings.ICON_SIZE_PREFERENCE);
icon_size_preference.setValue(mPrefs.getString(Settings.ICON_SIZE_PREFERENCE, Integer.toString(Settings.ICON_SIZE_DEFAULT)));
icon_size_preference.setOnPreferenceChangeListener(changeListener);
alignment_preference = (UpdatingListPreference)findPreference(Settings.ALIGNMENT_PREFERENCE);
alignment_preference.setValue(mPrefs.getString(Settings.ALIGNMENT_PREFERENCE,
Integer.toString(Settings.ALIGNMENT_DEFAULT)));
alignment_preference.setOnPreferenceChangeListener(changeListener);
}