Example usage for android.preference CheckBoxPreference isChecked

List of usage examples for android.preference CheckBoxPreference isChecked

Introduction

In this page you can find the example usage for android.preference CheckBoxPreference isChecked.

Prototype

public boolean isChecked() 

Source Link

Document

Returns the checked state.

Usage

From source file:Main.java

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);//  ww w  .  j  av a2s .  c om
    switchPref.setDependency(checkBox.getDependency());
}

From source file:de.grobox.blitzmail.MainActivity.java

private void setPrefState() {
    CheckBoxPreference authPref = (CheckBoxPreference) findPreference("pref_smtp_auth");
    if (authPref.isChecked()) {
        findPreference("pref_smtp_encryption").setEnabled(true);
        findPreference("pref_smtp_user").setEnabled(true);
        findPreference("pref_smtp_pass").setEnabled(true);
    } else {//from www .j  av a2  s.  co m
        findPreference("pref_smtp_encryption").setEnabled(false);
        findPreference("pref_smtp_user").setEnabled(false);
        findPreference("pref_smtp_pass").setEnabled(false);
    }
}

From source file:com.adam.aslfms.MusicAppsActivity.java

@Override
public boolean onPreferenceTreeClick(PreferenceScreen prefScreen, Preference pref) {

    // we clicked an "enable music app" checkbox
    MusicAPI mapi = mPrefsToMapisMap.get(pref);
    if (mapi != null) {
        CheckBoxPreference cbp = (CheckBoxPreference) pref;
        boolean checked = cbp.isChecked();
        mapi.setEnabled(this, checked);
        setSMASummary(pref, mapi);/*from  w ww.j a va2s . c  o m*/

        if (checked && mScrobbleDroidInstalled && mapi.clashesWithScrobbleDroid()) {
            Util.warningDialog(this,
                    getString(R.string.incompatability_long).replaceAll("%1", mScrobbleDroidLabel));
        }
        return true;
    }

    return super.onPreferenceTreeClick(prefScreen, pref);
}

From source file:de.badaix.snapcast.GroupSettingsFragment.java

public ArrayList<String> getClients() {
    ArrayList<String> clients = new ArrayList<>();
    for (int i = 0; i < prefCatClients.getPreferenceCount(); ++i) {
        CheckBoxPreference checkBoxPref = (CheckBoxPreference) prefCatClients.getPreference(i);
        if (checkBoxPref.isChecked())
            clients.add(checkBoxPref.getKey());
    }/*from   ww w  .  j  av  a 2 s.  c  om*/
    return clients;
}

From source file:net.imatruck.betterweather.settings.BetterWeatherSettingsActivity.java

private void updateShortcutPreferenceState(String key) {
    Preference pref = findPreference(key);
    if (pref instanceof CheckBoxPreference) {
        CheckBoxPreference refreshOnTouchPref = (CheckBoxPreference) pref;

        Preference shortcutPref = findPreference(BetterWeatherExtension.PREF_WEATHER_SHORTCUT);

        if (shortcutPref == null)
            return;

        if (refreshOnTouchPref.isChecked()) {
            shortcutPref.setEnabled(false);
            shortcutPref.setSummary(R.string.shortcut_pref_help_text);
        } else {//from   w  w w.  j  a v  a2  s  .c  o m
            shortcutPref.setEnabled(true);
            bindPreferenceSummaryToValue(findPreference(BetterWeatherExtension.PREF_WEATHER_SHORTCUT));
        }
    }
}

From source file:de.Maxr1998.xposed.maxlock.ui.settings.SettingsFragment.java

@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    super.onPreferenceTreeClick(preferenceScreen, preference);
    if (preference == findPreference(Common.LOCKING_TYPE_SETTINGS)) {
        launchFragment(new LockingTypeSettingsFragment(), true, this);
        return true;
    } else if (preference == findPreference(Common.LOCKING_UI_SETTINGS)) {
        launchFragment(new LockingUISettingsFragment(), true, this);
        return true;
    } else if (preference == findPreference(Common.LOCKING_OPTIONS)) {
        PREFS.edit().putBoolean(Common.ENABLE_LOGGING, PREFS.getBoolean(Common.ENABLE_PRO, false)).apply();
        launchFragment(new LockingOptionsFragment(), true, this);
        return true;
    } else if (preference == findPreference(Common.IIMOD_OPTIONS)) {
        // Setup remain timer
        long timer = PREFS.getInt(Common.IMOD_DELAY_GLOBAL, 600000)
                - (System.currentTimeMillis() - PREFS.getLong(Common.IMOD_LAST_UNLOCK_GLOBAL, 0));
        if (timer < 0) {
            timer = 0L;/*  w  w w  .j  av a  2s  .c  o m*/
        }
        PREFS.edit().putInt(Common.IMOD_REMAIN_TIMER_GLOBAL, (int) timer).apply();
        launchFragment(new LockingIntikaFragment(), true, this);
        return true;
    } else if (preference == findPreference(Common.CHOOSE_APPS)) {
        launchFragment(new AppListFragment(), true, this);
        return true;
    } else if (preference == findPreference(Common.HIDE_APP_FROM_LAUNCHER)
            && preference instanceof CheckBoxPreference) {
        CheckBoxPreference hideApp = (CheckBoxPreference) preference;
        if (hideApp.isChecked()) {
            Toast.makeText(getActivity(), R.string.reboot_required, Toast.LENGTH_SHORT).show();
            ComponentName componentName = new ComponentName(getActivity(), "de.Maxr1998.xposed.maxlock.Main");
            getActivity().getPackageManager().setComponentEnabledSetting(componentName,
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
        } else {
            ComponentName componentName = new ComponentName(getActivity(), "de.Maxr1998.xposed.maxlock.Main");
            getActivity().getPackageManager().setComponentEnabledSetting(componentName,
                    PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
        }
    } else if (preference == findPreference(Common.USE_DARK_STYLE)
            || preference == findPreference(Common.ENABLE_PRO)) {
        ((SettingsActivity) getActivity()).restart();
        return true;
    } else if (preference == findPreference(Common.UNINSTALL)) {
        if (!isDeviceAdminActive()) {
            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin);
            startActivity(intent);
        } else {
            devicePolicyManager.removeActiveAdmin(deviceAdmin);
        }
        return true;
    }
    return false;
}

