Updating new widget api to account for view type count
Change-Id: Iab3a905aaec0b42ef31cd23e0711f6f7bf299486
diff --git a/api/current.txt b/api/current.txt
index 72e7601..1cf14aa 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -29106,7 +29106,7 @@
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);
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 57e3c8b..79fc51e 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -487,13 +487,15 @@
}
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 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 @@
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 @@
return "SetRemoteViewsAdapterList";
}
+ int viewTypeCount;
ArrayList<RemoteViews> list;
public final static int TAG = 15;
}
@@ -2099,9 +2103,13 @@
*
* @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));
}
/**
diff --git a/core/java/android/widget/RemoteViewsListAdapter.java b/core/java/android/widget/RemoteViewsListAdapter.java
index 9598771..e490458 100644
--- a/core/java/android/widget/RemoteViewsListAdapter.java
+++ b/core/java/android/widget/RemoteViewsListAdapter.java
@@ -30,10 +30,13 @@
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 @@
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 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 int getViewTypeCount() {
- return mViewTypes.size();
+ return mViewTypeCount;
}
@Override