diff options
Diffstat (limited to 'assetstudio/src')
7 files changed, 58 insertions, 84 deletions
diff --git a/assetstudio/src/com/android/assetstudiolib/ActionBarIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/ActionBarIconGenerator.java index b54aad5..9ed88e9 100644 --- a/assetstudio/src/com/android/assetstudiolib/ActionBarIconGenerator.java +++ b/assetstudio/src/com/android/assetstudiolib/ActionBarIconGenerator.java @@ -17,7 +17,6 @@ package com.android.assetstudiolib; import com.android.assetstudiolib.Util.Effect; import com.android.assetstudiolib.Util.FillEffect; -import com.android.assetstudiolib.Util.ShadowEffect; import java.awt.Color; import java.awt.Graphics2D; @@ -35,11 +34,11 @@ public class ActionBarIconGenerator extends GraphicGenerator { @Override public BufferedImage generate(GraphicGeneratorContext context, Options options) { - Rectangle iconSizeHdpi = new Rectangle(0, 0, 48, 48); - Rectangle targetRectHdpi = new Rectangle(6, 6, 36, 36); - final float scaleFactor = GraphicGenerator.getHdpiScaleFactor(options.density); - Rectangle imageRect = Util.scaleRectangle(iconSizeHdpi, scaleFactor); - Rectangle targetRect = Util.scaleRectangle(targetRectHdpi, scaleFactor); + Rectangle iconSizeMdpi = new Rectangle(0, 0, 32, 32); + Rectangle targetRectMdpi = new Rectangle(4, 4, 24, 24); + final float scaleFactor = GraphicGenerator.getMdpiScaleFactor(options.density); + Rectangle imageRect = Util.scaleRectangle(iconSizeMdpi, scaleFactor); + Rectangle targetRect = Util.scaleRectangle(targetRectMdpi, scaleFactor); BufferedImage outImage = Util.newArgbBufferedImage(imageRect.width, imageRect.height); Graphics2D g = (Graphics2D) outImage.getGraphics(); @@ -51,21 +50,12 @@ public class ActionBarIconGenerator extends GraphicGenerator { ActionBarOptions actionBarOptions = (ActionBarOptions) options; if (actionBarOptions.theme == Theme.HOLO_LIGHT) { Util.drawEffects(g, tempImage, 0, 0, new Effect[] { - new FillEffect(new Color(0x898989)), + new FillEffect(new Color(0x333333), 0.6), }); } else { assert actionBarOptions.theme == Theme.HOLO_DARK; Util.drawEffects(g, tempImage, 0, 0, new Effect[] { - // TODO: should be white @ 60% opacity, but - // the fill then blends with the drop shadow - new FillEffect(new Color(0x909090)), - new ShadowEffect( - 0, - 0, - 3 * scaleFactor, - Color.BLACK, - 0.85, - false), + new FillEffect(new Color(0xFFFFFF), 0.8) }); } diff --git a/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java b/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java index 0269c74..fa81392 100644 --- a/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java +++ b/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java @@ -183,29 +183,14 @@ public abstract class GraphicGenerator { } /** - * Returns the scale factor to apply for a given HDPI density to compute the + * Returns the scale factor to apply for a given MDPI density to compute the * absolute pixel count to use to draw an icon of the given target density * * @param density the density - * @return a factor to multiple hdpi distances with to compute the target density + * @return a factor to multiple mdpi distances with to compute the target density */ - public static float getHdpiScaleFactor(Density density) { - // We used to do this: - //return density.getDpiValue() / (float) Density.DEFAULT_DENSITY; - // However, the HTML5 version of the AssetStudio would end up with different - // sizes for the assets, because it uses this table: - // studio.util.getMultBaseHdpi = function(density) { - // switch (density) { - // case 'xhdpi': return 1.333333; - // case 'hdpi': return 1.0; - // case 'mdpi': return 0.666667; - // case 'ldpi': return 0.5; - // } - // return 1.0; - // }; - // This corresponds to dividing the dpi value not by Density.MEDIUM but - // Density.HIGH: - return density.getDpiValue() / (float) Density.HIGH.getDpiValue(); + public static float getMdpiScaleFactor(Density density) { + return density.getDpiValue() / (float) Density.MEDIUM.getDpiValue(); } /** diff --git a/assetstudio/src/com/android/assetstudiolib/LauncherIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/LauncherIconGenerator.java index 2f76b2d..4e0534d 100644 --- a/assetstudio/src/com/android/assetstudiolib/LauncherIconGenerator.java +++ b/assetstudio/src/com/android/assetstudiolib/LauncherIconGenerator.java @@ -28,20 +28,8 @@ import java.util.Map; * A {@link GraphicGenerator} that generates Android "launcher" icons. */ public class LauncherIconGenerator extends GraphicGenerator { - private static final Rectangle IMAGE_SIZE_HDPI = new Rectangle(0, 0, 72, 72); - /* TODO: Adapt from html version: - 'square-web-targetRect': { x: 21, y: 21, w: 470, h: 470 }, - 'circle-web-targetRect': { x: 21, y: 21, w: 470, h: 470 }, - 'square-xhdpi-targetRect': { x: 4, y: 4, w: 88, h: 88 }, - 'circle-xhdpi-targetRect': { x: 4, y: 4, w: 88, h: 88 }, - 'square-hdpi-targetRect': { x: 3, y: 3, w: 66, h: 66 }, - 'circle-hdpi-targetRect': { x: 3, y: 3, w: 66, h: 66 }, <==== - 'square-mdpi-targetRect': { x: 2, y: 2, w: 44, h: 44 }, - 'circle-mdpi-targetRect': { x: 2, y: 2, w: 44, h: 44 }, - 'square-ldpi-targetRect': { x: 1, y: 1, w: 34, h: 34 }, - 'circle-ldpi-targetRect': { x: 1, y: 1, w: 34, h: 34 } - */ - private static final Rectangle TARGET_RECT_HDPI = new Rectangle(3, 3, 66, 66); + 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); @Override public BufferedImage generate(GraphicGeneratorContext context, Options options) { @@ -61,13 +49,13 @@ public class LauncherIconGenerator extends GraphicGenerator { BufferedImage mMaskImage = context.loadImageResource("/images/launcher_stencil/" + shape + "/" + density + "/mask.png"); - float scaleFactor = GraphicGenerator.getHdpiScaleFactor(launcherOptions.density); + float scaleFactor = GraphicGenerator.getMdpiScaleFactor(launcherOptions.density); if (launcherOptions.isWebGraphic) { // Target size for the web graphic is 512 - scaleFactor = 512 / (float) IMAGE_SIZE_HDPI.height; + scaleFactor = 512 / (float) IMAGE_SIZE_MDPI.height; } - Rectangle imageRect = Util.scaleRectangle(IMAGE_SIZE_HDPI, scaleFactor); - Rectangle targetRect = Util.scaleRectangle(TARGET_RECT_HDPI, scaleFactor); + 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(); diff --git a/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java index 8fdbddf..33b9c34 100644 --- a/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java +++ b/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java @@ -36,9 +36,9 @@ public class MenuIconGenerator extends GraphicGenerator { @Override public BufferedImage generate(GraphicGeneratorContext context, Options options) { - Rectangle imageSizeHdpi = new Rectangle(0, 0, 72, 72); - Rectangle targetRectHdpi = new Rectangle(12, 12, 48, 48); - float scaleFactor = GraphicGenerator.getHdpiScaleFactor(options.density); + Rectangle imageSizeHdpi = new Rectangle(0, 0, 48, 48); + Rectangle targetRectHdpi = new Rectangle(8, 8, 32, 32); + float scaleFactor = GraphicGenerator.getMdpiScaleFactor(options.density); Rectangle imageRect = Util.scaleRectangle(imageSizeHdpi, scaleFactor); Rectangle targetRect = Util.scaleRectangle(targetRectHdpi, scaleFactor); @@ -59,8 +59,8 @@ public class MenuIconGenerator extends GraphicGenerator { new Color(0x787878))), new ShadowEffect( 0, - 3 * scaleFactor, - 3 * scaleFactor, + 2 * scaleFactor, + 2 * scaleFactor, Color.BLACK, 0.2, true), diff --git a/assetstudio/src/com/android/assetstudiolib/NotificationIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/NotificationIconGenerator.java index 4bda2bf..b4aa6a6 100644 --- a/assetstudio/src/com/android/assetstudiolib/NotificationIconGenerator.java +++ b/assetstudio/src/com/android/assetstudiolib/NotificationIconGenerator.java @@ -36,24 +36,24 @@ public class NotificationIconGenerator extends GraphicGenerator { @Override public BufferedImage generate(GraphicGeneratorContext context, Options options) { - Rectangle iconSizeHdpi; - Rectangle targetRectHdpi; + Rectangle iconSizeMdpi; + Rectangle targetRectMdpi; NotificationOptions notificationOptions = (NotificationOptions) options; if (notificationOptions.version == Version.OLDER) { - iconSizeHdpi = new Rectangle(0, 0, 38, 38); - targetRectHdpi = new Rectangle(6, 6, 26, 26); + iconSizeMdpi = new Rectangle(0, 0, 25, 25); + targetRectMdpi = new Rectangle(4, 4, 17, 17); } else if (notificationOptions.version == Version.V11) { - iconSizeHdpi = new Rectangle(0, 0, 48, 48); - targetRectHdpi = new Rectangle(6, 6, 36, 36); + iconSizeMdpi = new Rectangle(0, 0, 24, 24); + targetRectMdpi = new Rectangle(1, 1, 22, 22); } else { assert notificationOptions.version == Version.V9; - iconSizeHdpi = new Rectangle(0, 0, 24, 38); - targetRectHdpi = new Rectangle(0, 7, 24, 24); + iconSizeMdpi = new Rectangle(0, 0, 16, 25); + targetRectMdpi = new Rectangle(0, 5, 16, 16); } - final float scaleFactor = GraphicGenerator.getHdpiScaleFactor(options.density); - Rectangle imageRect = Util.scaleRectangle(iconSizeHdpi, scaleFactor); - Rectangle targetRect = Util.scaleRectangle(targetRectHdpi, scaleFactor); + final float scaleFactor = GraphicGenerator.getMdpiScaleFactor(options.density); + Rectangle imageRect = Util.scaleRectangle(iconSizeMdpi, scaleFactor); + Rectangle targetRect = Util.scaleRectangle(targetRectMdpi, scaleFactor); BufferedImage outImage = Util.newArgbBufferedImage(imageRect.width, imageRect.height); Graphics2D g = (Graphics2D) outImage.getGraphics(); diff --git a/assetstudio/src/com/android/assetstudiolib/TabIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/TabIconGenerator.java index 5d8b500..3d2ac30 100644 --- a/assetstudio/src/com/android/assetstudiolib/TabIconGenerator.java +++ b/assetstudio/src/com/android/assetstudiolib/TabIconGenerator.java @@ -37,11 +37,11 @@ public class TabIconGenerator extends GraphicGenerator { @Override public BufferedImage generate(GraphicGeneratorContext context, Options options) { - Rectangle iconSizeHdpi = new Rectangle(0, 0, 48, 48); - Rectangle targetRectHdpi = new Rectangle(3, 3, 42, 42); - final float scaleFactor = GraphicGenerator.getHdpiScaleFactor(options.density); - Rectangle imageRect = Util.scaleRectangle(iconSizeHdpi, scaleFactor); - Rectangle targetRect = Util.scaleRectangle(targetRectHdpi, scaleFactor); + Rectangle iconSizeMdpi = new Rectangle(0, 0, 32, 32); + Rectangle targetRectMdpi = new Rectangle(2, 2, 28, 28); + final float scaleFactor = GraphicGenerator.getMdpiScaleFactor(options.density); + Rectangle imageRect = Util.scaleRectangle(iconSizeMdpi, scaleFactor); + Rectangle targetRect = Util.scaleRectangle(targetRectMdpi, scaleFactor); BufferedImage outImage = Util.newArgbBufferedImage(imageRect.width, imageRect.height); Graphics2D g = (Graphics2D) outImage.getGraphics(); @@ -62,8 +62,8 @@ public class TabIconGenerator extends GraphicGenerator { new Color(0x787878))), new ShadowEffect( 0, - 3 * scaleFactor, - 3 * scaleFactor, + 2 * scaleFactor, + 2 * scaleFactor, Color.BLACK, 0.2, true), @@ -88,7 +88,7 @@ public class TabIconGenerator extends GraphicGenerator { new ShadowEffect( 0, 0, - 5 * scaleFactor, + 3 * scaleFactor, Color.BLACK, 0.25, false), @@ -106,8 +106,8 @@ public class TabIconGenerator extends GraphicGenerator { new Color(0xdfdfdf))), new ShadowEffect( 0, - 3 * scaleFactor, - 3 * scaleFactor, + 2 * scaleFactor, + 2 * scaleFactor, Color.BLACK, 0.1, true), diff --git a/assetstudio/src/com/android/assetstudiolib/Util.java b/assetstudio/src/com/android/assetstudiolib/Util.java index 927ca30..ee2a5f7 100644 --- a/assetstudio/src/com/android/assetstudiolib/Util.java +++ b/assetstudio/src/com/android/assetstudiolib/Util.java @@ -47,10 +47,10 @@ public class Util { */ public static Rectangle scaleRectangle(Rectangle rect, float scaleFactor) { return new Rectangle( - (int) (rect.x * scaleFactor), - (int) (rect.y * scaleFactor), - (int) (rect.width * scaleFactor), - (int) (rect.height * scaleFactor)); + (int) Math.round(rect.x * scaleFactor), + (int) Math.round(rect.y * scaleFactor), + (int) Math.round(rect.width * scaleFactor), + (int) Math.round(rect.height * scaleFactor)); } /** @@ -279,6 +279,7 @@ public class Util { final Rectangle imageRect = new Rectangle(0, 0, source.getWidth(), source.getHeight()); BufferedImage out = newArgbBufferedImage(imageRect.width, imageRect.height); Graphics2D g2 = (Graphics2D) out.getGraphics(); + double fillOpacity = 1.0; g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.drawImage(source, 0, 0, null); @@ -288,6 +289,7 @@ public class Util { for (FillEffect effect : fillEffects) { g2.setPaint(effect.paint); g2.fillRect(0, 0, imageRect.width, imageRect.height); + fillOpacity = Math.max(0, Math.min(1, effect.opacity)); } // Inner shadows @@ -309,7 +311,9 @@ public class Util { 0, 0, null); } + g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) fillOpacity)); g.drawImage(out, x, y, null); + g.setComposite(oldComposite); } /** @@ -432,9 +436,16 @@ public class Util { */ public static class FillEffect extends Effect { public Paint paint; + public double opacity; + + public FillEffect(Paint paint, double opacity) { + this.paint = paint; + this.opacity = opacity; + } public FillEffect(Paint paint) { this.paint = paint; + this.opacity = 1.0; } } } |