summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherModel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r--src/com/android/launcher3/LauncherModel.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 79e7cbf43..abd41b0bc 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -178,6 +178,9 @@ public class LauncherModel extends BroadcastReceiver
// </ only access in worker thread >
+ public static final String ACTION_UNREAD_CHANGED =
+ "com.android.launcher.action.UNREAD_CHANGED";
+
private IconCache mIconCache;
protected int mPreviousConfigMcc;
@@ -214,6 +217,58 @@ public class LauncherModel extends BroadcastReceiver
public void dumpLogsToLocalData();
}
+ private HashMap<ComponentName, UnreadInfo> unreadChangedMap =
+ new HashMap<ComponentName, LauncherModel.UnreadInfo>();
+
+ private class UnreadInfo {
+ ComponentName mComponentName;
+ int mUnreadNum;
+
+ public UnreadInfo(ComponentName componentName, int unreadNum) {
+ mComponentName = componentName;
+ mUnreadNum = unreadNum;
+ }
+ }
+
+ private class UnreadNumberChangeTask implements Runnable {
+ public void run() {
+ ArrayList<UnreadInfo> unreadInfos = new ArrayList<LauncherModel.UnreadInfo>();
+ synchronized (unreadChangedMap) {
+ unreadInfos.addAll(unreadChangedMap.values());
+ unreadChangedMap.clear();
+ }
+
+ Context context = mApp.getContext();
+ final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
+ if (callbacks == null) {
+ Log.w(TAG, "Nobody to tell about the new app. Launcher is probably loading.");
+ return;
+ }
+
+ final ArrayList<AppInfo> unreadChangeFinal = new ArrayList<AppInfo>();
+ for (UnreadInfo uInfo : unreadInfos) {
+ AppInfo info = mBgAllAppsList.unreadNumbersChanged(context,
+ uInfo.mComponentName, uInfo.mUnreadNum);
+ if (info != null) {
+ unreadChangeFinal.add(info);
+ }
+ }
+
+ if (unreadChangeFinal.isEmpty()) return;
+
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
+ if (callbacks == cb && cb != null) {
+ callbacks.bindAppsUpdated(unreadChangeFinal);
+ }
+ }
+ });
+ }
+ }
+
+ private UnreadNumberChangeTask mUnreadUpdateTask = new UnreadNumberChangeTask();
+
public interface ItemInfoFilter {
public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn);
}
@@ -1334,6 +1389,16 @@ public class LauncherModel extends BroadcastReceiver
callbacks.bindSearchablesChanged();
}
}
+ } else if (ACTION_UNREAD_CHANGED.equals(action)) {
+ ComponentName componentName = intent.getParcelableExtra("component_name");
+ int unreadNum = intent.getIntExtra("unread_number", 0);
+
+ if (componentName == null) return;
+ synchronized (unreadChangedMap) {
+ unreadChangedMap.put(componentName, new UnreadInfo(componentName, unreadNum));
+ }
+ sWorker.removeCallbacks(mUnreadUpdateTask);
+ sWorker.post(mUnreadUpdateTask);
}
}