Java Code Examples for android.preference.PreferenceGroup#getPreferenceCount()

The following examples show how to use android.preference.PreferenceGroup#getPreferenceCount() . 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: DictionarySettingsFragment.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
private WordListPreference findWordListPreference(final String id) {
    final PreferenceGroup prefScreen = getPreferenceScreen();
    if (null == prefScreen) {
        Log.e(TAG, "Could not find the preference group");
        return null;
    }
    for (int i = prefScreen.getPreferenceCount() - 1; i >= 0; --i) {
        final Preference pref = prefScreen.getPreference(i);
        if (pref instanceof WordListPreference) {
            final WordListPreference wlPref = (WordListPreference)pref;
            if (id.equals(wlPref.mWordlistId)) {
                return wlPref;
            }
        }
    }
    Log.e(TAG, "Could not find the preference for a word list id " + id);
    return null;
}
 
Example 2
Source File: TwoStatePreferenceHelper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
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));
    }
    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);
            }
        }
    }
}
 
Example 3
Source File: Settings.java    From SpeedMeter with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.pref_general);

    for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); ++i) {
        Preference preference = getPreferenceScreen().getPreference(i);
        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) {
                updatePreference(preferenceGroup.getPreference(j));
            }
        } else {
            updatePreference(preference);
        }
    }
}
 
Example 4
Source File: Settings.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    PreferenceScreen preferenceScreen = getPreferenceScreen();
    for (int i = 0; i < preferenceScreen.getPreferenceCount(); i++) {
        Preference preference = preferenceScreen.getPreference(i);
        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); j++) {
                Preference subPref = preferenceGroup.getPreference(j);
                updatePreference(subPref, subPref.getKey());
            }
        } else {
            updatePreference(preference, preference.getKey());
        }
    }
}
 
Example 5
Source File: TwoStatePreferenceHelper.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
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));
    }
    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);
            }
        }
    }
}
 
Example 6
Source File: GatewayEditTextPreferenceTest.java    From openwebnet-android with MIT License 6 votes vote down vote up
private void initGatewayEditTextPreference(Preference preference) {
    if (preference instanceof PreferenceGroup) {
        PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
        for (int i=0; i<preferenceGroup.getPreferenceCount(); i++) {
            if (preferenceGroup.getPreference(i).getTitle().equals("Gateway")) {
                PreferenceCategory preferenceCategory = (PreferenceCategory) preferenceGroup.getPreference(i);
                initGatewayEditTextPreference(preferenceCategory.getPreference(0));
            } else {
                initGatewayEditTextPreference(preferenceGroup.getPreference(i));
            }
        }
    } else if (preference instanceof EditTextPreference) {
        // TODO wrong ClassCastException ?!?!
        gatewayEditTextPreference = (GatewayEditTextPreference) preference;
    }
}
 
Example 7
Source File: CameraSettingsActivity.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * Recursively traverses the tree from the given group as the route and
 * tries to delete the preference. Traversal stops once the preference
 * was found and removed.
 */
private boolean recursiveDelete(PreferenceGroup group, Preference preference)
{
    if (group == null)
    {
        Log.d(TAG, "attempting to delete from null preference group");
        return false;
    }
    if (preference == null)
    {
        Log.d(TAG, "attempting to delete null preference");
        return false;
    }
    if (group.removePreference(preference))
    {
        // Removal was successful.
        return true;
    }

    for (int i = 0; i < group.getPreferenceCount(); ++i)
    {
        Preference pref = group.getPreference(i);
        if (pref instanceof PreferenceGroup)
        {
            if (recursiveDelete((PreferenceGroup) pref, preference))
            {
                return true;
            }
        }
    }
    return false;
}
 
Example 8
Source File: PreferenceFragment.java    From habpanelviewer with GNU General Public License v3.0 5 votes vote down vote up
private List<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
        }
    } else if (p != null) {
        list.add(p);
    }
    return list;
}
 
Example 9
Source File: MobileMainActivity.java    From android-wear-gopro-remote with Apache License 2.0 5 votes vote down vote up
private void bindPreferencesSummaryToValue(PreferenceGroup group) {
    int prefCount = group.getPreferenceCount();
    for(int c = 0; c < prefCount; c++) {
        Preference preference = group.getPreference(c);
        if(preference instanceof PreferenceGroup) {
            bindPreferencesSummaryToValue((PreferenceGroup)preference);
        } else {
            bindPreferenceSummaryToValue(preference);
        }
    }
}
 
Example 10
Source File: PreferenceFragment.java    From material-preferences with MIT License 5 votes vote down vote up
private ArrayList<Preference> getAllPreferenceScreen(Preference p, ArrayList<Preference> list) {
    if( p instanceof PreferenceCategory || p instanceof PreferenceScreen) {
        PreferenceGroup pGroup = (PreferenceGroup) p;
        int pCount = pGroup.getPreferenceCount();
        if(p instanceof PreferenceScreen){
            list.add(p);
        }
        for(int i = 0; i < pCount; i++) {
            getAllPreferenceScreen(pGroup.getPreference(i), list);
        }
    }
    return list;
}
 
