Fields Summary |
---|
private static final String | TAG |
private PreferenceGroup | mPreferenceGroupThe group that we are providing data from. |
private List | mPreferenceListMaps a position into this adapter -> {@link Preference}. These
{@link Preference}s don't have to be direct children of this
{@link PreferenceGroup}, they can be grand children or younger) |
private List | mPreferenceClassNamesList of unique Preference and its subclasses' names. This is used to find
out how many types of views this adapter can return. Once the count is
returned, this cannot be modified (since the ListView only checks the
count once--when the adapter is being set). We will not recycle views for
Preference subclasses seen after the count has been returned. |
private boolean | mHasReturnedViewTypeCountBlocks the mPreferenceClassNames from being changed anymore. |
private volatile boolean | mIsSyncing |
private android.os.Handler | mHandler |
private Runnable | mSyncRunnable |
Methods Summary |
---|
private void | addPreferenceClassName(Preference preference)
final String name = preference.getClass().getName();
int insertPos = Collections.binarySearch(mPreferenceClassNames, name);
// Only insert if it doesn't exist (when it is negative).
if (insertPos < 0) {
// Convert to insert index
insertPos = insertPos * -1 - 1;
mPreferenceClassNames.add(insertPos, name);
}
|
public boolean | areAllItemsEnabled()
// There should always be a preference group, and these groups are always
// disabled
return false;
|
private void | flattenPreferenceGroup(java.util.List preferences, PreferenceGroup group)
// TODO: shouldn't always?
group.sortPreferences();
final int groupSize = group.getPreferenceCount();
for (int i = 0; i < groupSize; i++) {
final Preference preference = group.getPreference(i);
preferences.add(preference);
if (!mHasReturnedViewTypeCount) {
addPreferenceClassName(preference);
}
if (preference instanceof PreferenceGroup) {
final PreferenceGroup preferenceAsGroup = (PreferenceGroup) preference;
if (preferenceAsGroup.isOnSameScreenAsChildren()) {
flattenPreferenceGroup(preferences, preferenceAsGroup);
}
}
preference.setOnPreferenceChangeInternalListener(this);
}
|
public int | getCount()
return mPreferenceList.size();
|
public Preference | getItem(int position)
if (position < 0 || position >= getCount()) return null;
return mPreferenceList.get(position);
|
public long | getItemId(int position)
if (position < 0 || position >= getCount()) return ListView.INVALID_ROW_ID;
return this.getItem(position).getId();
|
public int | getItemViewType(int position)
if (!mHasReturnedViewTypeCount) {
mHasReturnedViewTypeCount = true;
}
final Preference preference = this.getItem(position);
if (preference.hasSpecifiedLayout()) {
return IGNORE_ITEM_VIEW_TYPE;
}
final String name = preference.getClass().getName();
int viewType = Collections.binarySearch(mPreferenceClassNames, name);
if (viewType < 0) {
// This is a class that was seen after we returned the count, so
// don't recycle it.
return IGNORE_ITEM_VIEW_TYPE;
} else {
return viewType;
}
|
public android.view.View | getView(int position, android.view.View convertView, android.view.ViewGroup parent)
final Preference preference = this.getItem(position);
if (preference.hasSpecifiedLayout()) {
// If the preference had specified a layout (as opposed to the
// default), don't use convert views.
convertView = null;
} else {
// TODO: better way of doing this
final String name = preference.getClass().getName();
if (Collections.binarySearch(mPreferenceClassNames, name) < 0) {
convertView = null;
}
}
return preference.getView(convertView, parent);
|
public int | getViewTypeCount()
if (!mHasReturnedViewTypeCount) {
mHasReturnedViewTypeCount = true;
}
return Math.max(1, mPreferenceClassNames.size());
|
public boolean | hasStableIds()
return true;
|
public boolean | isEnabled(int position)
if (position < 0 || position >= getCount()) return true;
return this.getItem(position).isSelectable();
|
public void | onPreferenceChange(Preference preference)
notifyDataSetChanged();
|
public void | onPreferenceHierarchyChange(Preference preference)
mHandler.removeCallbacks(mSyncRunnable);
mHandler.post(mSyncRunnable);
|
private void | syncMyPreferences()
synchronized(this) {
if (mIsSyncing) {
return;
}
mIsSyncing = true;
}
List<Preference> newPreferenceList = new ArrayList<Preference>(mPreferenceList.size());
flattenPreferenceGroup(newPreferenceList, mPreferenceGroup);
mPreferenceList = newPreferenceList;
notifyDataSetChanged();
synchronized(this) {
mIsSyncing = false;
notifyAll();
}
|