Search in sources :

Example 31 with Preference

use of android.preference.Preference in project NimbusBase_Android_Tutorial by NimbusBase.

the class IndexFragment method initiatePreferenceScreen.

protected PreferenceScreen initiatePreferenceScreen(Base base, int preferencesResID) {
    addPreferencesFromResource(preferencesResID);
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    final PreferenceCategory serverCate = getServerCategory(preferenceScreen);
    serverCate.setOrderingAsAdded(true);
    final Server[] servers = base.getServers();
    for (int index = 0; index < servers.length; index++) {
        final Server server = servers[index];
        final ListItemServer item = new ListItemServer(getActivity(), server);
        item.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                onServerItemStateChange((ListItemServer) preference, (Boolean) newValue);
                return false;
            }
        });
        item.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                onServerItemClick((ListItemServer) preference);
                return true;
            }
        });
        serverCate.addPreference(item);
        onServerStateChange(server, index);
    }
    final PreferenceCategory databaseCate = getDatabaseCategory(preferenceScreen);
    final PreferenceScreen playgroundItem = (PreferenceScreen) databaseCate.findPreference(getString(R.string.item_playground));
    playgroundItem.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            return onPlaygroundItemClick(preference);
        }
    });
    return preferenceScreen;
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) Server(com.nimbusbase.nimbusbase.Server) PreferenceCategory(android.preference.PreferenceCategory) Preference(android.preference.Preference)

Example 32 with Preference

use of android.preference.Preference in project NimbusBase_Android_Tutorial by NimbusBase.

the class PGFragmentTable method reload.

protected void reload(List<? extends PGRecord> records) {
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    preferenceScreen.removeAll();
    for (final PGRecord user : records) {
        final PGListItemRecord item = new PGListItemRecord(getActivity(), user);
        item.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                return onRecordPressed((PGListItemRecord) preference);
            }
        });
        preferenceScreen.addPreference(item);
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) Preference(android.preference.Preference)

Example 33 with Preference

use of android.preference.Preference in project NimbusBase_Android_Tutorial by NimbusBase.

the class PGFragmentTable method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final ActionBar actionBar = getActivity().getActionBar();
    if (actionBar != null)
        actionBar.setTitle("Table " + mTableName);
    final SQLiteDatabase database = mSQLiteOpenHelper.getReadableDatabase();
    final List<MDLUser> records = MDLUser.fetchAll(database);
    database.close();
    if (!records.equals(mRecords)) {
        this.mRecords = records;
        reload(records);
        final PreferenceScreen preferenceScreen = getPreferenceScreen();
        preferenceScreen.removeAll();
        for (final MDLUser user : records) {
            final PGListItemRecord item = new PGListItemRecord(getActivity(), user);
            item.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    return onRecordPressed((PGListItemRecord) preference);
                }
            });
            preferenceScreen.addPreference(item);
        }
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Preference(android.preference.Preference) ActionBar(android.app.ActionBar)

Example 34 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 35 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)

Aggregations

Preference (android.preference.Preference)183 CheckBoxPreference (android.preference.CheckBoxPreference)54 ListPreference (android.preference.ListPreference)54 PreferenceScreen (android.preference.PreferenceScreen)37 Intent (android.content.Intent)33 EditTextPreference (android.preference.EditTextPreference)29 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 PreferenceGroup (android.preference.PreferenceGroup)15 Test (org.junit.Test)15 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