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/TabIconGenerator.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/TabIconGenerator.java')
-rw-r--r-- | assetstudio/src/com/android/assetstudiolib/TabIconGenerator.java | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/assetstudio/src/com/android/assetstudiolib/TabIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/TabIconGenerator.java new file mode 100644 index 0000000..506aebd --- /dev/null +++ b/assetstudio/src/com/android/assetstudiolib/TabIconGenerator.java @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.eclipse.org/org/documents/epl-v10.php + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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.GradientPaint; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; +import java.util.Map; + + +/** + * Generate icons for tabs + */ +public class TabIconGenerator extends GraphicGenerator { + /** Creates a new {@link TabIconGenerator} */ + public TabIconGenerator() { + } + + @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); + 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, options.sourceImage, targetRect); + + TabOptions tabOptions = (TabOptions) options; + if (tabOptions.selected) { + if (tabOptions.oldStyle) { + 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), + }); + } else { + Util.drawEffects(g, tempImage, 0, 0, new Effect[] { + new FillEffect(Color.WHITE), + new ShadowEffect( + 0, + 0, + 5 * scaleFactor, + Color.BLACK, + 0.25, + false), + }); + } + } else { + // Unselected + if (tabOptions.oldStyle) { + Util.drawEffects(g, tempImage, 0, 0, new Effect[] { + new FillEffect( + new GradientPaint( + 0, 0.25f * imageRect.height, + new Color(0xf9f9f9), + 0, imageRect.height, + new Color(0xdfdfdf))), + new ShadowEffect( + 0, + 3 * scaleFactor, + 3 * scaleFactor, + Color.BLACK, + 0.1, + true), + new ShadowEffect( + 0, + 1, + 0, + Color.BLACK, + 0.35, + true), + new ShadowEffect( + 0, + -1, + 0, + Color.WHITE, + 0.35, + true), + }); + } else { + Util.drawEffects(g, tempImage, 0, 0, new Effect[] { + new FillEffect(new Color(0x808080)), + }); + } + } + + g.dispose(); + g2.dispose(); + + return outImage; + } + + @Override + public void generate(String category, Map<String, Map<String, BufferedImage>> categoryMap, + GraphicGeneratorContext context, Options options, String name) { + TabOptions tabOptions = (TabOptions) options; + // Generate all permutations of tabOptions.selected and tabOptions.oldStyle + tabOptions.selected = true; + tabOptions.oldStyle = false; + super.generate("Selected (v5+)", categoryMap, context, options, name); + tabOptions.oldStyle = true; + super.generate("Selected", categoryMap, context, options, name); + tabOptions.selected = false; + tabOptions.oldStyle = false; + super.generate("Unselected (v5+)", categoryMap, context, options, name); + tabOptions.oldStyle = true; + super.generate("Unselected", categoryMap, context, options, name); + } + + @Override + protected String getIconFolder(Options options) { + String folder = super.getIconFolder(options); + + TabOptions tabOptions = (TabOptions) options; + if (tabOptions.oldStyle) { + return folder; + } else { + return folder + "-v5"; //$NON-NLS-1$ + } + } + + @Override + protected String getIconName(Options options, String name) { + TabOptions tabOptions = (TabOptions) options; + if (tabOptions.selected) { + return name + "_selected.png"; //$NON-NLS-1$ + } else { + return name + "_unselected.png"; //$NON-NLS-1$ + } + } + + /** Options specific to generating tab icons */ + public static class TabOptions extends GraphicGenerator.Options { + /** Generate icon in the style used prior to v5 */ + public boolean oldStyle; + /** Generate "selected" icon if true, and "unselected" icon if false */ + public boolean selected = true; + } +} |