summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanesh Mondegarian <daneshm90@gmail.com>2014-02-14 23:07:32 +0000
committerGerrit Code Review <gerrit@cyanogenmod.org>2014-02-14 23:07:32 +0000
commit6b96af3d99a5d67030c3530c05e592b913df6786 (patch)
tree85455d63f2941a92d5eb9b845dcce03e4a854879
parent474d306a10895ae1cc23020f97845920810b3914 (diff)
parentc4627bba1f76f8ee7abfb577bf24aafcae7b182f (diff)
downloadandroid_packages_apps_Trebuchet-6b96af3d99a5d67030c3530c05e592b913df6786.tar.gz
android_packages_apps_Trebuchet-6b96af3d99a5d67030c3530c05e592b913df6786.tar.bz2
android_packages_apps_Trebuchet-6b96af3d99a5d67030c3530c05e592b913df6786.zip
Merge "Trebuchet : Add iconMask/iconBack/iconUpon/iconScale support" into cm-11.0
-rw-r--r--src/com/android/launcher3/IconCache.java12
-rw-r--r--src/com/android/launcher3/IconPackHelper.java86
-rw-r--r--src/com/android/launcher3/Utilities.java31
3 files changed, 118 insertions, 11 deletions
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index b4bb5b9c3..e1659e795 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -252,8 +252,16 @@ public class IconCache {
entry.title = info.activityInfo.name;
}
- entry.icon = Utilities.createIconBitmap(
- getFullResIcon(info), mContext);
+ Drawable icon = getFullResIcon(info);
+ if (mIconPackHelper.isIconPackLoaded() && (mIconPackHelper
+ .getResourceIdForActivityIcon(info.activityInfo) == 0)) {
+ entry.icon = Utilities.createIconBitmap(
+ icon, mContext, mIconPackHelper.getIconBack(),
+ mIconPackHelper.getIconMask(), mIconPackHelper.getIconUpon(), mIconPackHelper.getIconScale());
+ } else {
+ entry.icon = Utilities.createIconBitmap(
+ icon, mContext);
+ }
}
return entry;
}
diff --git a/src/com/android/launcher3/IconPackHelper.java b/src/com/android/launcher3/IconPackHelper.java
index 82e5f9e46..69fadd965 100644
--- a/src/com/android/launcher3/IconPackHelper.java
+++ b/src/com/android/launcher3/IconPackHelper.java
@@ -40,6 +40,11 @@ import com.android.launcher3.settings.SettingsProvider;
public class IconPackHelper {
+ static final String ICON_MASK_TAG = "iconmask";
+ static final String ICON_BACK_TAG = "iconback";
+ static final String ICON_UPON_TAG = "iconupon";
+ static final String ICON_SCALE_TAG = "scale";
+
public final static String[] sSupportedActions = new String[] {
"org.adw.launcher.THEMES",
"com.gau.go.launcherex.theme"
@@ -56,12 +61,43 @@ public class IconPackHelper {
private final Context mContext;
private String mLoadedIconPackName;
private Resources mLoadedIconPackResource;
+ private Drawable mIconBack, mIconUpon, mIconMask;
+ private float mIconScale;
+
+ public Drawable getIconBack() {
+ return mIconBack;
+ }
+
+ public Drawable getIconMask() {
+ return mIconMask;
+ }
+
+ public Drawable getIconUpon() {
+ return mIconUpon;
+ }
+
+ public float getIconScale() {
+ return mIconScale;
+ }
IconPackHelper(Context context) {
mContext = context;
mIconPackResources = new HashMap<String, String>();
}
+ private Drawable getDrawableForName(String name) {
+ if (isIconPackLoaded()) {
+ String item = mIconPackResources.get(name);
+ if (!TextUtils.isEmpty(item)) {
+ int id = getResourceIdForDrawable(item);
+ if (id != 0) {
+ return mLoadedIconPackResource.getDrawable(id);
+ }
+ }
+ }
+ return null;
+ }
+
public static Map<String, IconPackInfo> getSupportedPackages(Context context) {
Intent i = new Intent();
Map<String, IconPackInfo> packages = new HashMap<String, IconPackInfo>();
@@ -94,6 +130,30 @@ public class IconPackHelper {
continue;
}
+ if (parser.getName().equalsIgnoreCase(ICON_MASK_TAG) ||
+ parser.getName().equalsIgnoreCase(ICON_BACK_TAG) ||
+ parser.getName().equalsIgnoreCase(ICON_UPON_TAG)) {
+ String icon = parser.getAttributeValue(null, "img");
+ if (icon == null) {
+ if (parser.getAttributeCount() == 1) {
+ icon = parser.getAttributeValue(0);
+ }
+ }
+ iconPackResources.put(parser.getName().toLowerCase(), icon);
+ continue;
+ }
+
+ if (parser.getName().equalsIgnoreCase(ICON_SCALE_TAG)) {
+ String factor = parser.getAttributeValue(null, "factor");
+ if (factor == null) {
+ if (parser.getAttributeCount() == 1) {
+ factor = parser.getAttributeValue(0);
+ }
+ }
+ iconPackResources.put(parser.getName().toLowerCase(), factor);
+ continue;
+ }
+
if (!parser.getName().equalsIgnoreCase("item")) {
continue;
}
@@ -179,6 +239,16 @@ public class IconPackHelper {
}
mLoadedIconPackResource = res;
mLoadedIconPackName = packageName;
+ mIconBack = getDrawableForName(ICON_BACK_TAG);
+ mIconMask = getDrawableForName(ICON_MASK_TAG);
+ mIconUpon = getDrawableForName(ICON_UPON_TAG);
+ String scale = mIconPackResources.get(ICON_SCALE_TAG);
+ if (scale != null) {
+ try {
+ mIconScale = Float.valueOf(scale);
+ } catch (NumberFormatException e) {
+ }
+ }
return true;
}
@@ -280,9 +350,11 @@ public class IconPackHelper {
public void unloadIconPack() {
mLoadedIconPackResource = null;
mLoadedIconPackName = null;
- if (mIconPackResources != null) {
- mIconPackResources.clear();
- }
+ mIconPackResources = null;
+ mIconMask = null;
+ mIconBack = null;
+ mIconUpon = null;
+ mIconScale = 1f;
}
public static void pickIconPack(final Context context, final boolean pickIcon) {
@@ -298,7 +370,7 @@ public class IconPackHelper {
if (!pickIcon) {
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int position) {
- if (adapter.isOriginalIconPack(position)) {
+ if (adapter.isCurrentIconPack(position)) {
((Launcher) context).getWorkspace().exitOverviewMode(true);
return;
}
@@ -382,7 +454,7 @@ public class IconPackHelper {
ArrayList<IconPackInfo> mSupportedPackages;
LayoutInflater mLayoutInflater;
String mCurrentIconPack;
- int mCurrentIconPackPosition;
+ int mCurrentIconPackPosition = -1;
IconAdapter(Context ctx, Map<String, IconPackInfo> supportedPackages) {
mLayoutInflater = LayoutInflater.from(ctx);
@@ -390,7 +462,7 @@ public class IconPackHelper {
Collections.sort(mSupportedPackages, new Comparator<IconPackInfo>() {
@Override
public int compare(IconPackInfo lhs, IconPackInfo rhs) {
- return lhs.label.toString().compareToIgnoreCase(rhs.toString());
+ return lhs.label.toString().compareToIgnoreCase(rhs.label.toString());
}
});
@@ -418,7 +490,7 @@ public class IconPackHelper {
return 0;
}
- public boolean isOriginalIconPack(int position) {
+ public boolean isCurrentIconPack(int position) {
return mCurrentIconPackPosition == position;
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index f41a1c2e5..9b5cbe7eb 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -103,10 +103,15 @@ final class Utilities {
}
}
+ static Bitmap createIconBitmap(Drawable icon, Context context) {
+ return createIconBitmap(icon, context, null, null, null, 1f);
+ }
+
/**
* Returns a bitmap suitable for the all apps view.
*/
- static Bitmap createIconBitmap(Drawable icon, Context context) {
+ static Bitmap createIconBitmap(Drawable icon, Context context, Drawable iconBack,
+ Drawable iconMask, Drawable iconUpon, float scale) {
synchronized (sCanvas) { // we share the statics :-(
if (sIconWidth == -1) {
initStatics(context);
@@ -143,7 +148,7 @@ final class Utilities {
int textureWidth = sIconTextureWidth;
int textureHeight = sIconTextureHeight;
- final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight,
+ Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight,
Bitmap.Config.ARGB_8888);
final Canvas canvas = sCanvas;
canvas.setBitmap(bitmap);
@@ -164,7 +169,29 @@ final class Utilities {
sOldBounds.set(icon.getBounds());
icon.setBounds(left, top, left+width, top+height);
+ canvas.save();
+ if (iconMask != null && iconBack != null) {
+ canvas.scale(scale, scale, width / 2, height/2);
+ }
icon.draw(canvas);
+ canvas.restore();
+ if (iconBack != null && iconMask != null) {
+ iconMask.setBounds(icon.getBounds());
+ ((BitmapDrawable) iconMask).getPaint().setXfermode(
+ new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
+ iconMask.draw(canvas);
+ canvas.setBitmap(null);
+ Bitmap finalBitmap = Bitmap.createBitmap(textureWidth, textureHeight,
+ Bitmap.Config.ARGB_8888);
+ canvas.setBitmap(finalBitmap);
+ iconBack.setBounds(icon.getBounds());
+ iconBack.draw(canvas);
+ canvas.drawBitmap(bitmap, null, icon.getBounds(), null);
+ bitmap = finalBitmap;
+ }
+ if (iconUpon != null) {
+ iconUpon.draw(canvas);
+ }
icon.setBounds(sOldBounds);
canvas.setBitmap(null);