diff --git a/android/core/.classpath b/android/core/.classpath index d2c8687f8..03699eb51 100644 --- a/android/core/.classpath +++ b/android/core/.classpath @@ -1,6 +1,6 @@ - + diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index 588299af4..2e12f4718 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -81,7 +81,12 @@ public class PApplet extends Activity implements PConstants, Runnable { */ // public String[] args; - /** Path to where sketch can read/write files (read-only) */ + /** + * Path to where sketch can read/write files (read-only). + * Android: This is the writable area for the Activity, which is correct + * for purposes of how sketchPath is used in practice from a sketch, + * even though it's technically different than the desktop version. + */ public String sketchPath; //folder; /** When debugging headaches */ @@ -295,6 +300,11 @@ public class PApplet extends Activity implements PConstants, Runnable { * For Android, true if the activity has been paused. */ protected boolean paused; + + /** + * The Window object for Android. + */ +// protected Window window; /** * true if exit() has been called so that things shut down @@ -388,6 +398,7 @@ public class PApplet extends Activity implements PConstants, Runnable { super.onCreate(savedInstanceState); // println("PApplet.onCreate()"); + Window window = getWindow(); // Take up as much area as possible @@ -408,6 +419,7 @@ public class PApplet extends Activity implements PConstants, Runnable { getWindowManager().getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels; screenHeight = dm.heightPixels; + //println("screen size is " + screenWidth + "x" + screenHeight); if (sketchRenderer().equals(A2D)) { surfaceView = new SketchSurfaceView2D(this); @@ -427,41 +439,10 @@ public class PApplet extends Activity implements PConstants, Runnable { looping = true; redraw = true; // draw this guy once firstMotion = true; - - // TODO is there a better way to set the sketch path? -// try { -// if (sketchPath == null) { -// sketchPath = System.getProperty("user.dir"); -// } -// } catch (Exception e) { } // may be a security problem + Context context = getApplicationContext(); sketchPath = context.getFilesDir().getAbsolutePath(); - - /* - Dimension size = getSize(); - if ((size.width != 0) && (size.height != 0)) { - // When this PApplet is embedded inside a Java application with other - // Component objects, its size() may already be set externally (perhaps - // by a LayoutManager). In this case, honor that size as the default. - // Size of the component is set, just create a renderer. - g = makeGraphics(size.width, size.height, sketchRenderer(), null, true); - // This doesn't call setSize() or setPreferredSize() because the fact - // that a size was already set means that someone is already doing it. - - } else { - // Set the default size, until the user specifies otherwise - this.defaultSize = true; - int w = sketchWidth(); - int h = sketchHeight(); - g = makeGraphics(w, h, sketchRenderer(), null, true); - // Fire component resize event - setSize(w, h); - setPreferredSize(new Dimension(w, h)); - } - width = g.width; - height = g.height; - */ - + start(); } @@ -549,8 +530,8 @@ public class PApplet extends Activity implements PConstants, Runnable { // this.onResume() and thus require a valid renderer) are triggered // before surfaceChanged() is ever called. PGraphics newGraphics = new PGraphicsAndroid3D(); - // Set arbitrary size; will be set properly when surfaceChanged() called - newGraphics.setSize(100, 100); + // Set semi-arbitrary size; will be set properly when surfaceChanged() called + newGraphics.setSize(screenWidth, screenHeight); newGraphics.setParent(PApplet.this); newGraphics.setPrimary(true); g = newGraphics; @@ -650,8 +631,8 @@ public class PApplet extends Activity implements PConstants, Runnable { // println("creating graphics"); PGraphics newGraphics = new PGraphicsAndroid2D(); - // Set arbitrary size; will be set properly when surfaceChanged() called - newGraphics.setSize(100, 100); + // Set semi-arbitrary size; will be set properly when surfaceChanged() called + newGraphics.setSize(screenWidth, screenHeight); // newGraphics.setSize(getWidth(), getHeight()); newGraphics.setParent(PApplet.this); newGraphics.setPrimary(true); diff --git a/android/core/src/processing/core/PGraphics.java b/android/core/src/processing/core/PGraphics.java index 97f9da57e..317ebc372 100644 --- a/android/core/src/processing/core/PGraphics.java +++ b/android/core/src/processing/core/PGraphics.java @@ -370,7 +370,7 @@ public class PGraphics extends PImage implements PConstants { * it will be the offscreen drawing buffer. */ //public Image image; - public Bitmap image; + public Bitmap bitmap; // ........................................................ diff --git a/android/core/src/processing/core/PGraphicsAndroid2D.java b/android/core/src/processing/core/PGraphicsAndroid2D.java index 04dc16e44..6ea55b4e5 100644 --- a/android/core/src/processing/core/PGraphicsAndroid2D.java +++ b/android/core/src/processing/core/PGraphicsAndroid2D.java @@ -121,8 +121,8 @@ public class PGraphicsAndroid2D extends PGraphics { protected void allocate() { - image = Bitmap.createBitmap(width, height, Config.ARGB_8888); - canvas = new Canvas(image); + bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); + canvas = new Canvas(bitmap); // image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // canvas = (Graphics2D) image.getGraphics(); } @@ -185,7 +185,7 @@ public class PGraphicsAndroid2D extends PGraphics { try { screen = parent.getSurfaceHolder().lockCanvas(null); if (screen != null) { - screen.drawBitmap(image, new Matrix(), null); + screen.drawBitmap(bitmap, new Matrix(), null); } } finally { if (screen != null) { @@ -1782,7 +1782,7 @@ public class PGraphicsAndroid2D extends PGraphics { } // WritableRaster raster = ((BufferedImage) image).getRaster(); // raster.getDataElements(0, 0, width, height, pixels); - image.getPixels(pixels, 0, width, 0, 0, width, height); + bitmap.getPixels(pixels, 0, width, 0, 0, width, height); } @@ -1795,7 +1795,7 @@ public class PGraphicsAndroid2D extends PGraphics { public void updatePixels() { // WritableRaster raster = ((BufferedImage) image).getRaster(); // raster.setDataElements(0, 0, width, height, pixels); - image.setPixels(pixels, 0, width, 0, 0, width, height); + bitmap.setPixels(pixels, 0, width, 0, 0, width, height); } @@ -1834,7 +1834,7 @@ public class PGraphicsAndroid2D extends PGraphics { // WritableRaster raster = ((BufferedImage) image).getRaster(); // raster.getDataElements(x, y, getset); // return getset[0]; - return image.getPixel(x, y); + return bitmap.getPixel(x, y); } @@ -1847,7 +1847,7 @@ public class PGraphicsAndroid2D extends PGraphics { // WritableRaster raster = ((BufferedImage) image).getRaster(); // raster.getDataElements(x, y, w, h, output.pixels); - Bitmap bitsy = Bitmap.createBitmap(image, x, y, w, h); + Bitmap bitsy = Bitmap.createBitmap(bitmap, x, y, w, h); bitsy.getPixels(output.pixels, 0, w, 0, 0, w, h); return output; @@ -1864,7 +1864,7 @@ public class PGraphicsAndroid2D extends PGraphics { // getset[0] = argb; // WritableRaster raster = ((BufferedImage) image).getRaster(); // raster.setDataElements(x, y, getset); - image.setPixel(x, y, argb); + bitmap.setPixel(x, y, argb); } @@ -1963,7 +1963,7 @@ public class PGraphicsAndroid2D extends PGraphics { // canvas.drawBitmap(bitsy, rect.set(sx, sy, sx+sw, sy+sh); Rect src = new Rect(dx, dy, dx+dw, dy+dh); - canvas.drawBitmap(image, src, rect, null); + canvas.drawBitmap(bitmap, src, rect, null); // if ((sw != dw) || (sh != dh)) { // // use slow version if changing size diff --git a/android/todo.txt b/android/todo.txt index 929ae5163..65b5cbef5 100644 --- a/android/todo.txt +++ b/android/todo.txt @@ -8,11 +8,14 @@ X http://dev.processing.org/bugs/show_bug.cgi?id=1404 P4 _ excessive rotation of application causes memory to run out P4 _ this probably means that some memory isn't being freed that should be +P4 _ new window and surfaceview objects are being created in onCreate +P4 _ so they should probably be taken down in onDestroy.. but how? P4 _ http://dev.processing.org/bugs/show_bug.cgi?id=1480 -_ creating new windows each time through, that's yer memory problem _ if !looping, is it necessary to call redraw() in onResume()? +_ prevent rotation of applications? (or require a certain orientation) + cleaning X move to eclair (donut devices will have terrible performance anyway)