Example 11
Source File: SettingsFragment.java    From 920-text-editor-v2 with Apache License 2.0 5 votes vote down vote up
private static void dependBindPreference(PreferenceGroup pg) {
        int count = pg.getPreferenceCount();
        Preference preference;
        String key;
        Object value;

        Pref pref = Pref.getInstance(pg.getContext());

        for(int i = 0; i < count; i++) {
            preference = pg.getPreference(i);
            key = preference.getKey();

            if(preference instanceof PreferenceGroup) {
                dependBindPreference((PreferenceGroup) preference);
                continue;
            }

            Class<? extends Preference> cls = preference.getClass();
            if(cls.equals(Preference.class))
                continue;

            value = pref.getValue(key);

            if(preference instanceof JecListPreference) {
//                if("pref_font_size".equals(key)) {
//                    new FontSizePreference((JecListPreference)preference);
//                } else if("pref_cursor_width".equals(key)) {
//                    new CursorWidthPreference((JecListPreference)preference);
//                }
            } else if(preference instanceof EditTextPreference) {
                ((EditTextPreference)preference).setText(String.valueOf(value));
            } else if(preference instanceof CheckBoxPreference) {
                ((CheckBoxPreference)preference).setChecked((boolean)value);
            }

            if (!Pref.KEY_SYMBOL.equals(key))
                bindPreferenceSummaryToValue(preference);
        }
    }
 
Example 12
Source File: SettingsActivity.java    From lrkFM with MIT License 5 votes vote down vote up
/**
 * Adds a generic {@link android.preference.Preference.OnPreferenceChangeListener} to update the preferences with {@link Pref}.
 * It does that recursively for every Preference contained in the supplied {@link PreferenceGroup}.
 * This is what you get, when customizing too much stuff.
 *
 * @param preferenceGroup the current {@link PreferenceGroup}
 */
private static void addOnPreferenceChangeListeners(PreferenceGroup preferenceGroup) {
    for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
        Preference p = preferenceGroup.getPreference(i);
        if (p instanceof PreferenceCategory) {
            addOnPreferenceChangeListeners((PreferenceCategory) p);
        } else {
            setOnPreferenceChangeListener(p);
        }
    }
}
 
Example 13
Source File: CustomInputStyleSettingsFragment.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
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());
        }
    }
    return subtypes.toArray(new InputMethodSubtype[subtypes.size()]);
}
 
Example 14
Source File: CameraSettingsActivity.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * Recursively go through settings and fill entries and summaries of our
 * preferences.
 */
private void fillEntriesAndSummaries(PreferenceGroup group)
{
    for (int i = 0; i < group.getPreferenceCount(); ++i)
    {
        Preference pref = group.getPreference(i);
        if (pref instanceof PreferenceGroup)
        {
            fillEntriesAndSummaries((PreferenceGroup) pref);
        }
        setSummary(pref);
        setEntries(pref);
    }
}
 
Example 15
Source File: ConfigBase.java    From HeadsUp with GNU General Public License v2.0 5 votes vote down vote up
private boolean removePreference(@NonNull PreferenceGroup pg,
                                 @NonNull Preference preference) {
    for (int i = pg.getPreferenceCount() - 1; i >= 0; i--) {
        Preference child = pg.getPreference(i);
        if (child == preference) {
            pg.removePreference(preference);
            return true;
        } else if (child instanceof PreferenceGroup) {
            if (removePreference((PreferenceGroup) child, preference)) return true;
        }
    }
    return false;
}
 
Example 16
Source File: CustomInputStyleSettingsFragment.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
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());
        }
    }
    return subtypes.toArray(new InputMethodSubtype[subtypes.size()]);
}
 
Example 17
Source File: CustomInputStyleSettingsFragment.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
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());
        }
    }
    return subtypes.toArray(new InputMethodSubtype[subtypes.size()]);
}
 
Example 18
Source File: SettingsActivity.java    From AudioAnchor with GNU General Public License v3.0 5 votes vote down vote up
private void initSummary(Preference p) {
    if (p instanceof PreferenceGroup) {
        PreferenceGroup pGrp = (PreferenceGroup) p;
        for (int i = 0; i < pGrp.getPreferenceCount(); i++) {
            initSummary(pGrp.getPreference(i));
        }
    } else {
        updatePrefSummary(p);
    }
}
 
Example 19
Source File: SettingsFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
private void mapping(PreferenceGroup group) {
        for (int i = 0; i < group.getPreferenceCount(); i++) {
            Preference preference = group.getPreference(i);
            if (preference instanceof PreferenceGroup) {
                mapping((PreferenceGroup) preference);
            } else {
                preference.setOnPreferenceChangeListener(this);
//                if (preference instanceof ListPreference) {
//                    preference.setSummary(((ListPreference) preference).getEntry());
//                }
            }
        }
    }
 
Example 20
Source File: DictionarySettingsFragment.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
static void removeAnyDictSettings(final PreferenceGroup prefGroup) {
    for (int i = prefGroup.getPreferenceCount() - 1; i >= 0; --i) {
        prefGroup.removePreference(prefGroup.getPreference(i));
    }
}