Java Code Examples for android.preference.CheckBoxPreference#setDefaultValue()

The following examples show how to use android.preference.CheckBoxPreference#setDefaultValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsActivity.java    From nitroshare-android with MIT License 6 votes vote down vote up
/**
 * Create a SwitchPreference for the specified preference
 * @param titleResId resource ID to use for the title
 * @param summaryResId resource ID to use for the summary
 * @param key preference key
 * @return newly created preference
 */
private CheckBoxPreference createCheckBoxPreference(@StringRes int titleResId, @StringRes int summaryResId, Settings.Key key) {
    final CheckBoxPreference checkBoxPreference = new CheckBoxPreference(getActivity());
    checkBoxPreference.setDefaultValue(mSettings.getDefault(key));
    checkBoxPreference.setKey(key.name());
    checkBoxPreference.setSummary(summaryResId);
    checkBoxPreference.setTitle(titleResId);
    checkBoxPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            checkBoxPreference.setChecked((boolean) newValue);
            return true;
        }
    });
    return checkBoxPreference;
}
 
Example 2
Source File: DvachModule.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    addPasswordPreference(preferenceGroup);
    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);
    onionPref.setDisableDependentsState(true);
    preferenceGroup.addPreference(onionPref);
    EditTextPreference domainPref = new EditTextPreference(context);
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.getEditText().setHint(DEFAULT_DOMAIN);
    domainPref.getEditText().setSingleLine();
    domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    preferenceGroup.addPreference(domainPref);
    domainPref.setDependency(getSharedKey(PREF_KEY_USE_ONION));
    addProxyPreferences(preferenceGroup);
}
 
Example 3
Source File: Pref.java    From GeoLog with Apache License 2.0 5 votes vote down vote up
public static CheckBoxPreference Check(Context context, PreferenceCategory category, int caption, int summary, String key, Object defaultValue, boolean enabled) {
	CheckBoxPreference retval = new CheckBoxPreference(context);
	if (caption > 0) retval.setTitle(caption);
	if (summary > 0) retval.setSummary(summary);
	retval.setEnabled(enabled);
	retval.setKey(key);
	retval.setDefaultValue(defaultValue);
	if (category != null) category.addPreference(retval);
	return retval;
}
 
Example 4
Source File: SettingFragment.java    From ZhihuDaily with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.setting);

    Preference clearCache = getPreferenceScreen().findPreference("clear_cache");
    CheckBoxPreference noImgMode = (CheckBoxPreference) findPreference("NO_IMAGE_MODE");
    if ((boolean) SharedPreferencesUtils.get(App.getContext(), "NO_IMAGE_MODE", false)) {
        noImgMode.setDefaultValue(true);
    } else {
        noImgMode.setDefaultValue(false);
    }
    clearCache.setOnPreferenceClickListener(this);
    noImgMode.setOnPreferenceClickListener(this);
}
 
Example 5
Source File: Pref.java    From GeoLog with Apache License 2.0 5 votes vote down vote up
public static CheckBoxPreference Check(Context context, PreferenceCategory category, String caption, String summary, String key, Object defaultValue, boolean enabled) {
	CheckBoxPreference retval = new CheckBoxPreference(context);
	retval.setTitle(caption);
	retval.setSummary(summary);
	retval.setEnabled(enabled);
	retval.setKey(key);
	retval.setDefaultValue(defaultValue);
	if (category != null) category.addPreference(retval);
	return retval;
}
 
Example 6
Source File: BasePreferenceFragment.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public CheckBoxPreference makeCheckBox(PreferenceGroup parent, boolean persistent, String key,
		boolean defaultValue, CharSequence title, CharSequence summary) {
	CheckBoxPreference preference = new CheckBoxPreference(getActivity());
	preference.setPersistent(persistent);
	preference.setKey(key);
	preference.setTitle(title);
	if (summary != null) {
		preference.setSummary(summary);
	}
	preference.setDefaultValue(defaultValue);
	addPreference(parent, preference);
	return preference;
}
 
Example 7
Source File: FourchanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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
        public boolean onPreferenceClick(Preference preference) {
            fallbackRecaptchaPref.setEnabled(!proxyPreference.isChecked());
            if (proxyPreference.isChecked() && !fallbackRecaptchaPref.isChecked()) fallbackRecaptchaPref.setChecked(true);
            return false;
        }
    });
}
 
