summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhuiwan <huiwan@codeaurora.org>2014-11-10 10:35:03 -0800
committerRajesh Yengisetty <rajesh@cyngn.com>2014-11-21 00:13:25 +0000
commit9b398417ff00bb67a43579c748fd335effad1c5b (patch)
treeaa112a7fc0d0128df46e63795c4717f9263e2cf4
parent783be63c0a6d9b47f900c5d711a6a1663f1ca112 (diff)
downloadandroid_packages_apps_Trebuchet-9b398417ff00bb67a43579c748fd335effad1c5b.tar.gz
android_packages_apps_Trebuchet-9b398417ff00bb67a43579c748fd335effad1c5b.tar.bz2
android_packages_apps_Trebuchet-9b398417ff00bb67a43579c748fd335effad1c5b.zip
Launcher: show unread notify info number at APP icon on Launcher
Show APP's unread info number at Launcher: - Register a receiver to receive the UNREAD_CHANGED event to update the APP icon - When the unread number changed, recreate the icon bitmap of icon cache Change-Id: I7dd0fb2c29959f1584682965fb1476e3f3c77739
-rw-r--r--res/values/colors.xml2
-rw-r--r--res/values/config.xml15
-rw-r--r--res/values/dimens.xml5
-rw-r--r--src/com/android/launcher3/AllAppsList.java37
-rw-r--r--src/com/android/launcher3/AppInfo.java4
-rw-r--r--src/com/android/launcher3/IconCache.java16
-rw-r--r--src/com/android/launcher3/LauncherAppState.java7
-rw-r--r--src/com/android/launcher3/LauncherApplication.java6
-rw-r--r--src/com/android/launcher3/LauncherModel.java65
-rw-r--r--src/com/android/launcher3/Utilities.java45
10 files changed, 186 insertions, 16 deletions
diff --git a/res/values/colors.xml b/res/values/colors.xml
index b2164de89..fd50ffd73 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -44,4 +44,6 @@
<color name="settings_bg_header_color">#FFb2b0ab</color>
<color name="settings_bg_selected_color">#26000000</color>
<color name="settings_transition_selected_color">#50000000</color>
+
+ <color name="infomation_count_circle_color">#F44336</color>
</resources>
diff --git a/res/values/config.xml b/res/values/config.xml
index 52d08718f..8ce37fe28 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -100,9 +100,6 @@
<!-- Camera distance for the overscroll effect -->
<integer name="config_cameraDistance">8000</integer>
-<!-- Hotseat -->
- <bool name="hotseat_transpose_layout_with_orientation">true</bool>
-
<!-- Memory debugging, including a memory dump icon -->
<bool name="debug_memory_enabled">false</bool>
@@ -113,4 +110,16 @@
<!-- Name of a subclass of com.android.launcher3.BuildInfo used to
get build information. Can be empty. -->
<string name="build_info_class" translatable="false"></string>
+
+<!-- Hotseat -->
+ <bool name="hotseat_transpose_layout_with_orientation">true</bool>
+ <integer name="hotseat_cell_count">5</integer>
+ <integer name="hotseat_all_apps_index">2</integer>
+ <!-- must be between 0 and 100 -->
+ <integer name="hotseat_item_scale_percentage">100</integer>
+
+ <bool name="config_launcher_sort">false</bool>
+ <bool name="config_launcher_page">false</bool>
+ <bool name="config_launcher_shortcut">false</bool>
+ <bool name="config_launcher_show_unread_number">false</bool>
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 15f37ad41..d591535d3 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -70,6 +70,11 @@
<!-- Drag padding to add to the bottom of drop targets -->
<dimen name="drop_target_drag_padding">14dp</dimen>
+ <dimen name="infomation_count_height">14dp</dimen>
+ <dimen name="infomation_count_min_width">14dp</dimen>
+ <dimen name="infomation_count_textsize">11dp</dimen>
+ <dimen name="infomation_count_padding">4dp</dimen>
+ <dimen name="infomation_count_circle_radius">7dp</dimen>
<!-- Dragging -->
<!-- the area at the edge of the screen that makes the workspace go left
or right while you're dragging. -->
diff --git a/src/com/android/launcher3/AllAppsList.java b/src/com/android/launcher3/AllAppsList.java
index 38d2fa541..f9900e604 100644
--- a/src/com/android/launcher3/AllAppsList.java
+++ b/src/com/android/launcher3/AllAppsList.java
@@ -18,11 +18,6 @@ package com.android.launcher3;
import android.content.ComponentName;
import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-
import com.android.launcher3.compat.LauncherActivityInfoCompat;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserHandleCompat;
@@ -231,4 +226,36 @@ class AllAppsList {
}
return null;
}
+
+ public AppInfo unreadNumbersChanged(Context context, ComponentName component,
+ int unreadNum) {
+
+ if (component == null) { return null; }
+
+ LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
+ UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle();
+ List<LauncherActivityInfoCompat> matches =
+ launcherApps.getActivityList(component.getPackageName(), myUserHandle);
+
+ for (LauncherActivityInfoCompat launcherActivityInfoCompat : matches) {
+ if (component.getPackageName().equals(
+ launcherActivityInfoCompat.getComponentName().getPackageName())) {
+
+ AppInfo appInfo = findApplicationInfoLocked(
+ component.getPackageName(), myUserHandle,
+ component.getClassName());
+
+ if (appInfo == null) {
+ return null;
+ } else {
+ appInfo.unreadNum = unreadNum;
+ mIconCache.remove(appInfo.componentName, myUserHandle);
+ mIconCache.getTitleAndIcon(appInfo, launcherActivityInfoCompat, null);
+ return appInfo;
+ }
+ }
+ }
+
+ return null;
+ }
}
diff --git a/src/com/android/launcher3/AppInfo.java b/src/com/android/launcher3/AppInfo.java
index bfcad84b3..b1af370b1 100644
--- a/src/com/android/launcher3/AppInfo.java
+++ b/src/com/android/launcher3/AppInfo.java
@@ -56,6 +56,10 @@ public class AppInfo extends ItemInfo {
ComponentName componentName;
+ int count;
+
+ int unreadNum = 0;
+
static final int DOWNLOADED_FLAG = 1;
static final int UPDATED_SYSTEM_APP_FLAG = 2;
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index bb71d776c..03684f600 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -245,7 +245,7 @@ public class IconCache {
HashMap<Object, CharSequence> labelCache) {
synchronized (mCache) {
CacheEntry entry = cacheLocked(application.componentName, info, labelCache,
- info.getUser(), false);
+ info.getUser(), false, application.unreadNum);
application.title = entry.title;
application.iconBitmap = entry.icon;
@@ -267,7 +267,7 @@ public class IconCache {
}
LauncherActivityInfoCompat launcherActInfo = mLauncherApps.resolveActivity(intent, user);
- CacheEntry entry = cacheLocked(component, launcherActInfo, null, user, usePkgIcon);
+ CacheEntry entry = cacheLocked(component, launcherActInfo, null, user, usePkgIcon, -1);
if (title != null) {
entry.title = title;
entry.contentDescription = mUserManager.getBadgedLabelForUser(title, user);
@@ -292,7 +292,8 @@ public class IconCache {
} else {
LauncherActivityInfoCompat launcherActInfo =
mLauncherApps.resolveActivity(intent, user);
- CacheEntry entry = cacheLocked(component, launcherActInfo, null, user, usePkgIcon);
+ CacheEntry entry = cacheLocked(component, launcherActInfo, null, user, usePkgIcon,
+ -1);
shortcutInfo.setIcon(entry.icon);
shortcutInfo.title = entry.title;
@@ -316,7 +317,7 @@ public class IconCache {
return null;
}
- CacheEntry entry = cacheLocked(component, info, labelCache, info.getUser(), false);
+ CacheEntry entry = cacheLocked(component, info, labelCache, info.getUser(), false, -1);
return entry.icon;
}
}
@@ -326,10 +327,11 @@ public class IconCache {
}
private CacheEntry cacheLocked(ComponentName componentName, LauncherActivityInfoCompat info,
- HashMap<Object, CharSequence> labelCache, UserHandleCompat user, boolean usePackageIcon) {
+ HashMap<Object, CharSequence> labelCache, UserHandleCompat user,
+ boolean usePackageIcon, int unreadNum) {
CacheKey cacheKey = new CacheKey(componentName, user);
CacheEntry entry = mCache.get(cacheKey);
- if (entry == null) {
+ if (entry == null || unreadNum >= 0) {
entry = new CacheEntry();
mCache.put(cacheKey, entry);
@@ -347,7 +349,7 @@ public class IconCache {
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
entry.icon = Utilities.createIconBitmap(
- info.getBadgedIcon(mIconDpi), mContext);
+ info.getBadgedIcon(mIconDpi), mContext, unreadNum);
} else {
entry.title = "";
Bitmap preloaded = getPreloadedIcon(componentName, user);
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 128065ab6..a207f1e2c 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -111,6 +111,13 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks {
filter = new IntentFilter();
filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
sContext.registerReceiver(mModel, filter);
+
+ filter = new IntentFilter();
+ if (LauncherApplication.LAUNCHER_SHOW_UNREAD_NUMBER) {
+ filter.addAction(LauncherModel.ACTION_UNREAD_CHANGED);
+ sContext.registerReceiver(mModel, filter);
+ }
+
filter = new IntentFilter();
filter.addAction(SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED);
sContext.registerReceiver(mModel, filter);
diff --git a/src/com/android/launcher3/LauncherApplication.java b/src/com/android/launcher3/LauncherApplication.java
index 8b179f1e7..f0a08ffbe 100644
--- a/src/com/android/launcher3/LauncherApplication.java
+++ b/src/com/android/launcher3/LauncherApplication.java
@@ -19,9 +19,13 @@ package com.android.launcher3;
import android.app.Application;
public class LauncherApplication extends Application {
+ public static boolean LAUNCHER_SHOW_UNREAD_NUMBER;
+
@Override
public void onCreate() {
super.onCreate();
+ LAUNCHER_SHOW_UNREAD_NUMBER = getResources().getBoolean(
+ R.bool.config_launcher_show_unread_number);
LauncherAppState.setApplicationContext(this);
LauncherAppState.getInstance();
}
@@ -31,4 +35,4 @@ public class LauncherApplication extends Application {
super.onTerminate();
LauncherAppState.getInstance().onTerminate();
}
-} \ No newline at end of file
+}
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);
}
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 80d4b22ce..addd74cfc 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -32,8 +32,11 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
+import android.graphics.Paint.Style;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
@@ -75,6 +78,48 @@ public final class Utilities {
static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
+ static Bitmap createIconBitmap(Drawable icon, Context context, int count) {
+ Bitmap b = createIconBitmap(icon, context);
+
+ if (!LauncherApplication.LAUNCHER_SHOW_UNREAD_NUMBER || count <= 0) {
+ return b;
+ }
+
+ int textureWidth = b.getWidth();
+ final Resources resources = context.getResources();
+ final Canvas canvas = sCanvas;
+ canvas.setBitmap(b);
+
+ float textsize = resources.getDimension(R.dimen.infomation_count_textsize);
+ Paint countPaint = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.DEV_KERN_TEXT_FLAG);
+ countPaint.setColor(Color.WHITE);
+ countPaint.setTextSize(textsize);
+
+ String text = String.valueOf(count);
+ if (count >= 1000) {
+ text = "999+";
+ }
+
+ float count_hight = resources.getDimension(R.dimen.infomation_count_height);
+ float padding = resources.getDimension(R.dimen.infomation_count_padding);
+ float radius = resources.getDimension(R.dimen.infomation_count_circle_radius);
+ int textwidth = (int) (countPaint.measureText(text) + 1);
+ float width =textwidth + padding * 2;
+ width = Math.max(width, resources.getDimensionPixelSize(R.dimen.infomation_count_min_width));
+
+ RectF rect = new RectF(textureWidth - width -1, 1, textureWidth - 1, count_hight + 1);
+ Paint paint = new Paint();
+ paint.setAntiAlias(true);
+ paint.setColor(resources.getColor(R.color.infomation_count_circle_color));
+ canvas.drawRoundRect(rect , radius, radius, paint);
+
+ float x = textureWidth - (width + textwidth ) / 2 - 1;
+ float y = textsize;
+ canvas.drawText(text, x, y, countPaint);
+
+ return b;
+ }
+
/**
* Returns a FastBitmapDrawable with the icon, accurately sized.
*/