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

The following examples show how to use android.preference.PreferenceGroup#getPreference() . 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: SettingsFragment.java    From NoiseCapture with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    PreferenceScreen preferenceScreen = getPreferenceScreen();
    SharedPreferenceListener sharedPreferenceListener = new SharedPreferenceListener();
    for(int idPreference = 0; idPreference < preferenceScreen.getPreferenceCount(); idPreference++) {
        Preference preference = preferenceScreen.getPreference(idPreference);
        if(preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup)preference;
            for(int IdGroupReference = 0; IdGroupReference < preferenceGroup.getPreferenceCount(); IdGroupReference++) {
                preference = preferenceGroup.getPreference(IdGroupReference);
                preference.setOnPreferenceChangeListener(sharedPreferenceListener);
            }
        } else {
            preference.setOnPreferenceChangeListener(sharedPreferenceListener);
        }
    }
}
 
Example 2
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 3
Source File: PreferenceActivity.java    From MaterialPreferenceLibrary with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public static Map<Preference, PreferenceGroup> buildPreferenceParentTree(final android.preference.PreferenceActivity activity) {
    final Map<Preference, PreferenceGroup> result = new HashMap<>();
    final Stack<PreferenceGroup> curParents = new Stack<>();
    curParents.add(activity.getPreferenceScreen());
    while (!curParents.isEmpty()) {
        final PreferenceGroup parent = curParents.pop();
        final int childCount = parent.getPreferenceCount();
        for (int i = 0; i < childCount; ++i) {
            final Preference child = parent.getPreference(i);
            result.put(child, parent);
            if (child instanceof PreferenceGroup)
                curParents.push((PreferenceGroup) child);
        }
    }
    return result;
}
 
Example 4
Source File: FragmentSettings.java    From android-port with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    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) {
                Preference singlePref = preferenceGroup.getPreference(j);
                updatePreference(singlePref, singlePref.getKey());
            }
        } else {
            updatePreference(preference, preference.getKey());
        }
    }
}
 
Example 5
Source File: BasePreferenceFragment.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
private static PreferenceGroup getParentGroup(PreferenceGroup preferenceGroup, Preference preference) {
	for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) {
		Preference childPreference = preferenceGroup.getPreference(i);
		if (childPreference == preference) {
			return preferenceGroup;
		}
		if (childPreference instanceof PreferenceGroup) {
			PreferenceGroup foundPreferenceGroup = getParentGroup((PreferenceGroup) childPreference,
					preference);
			if (foundPreferenceGroup != null) {
				return foundPreferenceGroup;
			}
		}
	}
	return null;
}
 
Example 6
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 7
Source File: SettingsActivity.java    From wshell with GNU General Public License v3.0 5 votes vote down vote up
private void initSummaries(PreferenceGroup pg) {
	for (int i = 0; i < pg.getPreferenceCount(); ++i) {
		Preference p = pg.getPreference(i);
		if (p instanceof PreferenceGroup)
			this.initSummaries((PreferenceGroup) p);
		else
			this.setSummary(p, false);
	}
}
 
Example 8
Source File: SettingsActivity.java    From island with Apache License 2.0 5 votes vote down vote up
protected static boolean removeLeafPreference(final PreferenceGroup root, final Preference preference) {
	if (root.removePreference(preference)) return true;
	for (int i = 0; i < root.getPreferenceCount(); i ++) {
		final Preference child = root.getPreference(i);
		if (child instanceof PreferenceGroup && removeLeafPreference((PreferenceGroup) child, preference)) return true;
	}
	return false;
}
 
Example 9
Source File: SettingsFragment.java    From Document-Scanner with GNU General Public License v3.0 5 votes vote down vote up
public void updatePreferenceScreen(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 singlePref = preferenceGroup.getPreference(j);
                updatePreference(singlePref, singlePref.getKey());
            }
        } else {
            updatePreference(preference, preference.getKey());
        }
    }
}
 
Example 10
Source File: SettingsActivity.java    From busybox with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Recursive set summaries
 *
 * @param pg group
 */
private void initSummaries(PreferenceGroup pg) {
    for (int i = 0; i < pg.getPreferenceCount(); ++i) {
        Preference p = pg.getPreference(i);
        if (p instanceof PreferenceGroup)
            initSummaries((PreferenceGroup) p);
        else
            setSummary(p, false);
        if (p instanceof PreferenceScreen)
            p.setOnPreferenceClickListener(this);
    }
}
 
Example 11
Source File: Preferences.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static List<Preference> getAllPreferences(final PreferenceGroup parent) {
    final int preferenceCount = parent.getPreferenceCount();
    final List<Preference> results = new ArrayList<>(preferenceCount);
    for (int i = 0; i < preferenceCount; i++) {
        final Preference preference = parent.getPreference(i);
        results.add(preference);
        if (preference instanceof PreferenceGroup) {
            // recurse
            results.addAll(getAllPreferences((PreferenceGroup)preference));
        }
    }
    return results;
}
 
Example 12
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void recursive_notify_all_preference_screens(PreferenceGroup preferenceGroup) {
    if (preferenceGroup instanceof PreferenceScreen) {
        ((BaseAdapter) ((PreferenceScreen) preferenceGroup).getRootAdapter()).notifyDataSetChanged();
    } else {
        for (int index = 0; index < preferenceGroup.getPreferenceCount(); index++) {
            final Preference pref = preferenceGroup.getPreference(index);
            if (pref instanceof PreferenceGroup) {
                recursive_notify_all_preference_screens((PreferenceGroup) pref);
            }
        }
    }
}
 
Example 13
Source File: Preferences.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static List<Preference> getAllPreferences(final PreferenceGroup parent) {
    final int preferenceCount = parent.getPreferenceCount();
    final List<Preference> results = new ArrayList<>(preferenceCount);
    for (int i = 0; i < preferenceCount; i++) {
        final Preference preference = parent.getPreference(i);
        results.add(preference);
        if (preference instanceof PreferenceGroup) {
            // recurse
            results.addAll(getAllPreferences((PreferenceGroup)preference));
        }
    }
    return results;
}
 
Example 14
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 15
Source File: CustomInputStyleSettingsFragment.java    From AOSP-Kayboard-7.1.2 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 16
Source File: CustomInputStyleSettingsFragment.java    From simple-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 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 18
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 19
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 20
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()]);
}