Example 8
Source File: MakabaModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/** Добавить категорию настроек домена (в т.ч. https) */
private void addDomainPreferences(PreferenceGroup group) {
    Context context = group.getContext();
    Preference.OnPreferenceChangeListener updateDomainListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (preference.getKey().equals(getSharedKey(PREF_KEY_DOMAIN))) {
                updateDomain((String) newValue, preferences.getBoolean(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA), true));
                return true;
            } else if (preference.getKey().equals(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA))) {
                updateDomain(preferences.getString(getSharedKey(PREF_KEY_DOMAIN), DEFAULT_DOMAIN), (boolean)newValue);
                return true;
            }
            return false;
        }
    };
    PreferenceCategory domainCat = new PreferenceCategory(context);
    domainCat.setTitle(R.string.makaba_prefs_domain_category);
    group.addPreference(domainCat);
    EditTextPreference domainPref = new EditTextPreference(context); //поле ввода домена
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT));
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.getEditText().setHint(DEFAULT_DOMAIN);
    domainPref.getEditText().setSingleLine();
    domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    domainPref.setOnPreferenceChangeListener(updateDomainListener);
    domainCat.addPreference(domainPref);
    CheckBoxPreference httpsPref = new LazyPreferences.CheckBoxPreference(context); //чекбокс "использовать https"
    httpsPref.setTitle(R.string.pref_use_https);
    httpsPref.setSummary(R.string.pref_use_https_summary);
    httpsPref.setKey(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA));
    httpsPref.setDefaultValue(true);
    httpsPref.setOnPreferenceChangeListener(updateDomainListener);
    domainCat.addPreference(httpsPref);
}
 
Example 9
Source File: MakabaModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private void addMobileAPIPreference(PreferenceGroup group) {
    final Context context = group.getContext();
    CheckBoxPreference mobileAPIPref = new LazyPreferences.CheckBoxPreference(context);
    mobileAPIPref.setTitle(R.string.makaba_prefs_mobile_api);
    mobileAPIPref.setSummary(R.string.pref_only_new_posts_summary);
    mobileAPIPref.setKey(getSharedKey(PREF_KEY_MOBILE_API));
    mobileAPIPref.setDefaultValue(true);
    group.addPreference(mobileAPIPref);
}
 
Example 10
Source File: InfinityModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@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);
    onionPref.setDisableDependentsState(true);
    preferenceGroup.addPreference(onionPref);
    httpsPref.setDependency(getSharedKey(PREF_KEY_USE_ONION));
    addProxyPreferences(preferenceGroup);
}
 
Example 11
Source File: HorochanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    addOnlyNewPostsPreference(preferenceGroup, true);
    CheckBoxPreference fallbackRecaptchaPref = new LazyPreferences.CheckBoxPreference(context); // recaptcha fallback
    fallbackRecaptchaPref.setTitle(R.string.fourchan_prefs_new_recaptcha_fallback);
    fallbackRecaptchaPref.setSummary(R.string.fourchan_prefs_new_recaptcha_fallback_summary);
    fallbackRecaptchaPref.setKey(getSharedKey(PREF_KEY_RECAPTCHA_FALLBACK));
    fallbackRecaptchaPref.setDefaultValue(false);
    preferenceGroup.addPreference(fallbackRecaptchaPref);
    addHttpsPreference(preferenceGroup, true); //https
    addCloudflareRecaptchaFallbackPreference(preferenceGroup);
    addProxyPreferences(preferenceGroup);
}
 
Example 12
Source File: DobroModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private void addCaptchaPreference(PreferenceGroup group) {
    Context context = group.getContext();
    CheckBoxPreference showCaptchaPreference = new LazyPreferences.CheckBoxPreference(context);
    showCaptchaPreference.setTitle(R.string.dobrochan_prefs_show_captcha);
    showCaptchaPreference.setSummary(R.string.dobrochan_prefs_show_captcha_summary);
    showCaptchaPreference.setKey(getSharedKey(PREF_KEY_SHOW_CAPTCHA));
    showCaptchaPreference.setDefaultValue(false);
    group.addPreference(showCaptchaPreference);
}
 
