FakeAdapterpublic class FakeAdapter extends android.widget.BaseAdapter Fake adapter to do fake data binding in {@link AdapterView} objects for {@link ListAdapter}
and {@link SpinnerAdapter}. |
Fields Summary |
---|
private final List | mTypes | private final com.android.ide.common.rendering.api.IProjectCallback | mCallback | private final com.android.ide.common.rendering.api.ResourceReference | mAdapterRef | private final List | mItems | private boolean | mSkipCallbackParser |
Constructors Summary |
---|
public FakeAdapter(com.android.ide.common.rendering.api.ResourceReference adapterRef, com.android.ide.common.rendering.api.AdapterBinding binding, com.android.ide.common.rendering.api.IProjectCallback callback)
mAdapterRef = adapterRef;
mCallback = callback;
final int repeatCount = binding.getRepeatCount();
final int itemCount = binding.getItemCount();
// Need an array to count for each type.
// This is likely too big, but is the max it can be.
int[] typeCount = new int[itemCount];
// We put several repeating sets.
for (int r = 0 ; r < repeatCount ; r++) {
// loop on the type of list items, and add however many for each type.
for (DataBindingItem dataBindingItem : binding) {
ResourceReference viewRef = dataBindingItem.getViewReference();
int typeIndex = mTypes.indexOf(viewRef);
if (typeIndex == -1) {
typeIndex = mTypes.size();
mTypes.add(viewRef);
}
int count = dataBindingItem.getCount();
int index = typeCount[typeIndex];
typeCount[typeIndex] += count;
for (int k = 0 ; k < count ; k++) {
mItems.add(new AdapterItem(dataBindingItem, typeIndex, mItems.size(), index++));
}
}
}
|
Methods Summary |
---|
public int | getCount()
return mItems.size();
| public android.view.View | getDropDownView(int position, android.view.View convertView, android.view.ViewGroup parent)
// pass
return null;
| public java.lang.Object | getItem(int position)
return mItems.get(position);
| public long | getItemId(int position)
return position;
| public int | getItemViewType(int position)
return mItems.get(position).getType();
| public android.view.View | getView(int position, android.view.View convertView, android.view.ViewGroup parent)
// we don't care about recycling here because we never scroll.
AdapterItem item = mItems.get(position);
Pair<View, Boolean> pair = AdapterHelper.getView(item, null /*parentGroup*/, parent,
mCallback, mAdapterRef, mSkipCallbackParser);
mSkipCallbackParser = pair.getSecond();
return pair.getFirst();
| public int | getViewTypeCount()
return mTypes.size();
| public boolean | isEnabled(int position)
return true;
|
|