[Android Themes] jsmith8858:
8/14/2011 Update: See this post for details. Now you can make circular progress bars, dotted progress bars, the text is anti-aliased and smoothed, and more!

Attached is a very simple, small Windows .NET application that will generate a 101 Battery Icon images (for percentages 0-100) with a growing battery indicator bar and also the battery percentage text using the font, style, format and position that you desire.

Using an XML configuration file and some image templates, you can quickly generate a wide range of icons for your battery icon theme.

To start, just unzip the files into a folder and open up the "Config.XML" file in a text editor. Here's the one I've included to use as a guide/template/example:

<?xml version="1.0" encoding="utf-8" ?>
<batteryIcon>
<output folder="output" filename="stat_sys_battery_{0:0}.png" />
<batteryLevels>
<level max="24">
<background filename="Files\template.png"/>
<bar startX="6" startY="21" endX="31" endY="21" filename="Files\bar-red.png"/>
<pctStyle colorRGB="FFFFFF" fontFamily="Arial" fontSize="11" italic="false" bold="true" formatString="{0:0}%"/>
<pctPosition centerX="true" centerY="false" offsetX="1" offsetY="3"/>
</level>
<level max="49">
<bar filename="Files\bar-orange.png"/>
</level>
<level max="74">
<bar filename="Files\bar-green.png"/>
</level>
<level max="100">
<bar filename="Files\bar-blue.png"/>
</level>
</batteryLevels>
</batteryIcon>

In addition, in the "Files" folder, I have an example image called template.png, which is the example icon's background image, and some bar-xxx.png images, which are different colored 1-pixel-wide images that are used in the example to draw the horizontal battery meter over the background. Attached to this post is a picture of the output from this configuration and image files so you can get a basic idea of what it can do.

Using this application is (hopefully) quite simple: Create your template images, edit the config file to specify your parameters, then run the executable. 101 images, for battery levels 0-100 percent, will be created as specified. Tweak and run again as needed until you get it right. The "level" elements allow you to change any of the icon's characteristics (text color, size, position; background image; progress bar image) for different battery level intervals. Anything not changed from the previous level is carried over, so you only need to specify changes.

For most of you, editing the config.xml file is probably obvious from the example; you can probably just tweak it file and get what you want, but below are more details.

Documentation

The output element just indicates where the final images will be stored and how they will be named. The {0:0} part is a standard .NET format string and indicates where and how to put the battery percentage in the file name. (You probably won't need to change this; {0:0} will format numbers from 1-100, no leading zeroes, and we don't need to worry about commas or decimal places or anything).

After that, under the batteryLevels element, there are a series of level elements that define the icon options at each battery percentage interval. The end of the interval is defined using the "max" attribute, which is a number from 0-100 for the battery percentage.

The first level should include all layout and image and formatting options, but then after that, you just need to specify things that change from the previous interval. The level elements should go in order from lowest battery level to highest.

At each level, we can specify:

The background element which sets the base background image for the icon, on which the progress bar and pct text will be overlayed.

The bar element which determines how the progress bar is drawn over the background. startX/startY and endX/endY are the range of positions for which the progress bar image will be drawn. The image should be 1 pixel tall or wide, depending on if the bar is progressing vertically or horizontally. Omit this element completely if you do not wish to draw a progress bar -- i.e., for just the battery percentage text on top of one or more background images.

pctStyle lets you theme the battery percentage text a bit. formatString is a .NET format string, and is probably fine as is, except notice that it ends with a % symbol. Remove this if you don't want a % after the number. (i.e., it would be just "{0:0}")

pctPosition is used to indicate where on the background image the text is drawn. centerX/centerY are true/false if you want the text to be centered in that dimension, otherwise it is drawn at the top and/or left of the background. offsetX/offsetY let you move the text up/down or left/right pixels as needed from either the center or top/left position.

That's really it. Anything that doesn't change from the previous battery level will be carried over, so you just need to specify what has changed.

Tweak the XML file and re-run until you get the battery icons you are looking for! You can also create and drop different configuration XML files on the executable (or specify the file via the command line as the first argument) and it will run using that file as opposed to the default "config.xml" file in the application directory.

Additional Notes:

Specify an empty string ("") for the filename attribute of the bar element if you do not want a progress bar drawn.

Specify an empty string ("") for the fontFamily attribute of the pctStyle element if you do not want the percentage text drawn.

Remember that the background image can change at any interval as well, if you'd like to use a series of different backgrounds with percentage text overlayed and no progress bar, for example.

the start/end positions of the progress bar should be specified once and cover the entire range of the progress bar, from 0-100 %, and not change at different intervals (unless that is an effect that you want for some reason).

You can specify the filename for any valid configuration file as the single parameter for the executable to use that file instead of the default config.xml file if you like.