Example 13
Source File: AbstractChanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Добавить в группу параметров (на экран/в категорию) настройку выбора использования инкрементальной загрузки (загрузки только новых постов).
 * Для хранения используется ключ общих параметров {@link #PREF_KEY_ONLY_NEW_POSTS} ({@link #getSharedKey(String)}).
 * См. также: {@link #loadOnlyNewPosts(boolean)} - для получения значения параметра.
 * @param group группа, на которую добавляется параметр
 * @param defaultValue значение параметра по умолчанию
 * return объект {@link CheckBoxPreference} с параметром
 */
protected CheckBoxPreference addOnlyNewPostsPreference(PreferenceGroup group, boolean defaultValue) {
    final Context context = group.getContext();
    CheckBoxPreference onlyNewPostsPref = new LazyPreferences.CheckBoxPreference(context);
    onlyNewPostsPref.setTitle(R.string.pref_only_new_posts);
    onlyNewPostsPref.setSummary(R.string.pref_only_new_posts_summary);
    onlyNewPostsPref.setKey(getSharedKey(PREF_KEY_ONLY_NEW_POSTS));
    onlyNewPostsPref.setDefaultValue(defaultValue);
    group.addPreference(onlyNewPostsPref);
    return onlyNewPostsPref;
}
 
Example 14
Source File: AbstractChanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Добавить в группу параметров (на экран/в категорию) настройку выбора HTTPS (защищённого соединения).
 * Для хранения используется ключ общих параметров {@link #PREF_KEY_USE_HTTPS} ({@link #getSharedKey(String)}).
 * См. также: {@link #useHttps(boolean)} - для получения значения параметра.
 * @param group группа, на которую добавляется параметр
 * @param defaultValue значение параметра по умолчанию
 * return объект {@link CheckBoxPreference} с параметром
 */
protected CheckBoxPreference addHttpsPreference(PreferenceGroup group, boolean defaultValue) {
    final Context context = group.getContext();
    CheckBoxPreference httpsPref = new LazyPreferences.CheckBoxPreference(context);
    httpsPref.setTitle(R.string.pref_use_https);
    httpsPref.setSummary(R.string.pref_use_https_summary);
    httpsPref.setKey(getSharedKey(PREF_KEY_USE_HTTPS));
    httpsPref.setDefaultValue(defaultValue);
    group.addPreference(httpsPref);
    return httpsPref;
}
 
Example 15
Source File: AbstractChanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Добавить в группу параметров (на экран/в категорию) новую категорию настроек прокси-сервера
 * @param group группа, на которую добавляются параметры
 */
protected void addProxyPreferences(PreferenceGroup group) {
    final Context context = group.getContext();
    PreferenceCategory proxyCat = new PreferenceCategory(context); //категория настроек прокси
    proxyCat.setTitle(R.string.pref_cat_proxy);
    group.addPreference(proxyCat);
    CheckBoxPreference useProxyPref = new LazyPreferences.CheckBoxPreference(context); //чекбокс "использовать ли прокси вообще"
    useProxyPref.setTitle(R.string.pref_use_proxy);
    useProxyPref.setSummary(R.string.pref_use_proxy_summary);
    useProxyPref.setKey(getSharedKey(PREF_KEY_USE_PROXY));
    useProxyPref.setDefaultValue(false);
    useProxyPref.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(useProxyPref);
    EditTextPreference proxyHostPref = new LazyPreferences.EditTextPreference(context); //поле ввода адреса прокси-сервера
    proxyHostPref.setTitle(R.string.pref_proxy_host);
    proxyHostPref.setDialogTitle(R.string.pref_proxy_host);
    proxyHostPref.setSummary(R.string.pref_proxy_host_summary);
    proxyHostPref.setKey(getSharedKey(PREF_KEY_PROXY_HOST));
    proxyHostPref.setDefaultValue(DEFAULT_PROXY_HOST);
    proxyHostPref.getEditText().setSingleLine();
    proxyHostPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    proxyHostPref.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(proxyHostPref);
    proxyHostPref.setDependency(getSharedKey(PREF_KEY_USE_PROXY));
    EditTextPreference proxyHostPort = new LazyPreferences.EditTextPreference(context); //поле ввода порта прокси-сервера
    proxyHostPort.setTitle(R.string.pref_proxy_port);
    proxyHostPort.setDialogTitle(R.string.pref_proxy_port);
    proxyHostPort.setSummary(R.string.pref_proxy_port_summary);
    proxyHostPort.setKey(getSharedKey(PREF_KEY_PROXY_PORT));
    proxyHostPort.setDefaultValue(DEFAULT_PROXY_PORT);
    proxyHostPort.getEditText().setSingleLine();
    proxyHostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    proxyHostPort.setOnPreferenceChangeListener(updateHttpListener);
    proxyCat.addPreference(proxyHostPort);
    proxyHostPort.setDependency(getSharedKey(PREF_KEY_USE_PROXY));
}
 
Example 16
Source File: CloudflareChanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
protected void addCloudflareRecaptchaFallbackPreference(PreferenceGroup preferenceGroup) {
    if (canCloudflare()) {
        Context context = preferenceGroup.getContext();
        CheckBoxPreference fallbackPref = new LazyPreferences.CheckBoxPreference(context);
        fallbackPref.setTitle(R.string.pref_cf_recaptcha_fallback);
        fallbackPref.setSummary(R.string.pref_cf_recaptcha_fallback_summary);
        fallbackPref.setKey(getSharedKey(PREF_KEY_CLOUDFLARE_RECAPTCHA_FALLBACK));
        fallbackPref.setDefaultValue(false);
        preferenceGroup.addPreference(fallbackPref);
    }
}
 
Example 17
Source File: NotifySettingsActivity.java    From AndroidPNClient with Apache License 2.0 4 votes vote down vote up
private PreferenceScreen createPreferenceHierarchy() {
    Log.d(LOGTAG, "createSettingsPreferenceScreen()...");

    PreferenceManager preferenceManager = getPreferenceManager();
    preferenceManager
            .setSharedPreferencesName(Constants.SHARED_PREFERENCE_NAME);
    preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);

    PreferenceScreen root = preferenceManager.createPreferenceScreen(this);

    //        PreferenceCategory prefCat = new PreferenceCategory(this);
    //        // inlinePrefCat.setTitle("");
    //        root.addPreference(prefCat);

    CheckBoxPreference notifyPref = new CheckBoxPreference(this);
    notifyPref.setKey(Constants.SETTINGS_NOTIFICATION_ENABLED);
    notifyPref.setTitle(R.string.notifications_enabled);
    notifyPref.setSummaryOn(R.string.receive_push_messages);
    notifyPref.setSummaryOff(R.string.do_not_receive_push_messages);
    notifyPref.setDefaultValue(Boolean.TRUE);
    notifyPref
            .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    boolean checked = Boolean.valueOf(newValue.toString());
                    if (checked) {
                        preference.setTitle(R.string.notifications_enabled);
                    } else {
                        preference.setTitle(R.string.notifications_disabled);
                    }
                    return true;
                }
            });

    CheckBoxPreference soundPref = new CheckBoxPreference(this);
    soundPref.setKey(Constants.SETTINGS_SOUND_ENABLED);
    soundPref.setTitle(R.string.sound);
    soundPref.setSummary(R.string.play_sound_for_notifications);
    soundPref.setDefaultValue(Boolean.TRUE);
    // soundPref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED);

    CheckBoxPreference vibratePref = new CheckBoxPreference(this);
    vibratePref.setKey(Constants.SETTINGS_VIBRATE_ENABLED);
    vibratePref.setTitle(R.string.vibrate);
    vibratePref.setSummary(R.string.vibrate_the_phone_for_notifications);
    vibratePref.setDefaultValue(Boolean.TRUE);
    // vibratePref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED);

    root.addPreference(notifyPref);
    root.addPreference(soundPref);
    root.addPreference(vibratePref);

    //        prefCat.addPreference(notifyPref);
    //        prefCat.addPreference(soundPref);
    //        prefCat.addPreference(vibratePref);
    //        root.addPreference(prefCat);

    return root;
}
 
