当前位置: 首页>>代码示例>>Java>>正文


Java SwitchPreference.isChecked方法代码示例

本文整理汇总了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;
                }
            });
}
 
开发者ID:googlesamples,项目名称:android-WearAccessibilityApp,代码行数:13,代码来源:NotificationsActivity.java

示例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;
                }
            });
}
 
开发者ID:googlesamples,项目名称:android-WearAccessibilityApp,代码行数:13,代码来源:NotificationsActivity.java

示例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);
}
 
开发者ID:woxingxiao,项目名称:GracefulMovies,代码行数:35,代码来源:SettingsFragment.java

示例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);
}
 
开发者ID:pvarry,项目名称:intra42,代码行数:11,代码来源:SettingsActivity.java

示例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);
    }
}
 
开发者ID:CreateChance,项目名称:AndroidSettingsDemo,代码行数:12,代码来源:PrefsFragmentTwo.java

示例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);
    }
}
 
开发者ID:firebirdberlin,项目名称:nightdream,代码行数:10,代码来源:PreferencesFragment.java

示例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);
    }
}
 
开发者ID:Redgram,项目名称:redgram-for-reddit,代码行数:11,代码来源:GeneralPreferenceFragment.java

示例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();
        }
    }
}
 
开发者ID:ItsCalebJones,项目名称:SpaceLaunchNow-Android,代码行数:16,代码来源:GeneralFragment.java

示例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);
}
 
开发者ID:mfitz,项目名称:android-002,代码行数:54,代码来源:SettingsFragment.java

示例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;
					}
				}
			});
		}
	}
}
 
开发者ID:myHealthAssistant-tudarmstadt,项目名称:myHealthHub,代码行数:44,代码来源:InternalSensorPreference.java

示例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);
}
 
开发者ID:corcoran,项目名称:Hangar,代码行数:50,代码来源:StatsWidgetSettings.java

示例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);
}
 
开发者ID:corcoran,项目名称:Hangar,代码行数:72,代码来源:AppsWidgetSettings.java


注:本文中的android.preference.SwitchPreference.isChecked方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。