Search in sources :

Example 21 with PreferenceGroup

use of android.preference.PreferenceGroup in project collect by opendatakit.

the class DisabledPreferencesRemover method getParent.

private PreferenceGroup getParent(PreferenceGroup groupToSearchIn, Preference preference) {
    for (int i = 0; i < groupToSearchIn.getPreferenceCount(); ++i) {
        Preference child = groupToSearchIn.getPreference(i);
        if (child == preference) {
            return groupToSearchIn;
        }
        if (child instanceof PreferenceGroup) {
            PreferenceGroup childGroup = (PreferenceGroup) child;
            PreferenceGroup result = getParent(childGroup, preference);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
Also used : Preference(android.preference.Preference) PreferenceGroup(android.preference.PreferenceGroup)

Example 22 with PreferenceGroup

use of android.preference.PreferenceGroup in project collect by opendatakit.

the class DisabledPreferencesRemover method removeEmptyCategories.

private void removeEmptyCategories(PreferenceGroup pc) {
    final boolean adminMode = pa.getIntent().getBooleanExtra(INTENT_KEY_ADMIN_MODE, false);
    if (adminMode || pc == null) {
        return;
    }
    for (int i = 0; i < pc.getPreferenceCount(); i++) {
        Preference preference = pc.getPreference(i);
        if (preference instanceof PreferenceGroup) {
            if (!removeEmptyPreference(pc, preference)) {
                removeEmptyCategories((PreferenceGroup) preference);
                // try to remove preference group if it is empty now
                removeEmptyPreference(pc, preference);
            }
        }
    }
}
Also used : Preference(android.preference.Preference) PreferenceGroup(android.preference.PreferenceGroup)

Example 23 with PreferenceGroup

use of android.preference.PreferenceGroup in project collect by opendatakit.

the class DisabledPreferencesRemover method remove.

/**
 * Removes any preferences from the category that are excluded by the admin settings.
 *
 * @param keyPairs one or more AdminAndGeneralKeys objects.
 */
void remove(AdminAndGeneralKeys... keyPairs) {
    for (AdminAndGeneralKeys agKeys : keyPairs) {
        boolean prefAllowed = (boolean) AdminSharedPreferences.getInstance().get(agKeys.adminKey);
        if (!prefAllowed) {
            Preference preference = pf.findPreference(agKeys.generalKey);
            if (preference == null) {
                // preference not found in the current preference fragment, so ignore
                continue;
            }
            PreferenceGroup parent = getParent(pf.getPreferenceScreen(), preference);
            if (parent == null) {
                throw new RuntimeException("Couldn't find preference");
            }
            parent.removePreference(preference);
            Timber.d("Removed %s", preference.toString());
        }
    }
}
Also used : Preference(android.preference.Preference) PreferenceGroup(android.preference.PreferenceGroup)

Example 24 with PreferenceGroup

use of android.preference.PreferenceGroup in project KISS by Neamar.

the class SettingsActivity method addExcludedAppSettings.

@SuppressWarnings("deprecation")
private void addExcludedAppSettings(final SharedPreferences prefs) {
    final MultiSelectListPreference multiPreference = new MultiSelectListPreference(this);
    multiPreference.setTitle(R.string.ui_excluded_apps);
    multiPreference.setDialogTitle(R.string.ui_excluded_apps_dialog_title);
    multiPreference.setKey("excluded_apps_ui");
    multiPreference.setOrder(15);
    PreferenceGroup category = (PreferenceGroup) findPreference("history_category");
    category.addPreference(multiPreference);
    loadExcludedAppsToPreference(multiPreference);
    multiPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        @SuppressWarnings("unchecked")
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Set<String> appListToBeExcluded = (HashSet<String>) newValue;
            StringBuilder builder = new StringBuilder();
            for (String s : appListToBeExcluded) {
                builder.append(s).append(";");
            }
            prefs.edit().putString("excluded-apps-list", builder.toString() + SettingsActivity.this.getPackageName() + ";").apply();
            loadExcludedAppsToPreference(multiPreference);
            if (!hasExcludedApps(prefs)) {
                multiPreference.setDialogMessage(R.string.ui_excluded_apps_not_found);
            }
            KissApplication.getDataHandler(SettingsActivity.this).getAppProvider().reload();
            return false;
        }
    });
    if (!hasExcludedApps(prefs)) {
        multiPreference.setDialogMessage(R.string.ui_excluded_apps_not_found);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) MultiSelectListPreference(android.preference.MultiSelectListPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) MultiSelectListPreference(android.preference.MultiSelectListPreference) PreferenceGroup(android.preference.PreferenceGroup)

Example 25 with PreferenceGroup

use of android.preference.PreferenceGroup in project PhoneProfilesPlus by henrichg.

the class PreferenceFragment method getAllPreferenceScreen.

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;
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) PreferenceCategory(android.preference.PreferenceCategory) PreferenceGroup(android.preference.PreferenceGroup)

Aggregations

PreferenceGroup (android.preference.PreferenceGroup)38 Preference (android.preference.Preference)26 ListPreference (android.preference.ListPreference)7 SharedPreferences (android.content.SharedPreferences)6 CheckBoxPreference (android.preference.CheckBoxPreference)6 PreferenceScreen (android.preference.PreferenceScreen)6 Intent (android.content.Intent)5 Bundle (android.os.Bundle)4 TwoStatePreference (android.preference.TwoStatePreference)4 ArrayList (java.util.ArrayList)4 EditTextPreference (android.preference.EditTextPreference)3 MultiSelectListPreference (android.preference.MultiSelectListPreference)3 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)3 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)3 Point (android.graphics.Point)2 DialogPreference (android.preference.DialogPreference)2 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)2 PreferenceCategory (android.preference.PreferenceCategory)2 SpannableString (android.text.SpannableString)2 View (android.view.View)2