Search in sources :

Example 1 with Preference

use of android.preference.Preference in project Anki-Android by Ramblurr.

the class CramDeckOptions method updateSummaries.

protected void updateSummaries() {
    mAllowCommit = false;
    // for all text preferences, set summary as current database value
    for (String key : mPref.mValues.keySet()) {
        Preference pref = this.findPreference(key);
        String value = null;
        if (pref == null) {
            continue;
        } else if (pref instanceof CheckBoxPreference) {
            continue;
        } else if (pref instanceof ListPreference) {
            ListPreference lp = (ListPreference) pref;
            value = lp.getEntry().toString();
        } else {
            value = this.mPref.getString(key, "");
        }
        // update value for EditTexts
        if (pref instanceof EditTextPreference) {
            ((EditTextPreference) pref).setText(value);
        }
        // update summary
        if (!mPref.mSummaries.containsKey(key)) {
            CharSequence s = pref.getSummary();
            mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null);
        }
        String summ = mPref.mSummaries.get(key);
        if (summ != null && summ.contains("XXX")) {
            pref.setSummary(summ.replace("XXX", value));
        } else {
            pref.setSummary(value);
        }
    }
    mAllowCommit = true;
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) StepsPreference(com.ichi2.preferences.StepsPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) EditTextPreference(android.preference.EditTextPreference)

Example 2 with Preference

use of android.preference.Preference in project Anki-Android by Ramblurr.

the class DeckOptions method updateSummaries.

protected void updateSummaries() {
    Resources res = getResources();
    // for all text preferences, set summary as current database value
    for (String key : mPref.mValues.keySet()) {
        Preference pref = this.findPreference(key);
        if (key.equals("deckConf")) {
            String groupName = getOptionsGroupName();
            int count = getOptionsGroupCount();
            pref.setSummary(res.getQuantityString(R.plurals.deck_conf_group_summ, count, groupName, count));
            continue;
        }
        String value = null;
        if (pref == null) {
            continue;
        } else if (pref instanceof CheckBoxPreference) {
            continue;
        } else if (pref instanceof ListPreference) {
            ListPreference lp = (ListPreference) pref;
            value = lp.getEntry() != null ? lp.getEntry().toString() : "";
        } else {
            value = this.mPref.getString(key, "");
        }
        // update summary
        if (!mPref.mSummaries.containsKey(key)) {
            CharSequence s = pref.getSummary();
            mPref.mSummaries.put(key, s != null ? pref.getSummary().toString() : null);
        }
        String summ = mPref.mSummaries.get(key);
        if (summ != null && summ.contains("XXX")) {
            pref.setSummary(summ.replace("XXX", value));
        } else {
            pref.setSummary(value);
        }
    }
    // Update summaries of preference items that don't have values (aren't in mValues)
    int subDeckCount = getSubdeckCount();
    this.findPreference("confSetSubdecks").setSummary(res.getQuantityString(R.plurals.deck_conf_set_subdecks_summ, subDeckCount, subDeckCount));
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) StepsPreference(com.ichi2.preferences.StepsPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) CheckBoxPreference(android.preference.CheckBoxPreference) Resources(android.content.res.Resources) ListPreference(android.preference.ListPreference)

Example 3 with Preference

use of android.preference.Preference in project meatspace-android by RomainPiel.

the class SettingsFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ListPreference urlPreference = (ListPreference) findPreference(getString(R.string.settings_url_key));
    if (urlPreference.getValue() == null) {
        urlPreference.setValue(getString(BuildConfig.MEATSPACE_BASE_URL));
    }
    urlPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            getActivity().sendBroadcast(new Intent(Constants.FILTER_CHAT_CLOSE));
            return true;
        }
    });
}
Also used : ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) Intent(android.content.Intent) ListPreference(android.preference.ListPreference)

Example 4 with Preference

use of android.preference.Preference in project storymaker by StoryMaker.

the class SimplePreferences method onCreate.