Example 18
Source File: NotificationSettingsActivity.java    From AndroidPNClient with Apache License 2.0 4 votes vote down vote up
private PreferenceScreen createPreferenceHierarchy() {
    Log.d(LOGTAG, "createSettingsPreferenceScreen()...");

    PreferenceManager preferenceManager = getPreferenceManager();
    preferenceManager
            .setSharedPreferencesName(Constants.SHARED_PREFERENCE_NAME);
    preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);

    PreferenceScreen root = preferenceManager.createPreferenceScreen(this);

    CheckBoxPreference notifyPref = new CheckBoxPreference(this);
    notifyPref.setKey(Constants.SETTINGS_NOTIFICATION_ENABLED);
    notifyPref.setTitle("Notifications Enabled");
    notifyPref.setSummaryOn("Receive push messages");
    notifyPref.setSummaryOff("Do not receive push messages");
    notifyPref.setDefaultValue(Boolean.TRUE);
    notifyPref
            .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    boolean checked = Boolean.valueOf(newValue.toString());
                    if (checked) {
                        preference.setTitle("Notifications Enabled");
                    } else {
                        preference.setTitle("Notifications Disabled");
                    }
                    return true;
                }
            });

    CheckBoxPreference soundPref = new CheckBoxPreference(this);
    soundPref.setKey(Constants.SETTINGS_SOUND_ENABLED);
    soundPref.setTitle("Sound");
    soundPref.setSummary("Play a sound for notifications");
    soundPref.setDefaultValue(Boolean.TRUE);

    CheckBoxPreference vibratePref = new CheckBoxPreference(this);
    vibratePref.setKey(Constants.SETTINGS_VIBRATE_ENABLED);
    vibratePref.setTitle("Vibrate");
    vibratePref.setSummary("Vibrate the phone for notifications");
    vibratePref.setDefaultValue(Boolean.TRUE);

    root.addPreference(notifyPref);
    root.addPreference(soundPref);
    root.addPreference(vibratePref);


    return root;
}
 
