summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tools/image_generator/Android.bp6
-rw-r--r--tools/image_generator/ImageGenerator.java78
-rw-r--r--tools/image_generator/README.md3
3 files changed, 72 insertions, 15 deletions
diff --git a/tools/image_generator/Android.bp b/tools/image_generator/Android.bp
index 3f718fec5..ce6e277bc 100644
--- a/tools/image_generator/Android.bp
+++ b/tools/image_generator/Android.bp
@@ -17,7 +17,11 @@ java_library_host {
manifest: "ImageGenerator.mf",
+ static_libs: [
+ "commons-cli-1.2",
+ ],
+
srcs: [
"ImageGenerator.java",
],
-} \ No newline at end of file
+}
diff --git a/tools/image_generator/ImageGenerator.java b/tools/image_generator/ImageGenerator.java
index f2262166a..b9103379e 100644
--- a/tools/image_generator/ImageGenerator.java
+++ b/tools/image_generator/ImageGenerator.java
@@ -38,6 +38,13 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -367,28 +374,73 @@ public class ImageGenerator {
ImageIO.write(mBufferedImage, "png", new File(outputPath));
}
- public static void printUsage() {
- System.out.println("Usage: java -jar path_to_jar imageWidth textName fontDirectory"
- + " resourceDirectory outputFilename");
+ public static void printUsage(Options options) {
+ new HelpFormatter().printHelp("java -jar path_to_jar [required_options]", options);
+
+ }
+
+ public static Options createOptions() {
+ Options options = new Options();
+ options.addOption(OptionBuilder
+ .withLongOpt("image_width")
+ .withDescription("The initial width of the image in pixels.")
+ .hasArgs(1)
+ .isRequired()
+ .create());
+
+ options.addOption(OptionBuilder
+ .withLongOpt("text_name")
+ .withDescription("The description of the text string, e.g. recovery_erasing")
+ .hasArgs(1)
+ .isRequired()
+ .create());
+
+ options.addOption(OptionBuilder
+ .withLongOpt("font_dir")
+ .withDescription("The directory that contains all the support font format files, e.g."
+ + " $OUT/system/fonts/")
+ .hasArgs(1)
+ .isRequired()
+ .create());
+
+ options.addOption(OptionBuilder
+ .withLongOpt("resource_dir")
+ .withDescription("The resource directory that contains all the translated strings in xml"
+ + " format, e.g. bootable/recovery/tools/recovery_l10n/res/")
+ .hasArgs(1)
+ .isRequired()
+ .create());
+
+ options.addOption(OptionBuilder
+ .withLongOpt("output_file")
+ .withDescription("Path to the generated image")
+ .hasArgs(1)
+ .isRequired()
+ .create());
+
+ return options;
}
public static void main(String[] args) throws NumberFormatException, IOException,
FontFormatException, LocalizedStringNotFoundException {
- if (args.length != 5) {
- printUsage();
- System.err.println("We expect 5 arguments, get " + args.length);
- System.exit(1);
+ Options options = createOptions();
+ CommandLine cmd;
+ try {
+ cmd = new GnuParser().parse(options, args);
+ } catch (ParseException e) {
+ System.err.println(e.getMessage());
+ printUsage(options);
+ return;
}
- // TODO(xunchang) switch to commandline parser
- int imageWidth = Integer.parseUnsignedInt(args[0]);
+ int imageWidth = Integer.parseUnsignedInt(cmd.getOptionValue("image_width"));
- ImageGenerator imageGenerator =
- new ImageGenerator(imageWidth, args[1], DEFAULT_FONT_SIZE, args[2]);
+ ImageGenerator imageGenerator = new ImageGenerator(imageWidth, cmd.getOptionValue("text_name"),
+ DEFAULT_FONT_SIZE, cmd.getOptionValue("font_dir"));
Map<Locale, String> localizedStringMap =
- imageGenerator.readLocalizedStringFromXmls(args[3]);
- imageGenerator.generateImage(localizedStringMap, args[4]);
+ imageGenerator.readLocalizedStringFromXmls(cmd.getOptionValue("resource_dir"));
+ imageGenerator.generateImage(localizedStringMap, cmd.getOptionValue("output_file"));
}
}
diff --git a/tools/image_generator/README.md b/tools/image_generator/README.md
index 22e32f6ce..5d70354e4 100644
--- a/tools/image_generator/README.md
+++ b/tools/image_generator/README.md
@@ -6,7 +6,8 @@ under recovery mode. And thus we don't need to do the manual work by running
emulators with different dpi.
# Usage:
- `java -jar path_to_jar imageWidth textName fontDirectory resourceDirectory outputFilename`
+ `java -jar path_to_jar --image_width imageWidth --text_name textName --font_dir fontDirectory
+ --resource_dir resourceDirectory --output_file outputFilename`
# Description of the parameters:
1. `imageWidth`: The number of pixels per line; and the text strings will be