1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.assetstudiolib; 17 18 import com.android.assetstudiolib.Util.Effect; 19 import com.android.assetstudiolib.Util.FillEffect; 20 21 import java.awt.Color; 22 import java.awt.Graphics2D; 23 import java.awt.Rectangle; 24 import java.awt.image.BufferedImage; 25 26 /** 27 * Generate icons for the action bar 28 */ 29 public class ActionBarIconGenerator extends GraphicGenerator { 30 31 /** Creates a new {@link ActionBarIconGenerator} */ 32 public ActionBarIconGenerator() { 33 } 34 35 @Override 36 public BufferedImage generate(GraphicGeneratorContext context, Options options) { 37 Rectangle iconSizeMdpi = new Rectangle(0, 0, 32, 32); 38 Rectangle targetRectMdpi = new Rectangle(4, 4, 24, 24); 39 final float scaleFactor = GraphicGenerator.getMdpiScaleFactor(options.density); 40 Rectangle imageRect = Util.scaleRectangle(iconSizeMdpi, scaleFactor); 41 Rectangle targetRect = Util.scaleRectangle(targetRectMdpi, scaleFactor); 42 BufferedImage outImage = Util.newArgbBufferedImage(imageRect.width, imageRect.height); 43 Graphics2D g = (Graphics2D) outImage.getGraphics(); 44 45 BufferedImage tempImage = Util.newArgbBufferedImage( 46 imageRect.width, imageRect.height); 47 Graphics2D g2 = (Graphics2D) tempImage.getGraphics(); 48 Util.drawCenterInside(g2, options.sourceImage, targetRect); 49 50 ActionBarOptions actionBarOptions = (ActionBarOptions) options; 51 if (actionBarOptions.theme == Theme.HOLO_LIGHT) { 52 Util.drawEffects(g, tempImage, 0, 0, new Effect[] { 53 new FillEffect(new Color(0x333333), 0.6), 54 }); 55 } else { 56 assert actionBarOptions.theme == Theme.HOLO_DARK; 57 Util.drawEffects(g, tempImage, 0, 0, new Effect[] { 58 new FillEffect(new Color(0xFFFFFF), 0.8) 59 }); 60 } 61 62 g.dispose(); 63 g2.dispose(); 64 65 return outImage; 66 } 67 68 /** Options specific to generating action bar icons */ 69 public static class ActionBarOptions extends GraphicGenerator.Options { 70 /** The theme to generate icons for */ 71 public Theme theme = Theme.HOLO_LIGHT; 72 } 73 74 /** The themes to generate action bar icons for */ 75 public enum Theme { 76 /** Theme.Holo - a dark (and default) version of the Honeycomb theme */ 77 HOLO_DARK, 78 79 /** Theme.HoloLight - a light version of the Honeycomb theme */ 80 HOLO_LIGHT; 81 } 82 } 83