From 11f56adb7aec87882c23e50bed6f32a5a337fae1 Mon Sep 17 00:00:00 2001 From: benfry Date: Sat, 14 Aug 2010 10:40:55 +0000 Subject: [PATCH] more cleanup --- android/core/src/processing/core/PApplet.java | 18 ++- android/todo.txt | 39 +++--- .../processing/app/tools/android/Build.java | 126 ++---------------- .../processing/app/tools/android/Keys.java | 4 +- .../app/tools/android/Preprocessor.java | 93 +++++++++++-- app/src/processing/app/debug/Runner.java | 1 + 6 files changed, 127 insertions(+), 154 deletions(-) diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index 70d70b3cc..5f62669ea 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -659,7 +659,9 @@ public class PApplet extends Activity implements PConstants, Runnable { // part of SurfaceHolder.Callback public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { - System.out.println("SketchSurfaceView2D.surfaceChanged() " + w + " " + h); + if (DEBUG) { + System.out.println("SketchSurfaceView2D.surfaceChanged() " + w + " " + h); + } surfaceChanged = true; // width = w; @@ -762,14 +764,18 @@ public class PApplet extends Activity implements PConstants, Runnable { // part of SurfaceHolder.Callback public void surfaceCreated(SurfaceHolder holder) { super.surfaceCreated(holder); - System.out.println("surfaceCreated()"); + if (DEBUG) { + System.out.println("surfaceCreated()"); + } } // part of SurfaceHolder.Callback public void surfaceDestroyed(SurfaceHolder holder) { super.surfaceDestroyed(holder); - System.out.println("surfaceDestroyed()"); + if (DEBUG) { + System.out.println("surfaceDestroyed()"); + } // I don't think we need this: //g.dispose(); } @@ -779,8 +785,10 @@ public class PApplet extends Activity implements PConstants, Runnable { public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { super.surfaceChanged(holder, format, w, h); -// System.out.println("SketchSurfaceView3D.surfaceChanged() " + w + " " + h); - surfaceChanged = true; + if (DEBUG) { + System.out.println("SketchSurfaceView3D.surfaceChanged() " + w + " " + h); + } +// surfaceChanged = true; // width = w; // height = h; // g.setSize(w, h); diff --git a/android/todo.txt b/android/todo.txt index 4be65d6a9..059dc19d5 100644 --- a/android/todo.txt +++ b/android/todo.txt @@ -27,11 +27,9 @@ X re: rewriting manifest on each build o http://dev.processing.org/bugs/show_bug.cgi?id=1429 X http://code.google.com/p/processing/issues/detail?id=221 X change skewX/Y to shearX/Y -_ need updated reference for this +X make updated reference X copy the changes over from the xml library -_ post processing-android-core-0190.zip to the download page -_ get some help w/ the dist script to make the right file -_ remove 'import processing.opengl.*' in the preprocessor? +X remove 'import processing.opengl.*' in the preprocessor? X add to wiki - rename 'data' folder to 'assets' when inside eclipse X prevent rotation of applications? (or require a certain orientation) o add to activity tag in the manifest: @@ -57,7 +55,6 @@ X make apps properly handle screen resize o remove SurfaceView2D/SurfaceView3D separation, or clean up o test controlp5 with android X get core.zip out of svn (once tool is separate, modes stuff working etc) -_ StreamPump has been quieted, but maybe this needs to be a global log setting X fix the width of the build window X some sort of warning re: messing with AndroidManifest.xml X added to the wiki @@ -87,6 +84,16 @@ earlier X if sketchRenderer() et al are used in android, need to add to desktop X remove processing.opengl.* classes and finish PGraphicsAndroid3D X http://dev.processing.org/bugs/show_bug.cgi?id=1401 +J need to prevent hitting 'run' twice (threaded, so would work) +J currently things just keep restarting the build, bad state +J http://dev.processing.org/bugs/show_bug.cgi?id=1387 + +before 0190 release +_ post processing-android-core-0190.zip to the download page +_ get some help w/ the dist script to make the right file +_ have casey do a reference build (skewX/Y to shearX/Y) +_ also changes to the xml api naming +_ change run/present/export/export application names in the menus android menu _ something to bring up the full console window @@ -143,6 +150,8 @@ confirm: [ ] alias, password, confirm, validity (years) first/last name, ounit, org, city/locale, state/province, country code (xx) +_ StreamPump has been quieted, but maybe this needs to be a global log setting + _ seems to have problems on 64-bit windows _ removing local version of java helped someone fix it @@ -229,17 +238,12 @@ DL _ http://code.google.com/p/processing/issues/detail?id=223 TOOLS -// jdf maybedone -_ only send error text to System.err (i.e. "Launching emulator" is not an error) -_ send these debug log messages to System.out +J only send error text to System.err (i.e. "Launching emulator" is not an error) +J send these debug log messages to System.out +o "Sketch started on emulator" in spite of the emulator only halfway booted +o sent email about this one -// jdf maybedone -_ "Sketch started on emulator" in spite of the emulator only halfway booted -_ sent email about this one - -// jdf don't understand _ errors in ActivityManager aren't coming through - _ if AVD is deleted while processing still running, things flake out _ also no error messages, just 'giving up on launching emulator' @@ -269,9 +273,6 @@ W/System.err( 242): at android.app.ApplicationContext.openFileOutput(Applicati W/System.err( 242): at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:158) W/System.err( 242): at processing.core.PApplet.createOutput(PApplet.java:3677) -P2 _ need to prevent hitting 'run' twice (threaded, so would work) -P2 _ currently things just keep restarting the build, bad state -P2 _ http://dev.processing.org/bugs/show_bug.cgi?id=1387 P2 _ move the android tools into its own source package in SVN P2 _ started, but needs proper Tool or Mode packaging P2 _ http://dev.processing.org/bugs/show_bug.cgi?id=1388 @@ -282,8 +283,8 @@ P2 _ http://dev.processing.org/bugs/show_bug.cgi?id=1379 P2 _ save state re: whether sketches are android or java mode (or others?) P2 _ http://dev.processing.org/bugs/show_bug.cgi?id=1380 -_ compiler errors on Windows not appearing, nor highlighting the line number -_ http://code.google.com/p/processing/issues/detail?id=253 +DM _ compiler errors on Windows not appearing, nor highlighting the line number +DM _ http://code.google.com/p/processing/issues/detail?id=253 P3 _ remove various debug messages on the console P3 _ right now, there are too many places where errors occur diff --git a/android/tool/src/processing/app/tools/android/Build.java b/android/tool/src/processing/app/tools/android/Build.java index 1b0788657..22a7490cf 100644 --- a/android/tool/src/processing/app/tools/android/Build.java +++ b/android/tool/src/processing/app/tools/android/Build.java @@ -44,78 +44,12 @@ class Build { File tempBuildFolder; File buildFile; - String sizeStatement; - String sketchWidth; - String sketchHeight; - String sketchRenderer; -// String sketchWidth = "screenWidth"; -// String sketchHeight = "screenHeight"; -// String sketchRenderer = "A2D"; - public Build(final Editor editor, final AndroidSDK sdk) { this.editor = editor; this.sdk = sdk; } - - // TODO this needs to be a generic function inside Sketch or elsewhere - - protected boolean calcSketchSize() { - // This matches against any uses of the size() function, whether numbers - // or variables or whatever. This way, no warning is shown if size() isn't - // actually used in the applet, which is the case especially for anyone - // who is cutting/pasting from the reference. - - Sketch sketch = editor.getSketch(); - String scrubbed = Sketch.scrubComments(sketch.getCode(0).getProgram()); - String[] matches = PApplet.match(scrubbed, Sketch.SIZE_REGEX); -// PApplet.println("matches: "); -// PApplet.println(matches); - - if (matches != null) { - boolean badSize = false; - - if (!matches[1].equals("screenWidth") && - !matches[1].equals("screenHeight") && - PApplet.parseInt(matches[1], -1) == -1) { - badSize = true; - } - if (!matches[2].equals("screenWidth") && - !matches[2].equals("screenHeight") && - PApplet.parseInt(matches[2], -1) == -1) { - badSize = true; - } - - if (badSize) { - // found a reference to size, but it didn't seem to contain numbers - final String message = - "The size of this applet could not automatically be determined\n" + - "from your code. Use only numeric values (not variables) for the\n" + - "size() command. See the size() reference for more information."; - Base.showWarning("Could not find sketch size", message, null); - System.out.println("More about the size() command on Android can be"); - System.out.println("found here: http://wiki.processing.org/w/Android"); - return false; - } - -// PApplet.println(matches); - sizeStatement = matches[0]; // the full method to be removed from the source - sketchWidth = matches[1]; - sketchHeight = matches[2]; - sketchRenderer = matches[3].trim(); - if (sketchRenderer.length() == 0) { - sketchRenderer = null; - } - } else { - sizeStatement = null; - sketchWidth = null; - sketchHeight = null; - sketchRenderer = null; - } - return true; - } - public File createProject(String target) { final Sketch sketch = editor.getSketch(); @@ -135,29 +69,17 @@ class Build { try { manifest = new Manifest(editor); -// System.out.println(manifest + " " + manifest.getPackageName()); - - // the preproc should take care of this now -// final File javaFolder = -// mkdirs(srcFolder, manifest.getPackageName().replace('.', '/')); -// // File srcFile = new File(actualSrc, className + ".java"); -// final String buildPath = javaFolder.getAbsolutePath(); - - // String prefsLine = Preferences.get("preproc.imports"); - // System.out.println("imports are " + prefsLine); - // Preferences.set("preproc.imports", ""); - - // need to change to a better set of imports here - - // grab code from current editing window + // grab code from current editing window (GUI only) sketch.prepare(); - if (!calcSketchSize()) { + // build the preproc and get to work + Preprocessor preproc = new Preprocessor(sketch, getPackageName()); + if (!preproc.parseSketchSize()) { editor.statusError("Could not parse the size() command."); return null; } - className = sketch.preprocess(srcFolder.getAbsolutePath(), //buildPath, + className = sketch.preprocess(srcFolder.getAbsolutePath(), manifest.getPackageName(), - new Preprocessor(sketch.getName(), this)); + preproc); if (className != null) { // final File androidXML = new File(tempBuildFolder, "AndroidManifest.xml"); // writeAndroidManifest(androidXML, sketch.getName(), className); @@ -549,17 +471,17 @@ class Build { // writer.close(); // } - - private void writeLibraries(final File libsFolder, final File assetsFolder) - throws IOException { + + private void writeLibraries(final File libsFolder, + final File assetsFolder) throws IOException { // Copy any libraries to the 'libs' folder final Sketch sketch = editor.getSketch(); for (final File libraryFolder : sketch.getImportedLibraries()) { // in the list is a File object that points the // library sketch's "library" folder final File exportSettings = new File(libraryFolder, "export.txt"); - final HashMap exportTable = Base - .readSettings(exportSettings); + final HashMap exportTable = + Base.readSettings(exportSettings); final String androidList = exportTable.get("android"); String exportList[] = null; if (androidList != null) { @@ -603,8 +525,7 @@ class Build { final String name = item.getName(); final String lcname = name.toLowerCase(); if (lcname.endsWith(".jar") || lcname.endsWith(".zip")) { - final String jarName = name.substring(0, name.length() - 4) - + ".jar"; + String jarName = name.substring(0, name.length() - 4) + ".jar"; Base.copyFile(item, new File(libsFolder, jarName)); } } @@ -618,32 +539,9 @@ class Build { } -// /** -// * Place quotes around a string to avoid dreadful syntax mess of escaping -// * quotes near quoted strings. Mmmm! -// */ -// private static final String q(final String what) { -// return "\"" + what + "\""; -// } - - public void cleanup() { // don't want to be responsible for this //rm(tempBuildFolder); tempBuildFolder.deleteOnExit(); } - -// private void rm(final File f) { -// if (f.isDirectory()) { -// final File[] kids = f.listFiles(new FilenameFilter() { -// public boolean accept(final File dir, final String name) { -// return !(name.equals(".") || name.equals("..")); -// } -// }); -// for (final File k : kids) { -// rm(k); -// } -// } -// f.delete(); -// } } \ No newline at end of file diff --git a/android/tool/src/processing/app/tools/android/Keys.java b/android/tool/src/processing/app/tools/android/Keys.java index dbb3a183b..9f6f0b8a4 100644 --- a/android/tool/src/processing/app/tools/android/Keys.java +++ b/android/tool/src/processing/app/tools/android/Keys.java @@ -38,9 +38,9 @@ import processing.app.Preferences; public class Keys extends JFrame { Editor editor; - + public Keys(Editor editor) { this.editor = editor; setVisible(true); } -} \ No newline at end of file +} diff --git a/android/tool/src/processing/app/tools/android/Preprocessor.java b/android/tool/src/processing/app/tools/android/Preprocessor.java index 1b1b12fb6..ba6f96bb9 100644 --- a/android/tool/src/processing/app/tools/android/Preprocessor.java +++ b/android/tool/src/processing/app/tools/android/Preprocessor.java @@ -26,7 +26,9 @@ import java.io.PrintWriter; import java.io.Writer; import java.util.List; +import processing.app.Base; import processing.app.Preferences; +import processing.app.Sketch; import processing.app.debug.RunnerException; import processing.app.preproc.PdePreprocessor; import processing.app.preproc.PreprocessResult; @@ -36,21 +38,84 @@ import antlr.TokenStreamException; public class Preprocessor extends PdePreprocessor { - Build build; + Sketch sketch; + String packageName; + + String sizeStatement; + String sketchWidth; + String sketchHeight; + String sketchRenderer; - public Preprocessor(final String sketchName, final Build build) throws IOException { - super(sketchName); - this.build = build; + public Preprocessor(final Sketch sketch, + final String packageName) throws IOException { + super(sketch.getName()); + this.sketch = sketch; + this.packageName = packageName; + } + + + // TODO this needs to be a generic function inside Sketch or elsewhere + + protected boolean parseSketchSize() { + // This matches against any uses of the size() function, whether numbers + // or variables or whatever. This way, no warning is shown if size() isn't + // actually used in the applet, which is the case especially for anyone + // who is cutting/pasting from the reference. + + String scrubbed = Sketch.scrubComments(sketch.getCode(0).getProgram()); + String[] matches = PApplet.match(scrubbed, Sketch.SIZE_REGEX); + + if (matches != null) { + boolean badSize = false; + + if (!matches[1].equals("screenWidth") && + !matches[1].equals("screenHeight") && + PApplet.parseInt(matches[1], -1) == -1) { + badSize = true; + } + if (!matches[2].equals("screenWidth") && + !matches[2].equals("screenHeight") && + PApplet.parseInt(matches[2], -1) == -1) { + badSize = true; + } + + if (badSize) { + // found a reference to size, but it didn't seem to contain numbers + final String message = + "The size of this applet could not automatically be determined\n" + + "from your code. Use only numeric values (not variables) for the\n" + + "size() command. See the size() reference for more information."; + Base.showWarning("Could not find sketch size", message, null); + System.out.println("More about the size() command on Android can be"); + System.out.println("found here: http://wiki.processing.org/w/Android"); + return false; + } + +// PApplet.println(matches); + sizeStatement = matches[0]; // the full method to be removed from the source + sketchWidth = matches[1]; + sketchHeight = matches[2]; + sketchRenderer = matches[3].trim(); + if (sketchRenderer.length() == 0) { + sketchRenderer = null; + } + } else { + sizeStatement = null; + sketchWidth = null; + sketchHeight = null; + sketchRenderer = null; + } + return true; } public PreprocessResult write(Writer out, String program, String codeFolderPackages[]) throws RunnerException, RecognitionException, TokenStreamException { - if (build.sizeStatement != null) { - int start = program.indexOf(build.sizeStatement); + if (sizeStatement != null) { + int start = program.indexOf(sizeStatement); program = program.substring(0, start) + - program.substring(start + build.sizeStatement.length()); + program.substring(start + sizeStatement.length()); } // String[] found = PApplet.match(program, "import\\s+processing.opengl.*\\s*"); // if (found != null) { @@ -65,7 +130,7 @@ public class Preprocessor extends PdePreprocessor { protected int writeImports(final PrintWriter out, final List programImports, final List codeFolderImports) { - out.println("package " + build.getPackageName() + ";"); + out.println("package " + packageName + ";"); out.println(); // add two lines for the package above return 2 + super.writeImports(out, programImports, codeFolderImports); @@ -81,14 +146,14 @@ public class Preprocessor extends PdePreprocessor { if ((mode == Mode.STATIC) || (mode == Mode.ACTIVE)) { out.println(); - if (build.sketchWidth != null) { - out.println(indent + "public int sketchWidth() { return " + build.sketchWidth + "; }"); + if (sketchWidth != null) { + out.println(indent + "public int sketchWidth() { return " + sketchWidth + "; }"); } - if (build.sketchHeight != null) { - out.println(indent + "public int sketchHeight() { return " + build.sketchHeight + "; }"); + if (sketchHeight != null) { + out.println(indent + "public int sketchHeight() { return " + sketchHeight + "; }"); } - if (build.sketchRenderer != null) { - out.println(indent + "public String sketchRenderer() { return " + build.sketchRenderer + "; }"); + if (sketchRenderer != null) { + out.println(indent + "public String sketchRenderer() { return " + sketchRenderer + "; }"); } // close off the class definition diff --git a/app/src/processing/app/debug/Runner.java b/app/src/processing/app/debug/Runner.java index 7b31fe989..202eb8310 100644 --- a/app/src/processing/app/debug/Runner.java +++ b/app/src/processing/app/debug/Runner.java @@ -285,6 +285,7 @@ public class Runner implements MessageConsumer { "java -Xrunjdwp:transport=dt_socket,address=" + addr + ",suspend=y "; } else { commandArgs = +// "java -Xrunjdwp:transport=dt_socket,address=" + addr + ",suspend=y "; "java -d32 -Xrunjdwp:transport=dt_socket,address=" + addr + ",suspend=y "; } }