aboutsummaryrefslogtreecommitdiffstats
path: root/assetstudio/src/com
diff options
context:
space:
mode:
authorRoman Nurik <romannurik@google.com>2012-12-18 13:10:40 -0800
committerRoman Nurik <romannurik@google.com>2012-12-18 15:59:13 -0800
commit62d195cf99759e254228a1ed9b35c1bf2c320bd0 (patch)
treef7e745ed2e9876e094828ace4002b5d0e191f3a9 /assetstudio/src/com
parent402c3b3f47c7c3ce236c7ce888a8e0da7fc713e3 (diff)
downloadsdk-62d195cf99759e254228a1ed9b35c1bf2c320bd0.zip
sdk-62d195cf99759e254228a1ed9b35c1bf2c320bd0.tar.gz
sdk-62d195cf99759e254228a1ed9b35c1bf2c320bd0.tar.bz2
Update Asset Studio launcher and icon generators. Also removes LDPI.
This change updates the Asset Studio launcher icon generator to the new visual style described in the Android Design guidelines. It also adds XXHDPI icon creation for launcher icons, which is important for some newer devices such as Nexus 10. The change also removes shape selection for notification icons, since this only affected pre-Gingerbread devices. Pre-Gingerbread icons are still generated, but they now always have a square shape for simplicity. Finally, this change removes LDPI for all icon generators. LDPI is much less relevant today than it was a few years ago, and allowing platform scaling of MDPI resources is normally an acceptable alternative to providing LDPI specific resources. Change-Id: I65afc5b38b25170604cf69ba355816288d30d6d5
Diffstat (limited to 'assetstudio/src/com')
-rw-r--r--assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java3
-rw-r--r--assetstudio/src/com/android/assetstudiolib/LauncherIconGenerator.java100
-rw-r--r--assetstudio/src/com/android/assetstudiolib/NotificationIconGenerator.java12
3 files changed, 79 insertions, 36 deletions
diff --git a/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java b/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java
index 91b2d2e..706adc8 100644
--- a/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java
+++ b/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java
@@ -160,7 +160,8 @@ public abstract class GraphicGenerator {
if (!density.isValidValueForDevice()) {
continue;
}
- if (density == Density.TV || density == Density.XXHIGH) {
+ if (density == Density.LOW || density == Density.TV ||
+ (density == Density.XXHIGH && !(this instanceof LauncherIconGenerator))) {
// TODO don't manually check and instead gracefully handle missing stencils.
// Not yet supported -- missing stencil image
continue;
diff --git a/assetstudio/src/com/android/assetstudiolib/LauncherIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/LauncherIconGenerator.java
index b3e327b..8902774 100644
--- a/assetstudio/src/com/android/assetstudiolib/LauncherIconGenerator.java
+++ b/assetstudio/src/com/android/assetstudiolib/LauncherIconGenerator.java
@@ -16,6 +16,9 @@
package com.android.assetstudiolib;
+import com.android.resources.Density;
+import com.android.utils.Pair;
+
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
@@ -28,8 +31,34 @@ import java.util.Map;
* A {@link GraphicGenerator} that generates Android "launcher" icons.
*/
public class LauncherIconGenerator extends GraphicGenerator {
+ private static final Rectangle IMAGE_SIZE_WEB = new Rectangle(0, 0, 512, 512);
private static final Rectangle IMAGE_SIZE_MDPI = new Rectangle(0, 0, 48, 48);
- private static final Rectangle TARGET_RECT_MDPI = new Rectangle(2, 2, 44, 44);
+
+ private static final Map<Pair<Shape, Density>, Rectangle> TARGET_RECTS
+ = new HashMap<Pair<Shape, Density>, Rectangle>();
+
+ static {
+ // None, Web
+ TARGET_RECTS.put(Pair.of(Shape.NONE, (Density) null), new Rectangle(32, 32, 448, 448));
+ // None, HDPI
+ TARGET_RECTS.put(Pair.of(Shape.NONE, Density.HIGH), new Rectangle(4, 4, 64, 64));
+ // None, MDPI
+ TARGET_RECTS.put(Pair.of(Shape.NONE, Density.MEDIUM), new Rectangle(3, 3, 42, 42));
+
+ // Circle, Web
+ TARGET_RECTS.put(Pair.of(Shape.CIRCLE, (Density) null), new Rectangle(32, 43, 448, 448));
+ // Circle, HDPI
+ TARGET_RECTS.put(Pair.of(Shape.CIRCLE, Density.HIGH), new Rectangle(4, 6, 64, 64));
+ // Circle, MDPI
+ TARGET_RECTS.put(Pair.of(Shape.CIRCLE, Density.MEDIUM), new Rectangle(3, 4, 42, 42));
+
+ // Square, Web
+ TARGET_RECTS.put(Pair.of(Shape.SQUARE, (Density) null), new Rectangle(32, 53, 448, 427));
+ // Square, HDPI
+ TARGET_RECTS.put(Pair.of(Shape.SQUARE, Density.HIGH), new Rectangle(4, 8, 64, 60));
+ // Square, MDPI
+ TARGET_RECTS.put(Pair.of(Shape.SQUARE, Density.MEDIUM), new Rectangle(3, 5, 42, 40));
+ }
@Override
public BufferedImage generate(GraphicGeneratorContext context, Options options) {
@@ -41,51 +70,69 @@ public class LauncherIconGenerator extends GraphicGenerator {
} else {
density = launcherOptions.density.getResourceValue();
}
- String shape = launcherOptions.shape.id;
- BufferedImage mBackImage = null;
- BufferedImage mForeImage = null;
- BufferedImage mMaskImage = null;
- if (launcherOptions.shape != Shape.NONE) {
- mBackImage = context.loadImageResource("/images/launcher_stencil/"
- + shape + "/" + density + "/back.png");
- mForeImage = context.loadImageResource("/images/launcher_stencil/"
- + shape + "/" + density + "/" + launcherOptions.style.id + ".png");
- mMaskImage = context.loadImageResource("/images/launcher_stencil/"
- + shape + "/" + density + "/mask.png");
+
+ BufferedImage backImage = null, foreImage = null, maskImage = null, maskInnerImage = null;
+ if (launcherOptions.shape != Shape.NONE && launcherOptions.shape != null) {
+ String shape = launcherOptions.shape.id;
+ backImage = context.loadImageResource("/images/launcher_stencil/"
+ + shape + "/" + density + "/back.png");
+ foreImage = context.loadImageResource("/images/launcher_stencil/"
+ + shape + "/" + density + "/" + launcherOptions.style.id + ".png");
+ maskImage = context.loadImageResource("/images/launcher_stencil/"
+ + shape + "/" + density + "/mask.png");
+ maskInnerImage = context.loadImageResource("/images/launcher_stencil/"
+ + shape + "/" + density + "/mask_inner.png");
}
- float scaleFactor = GraphicGenerator.getMdpiScaleFactor(launcherOptions.density);
- if (launcherOptions.isWebGraphic) {
- // Target size for the web graphic is 512
- scaleFactor = 512 / (float) IMAGE_SIZE_MDPI.height;
+ Rectangle imageRect = IMAGE_SIZE_WEB;
+ if (!launcherOptions.isWebGraphic) {
+ imageRect = Util.scaleRectangle(IMAGE_SIZE_MDPI,
+ GraphicGenerator.getMdpiScaleFactor(launcherOptions.density));
+ }
+
+ Rectangle targetRect = TARGET_RECTS.get(
+ Pair.of(launcherOptions.shape, launcherOptions.density));
+ if (targetRect == null) {
+ // Scale up from MDPI if no density-specific target rectangle is defined.
+ targetRect = Util.scaleRectangle(
+ TARGET_RECTS.get(Pair.of(launcherOptions.shape, Density.MEDIUM)),
+ GraphicGenerator.getMdpiScaleFactor(launcherOptions.density));
}
- Rectangle imageRect = Util.scaleRectangle(IMAGE_SIZE_MDPI, scaleFactor);
- Rectangle targetRect = Util.scaleRectangle(TARGET_RECT_MDPI, scaleFactor);
BufferedImage outImage = Util.newArgbBufferedImage(imageRect.width, imageRect.height);
Graphics2D g = (Graphics2D) outImage.getGraphics();
- if (mBackImage != null) {
- g.drawImage(mBackImage, 0, 0, null);
+ if (backImage != null) {
+ g.drawImage(backImage, 0, 0, null);
}
BufferedImage tempImage = Util.newArgbBufferedImage(imageRect.width, imageRect.height);
Graphics2D g2 = (Graphics2D) tempImage.getGraphics();
- if (mMaskImage != null) {
- g2.drawImage(mMaskImage, 0, 0, null);
+ if (maskImage != null) {
+ g2.drawImage(maskImage, 0, 0, null);
g2.setComposite(AlphaComposite.SrcAtop);
g2.setPaint(new Color(launcherOptions.backgroundColor));
g2.fillRect(0, 0, imageRect.width, imageRect.height);
}
+ BufferedImage tempImage2 = Util.newArgbBufferedImage(imageRect.width, imageRect.height);
+ Graphics2D g3 = (Graphics2D) tempImage2.getGraphics();
+ if (maskInnerImage != null) {
+ g3.drawImage(maskInnerImage, 0, 0, null);
+ g3.setComposite(AlphaComposite.SrcAtop);
+ g3.setPaint(new Color(launcherOptions.backgroundColor));
+ g3.fillRect(0, 0, imageRect.width, imageRect.height);
+ }
+
if (launcherOptions.crop) {
- Util.drawCenterCrop(g2, launcherOptions.sourceImage, targetRect);
+ Util.drawCenterCrop(g3, launcherOptions.sourceImage, targetRect);
} else {
- Util.drawCenterInside(g2, launcherOptions.sourceImage, targetRect);
+ Util.drawCenterInside(g3, launcherOptions.sourceImage, targetRect);
}
+ g2.drawImage(tempImage2, 0, 0, null);
g.drawImage(tempImage, 0, 0, null);
- if (mForeImage != null) {
- g.drawImage(mForeImage, 0, 0, null);
+ if (foreImage != null) {
+ g.drawImage(foreImage, 0, 0, null);
}
g.dispose();
@@ -104,6 +151,7 @@ public class LauncherIconGenerator extends GraphicGenerator {
if (generateWebImage) {
launcherOptions.isWebGraphic = true;
+ launcherOptions.density = null;
BufferedImage image = generate(context, options);
if (image != null) {
Map<String, BufferedImage> imageMap = new HashMap<String, BufferedImage>();
diff --git a/assetstudio/src/com/android/assetstudiolib/NotificationIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/NotificationIconGenerator.java
index b4aa6a6..b84af1b 100644
--- a/assetstudio/src/com/android/assetstudiolib/NotificationIconGenerator.java
+++ b/assetstudio/src/com/android/assetstudiolib/NotificationIconGenerator.java
@@ -63,12 +63,11 @@ public class NotificationIconGenerator extends GraphicGenerator {
Graphics2D g2 = (Graphics2D) tempImage.getGraphics();
if (notificationOptions.version == Version.OLDER) {
- BufferedImage mBackImage = context.loadImageResource(
+ BufferedImage backImage = context.loadImageResource(
"/images/notification_stencil/"
- + notificationOptions.shape.id + '/' +
- notificationOptions.density.getResourceValue()
+ + notificationOptions.density.getResourceValue()
+ ".png");
- g.drawImage(mBackImage, 0, 0, null);
+ g.drawImage(backImage, 0, 0, null);
BufferedImage top = options.sourceImage;
BufferedImage filled = Util.filledImage(top, Color.WHITE);
Util.drawCenterInside(g, filled, targetRect);
@@ -138,11 +137,6 @@ public class NotificationIconGenerator extends GraphicGenerator {
*/
public static class NotificationOptions extends GraphicGenerator.Options {
/**
- * The shape to use for graphics behind the icon (for {@link Version#OLDER} only)
- */
- public Shape shape = Shape.SQUARE;
-
- /**
* The version of the icon to generate - different styles are used for different
* versions of Android
*/