Example usage for android.preference CheckBoxPreference setDependency

List of usage examples for android.preference CheckBoxPreference setDependency

Introduction

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

Prototype

public void setDependency(String dependencyKey) 

Source Link

Document

Sets the key of a Preference that this Preference will depend on.

Usage

From source file:nya.miku.wishmaster.api.AbstractChanModule.java

/**
 *     ( ?/ ) -? "  SSL"//from w w w.j a v a2 s  . c om
 * @param group ,   ??? 
 * @param dependencyKey -?? ?  ,   null
 */
protected void addUnsafeSslPreference(PreferenceGroup group, String dependencyKey) {
    final Context context = group.getContext();
    CheckBoxPreference unsafeSslPref = new CheckBoxPreference(context); //? "  SSL"
    unsafeSslPref.setTitle(R.string.pref_ignore_ssl_errors);
    unsafeSslPref.setSummary(R.string.pref_ignore_ssl_errors_summary);
    unsafeSslPref.setKey(getSharedKey(PREF_KEY_UNSAFE_SSL));
    unsafeSslPref.setDefaultValue(false);
    unsafeSslPref.setOnPreferenceChangeListener(updateHttpListener);
    group.addPreference(unsafeSslPref);
    if (dependencyKey != null)
        unsafeSslPref.setDependency(dependencyKey);
}

From source file:com.nttec.everychan.chans.infinity.InfinityModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    addPasswordPreference(preferenceGroup);
    CheckBoxPreference httpsPref = addHttpsPreference(preferenceGroup, true);
    CheckBoxPreference onionPref = new LazyPreferences.CheckBoxPreference(context);
    onionPref.setTitle(R.string.pref_use_onion);
    onionPref.setSummary(R.string.pref_use_onion_summary);
    onionPref.setKey(getSharedKey(PREF_KEY_USE_ONION));
    onionPref.setDefaultValue(false);//from  ww  w  . j a  va 2s . c  o  m
    onionPref.setDisableDependentsState(true);
    preferenceGroup.addPreference(onionPref);
    httpsPref.setDependency(getSharedKey(PREF_KEY_USE_ONION));
    addProxyPreferences(preferenceGroup);
}

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//from  w w  w . j  ava2  s  .  co  m
        public boolean onPreferenceClick(Preference preference) {
            fallbackRecaptchaPref.setEnabled(!proxyPreference.isChecked());
            if (proxyPreference.isChecked() && !fallbackRecaptchaPref.isChecked())
                fallbackRecaptchaPref.setChecked(true);
            return false;
        }
    });
}