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

The following examples show how to use androidx.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: AppCompatPreferenceActivity.java    From onpc with GNU General Public License v3.0 6 votes vote down vote up
static void tintIcons(final Context c, Preference preference)
{
    if (preference instanceof PreferenceGroup)
    {
        PreferenceGroup group = ((PreferenceGroup) preference);
        Utils.setDrawableColorAttr(c, group.getIcon(), android.R.attr.textColorSecondary);
        for (int i = 0; i < group.getPreferenceCount(); i++)
        {
            tintIcons(c, group.getPreference(i));
        }
    }
    else
    {
        Utils.setDrawableColorAttr(c, preference.getIcon(), android.R.attr.textColorSecondary);
    }
}
 
Example 2
Source File: PreferenceFragment.java    From AndroidPreferenceActivity with Apache License 2.0 6 votes vote down vote up
/**
 * Restores the default preferences, which are contained by a specific preference group.
 *
 * @param preferenceGroup
 *         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);
            }

        }
    }
}
 
Example 3
Source File: TalkBackPreferencesActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Since the "%s" summary is currently broken, this sets the preference change listener for all
 * {@link ListPreference} views to fill in the summary with the current entry value.
 */
private void fixListSummaries(PreferenceGroup group) {
  if (group == null) {
    return;
  }

  final int count = group.getPreferenceCount();

  for (int i = 0; i < count; i++) {
    final Preference preference = group.getPreference(i);

    if (preference instanceof PreferenceGroup) {
      fixListSummaries((PreferenceGroup) preference);
    } else if (preference instanceof ListPreference) {
      // First make sure the current summary is correct, then set the
      // listener. This is necessary for summaries to show correctly
      // on SDKs < 14.
      preferenceChangeListener.onPreferenceChange(
          preference, ((ListPreference) preference).getValue());

      preference.setOnPreferenceChangeListener(preferenceChangeListener);
    }
  }
}
 
Example 4
Source File: TalkBackVerbosityPreferencesActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** Collects all preset-controlled preferences. */
private ArrayList<Preference> collectDetailedPreferences() {
  ArrayList<Preference> detailedPrefs = new ArrayList<Preference>();
  PreferenceGroup prefGroup =
      (PreferenceGroup) findPreference(R.string.pref_verbosity_category_preset_settings_key);
  if (prefGroup == null) {
    return detailedPrefs;
  }

  // For each preference... collect
  for (int p = 0; p < prefGroup.getPreferenceCount(); p++) {
    Preference preference = prefGroup.getPreference(p);
    if (preference != null) {
      detailedPrefs.add(preference);
    }
  }
  return detailedPrefs;
}
 
Example 5
Source File: BasePreferenceFragment.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
private void setAllPreferencesToAvoidHavingExtraSpace(Preference preference) {
    preference.setIconSpaceReserved(false);
    if (preference instanceof PreferenceGroup) {
        PreferenceGroup preferenceGroup = ((PreferenceGroup) preference);
        for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
            setAllPreferencesToAvoidHavingExtraSpace(preferenceGroup.getPreference(i));
        }
    }
}
 
Example 6
Source File: SettingsActivity.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
private static void tintIcons(final Context c, Preference preference)
{
    if (preference instanceof PreferenceGroup)
    {
        PreferenceGroup group = ((PreferenceGroup) preference);
        for (int i = 0; i < group.getPreferenceCount(); i++)
        {
            tintIcons(c, group.getPreference(i));
        }
    }
    else
    {
        CompatUtils.setDrawableColorAttr(c, preference.getIcon(), android.R.attr.textColorSecondary);
    }
}
 
Example 7
Source File: SettingsActivity.java    From AppOpsX with MIT License 5 votes vote down vote up
private void setAllPreferencesToAvoidHavingExtraSpace(Preference preference){
  if (preference != null){
    preference.setIconSpaceReserved(false);
    if (preference instanceof PreferenceGroup){
      PreferenceGroup group =  ((PreferenceGroup) preference);
      int count = group.getPreferenceCount();
      for (int i = 0; i < count; i++){
        setAllPreferencesToAvoidHavingExtraSpace(group.getPreference(i));
      }
    }
  }
}
 
Example 8
Source File: PreferenceSettingsUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
private static void hidePreferences(PreferenceGroup root, Set<String> preferenceKeysToBeHidden) {
  for (int i = 0; i < root.getPreferenceCount(); i++) {
    Preference preference = root.getPreference(i);
    if (preferenceKeysToBeHidden.contains(preference.getKey())) {
      root.removePreference(preference);
      i--;
    } else if (preference instanceof PreferenceGroup) {
      hidePreferences((PreferenceGroup) preference, preferenceKeysToBeHidden);
    }
  }
}
 
Example 9
Source File: MainPreferences.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
private static void tintIcons(Preference preference, int color) {
    if (preference instanceof PreferenceGroup) {
        PreferenceGroup group = ((PreferenceGroup) preference);
        for (int i = 0; i < group.getPreferenceCount(); i++) {
            tintIcons(group.getPreference(i), color);
        }
    } else {
        Drawable icon = preference.getIcon();
        if (icon != null) {
            DrawableCompat.setTint(icon, color);
        }
    }
}