diff options
| author | Winson Chung <winsonc@google.com> | 2010-08-16 10:14:56 -0700 |
|---|---|---|
| committer | Winson Chung <winsonc@google.com> | 2010-08-17 14:25:06 -0700 |
| commit | 6394c0e52cf641d93f678fd052499aa952e3595d (patch) | |
| tree | 94131f4b7bf90e48a741767f5d70036786209bb1 /core/java/android/widget/RemoteViewsAdapter.java | |
| parent | 385df2c7a5315fd114fd133b33e31f320987ad43 (diff) | |
Adding callback and fix to RemoteViewsFactory on notifyDataSetChanged.
Also removing extra parameter in AppWidgetManager.notifyDataSetChanged.
Change-Id: Ic771fe045ae793a6dacf09f1230e7c1c4b59a13e
Diffstat (limited to 'core/java/android/widget/RemoteViewsAdapter.java')
| -rw-r--r-- | core/java/android/widget/RemoteViewsAdapter.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/java/android/widget/RemoteViewsAdapter.java b/core/java/android/widget/RemoteViewsAdapter.java index ebf5d6ee9977..cd1e4220260b 100644 --- a/core/java/android/widget/RemoteViewsAdapter.java +++ b/core/java/android/widget/RemoteViewsAdapter.java @@ -202,6 +202,7 @@ public class RemoteViewsAdapter extends BaseAdapter { int count; int viewTypeCount; boolean hasStableIds; + boolean isDataDirty; Map<Integer, Integer> mTypeIdIndexMap; RemoteViewsInfo() { @@ -209,6 +210,7 @@ public class RemoteViewsAdapter extends BaseAdapter { // by default there is at least one dummy view type viewTypeCount = 1; hasStableIds = true; + isDataDirty = false; mTypeIdIndexMap = new HashMap<Integer, Integer>(); } } @@ -282,6 +284,39 @@ public class RemoteViewsAdapter extends BaseAdapter { } } + protected void onNotifyDataSetChanged() { + // we mark the data as dirty so that the next call to fetch views will result in + // an onDataSetDirty() call from the adapter + synchronized (mViewCacheInfo) { + mViewCacheInfo.isDataDirty = true; + } + } + + private void updateNotifyDataSetChanged() { + // actually calls through to the factory to notify it to update + if (mServiceConnection.isConnected()) { + IRemoteViewsFactory factory = mServiceConnection.getRemoteViewsFactory(); + try { + factory.onDataSetChanged(); + } catch (RemoteException e) { + e.printStackTrace(); + } + + } + + // re-request the new metadata (only after the notification to the factory) + requestMetaData(); + + // post a new runnable on the main thread to propagate the notification back + // to the base adapter + mMainQueue.post(new Runnable() { + @Override + public void run() { + completeNotifyDataSetChanged(); + } + }); + } + protected void updateRemoteViewsInfo(int position) { if (mServiceConnection.isConnected()) { IRemoteViewsFactory factory = mServiceConnection.getRemoteViewsFactory(); @@ -499,6 +534,16 @@ public class RemoteViewsAdapter extends BaseAdapter { @Override public void run() { while (mBackgroundLoaderEnabled) { + // notify the RemoteViews factory if necessary + boolean isDataDirty = false; + synchronized (mViewCacheInfo) { + isDataDirty = mViewCacheInfo.isDataDirty; + mViewCacheInfo.isDataDirty = false; + } + if (isDataDirty) { + updateNotifyDataSetChanged(); + } + int index = -1; synchronized (mViewCacheLoadIndices) { if (!mViewCacheLoadIndices.isEmpty()) { @@ -668,6 +713,12 @@ public class RemoteViewsAdapter extends BaseAdapter { public void notifyDataSetChanged() { // flush the cache so that we can reload new items from the service mViewCache.flushCache(); + + // notify the factory that it's data may no longer be valid + mViewCache.onNotifyDataSetChanged(); + } + + public void completeNotifyDataSetChanged() { super.notifyDataSetChanged(); } |