@SuppressWarnings("deprecation")
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setTitle(Utils.getAppName(this));
    addPreferencesFromResource(R.xml.simpleprefs);
    setResult(RESULT_OK);
    Preference prefVideoWidth = (Preference) getPreferenceScreen().findPreference(KEY_VIDEO_WIDTH);
    prefVideoWidth.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            int vWidth = Integer.parseInt(newValue.toString());
            if (vWidth > MAX_VIDEO_WIDTH) {
                Toast.makeText(getApplicationContext(), "Width must be less than 1920.", Toast.LENGTH_SHORT).show();
                return false;
            } else {
                return true;
            }
        }
    });
    Preference prefVideoHeight = (Preference) getPreferenceScreen().findPreference(KEY_VIDEO_HEIGHT);
    prefVideoHeight.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            int vHeight = Integer.parseInt(newValue.toString());
            if (vHeight > MAX_VIDEO_HEIGHT) {
                Toast.makeText(getApplicationContext(), "Height must be less than 1080.", Toast.LENGTH_SHORT).show();
                return false;
            } else {
                return true;
            }
        }
    });
    Preference prefUseTor = (Preference) getPreferenceScreen().findPreference(KEY_USE_TOR);
    prefUseTor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean useTor = Boolean.parseBoolean(newValue.toString());
            if (useTor) {
                //SharedPreferences settings = ((Preference)getPreferenceScreen().findPreference(KEY_USE_MANAGER)).getSharedPreferences();
                SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                boolean useManager = settings.getBoolean(KEY_USE_MANAGER, false);
                if (useManager) {
                    Toast.makeText(getApplicationContext(), "Can't select both \"Use Orbot\" and \"Use Download Manager\"", Toast.LENGTH_LONG).show();
                    return false;
                }
            }
            return true;
        }
    });
    Preference prefUseManager = (Preference) getPreferenceScreen().findPreference(KEY_USE_MANAGER);
    prefUseManager.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean useManager = Boolean.parseBoolean(newValue.toString());
            if (useManager) {
                //SharedPreferences settings = ((Preference)getPreferenceScreen().findPreference(KEY_USE_MANAGER)).getSharedPreferences();
                SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                boolean useTor = settings.getBoolean(KEY_USE_TOR, false);
                if (useTor) {
                    Toast.makeText(getApplicationContext(), "Can't select both \"Use Orbot\" and \"Use Download Manager\"", Toast.LENGTH_LONG).show();
                    return false;
                }
            }
            return true;
        }
    });
    Preference prefServer = (Preference) getPreferenceScreen().findPreference(KEY_SERVER);
    prefServer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String newUrl = newValue.toString();
            getActionBar().setTitle(Utils.getAppName(SimplePreferences.this));
            return true;
        }
    });
    Preference prefUseIOCipher = (Preference) getPreferenceScreen().findPreference(KEY_USE_IOCIPHER);
    prefUseIOCipher.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean useIOCipher = Boolean.parseBoolean(newValue.toString());
            SharedPreferences sp = getSharedPreferences("appPrefs", MODE_PRIVATE);
            String cachewordStatus = sp.getString("cacheword_status", "default");
            if (cachewordStatus.equals(BaseActivity.CACHEWORD_SET)) {
                if (mCacheWordHandler.isLocked()) {
                    Timber.d("onPreferenceChange - pin set but cacheword locked, cannot use iocipher");
                    Toast.makeText(getApplicationContext(), "App must be unlocked before IOCipher can be used", Toast.LENGTH_LONG).show();
                } else {
                    Timber.d("onPreferenceChange - pin set and cacheword unlocked, updating iocipher preferences");
                    if (useIOCipher) {
                        StorageHelper.migrateToIOCipher(getApplicationContext());
                        Toast.makeText(getApplicationContext(), "Migrating actual files to virtual file system", Toast.LENGTH_LONG).show();
                    } else {
                        StorageHelper.migrateFromIOCipher(getApplicationContext());
                        Toast.makeText(getApplicationContext(), "Migrating virtual files to actual file system", Toast.LENGTH_LONG).show();
                    }
                    return true;
                }
            } else {
                Timber.d("onPreferenceChange - no pin set, cannot use iocipher");
                Toast.makeText(getApplicationContext(), "A pin must be set before IOCipher can be used", Toast.LENGTH_LONG).show();
            }
            return false;
        }
    });
}
Also used : Preference(android.preference.Preference) SharedPreferences(android.content.SharedPreferences)

Example 5 with Preference

use of android.preference.Preference in project Reader by TheKeeperOfPie.

the class FragmentBehavior method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CustomApplication.getComponentMain().inject(this);
    addPreferencesFromResource(R.xml.prefs_behavior);
    findPreference(AppSettings.PREF_CLEAR_HISTORY).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            historian.clear(activity);
            Toast.makeText(activity, getString(R.string.history_cleared), Toast.LENGTH_SHORT).show();
            return true;
        }
    });
    Preference preferenceHistorySize = findPreference(AppSettings.PREF_HISTORY_SIZE);
    preferenceHistorySize.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            preference.setSummary(String.valueOf(newValue) + " entries");
            return true;
        }
    });
    preferenceHistorySize.getOnPreferenceChangeListener().onPreferenceChange(preferenceHistorySize, preferences.getString(AppSettings.PREF_HISTORY_SIZE, "5000"));
    Preference preferenceHomeSubreddit = findPreference(AppSettings.PREF_HOME_SUBREDDIT);
    preferenceHomeSubreddit.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String summary = String.valueOf(newValue);
            if (TextUtils.isEmpty(summary)) {
                preference.setSummary(R.string.pref_home_subreddit_summary);
            } else {
                preference.setSummary(getString(R.string.subreddit_formatted, UtilsReddit.parseRawSubredditString(summary)));
            }
            return true;
        }
    });
    preferenceHomeSubreddit.getOnPreferenceChangeListener().onPreferenceChange(preferenceHomeSubreddit, preferences.getString(AppSettings.PREF_HOME_SUBREDDIT, ""));
}
Also used : Preference(android.preference.Preference)

Aggregations

Preference (android.preference.Preference)173 CheckBoxPreference (android.preference.CheckBoxPreference)50 ListPreference (android.preference.ListPreference)49 PreferenceScreen (android.preference.PreferenceScreen)36 Intent (android.content.Intent)32 EditTextPreference (android.preference.EditTextPreference)26 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)23 PreferenceCategory (android.preference.PreferenceCategory)23 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)21 SharedPreferences (android.content.SharedPreferences)19 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)16 Test (org.junit.Test)15 PreferenceGroup (android.preference.PreferenceGroup)13 Uri (android.net.Uri)12 Bundle (android.os.Bundle)12 ArrayList (java.util.ArrayList)11 Resources (android.content.res.Resources)10 SwitchPreference (android.preference.SwitchPreference)10 View (android.view.View)10 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)10