diff options
author | Tor Norbye <tnorbye@google.com> | 2011-07-15 21:16:56 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-07-27 16:46:57 -0700 |
commit | 7208e72d510e1bf5d3860f4a15d135e42d64eaa0 (patch) | |
tree | b190a7e85efd913d5aaff25f0ccaa37ffb28312e /assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java | |
parent | c766a5e884fbb9a3a4f02809961942173c7cce8b (diff) | |
download | sdk-7208e72d510e1bf5d3860f4a15d135e42d64eaa0.zip sdk-7208e72d510e1bf5d3860f4a15d135e42d64eaa0.tar.gz sdk-7208e72d510e1bf5d3860f4a15d135e42d64eaa0.tar.bz2 |
Asset Studio wizard
This is an initial integration of the Android Asset Studio into
Eclipse, as a New Asset wizard. It uses the Java port of the Android
Asset Studio to generate the assets:
https://code.google.com/a/google.com/p/android-asset-studio-java/
It only supports launcher icons, and some of the configurable
parameters (file, shape, crop).
To run it, put the AssetStudioLib.jar file into the the adt libs
directory.
There's a new "Asset Set" wizard in the New wizard, which will open up
a two page wizard; the first page lets you select the project (which
it attempts to pick up from context), as well as the type of asset to
create, and the asset output name.
In the second page there are the various widgets to tweak the code
generator, and a preview area on the right which updates as you tweak
the various controls.
The main remaining work is to support additional asset types as
they are added to the assetstudio generator library.
Change-Id: I2e556337f8e5c3bc09e84b35a342ba05110abebc
Diffstat (limited to 'assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java')
-rw-r--r-- | assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java b/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java new file mode 100644 index 0000000..07b7a6b --- /dev/null +++ b/assetstudio/src/com/android/assetstudiolib/MenuIconGenerator.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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.resources.Density; + +import java.awt.Color; +import java.awt.GradientPaint; +import java.awt.Graphics2D; +import java.awt.Rectangle; +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; + } + + 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); + + 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); + + 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), + }); + } + + return outImage; + } + + public static class Options { + public BufferedImage sourceImage; + public Density density = Density.XHIGH; + } +} |