diff options
author | Tor Norbye <tnorbye@google.com> | 2011-08-25 13:13:34 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-09-01 13:56:48 -0700 |
commit | 59bddc5b09c091cfae54577ec36b16925b362b55 (patch) | |
tree | 6f23ab6c3e44ce59decd00667ab956bb306a9d0c /assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java | |
parent | b3ab7ef8a24a64bcd6f347e8e03bc647c12eb24b (diff) | |
download | sdk-59bddc5b09c091cfae54577ec36b16925b362b55.zip sdk-59bddc5b09c091cfae54577ec36b16925b362b55.tar.gz sdk-59bddc5b09c091cfae54577ec36b16925b362b55.tar.bz2 |
Add support for remaining asset types in Asset Studio Wizard
This changeset ports the remaining graphic generators from the HTML5
version (notifications, tabs, action bar), and hooks up wizard support
for them.
It also adds unit tests for the generators which generates images and
compares them to known good versions. I ran these tests comparing them
to the output from the HTML5 version of Asset Studio and all but 3 of
the images varied less than 5% (and I verified the remaining manually
and they're all fine and the difference is due to the images being
aligned slightly differently.)
The icon wizard is now also hooked up to the "New" button in the
Resource Chooser for drawable resources, and this changeset also fixes
a few related issues ("New" didn't work for file-based resources, and
newly created resources weren't showing up in the selection list.)
Change-Id: I48c49f1d5de452aa5b78e491d9b07e7156397fa9
Diffstat (limited to 'assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java')
-rw-r--r-- | assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java | 100 |
1 files changed, 48 insertions, 52 deletions
diff --git a/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java index 07b7a6b..8fdbddf 100644 --- a/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java +++ b/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java @@ -16,7 +16,9 @@ package com.android.assetstudiolib; -import com.android.resources.Density; +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.GradientPaint; @@ -28,65 +30,59 @@ import java.awt.image.BufferedImage; * A {@link GraphicGenerator} that generates Android "menu" icons. */ public class MenuIconGenerator extends GraphicGenerator { - private static final Rectangle BASE_IMAGE_RECT = new Rectangle(0, 0, 48, 48); - private static final Rectangle BASE_TARGET_RECT = new Rectangle(8, 8, 32, 32); - - private Options mOptions; - - public MenuIconGenerator(GraphicGeneratorContext context, Options options) { - mOptions = options; + /** Creates a menu icon generator */ + public MenuIconGenerator() { } - public BufferedImage generate() { - final float scaleFactor = GraphicGenerator.getScaleFactor(mOptions.density); - Rectangle imageRect = Util.scaleRectangle(BASE_IMAGE_RECT, scaleFactor); - Rectangle targetRect = Util.scaleRectangle(BASE_TARGET_RECT, scaleFactor); + @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 imageRect = Util.scaleRectangle(imageSizeHdpi, scaleFactor); + Rectangle targetRect = Util.scaleRectangle(targetRectHdpi, scaleFactor); BufferedImage outImage = Util.newArgbBufferedImage(imageRect.width, imageRect.height); Graphics2D g = (Graphics2D) outImage.getGraphics(); - { - BufferedImage tempImage = Util.newArgbBufferedImage( - imageRect.width, imageRect.height); - Graphics2D g2 = (Graphics2D) tempImage.getGraphics(); - Util.drawCenterInside(g2, mOptions.sourceImage, targetRect); + BufferedImage tempImage = Util.newArgbBufferedImage( + imageRect.width, imageRect.height); + Graphics2D g2 = (Graphics2D) tempImage.getGraphics(); + Util.drawCenterInside(g2, options.sourceImage, targetRect); - Util.drawEffects(g, tempImage, 0, 0, new Util.Effect[]{ - new Util.FillEffect( - new GradientPaint( - 0, 0, - new Color(0xa3a3a3), - 0, imageRect.height, - new Color(0x787878))), - new Util.ShadowEffect( - 0, - 3 * scaleFactor, - 3 * scaleFactor, - Color.black, - 0.2, - true), - new Util.ShadowEffect( - 0, - 1, - 0, - Color.black, - 0.35, - true), - new Util.ShadowEffect( - 0, - -1, - 0, - Color.white, - 0.35, - true), - }); - } + Util.drawEffects(g, tempImage, 0, 0, new Effect[] { + new FillEffect( + new GradientPaint( + 0, 0, + new Color(0xa3a3a3), + 0, imageRect.height, + new Color(0x787878))), + new ShadowEffect( + 0, + 3 * scaleFactor, + 3 * scaleFactor, + Color.BLACK, + 0.2, + true), + new ShadowEffect( + 0, + 1, + 0, + Color.BLACK, + 0.35, + true), + new ShadowEffect( + 0, + -1, + 0, + Color.WHITE, + 0.35, + true), + }); - return outImage; - } + g.dispose(); + g2.dispose(); - public static class Options { - public BufferedImage sourceImage; - public Density density = Density.XHIGH; + return outImage; } } |