Methods Summary |
---|
public void | addItemFromInflater(Preference preference)Called by the inflater to add an item to this group.
addPreference(preference);
|
public boolean | addPreference(Preference preference)Adds a {@link Preference} at the correct position based on the
preference's order.
if (mPreferenceList.contains(preference)) {
// Exists
return true;
}
if (preference.getOrder() == Preference.DEFAULT_ORDER) {
if (mOrderingAsAdded) {
preference.setOrder(mCurrentPreferenceOrder++);
}
if (preference instanceof PreferenceGroup) {
// TODO: fix (method is called tail recursively when inflating,
// so we won't end up properly passing this flag down to children
((PreferenceGroup)preference).setOrderingAsAdded(mOrderingAsAdded);
}
}
int insertionIndex = Collections.binarySearch(mPreferenceList, preference);
if (insertionIndex < 0) {
insertionIndex = insertionIndex * -1 - 1;
}
if (!onPrepareAddPreference(preference)) {
return false;
}
synchronized(this) {
mPreferenceList.add(insertionIndex, preference);
}
preference.onAttachedToHierarchy(getPreferenceManager());
if (mAttachedToActivity) {
preference.onAttachedToActivity();
}
notifyHierarchyChanged();
return true;
|
protected void | dispatchRestoreInstanceState(android.os.Bundle container)
super.dispatchRestoreInstanceState(container);
// Dispatch to all contained preferences
final int preferenceCount = getPreferenceCount();
for (int i = 0; i < preferenceCount; i++) {
getPreference(i).dispatchRestoreInstanceState(container);
}
|
protected void | dispatchSaveInstanceState(android.os.Bundle container)
super.dispatchSaveInstanceState(container);
// Dispatch to all contained preferences
final int preferenceCount = getPreferenceCount();
for (int i = 0; i < preferenceCount; i++) {
getPreference(i).dispatchSaveInstanceState(container);
}
|
public Preference | findPreference(java.lang.CharSequence key)Finds a {@link Preference} based on its key. If two {@link Preference}
share the same key (not recommended), the first to appear will be
returned (to retrieve the other preference with the same key, call this
method on the first preference). If this preference has the key, it will
not be returned.
This will recursively search for the preference into children that are
also {@link PreferenceGroup PreferenceGroups}.
if (TextUtils.equals(getKey(), key)) {
return this;
}
final int preferenceCount = getPreferenceCount();
for (int i = 0; i < preferenceCount; i++) {
final Preference preference = getPreference(i);
final String curKey = preference.getKey();
if (curKey != null && curKey.equals(key)) {
return preference;
}
if (preference instanceof PreferenceGroup) {
final Preference returnedPreference = ((PreferenceGroup)preference)
.findPreference(key);
if (returnedPreference != null) {
return returnedPreference;
}
}
}
return null;
|
public Preference | getPreference(int index)Returns the {@link Preference} at a particular index.
return mPreferenceList.get(index);
|
public int | getPreferenceCount()Returns the number of children {@link Preference}s.
return mPreferenceList.size();
|
protected boolean | isOnSameScreenAsChildren()Whether this preference group should be shown on the same screen as its
contained preferences.
return true;
|
public boolean | isOrderingAsAdded()Whether this group is ordering preferences in the order they are added.
return mOrderingAsAdded;
|
protected void | onAttachedToActivity()
super.onAttachedToActivity();
// Mark as attached so if a preference is later added to this group, we
// can tell it we are already attached
mAttachedToActivity = true;
// Dispatch to all contained preferences
final int preferenceCount = getPreferenceCount();
for (int i = 0; i < preferenceCount; i++) {
getPreference(i).onAttachedToActivity();
}
|
protected boolean | onPrepareAddPreference(Preference preference)Prepares a {@link Preference} to be added to the group.
if (!super.isEnabled()) {
preference.setEnabled(false);
}
return true;
|
protected void | onPrepareForRemoval()
super.onPrepareForRemoval();
// We won't be attached to the activity anymore
mAttachedToActivity = false;
|
public void | removeAll()Removes all {@link Preference Preferences} from this group.
synchronized(this) {
List<Preference> preferenceList = mPreferenceList;
for (int i = preferenceList.size() - 1; i >= 0; i--) {
removePreferenceInt(preferenceList.get(0));
}
}
notifyHierarchyChanged();
|
public boolean | removePreference(Preference preference)Removes a {@link Preference} from this group.
final boolean returnValue = removePreferenceInt(preference);
notifyHierarchyChanged();
return returnValue;
|
private boolean | removePreferenceInt(Preference preference)
synchronized(this) {
preference.onPrepareForRemoval();
return mPreferenceList.remove(preference);
}
|
public void | setEnabled(boolean enabled)
super.setEnabled(enabled);
// Dispatch to all contained preferences
final int preferenceCount = getPreferenceCount();
for (int i = 0; i < preferenceCount; i++) {
getPreference(i).setEnabled(enabled);
}
|
public void | setOrderingAsAdded(boolean orderingAsAdded)Whether to order the {@link Preference} children of this group as they
are added. If this is false, the ordering will follow each Preference
order and default to alphabetic for those without an order.
If this is called after preferences are added, they will not be
re-ordered in the order they were added, hence call this method early on.
mOrderingAsAdded = orderingAsAdded;
|
void | sortPreferences()
synchronized (this) {
Collections.sort(mPreferenceList);
}
|