Merge "Updating new widget api to account for view type count"
This commit is contained in:
@@ -29106,7 +29106,7 @@ package android.widget {
|
||||
method public void setRelativeScrollPosition(int, int);
|
||||
method public deprecated void setRemoteAdapter(int, int, android.content.Intent);
|
||||
method public void setRemoteAdapter(int, android.content.Intent);
|
||||
method public void setRemoteAdapter(int, java.util.ArrayList<android.widget.RemoteViews>);
|
||||
method public void setRemoteAdapter(int, java.util.ArrayList<android.widget.RemoteViews>, int);
|
||||
method public void setScrollPosition(int, int);
|
||||
method public void setShort(int, java.lang.String, short);
|
||||
method public void setString(int, java.lang.String, java.lang.String);
|
||||
|
||||
@@ -487,13 +487,15 @@ public class RemoteViews implements Parcelable, Filter {
|
||||
}
|
||||
|
||||
private class SetRemoteViewsAdapterList extends Action {
|
||||
public SetRemoteViewsAdapterList(int id, ArrayList<RemoteViews> list) {
|
||||
public SetRemoteViewsAdapterList(int id, ArrayList<RemoteViews> list, int viewTypeCount) {
|
||||
this.viewId = id;
|
||||
this.list = list;
|
||||
this.viewTypeCount = viewTypeCount;
|
||||
}
|
||||
|
||||
public SetRemoteViewsAdapterList(Parcel parcel) {
|
||||
viewId = parcel.readInt();
|
||||
viewTypeCount = parcel.readInt();
|
||||
int count = parcel.readInt();
|
||||
list = new ArrayList<RemoteViews>();
|
||||
|
||||
@@ -506,6 +508,7 @@ public class RemoteViews implements Parcelable, Filter {
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(TAG);
|
||||
dest.writeInt(viewId);
|
||||
dest.writeInt(viewTypeCount);
|
||||
|
||||
if (list == null || list.size() == 0) {
|
||||
dest.writeInt(0);
|
||||
@@ -540,18 +543,18 @@ public class RemoteViews implements Parcelable, Filter {
|
||||
if (target instanceof AbsListView) {
|
||||
AbsListView v = (AbsListView) target;
|
||||
Adapter a = v.getAdapter();
|
||||
if (a instanceof RemoteViewsListAdapter) {
|
||||
if (a instanceof RemoteViewsListAdapter && viewTypeCount <= a.getViewTypeCount()) {
|
||||
((RemoteViewsListAdapter) a).setViewsList(list);
|
||||
} else {
|
||||
v.setAdapter(new RemoteViewsListAdapter(v.getContext(), list));
|
||||
v.setAdapter(new RemoteViewsListAdapter(v.getContext(), list, viewTypeCount));
|
||||
}
|
||||
} else if (target instanceof AdapterViewAnimator) {
|
||||
AdapterViewAnimator v = (AdapterViewAnimator) target;
|
||||
Adapter a = v.getAdapter();
|
||||
if (a instanceof RemoteViewsListAdapter) {
|
||||
if (a instanceof RemoteViewsListAdapter && viewTypeCount <= a.getViewTypeCount()) {
|
||||
((RemoteViewsListAdapter) a).setViewsList(list);
|
||||
} else {
|
||||
v.setAdapter(new RemoteViewsListAdapter(v.getContext(), list));
|
||||
v.setAdapter(new RemoteViewsListAdapter(v.getContext(), list, viewTypeCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -560,6 +563,7 @@ public class RemoteViews implements Parcelable, Filter {
|
||||
return "SetRemoteViewsAdapterList";
|
||||
}
|
||||
|
||||
int viewTypeCount;
|
||||
ArrayList<RemoteViews> list;
|
||||
public final static int TAG = 15;
|
||||
}
|
||||
@@ -2099,9 +2103,13 @@ public class RemoteViews implements Parcelable, Filter {
|
||||
*
|
||||
* @param viewId The id of the {@link AdapterView}
|
||||
* @param list The list of RemoteViews which will populate the view specified by viewId.
|
||||
* @param viewTypeCount The maximum number of unique layout id's used to construct the list of
|
||||
* RemoteViews. This count cannot change during the life-cycle of a given widget, so this
|
||||
* parameter should account for the maximum possible number of types that may appear in the
|
||||
* See {@link Adapter#getViewTypeCount()}.
|
||||
*/
|
||||
public void setRemoteAdapter(int viewId, ArrayList<RemoteViews> list) {
|
||||
addAction(new SetRemoteViewsAdapterList(viewId, list));
|
||||
public void setRemoteAdapter(int viewId, ArrayList<RemoteViews> list, int viewTypeCount) {
|
||||
addAction(new SetRemoteViewsAdapterList(viewId, list, viewTypeCount));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,10 +30,13 @@ public class RemoteViewsListAdapter extends BaseAdapter {
|
||||
private Context mContext;
|
||||
private ArrayList<RemoteViews> mRemoteViewsList;
|
||||
private ArrayList<Integer> mViewTypes = new ArrayList<Integer>();
|
||||
private int mViewTypeCount;
|
||||
|
||||
public RemoteViewsListAdapter(Context context, ArrayList<RemoteViews> remoteViews) {
|
||||
public RemoteViewsListAdapter(Context context, ArrayList<RemoteViews> remoteViews,
|
||||
int viewTypeCount) {
|
||||
mContext = context;
|
||||
mRemoteViewsList = remoteViews;
|
||||
mViewTypeCount = viewTypeCount;
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -52,6 +55,11 @@ public class RemoteViewsListAdapter extends BaseAdapter {
|
||||
mViewTypes.add(rv.getLayoutId());
|
||||
}
|
||||
}
|
||||
|
||||
if (mViewTypes.size() > mViewTypeCount || mViewTypeCount < 1) {
|
||||
throw new RuntimeException("Invalid view type count -- view type count must be >= 1" +
|
||||
"and must be as large as the total number of distinct view types");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,6 +85,7 @@ public class RemoteViewsListAdapter extends BaseAdapter {
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (position < getCount()) {
|
||||
RemoteViews rv = mRemoteViewsList.get(position);
|
||||
rv.setIsWidgetCollectionChild(true);
|
||||
View v;
|
||||
if (convertView != null && rv != null &&
|
||||
convertView.getId() == rv.getLayoutId()) {
|
||||
@@ -102,7 +111,7 @@ public class RemoteViewsListAdapter extends BaseAdapter {
|
||||
}
|
||||
|
||||
public int getViewTypeCount() {
|
||||
return mViewTypes.size();
|
||||
return mViewTypeCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user