Example 19
Source File: NotificationSettingsActivity.java    From android-demo-xmpp-androidpn with Apache License 2.0 4 votes vote down vote up
private PreferenceScreen createPreferenceHierarchy() {
    Log.d(LOGTAG, "createSettingsPreferenceScreen()...");

    PreferenceManager preferenceManager = getPreferenceManager();
    preferenceManager
            .setSharedPreferencesName(Constants.SHARED_PREFERENCE_NAME);
    preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);

    PreferenceScreen root = preferenceManager.createPreferenceScreen(this);

    //        PreferenceCategory prefCat = new PreferenceCategory(this);
    //        // inlinePrefCat.setTitle("");
    //        root.addPreference(prefCat);

    CheckBoxPreference notifyPref = new CheckBoxPreference(this);
    notifyPref.setKey(Constants.SETTINGS_NOTIFICATION_ENABLED);
    notifyPref.setTitle("Notifications Enabled");
    notifyPref.setSummaryOn("Receive push messages");
    notifyPref.setSummaryOff("Do not receive push messages");
    notifyPref.setDefaultValue(Boolean.TRUE);
    notifyPref
            .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    boolean checked = Boolean.valueOf(newValue.toString());
                    if (checked) {
                        preference.setTitle("Notifications Enabled");
                    } else {
                        preference.setTitle("Notifications Disabled");
                    }
                    return true;
                }
            });

    CheckBoxPreference soundPref = new CheckBoxPreference(this);
    soundPref.setKey(Constants.SETTINGS_SOUND_ENABLED);
    soundPref.setTitle("Sound");
    soundPref.setSummary("Play a sound for notifications");
    soundPref.setDefaultValue(Boolean.TRUE);
    // soundPref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED);

    CheckBoxPreference vibratePref = new CheckBoxPreference(this);
    vibratePref.setKey(Constants.SETTINGS_VIBRATE_ENABLED);
    vibratePref.setTitle("Vibrate");
    vibratePref.setSummary("Vibrate the phone for notifications");
    vibratePref.setDefaultValue(Boolean.TRUE);
    // vibratePref.setDependency(Constants.SETTINGS_NOTIFICATION_ENABLED);

    root.addPreference(notifyPref);
    root.addPreference(soundPref);
    root.addPreference(vibratePref);

    //        prefCat.addPreference(notifyPref);
    //        prefCat.addPreference(soundPref);
    //        prefCat.addPreference(vibratePref);
    //        root.addPreference(prefCat);

    return root;
}