Example usage for android.preference PreferenceGroup getPreference

List of usage examples for android.preference PreferenceGroup getPreference

Introduction

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

Prototype

public Preference getPreference(int index) 

Source Link

Document

Returns the Preference at a particular index.

Usage

From source file:Main.java

private static ArrayList<Preference> getPreferenceList(Preference p, ArrayList<Preference> list) {
    if (p instanceof PreferenceCategory || p instanceof PreferenceScreen) {
        PreferenceGroup pGroup = (PreferenceGroup) p;
        int pCount = pGroup.getPreferenceCount();
        for (int i = 0; i < pCount; i++) {
            getPreferenceList(pGroup.getPreference(i), list); // recursive call
        }/*from w  w  w .  j a  v  a2  s  .c om*/
    } else {
        list.add(p);
    }
    return list;
}

From source file:Main.java

private static void replaceAllCheckBoxPreferencesBySwitchPreferences(final PreferenceGroup group) {
    final ArrayList<Preference> preferences = new ArrayList<>();
    final int count = group.getPreferenceCount();
    for (int index = 0; index < count; index++) {
        preferences.add(group.getPreference(index));
    }/*from  w w  w.ja  va  2  s  . c  o  m*/
    group.removeAll();
    for (int index = 0; index < count; index++) {
        final Preference preference = preferences.get(index);
        if (preference instanceof CheckBoxPreference) {
            addSwitchPreferenceBasedOnCheckBoxPreference((CheckBoxPreference) preference, group);
        } else {
            group.addPreference(preference);
            if (preference instanceof PreferenceGroup) {
                replaceAllCheckBoxPreferencesBySwitchPreferences((PreferenceGroup) preference);
            }
        }
    }
}

From source file:org.mozilla.gecko.GeckoPreferences.java

private void initGroups(PreferenceGroup preferences) {
    final int count = preferences.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        Preference pref = preferences.getPreference(i);
        if (pref instanceof PreferenceGroup)
            initGroups((PreferenceGroup) pref);
        else {/*from w w w  .  jav  a  2s  .  c  o  m*/
            pref.setOnPreferenceChangeListener(this);
            mPreferencesList.add(pref.getKey());
        }
    }
}

From source file:com.android.inputmethod.latin.settings.CustomInputStyleSettingsFragment.java

private InputMethodSubtype[] getSubtypes() {
    final PreferenceGroup group = getPreferenceScreen();
    final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
    final int count = group.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        final Preference pref = group.getPreference(i);
        if (pref instanceof CustomInputStylePreference) {
            final CustomInputStylePreference subtypePref = (CustomInputStylePreference) pref;
            // We should not save newly adding subtype to preference because it is incomplete.
            if (subtypePref.isIncomplete())
                continue;
            subtypes.add(subtypePref.getSubtype());
        }//from  w  ww . ja va  2  s  .  c om
    }
    return subtypes.toArray(new InputMethodSubtype[subtypes.size()]);
}

From source file:com.mobiletin.inputmethod.indic.settings.CustomInputStyleSettingsFragment.java

private InputMethodSubtype[] getSubtypes() {
    final PreferenceGroup group = getPreferenceScreen();
    final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
    final int count = group.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        final Preference pref = group.getPreference(i);
        if (pref instanceof SubtypePreference) {
            final SubtypePreference subtypePref = (SubtypePreference) pref;
            // We should not save newly adding subtype to preference because it is incomplete.
            if (subtypePref.isIncomplete())
                continue;
            subtypes.add(subtypePref.getSubtype());
        }/*  w  w w. ja v  a  2 s  . c  o m*/
    }
    return subtypes.toArray(new InputMethodSubtype[subtypes.size()]);
}

From source file:com.ichi2.anki.PreferenceContext.java

/**
 * Loop over every preference in the list and set the summary text
 *//*from w  w  w. ja v a 2  s .  com*/
private void initAllPreferences(PreferenceScreen screen) {
    for (int i = 0; i < screen.getPreferenceCount(); ++i) {
        Preference preference = screen.getPreference(i);
        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) {
                Preference nestedPreference = preferenceGroup.getPreference(j);
                if (nestedPreference instanceof PreferenceGroup) {
                    PreferenceGroup nestedPreferenceGroup = (PreferenceGroup) nestedPreference;
                    for (int k = 0; k < nestedPreferenceGroup.getPreferenceCount(); ++k) {
                        initPreference(nestedPreferenceGroup.getPreference(k));
                    }
                } else {
                    initPreference(preferenceGroup.getPreference(j));
                }
            }
        } else {
            initPreference(preference);
        }
    }
}

From source file:de.mrapp.android.preference.activity.PreferenceFragment.java

/**
 * Applies Material style on all preferences, which are contained by a specific preference
 * group, and on the group itself.// w  w w. j av  a2s .c o  m
 *
 * @param preferenceGroup
 *         The preference group, at whose preferences the Material style should be applied on,
 *         as an instance of the class {@link PreferenceGroup}. The preference group may not be
 *         null
 * @param decorator
 *         The decorator, which should be used to apply the Material style, as an instance of
 *         the class {@link PreferenceDecorator}. The decorator may not be null
 */
private void applyMaterialStyle(@NonNull final PreferenceGroup preferenceGroup,
        @NonNull final PreferenceDecorator decorator) {
    for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
        Preference preference = preferenceGroup.getPreference(i);

        if (preference instanceof PreferenceGroup) {
            decorator.applyDecorator(preference);
            applyMaterialStyle((PreferenceGroup) preference, decorator);
        } else {
            decorator.applyDecorator(preference);
        }
    }
}

From source file:de.mrapp.android.preference.activity.PreferenceFragment.java

/**
 * Restores the default preferences, which are contained by a specific preference group.
 *
 * @param preferenceGroup/*from w  w w  . j av  a2 s.  c o  m*/
 *         The preference group, whose preferences should be restored, as an instance of the
 *         class {@link PreferenceGroup}. The preference group may not be null
 * @param sharedPreferences
 *         The shared preferences, which should be used to restore the preferences, as an
 *         instance of the type {@link SharedPreferences}. The shared preferences may not be
 *         null
 */
private void restoreDefaults(@NonNull final PreferenceGroup preferenceGroup,
        @NonNull final SharedPreferences sharedPreferences) {
    for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
        Preference preference = preferenceGroup.getPreference(i);

        if (preference instanceof PreferenceGroup) {
            restoreDefaults((PreferenceGroup) preference, sharedPreferences);
        } else if (preference.getKey() != null && !preference.getKey().isEmpty()) {
            Object oldValue = sharedPreferences.getAll().get(preference.getKey());

            if (notifyOnRestoreDefaultValueRequested(preference, oldValue)) {
                sharedPreferences.edit().remove(preference.getKey()).apply();
                preferenceGroup.removePreference(preference);
                preferenceGroup.addPreference(preference);
                Object newValue = sharedPreferences.getAll().get(preference.getKey());
                notifyOnRestoredDefaultValue(preference, oldValue, newValue);
            } else {
                preferenceGroup.removePreference(preference);
                preferenceGroup.addPreference(preference);
            }

        }
    }
}