From source file:de.azapps.mirakel.settings.model_settings.special_list.SpecialListDetailFragment.java

private CheckBoxPreference getIsActivePreference() {
    final CheckBoxPreference active = new CheckBoxPreference(getActivity());
    active.setTitle(R.string.special_list_active);
    active.setChecked(mItem.isActive());
    active.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override/* w w w.ja  v a  2s  .com*/
        public boolean onPreferenceClick(Preference preference) {
            boolean a = !active.isChecked();
            mItem.setActive(a);
            mItem.save();
            active.setChecked(mItem.isActive());
            mAdapter.notifyDataSetChanged();
            return true;
        }
    });
    return active;
}

From source file:com.googlecode.mindbell.MindBellPreferences.java

/**
 * Ensures that the CheckBoxPreferences checkBoxPreferenceMuteOffHook and checkBoxPreferenceStatus cannot be both "on" without
 * having READ_PHONE_STATE permission by returning false when this rule is violated.
 *///from   w  ww. jav  a  2 s.  co m
private boolean mediateMuteOffHookAndStatus(CheckBoxPreference other, Object newValue, int requestCode) {
    if (!other.isChecked() || !((Boolean) newValue) || ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        // Allow setting this option to "on" if other option is "off" or permission is granted
        return true;
    } else {
        // Ask for permission if other option is "on" and this option shall be set to "on" but permission is missing
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_PHONE_STATE },
                requestCode);
        // As the permission request is asynchronous we have to deny setting this option (to "on")
        return false;
    }
}

From source file:com.googlecode.mindbell.MindBellPreferences.java

/**
 * Ensures that the CheckBoxPreferences checkBoxPreferenceShow, checkBoxPreferenceSound and checkBoxPreferenceVibrate cannot be
 * all "off", at least one must be checked.
 *///from w  ww  .j  a  v  a2  s  . c o  m
private boolean mediateShowAndSoundAndVibrate(CheckBoxPreference firstOther, CheckBoxPreference secondOther,
        Object newValue) {
    if (!firstOther.isChecked() && !secondOther.isChecked() && !((Boolean) newValue)) {
        Toast.makeText(this, R.string.atLeastOneRingingActionNeeded, Toast.LENGTH_SHORT).show();
        return false;
    }
    return true;
}

From source file:com.nttec.everychan.chans.fourchan.FourchanModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    addPasscodePreference(preferenceGroup);

    CheckBoxPreference newRecaptchaPref = new LazyPreferences.CheckBoxPreference(context);
    newRecaptchaPref.setTitle(R.string.fourchan_prefs_new_recaptcha);
    newRecaptchaPref.setSummary(R.string.fourchan_prefs_new_recaptcha_summary);
    newRecaptchaPref.setKey(getSharedKey(PREF_KEY_NEW_RECAPTCHA));
    newRecaptchaPref.setDefaultValue(NEW_RECAPTCHA_DEFAULT);
    preferenceGroup.addPreference(newRecaptchaPref);

    final CheckBoxPreference fallbackRecaptchaPref = new LazyPreferences.CheckBoxPreference(context);
    fallbackRecaptchaPref.setTitle(R.string.fourchan_prefs_new_recaptcha_fallback);
    fallbackRecaptchaPref.setSummary(R.string.fourchan_prefs_new_recaptcha_fallback_summary);
    fallbackRecaptchaPref.setKey(getSharedKey(PREF_KEY_NEW_RECAPTCHA_FALLBACK));
    fallbackRecaptchaPref.setDefaultValue(false);
    preferenceGroup.addPreference(fallbackRecaptchaPref);
    fallbackRecaptchaPref.setDependency(getSharedKey(PREF_KEY_NEW_RECAPTCHA));

    addPasswordPreference(preferenceGroup);
    addHttpsPreference(preferenceGroup, true);
    addProxyPreferences(preferenceGroup);

    final CheckBoxPreference proxyPreference = (CheckBoxPreference) preferenceGroup
            .findPreference(getSharedKey(PREF_KEY_USE_PROXY));
    fallbackRecaptchaPref.setEnabled(!proxyPreference.isChecked());
    proxyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override//w  ww  . j  ava2 s .  c  om
        public boolean onPreferenceClick(Preference preference) {
            fallbackRecaptchaPref.setEnabled(!proxyPreference.isChecked());
            if (proxyPreference.isChecked() && !fallbackRecaptchaPref.isChecked())
                fallbackRecaptchaPref.setChecked(true);
            return false;
        }
    });
}