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;
}
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);
}
}
}
}
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());
}
}
}
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);
}
}
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;
}
Aggregations