Android CheckBoxPreference - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android CheckBoxPreference class.

This code example shows how to use the following methods:setOnPreferenceChangeListener, setChecked
  public void onResume() { 
    super.onResume(); 
 
    CheckBoxPreference pref=(CheckBoxPreference)findPreference(KEY_ENABLED);
     
    pref.setChecked(mgr.isAdminActive(cn));
    pref.setOnPreferenceChangeListener(this);
  } 
 
  @Override 
  public boolean onPreferenceChange(Preference pref, Object newValue) {
    if (KEY_ENABLED.equals(pref.getKey())) {
      boolean value=((Boolean)newValue).booleanValue();
 
      if (value) {
        Intent intent=
            new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cn);
        intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                        getString(R.string.device_admin_explanation));
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setEnabled, setChecked
    } 
 
    private void handleNsdStateChanged(int newState) {
        switch (newState) {
            case NsdManager.NSD_STATE_DISABLED:
                mCheckbox.setChecked(false);
                mCheckbox.setEnabled(true);
                break; 
            case NsdManager.NSD_STATE_ENABLED:
                mCheckbox.setChecked(true);
                mCheckbox.setEnabled(true);
                break; 
        } 
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isChecked, setChecked
 
    @Override 
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
            Preference preference) {
        if (preference == mBackup) {
            if (!mBackup.isChecked()) {
                showEraseBackupDialog(); 
            } else { 
                setBackupEnabled(true); 
            } 
        } else if (preference == mAutoRestore) {
            boolean curState = mAutoRestore.isChecked();
            try { 
                mBackupManager.setAutoRestore(curState);
            } catch (RemoteException e) {
                mAutoRestore.setChecked(!curState);
            } 
        } 
        return super.onPreferenceTreeClick(preferenceScreen, preference);
    } 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getKey, setDependency
        } 
 
    } 
 
    private void setHapticButtonDep() { 
        mHapticFeedbackUpPref.setDependency(mHapticFeedbackPref.getKey());
        mHapticFeedbackAllPref.setDependency(mHapticFeedbackUpPref.getKey());
    } 
 
    public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
        if (HAPTIC_FEEDBACK_PREF.equals(key)) {
            Settings.System.putInt(getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED,
                    mHapticFeedbackPref.isChecked() ? 1 : 0);
        } else if (HAPTIC_FEEDBACK_UP_PREF.equals(key)) {
            Settings.System.putInt(getContentResolver(),
                    Settings.System.HAPTIC_FEEDBACK_UP_ENABLED, 
                    mHapticFeedbackUpPref.isChecked() ? 1 : 0);
        } else if (HAPTIC_FEEDBACK_ALL_PREF.equals(key)) {
            Settings.System.putInt(getContentResolver(),
                    Settings.System.HAPTIC_FEEDBACK_ALL_ENABLED, 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isChecked
    @Override 
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
 
        if (preference == mPurgeableAssetsPref) {
            SystemProperties.set(PURGEABLE_ASSETS_PERSIST_PROP,
                    mPurgeableAssetsPref.isChecked() ? "1" : "0");
            return true; 
        } 
 
        if (preference == mKSMPref) {
            Utils.fileWriteOneLine(KSM_RUN_FILE, mKSMPref.isChecked() ? "1" : "0");
            return true; 
        } 
 
        return false; 
    } 
 
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        if (preference == mzRAM) {
            if (newValue != null) {
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setDependency, setKey, setChecked
	 */ 
	@SuppressWarnings("deprecation") 
	protected final CheckBoxPreference initBooleanPreference(String baseName, boolean defValue, String dependency) {
		// Update the loaded Preference with the actual preference key to load/store with 
		CheckBoxPreference pref = (CheckBoxPreference) findPreference(baseName);
		pref.setKey(baseName + "_" + key);
		pref.setDependency(dependency == null? null: dependency + "_" + key);
		// Update the Preference by loading the current stored value into the Checkbox, if it exists 
		pref.setChecked(sharedPrefs.getBoolean(baseName + "_" + key, defValue));
		return pref;
	} 
 
	/** 
	 * Updates a preference that allows picking an item from a list. No default value will be shown. 
	 * @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under 
	 *            item_name_[key] 
	 * @return The concrete {@link ListPreference} that is bound to this preference 
	 */ 
	protected final ListPreference initListPreference(String baseName) {
		return initListPreference(baseName, null);
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setChecked
     * on one radio alone. We need to do the following: 
     * - handle the case of wifi/bluetooth failures 
     * - mobile does not send failure notification, fail on timeout. 
     */ 
    private void onAirplaneModeChanged() { 
        mCheckBoxPref.setChecked(isAirplaneModeOn(mContext));
    } 
     
    /** 
     * Called when someone clicks on the checkbox preference. 
     */ 
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        if (Boolean.parseBoolean(
                    SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { 
            // In ECM mode, do not update database at this point 
        } else { 
            setAirplaneModeOn((Boolean) newValue);
        } 
        return true; 
    } 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setChecked
    } 
 
    @Override 
    public void onDismiss(DialogInterface dialog) {
        if (!mOkClicked) {
            mEnableReporting.setChecked(false);
        } 
    } 
 
    @Override 
    public void onClick(DialogInterface dialog, int which) {
        if (which == DialogInterface.BUTTON_POSITIVE) {
            mOkClicked = true;
            mPrefs.edit().putBoolean(ANONYMOUS_OPT_IN, true).apply();
            ReportingServiceManager.launchService(getActivity()); 
        } else if (which == DialogInterface.BUTTON_NEGATIVE) {
            mEnableReporting.setChecked(false);
        } else { 
            Uri uri = Uri.parse("http://www.cyanogenmod.org/blog/cmstats-what-it-is-and-why-you-should-opt-in");
            startActivity(new Intent(Intent.ACTION_VIEW, uri));
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setDefaultValue, setKey, setSummary, setTitle
This code example shows how to use the following methods:setDefaultValue, setKey, setOnPreferenceChangeListener, setSummary, setTitle

Related Android CheckBoxPreference Questions & Answers:

See Code Examples for Android CheckBoxPreference Methods: