diff --git a/android/tool/src/processing/app/tools/android/AndroidTool.java b/android/tool/src/processing/app/tools/android/AndroidTool.java index 939805eb9..8b742ff57 100644 --- a/android/tool/src/processing/app/tools/android/AndroidTool.java +++ b/android/tool/src/processing/app/tools/android/AndroidTool.java @@ -204,7 +204,7 @@ public class AndroidTool implements Tool, DeviceListener { "Building and launching...", "Creating project..."); try { - if (build.createProject() == null) { + if (build.createProject(target) == null) { return; } try { @@ -264,7 +264,7 @@ public class AndroidTool implements Tool, DeviceListener { "Building and exporting...", "Creating project..."); try { - File tempFolder = build.createProject(); + File tempFolder = build.createProject("release"); if (tempFolder == null) { return; } diff --git a/android/tool/src/processing/app/tools/android/Build.java b/android/tool/src/processing/app/tools/android/Build.java index 8a8bc6dc2..3d937b4d8 100644 --- a/android/tool/src/processing/app/tools/android/Build.java +++ b/android/tool/src/processing/app/tools/android/Build.java @@ -101,7 +101,7 @@ class Build { } - public File createProject() { + public File createProject(String target) { final Sketch sketch = editor.getSketch(); try { @@ -142,7 +142,7 @@ class Build { // writeAndroidManifest(androidXML, sketch.getName(), className); manifest.setClassName(className); File tempManifest = new File(tempBuildFolder, "AndroidManifest.xml"); - manifest.save(tempManifest); + manifest.writeBuild(tempManifest, className, target.equals("debug")); writeBuildProps(new File(tempBuildFolder, "build.properties")); buildFile = new File(tempBuildFolder, "build.xml"); @@ -543,14 +543,74 @@ class Build { } - private void writeRes(final File resFolder, final String className) - throws RunnerException { - final File layoutFolder = mkdirs(resFolder, "layout"); - final File layoutFile = new File(layoutFolder, "main.xml"); + static final String ICON_72 = "icon-72.png"; + static final String ICON_48 = "icon-48.png"; + static final String ICON_36 = "icon-36.png"; + + private void writeRes(File resFolder, + String className) throws RunnerException { + File layoutFolder = mkdirs(resFolder, "layout"); + File layoutFile = new File(layoutFolder, "main.xml"); writeResLayoutMain(layoutFile); - final File valuesFolder = mkdirs(resFolder, "values"); - final File stringsFile = new File(valuesFolder, "strings.xml"); - writeResValuesStrings(stringsFile, className); + + // write the icon files + File sketchFolder = editor.getSketch().getFolder(); + File localIcon36 = new File(sketchFolder, ICON_36); + File localIcon48 = new File(sketchFolder, ICON_48); + File localIcon72 = new File(sketchFolder, ICON_72); + +// File drawableFolder = new File(resFolder, "drawable"); +// drawableFolder.mkdirs() + File buildIcon48 = new File(resFolder, "drawable/icon.png"); + File buildIcon36 = new File(resFolder, "drawable-ldpi/icon.png"); + File buildIcon72 = new File(resFolder, "drawable-hdpi/icon.png"); + + if (!localIcon36.exists() && + !localIcon48.exists() && + !localIcon72.exists()) { + // if no icons are in the sketch folder, then copy all the defaults + if (new File(resFolder, "drawable-ldpi").mkdirs()) { + PApplet.saveStream(buildIcon36, getClass().getResourceAsStream("data/icon-36.png")); + } else { + System.err.println("Could not create \"drawable-ldpi\" folder."); + } + if (new File(resFolder, "drawable").mkdirs()) { + PApplet.saveStream(buildIcon48, getClass().getResourceAsStream("data/icon-48.png")); + } else { + System.err.println("Could not create \"drawable\" folder."); + } + if (new File(resFolder, "drawable-hdpi").mkdirs()) { + PApplet.saveStream(buildIcon72, getClass().getResourceAsStream("data/icon-72.png")); + } else { + System.err.println("Could not create \"drawable-hdpi\" folder."); + } + } else { + // if at least one of the icons already exists, then use that across the board + try { + if (localIcon36.exists()) { + if (new File(resFolder, "drawable-ldpi").mkdirs()) { + Base.copyFile(localIcon36, buildIcon36); + } + } + if (localIcon48.exists()) { + if (new File(resFolder, "drawable").mkdirs()) { + Base.copyFile(localIcon48, buildIcon48); + } + } + if (localIcon72.exists()) { + if (new File(resFolder, "drawable-hdpi").mkdirs()) { + Base.copyFile(localIcon72, buildIcon72); + } + } + } catch (IOException e) { + System.err.println("Problem while copying icons."); + e.printStackTrace(); + } + } + +// final File valuesFolder = mkdirs(resFolder, "values"); +// final File stringsFile = new File(valuesFolder, "strings.xml"); +// writeResValuesStrings(stringsFile, className); } @@ -576,18 +636,20 @@ class Build { writer.close(); } - - /** This recommended to be a string resource so that it can be localized. */ - private static void writeResValuesStrings(final File file, - final String className) { - final PrintWriter writer = PApplet.createWriter(file); - writer.println(""); - writer.println(""); - writer.println(" " + className + ""); - writer.println(""); - writer.flush(); - writer.close(); - } + + // This recommended to be a string resource so that it can be localized. + // nah.. we're gonna be messing with it in the GUI anyway... + // people can edit themselves if they need to +// private static void writeResValuesStrings(final File file, +// final String className) { +// final PrintWriter writer = PApplet.createWriter(file); +// writer.println(""); +// writer.println(""); +// writer.println(" " + className + ""); +// writer.println(""); +// writer.flush(); +// writer.close(); +// } private void writeLibraries(final File libsFolder, final File assetsFolder) diff --git a/android/tool/src/processing/app/tools/android/Manifest.java b/android/tool/src/processing/app/tools/android/Manifest.java index 532390ff5..603c8dead 100644 --- a/android/tool/src/processing/app/tools/android/Manifest.java +++ b/android/tool/src/processing/app/tools/android/Manifest.java @@ -66,10 +66,12 @@ public class Manifest { return Build.basePackage + "." + sketch.getName().toLowerCase(); } - + + // called by other classes who want an actual package name + // internally, we'll figure this out ourselves whether it's filled or not public String getPackageName() { -// return packageName; - return xml.getString("package"); + String pkg = xml.getString("package"); + return pkg.length() == 0 ? defaultPackageName() : pkg; } @@ -128,14 +130,21 @@ public class Manifest { final PrintWriter writer = PApplet.createWriter(file); writer.println(""); writer.println(""); - writer.println(" "); - writer.println(" "); +// writer.println(" "); // insert sdk version +// writer.println(" "); - writer.println(" "); +// writer.println(" "); // pretty name + writer.println(" android:label=\"\">"); writer.println(" "); writer.println(" "); writer.println(" "); @@ -148,6 +157,38 @@ public class Manifest { } + /** + * Save a new version of the manifest info to the build location. + * Also fill in any missing attributes that aren't yet set properly. + */ + protected void writeBuild(File file, String className, boolean debug) { + // package name, or default + String p = xml.getString("package").trim(); + if (p.length() == 0) { + xml.setString("package", defaultPackageName()); + } + + // app name and label, or the class name + XMLElement app = xml.getChild("application"); + String label = app.getString("android:label"); + if (label.length() == 0) { + app.setString("android:label", className); + } + app.setString("android:debuggable", debug ? "true" : "false"); + + XMLElement activity = app.getChild("activity"); + activity.setString("android:name", "." + className); // this has to be right + label = activity.getString("android:label"); + if (label.length() == 0) { + activity.setString("android:label", className); + } + + PrintWriter writer = PApplet.createWriter(file); + xml.write(writer); + writer.close(); + } + + protected void load() { // Sketch sketch = editor.getSketch(); // File manifestFile = new File(sketch.getFolder(), MANIFEST_XML); @@ -192,23 +233,12 @@ public class Manifest { * Save to the sketch folder, so that it can be copied in later. */ protected void save() { - save(getManifestFile()); - } - - - /** - * Save to another location (such as the temp build folder). - */ - protected void save(File file) { -// Sketch sketch = editor.getSketch(); -// File manifestFile = new File(sketch.getFolder(), MANIFEST_XML); -// File manifestFile - PrintWriter writer = PApplet.createWriter(file); + PrintWriter writer = PApplet.createWriter(getManifestFile()); xml.write(writer); writer.close(); } - - + + private File getManifestFile() { return new File(sketch.getFolder(), MANIFEST_XML); }