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 */ 16package com.android.assetstudiolib; 17 18import com.android.assetstudiolib.Util.Effect; 19import com.android.assetstudiolib.Util.FillEffect; 20 21import java.awt.Color; 22import java.awt.Graphics2D; 23import java.awt.Rectangle; 24import java.awt.image.BufferedImage; 25 26/** 27 * Generate icons for the action bar 28 */ 29public 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 ActionBarOptions actionBarOptions = (ActionBarOptions) options; 38 Rectangle iconSizeMdpi = new Rectangle(0, 0, 32, 32); 39 Rectangle targetRectMdpi = actionBarOptions.sourceIsClipart 40 ? new Rectangle(0, 0, 32, 32) 41 : new Rectangle(4, 4, 24, 24); 42 final float scaleFactor = GraphicGenerator.getMdpiScaleFactor(options.density); 43 Rectangle imageRect = Util.scaleRectangle(iconSizeMdpi, scaleFactor); 44 Rectangle targetRect = Util.scaleRectangle(targetRectMdpi, scaleFactor); 45 BufferedImage outImage = Util.newArgbBufferedImage(imageRect.width, imageRect.height); 46 Graphics2D g = (Graphics2D) outImage.getGraphics(); 47 48 BufferedImage tempImage = Util.newArgbBufferedImage( 49 imageRect.width, imageRect.height); 50 Graphics2D g2 = (Graphics2D) tempImage.getGraphics(); 51 Util.drawCenterInside(g2, options.sourceImage, targetRect); 52 53 if (actionBarOptions.theme == Theme.HOLO_LIGHT) { 54 Util.drawEffects(g, tempImage, 0, 0, new Effect[] { 55 new FillEffect(new Color(0x333333), 0.6), 56 }); 57 } else { 58 assert actionBarOptions.theme == Theme.HOLO_DARK; 59 Util.drawEffects(g, tempImage, 0, 0, new Effect[] { 60 new FillEffect(new Color(0xFFFFFF), 0.8) 61 }); 62 } 63 64 g.dispose(); 65 g2.dispose(); 66 67 return outImage; 68 } 69 70 /** Options specific to generating action bar icons */ 71 public static class ActionBarOptions extends GraphicGenerator.Options { 72 /** The theme to generate icons for */ 73 public Theme theme = Theme.HOLO_LIGHT; 74 75 /** Whether or not the source image is a clipart source */ 76 public boolean sourceIsClipart = false; 77 } 78 79 /** The themes to generate action bar icons for */ 80 public enum Theme { 81 /** Theme.Holo - a dark (and default) version of the Honeycomb theme */ 82 HOLO_DARK, 83 84 /** Theme.HoloLight - a light version of the Honeycomb theme */ 85 HOLO_LIGHT; 86 } 87} 88