Example usage for android.preference PreferenceGroup addPreference

List of usage examples for android.preference PreferenceGroup addPreference

Introduction

In this page you can find the example usage for android.preference PreferenceGroup addPreference.

Prototype

public boolean addPreference(Preference preference) 

Source Link

Document

Adds a Preference at the correct position based on the preference's order.

Usage

From source file:nya.miku.wishmaster.chans.cirno.CirnoModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    final Context context = preferenceGroup.getContext();
    EditTextPreference passwordPref = new EditTextPreference(context);
    passwordPref.setTitle(R.string.iichan_prefs_report_thread);
    passwordPref.setDialogTitle(R.string.iichan_prefs_report_thread);
    passwordPref.setSummary(R.string.iichan_prefs_report_thread_summary);
    passwordPref.setKey(getSharedKey(PREF_KEY_REPORT_THREAD));
    passwordPref.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
    passwordPref.getEditText().setSingleLine();
    passwordPref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(255) });
    preferenceGroup.addPreference(passwordPref);

    super.addPreferencesOnScreen(preferenceGroup);
}

From source file:com.nttec.everychan.chans.makaba.MakabaModule.java

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);
}

From source file:com.nttec.everychan.chans.dobrochan.DobroModule.java

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);
}

From source file:com.doplgangr.secrecy.settings.SettingsFragment.java

private void preparePreferenceCreditList() {
    PreferenceGroup creditsList = (PreferenceGroup) findPreference("credits_list");
    for (int i = 0; i < creditsNames.length; i++) {
        Preference newPreference = new Preference(context);
        newPreference.setTitle(creditsNames[i]);
        newPreference.setSummary(creditsDescription[i]);
        final int finali = i;
        newPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override/*w  w w .ja  v  a2 s . co  m*/
            public boolean onPreferenceClick(Preference preference) {
                Uri uri = Uri.parse(creditsLinks[finali]);
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
                return true;
            }
        });
        creditsList.addPreference(newPreference);
    }
}

From source file:com.doplgangr.secrecy.settings.SettingsFragment.java

private void preparePreferenceTranslatorsList() {
    PreferenceGroup translatorList = (PreferenceGroup) findPreference("translators_list");
    for (int i = 0; i < contributorNames.length; i++) {
        Preference newPreference = new Preference(context);
        newPreference.setTitle(contributorNames[i]);
        newPreference.setSummary(contributorDescription[i]);
        final int finali = i;
        newPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override/*  ww  w .j ava2s  . c  om*/
            public boolean onPreferenceClick(Preference preference) {
                Uri uri = Uri.parse(contributorLinks[finali]);
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
                return true;
            }
        });
        translatorList.addPreference(newPreference);
    }
}

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  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;
        }
    });
}

From source file:com.nttec.everychan.chans.ponyach.PonyachModule.java

@Override
public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) {
    final Context context = preferenceGroup.getContext();
    ListPreference captchaLevel = new LazyPreferences.ListPreference(context);
    captchaLevel.setTitle(R.string.ponyach_prefs_captcha);
    captchaLevel.setDialogTitle(R.string.ponyach_prefs_captcha);
    captchaLevel.setKey(getSharedKey(PREF_KEY_CAPTCHA_LEVEL));
    captchaLevel.setEntryValues(new String[] { "3", "2", "1" });
    captchaLevel.setEntries(new String[] { "Easy", "Easy++", "Medium" });
    captchaLevel.setDefaultValue("1");
    preferenceGroup.addPreference(captchaLevel);

    EditTextPreference passcodePref = new EditTextPreference(context);
    passcodePref.setTitle(R.string.ponyach_prefs_passcode);
    passcodePref.setDialogTitle(R.string.ponyach_prefs_passcode);
    passcodePref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) });
    passcodePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override/*from   www  .j av a2s  .  c o m*/
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String newPasscode = (String) newValue;
            final CancellableTask passAuthTask = new CancellableTask.BaseCancellableTask();
            final ProgressDialog passAuthProgressDialog = new ProgressDialog(context);
            passAuthProgressDialog.setMessage("Logging in");
            passAuthProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    passAuthTask.cancel();
                }
            });
            passAuthProgressDialog.setCanceledOnTouchOutside(false);
            passAuthProgressDialog.show();
            Async.runAsync(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (passAuthTask.isCancelled())
                            return;
                        String url = getUsingUrl() + "passcode.php";
                        List<BasicNameValuePair> pairs = Collections
                                .singletonList(new BasicNameValuePair("passcode_just_set", newPasscode));
                        HttpRequestModel request = HttpRequestModel.builder()
                                .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).build();
                        HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, null,
                                passAuthTask, false);
                        savePhpCookies();
                    } catch (final Exception e) {
                        if (context instanceof Activity) {
                            ((Activity) context).runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    String message = e.getMessage() == null
                                            ? resources.getString(R.string.error_unknown)
                                            : e.getMessage();
                                    Toast.makeText(context, message, Toast.LENGTH_LONG).show();
                                }
                            });
                        }
                    } finally {
                        passAuthProgressDialog.dismiss();
                    }
                }
            });
            return false;
        }
    });
    preferenceGroup.addPreference(passcodePref);

    ListPreference domainPref = new LazyPreferences.ListPreference(context);
    domainPref.setTitle(R.string.pref_domain);
    domainPref.setDialogTitle(R.string.pref_domain);
    domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN));
    domainPref.setEntryValues(DOMAINS);
    domainPref.setEntries(DOMAINS);
    domainPref.setDefaultValue(DEFAULT_DOMAIN);
    domainPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            loadPhpCookies((String) newValue);
            return true;
        }
    });
    preferenceGroup.addPreference(domainPref);

    addHttpsPreference(preferenceGroup, useHttpsDefaultValue());
    addProxyPreferences(preferenceGroup);
    captchaLevel.setSummary(captchaLevel.getEntry());
    domainPref.setSummary(domainPref.getEntry());
}

From source file:nya.miku.wishmaster.chans.krautchan.KrautModule.java

public void addKompturcodePreference(PreferenceGroup preferenceGroup) {
    Context context = preferenceGroup.getContext();
    EditTextPreference kompturcodePreference = new EditTextPreference(context);
    kompturcodePreference.setTitle(R.string.kraut_prefs_kompturcode);
    kompturcodePreference.setDialogTitle(R.string.kraut_prefs_kompturcode);
    kompturcodePreference.setSummary(R.string.kraut_prefs_kompturcode_summary);
    kompturcodePreference.setKey(getSharedKey(PREF_KEY_KOMPTURCODE_COOKIE));
    kompturcodePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override//from ww w.j av a2  s .  c om
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            setKompturcodeCookie((String) newValue);
            return true;
        }
    });
    preferenceGroup.addPreference(kompturcodePreference);
}