當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。