From e6a42723b085830462e4f09b501b9034dd3562a8 Mon Sep 17 00:00:00 2001 From: benfry Date: Fri, 26 Feb 2010 15:36:23 +0000 Subject: [PATCH] fix noLoop(), fix switching between applications --- android/about.txt | 1 + android/build.xml | 5 +- android/core/src/processing/core/PApplet.java | 126 ++++++++---------- android/todo.txt | 33 +++-- 4 files changed, 80 insertions(+), 85 deletions(-) diff --git a/android/about.txt b/android/about.txt index a580a851e..853c28c9b 100644 --- a/android/about.txt +++ b/android/about.txt @@ -71,3 +71,4 @@ + Cannot use .gz files in the data or assets folder, because Android wants to compress the files itself. ++ Use screenWidth and screenHeight instead of screen.width and screen.height. diff --git a/android/build.xml b/android/build.xml index 636678f93..cd1e91b51 100644 --- a/android/build.xml +++ b/android/build.xml @@ -14,9 +14,8 @@ srcdir="core/src" destdir="core/bin"/> - - - + + diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index 8226c80b9..588299af4 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -8,8 +8,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + License as published by the Free Software Foundation, version 2. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -39,6 +38,7 @@ import java.util.zip.*; import android.app.Activity; import android.opengl.GLSurfaceView; +import android.util.DisplayMetrics; import android.view.SurfaceView; import android.view.WindowManager; import android.os.Bundle; @@ -72,14 +72,14 @@ public class PApplet extends Activity implements PConstants, Runnable { */ // public Dimension screen = // Toolkit.getDefaultToolkit().getScreenSize(); -// int screenWidth, screenHeight; + public int screenWidth, screenHeight; /** * Command line options passed in from main(). *

* This does not include the arguments passed in to PApplet itself. */ - public String args[]; +// public String[] args; /** Path to where sketch can read/write files (read-only) */ public String sketchPath; //folder; @@ -110,15 +110,21 @@ public class PApplet extends Activity implements PConstants, Runnable { */ // static public class RendererChangeException extends RuntimeException { } + /** + * Set true when the surface dimensions have changed, so that the PGraphics + * object can be resized on the next trip through handleDraw(). + */ + protected boolean surfaceChanged; + /** * true if no size() command has been executed. This is used to wait until * a size has been set before placing in the window and showing it. */ public boolean defaultSize; - volatile boolean resizeRequest; - volatile int resizeWidth; - volatile int resizeHeight; +// volatile boolean resizeRequest; +// volatile int resizeWidth; +// volatile int resizeHeight; /** * Pixel buffer from this applet's PGraphics. @@ -356,7 +362,6 @@ public class PApplet extends Activity implements PConstants, Runnable { /** true if this sketch is being run by the PDE */ boolean external = false; - static final String ERROR_MIN_MAX = "Cannot use min() or max() on an empty array."; @@ -382,6 +387,7 @@ public class PApplet extends Activity implements PConstants, Runnable { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); +// println("PApplet.onCreate()"); Window window = getWindow(); // Take up as much area as possible @@ -398,17 +404,21 @@ public class PApplet extends Activity implements PConstants, Runnable { // println("window width = " + attrs.width); // println("window height = " + attrs.height); + DisplayMetrics dm = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(dm); + screenWidth = dm.widthPixels; + screenHeight = dm.heightPixels; + if (sketchRenderer().equals(A2D)) { surfaceView = new SketchSurfaceView2D(this); } else if (sketchRenderer().equals(A3D)) { surfaceView = new SketchSurfaceView3D(this); } - + window.setContentView(surfaceView); // attempt to fix full-screen - // code below here formerly from init() - + millisOffset = System.currentTimeMillis(); finished = false; // just for clarity @@ -457,18 +467,21 @@ public class PApplet extends Activity implements PConstants, Runnable { protected void onResume() { + super.onResume(); + // TODO need to bring back app state here! // surfaceView.onResume(); System.out.println("PApplet.onResume() called"); paused = false; - start(); // kick the thread back on + //start(); // kick the thread back on resume(); - super.onResume(); // surfaceView.onResume(); } protected void onPause() { + super.onPause(); + // TODO need to save all application state here! // System.out.println("PApplet.onPause() called"); paused = true; @@ -476,7 +489,6 @@ public class PApplet extends Activity implements PConstants, Runnable { // synchronized (this) { // paused = true; //} - super.onPause(); // surfaceView.onPause(); } @@ -498,9 +510,10 @@ public class PApplet extends Activity implements PConstants, Runnable { public void onDestroy() { + stop(); System.out.println("PApplet.onDestroy() called"); super.onDestroy(); - finish(); + //finish(); } @@ -519,45 +532,6 @@ public class PApplet extends Activity implements PConstants, Runnable { return surfaceHolder; } -// public class SketchSurfaceView { -// -// SketchSurfaceView(Context context) { -// if (sketchRenderer().equals(A2D)) { -// surfaceA2D = new SketchSurfaceView2D(context); -// surfaceA3D = null; -// } -// else if (sketchRenderer().equals(A3D)) { -// surfaceA2D = null; -// surfaceA3D = new SketchSurfaceView3D(context); -// } -// else { -// // Should throw exception here, since the renderer in unknown. -// } -// } -// -// void requestDraw() { -// if (surfaceA2D != null) handleDraw(); -// else surfaceA3D.requestRender(); -// } -// -// void onPause() { -// if (surfaceA2D != null) surfaceA2D.onPause(); -// else surfaceA3D.onPause(); -// } -// -// void onResume() { -// if (surfaceA2D != null) surfaceA2D.onResume(); -// else surfaceA3D.onResume(); -// } -// -// SurfaceView getSurface() { -// if (surfaceA2D != null) return surfaceA2D; -// else return surfaceA3D; -// } -// -// SketchSurfaceView2D surfaceA2D; -// SketchSurfaceView3D surfaceA3D; -// } public class SketchSurfaceView3D extends GLSurfaceView { @@ -611,12 +585,11 @@ 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("surfaceChanged() " + w + " " + h); - - width = w; - height = h; - - g.setSize(w, h); +// System.out.println("SketchSurfaceView3D.surfaceChanged() " + w + " " + h); + surfaceChanged = true; +// width = w; +// height = h; +// g.setSize(w, h); // No need to call g.setSize(width, height) b/c super.surfaceChanged() // will trigger onSurfaceChanged in the renderer, which calls setSize(). @@ -668,14 +641,14 @@ public class PApplet extends Activity implements PConstants, Runnable { public SketchSurfaceView2D(Context context) { super(context); - println("surface holder"); +// println("surface holder"); // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed surfaceHolder = getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU); - println("creating graphics"); +// println("creating graphics"); PGraphics newGraphics = new PGraphicsAndroid2D(); // Set arbitrary size; will be set properly when surfaceChanged() called newGraphics.setSize(100, 100); @@ -686,12 +659,12 @@ public class PApplet extends Activity implements PConstants, Runnable { // may attempt before setSize(), setParent() etc) g = newGraphics; - println("setting focusable, requesting focus"); +// println("setting focusable, requesting focus"); setFocusable(true); setFocusableInTouchMode(true); requestFocus(); - println("done making surface view"); +// println("done making surface view"); } @@ -708,12 +681,13 @@ 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("surfaceChanged() " + w + " " + h); + System.out.println("SketchSurfaceView2D.surfaceChanged() " + w + " " + h); + surfaceChanged = true; - width = w; - height = h; - - g.setSize(w, h); +// width = w; +// height = h; +// +// g.setSize(w, h); } @@ -1267,7 +1241,19 @@ public class PApplet extends Activity implements PConstants, Runnable { public void handleDraw() { - if (g != null && !paused && (looping || redraw)) { + if (surfaceChanged) { + width = surfaceView.getWidth(); + height = surfaceView.getHeight(); + g.setSize(width, height); + surfaceChanged = false; +// println("surfaceChanged true, resized to " + width + "x" + height); + } + + // don't start drawing (e.g. don't call setup) until there's a legitimate + // width and height that have been set by surfaceChanged(). + boolean validSize = width != 0 && height != 0; +// println("valid size = " + validSize + " (" + width + "x" + height + ")"); + if (g != null && validSize && !paused && (looping || redraw)) { if (!g.canDraw()) { // Don't draw if the renderer is not yet ready. // (e.g. OpenGL has to wait for a peer to be on screen) diff --git a/android/todo.txt b/android/todo.txt index 56195e5f0..929ae5163 100644 --- a/android/todo.txt +++ b/android/todo.txt @@ -1,4 +1,24 @@ 0178 (private) +X noLoop() is broken (draw is never called) +X http://dev.processing.org/bugs/show_bug.cgi?id=1467 +X fix the freakout that happens with onPause() +o solution is to call stop() to kill the thread, but that's not a pause +X app not pausing or closing when switching to another activity +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 _ 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()? + + +cleaning +X move to eclair (donut devices will have terrible performance anyway) +X make change from src folder to assets folder for export +X what to do with other classes that rely on PApplet? (e.g. vida) + _ Errors show up that .java files are duplicates with the Android tools. _ http://dev.processing.org/bugs/show_bug.cgi?id=1472 @@ -22,21 +42,15 @@ _ http://dev.processing.org/bugs/show_bug.cgi?id=1439 _ how does size work? _ if size() method is used, things are scaled based on that _ if no size() method, then the full screen/full resolution is used +_ make apps properly handle screen resize _ should alpha PImage stuff use a non-4byte config? -_ move to eclair (donut devices will have terrible performance anyway) -_ deal with path problems - _ remove SurfaceView2D/SurfaceView3D separation, or clean up _ what is resetLights() in PGraphics? _ remove drawCube() method from PApplet _ remove model() method from end of PApplet (make it shape(PShape)) -_ make apps properly handle screen resize -_ make change from src folder to assets folder for export -_ what to do with other classes that rely on PApplet? (e.g. vida) - from romain _ colorMode() error _ http://dev.processing.org/bugs/show_bug.cgi?id=1436 @@ -70,11 +84,6 @@ P5 nice to have android bugs, sorted by priority http://dev.processing.org/bugs/buglist.cgi?bug_status=&field0-0-0=product&type0-0-0=substring&value0-0-0=android&field0-0-1=component&type0-0-1=substring&value0-0-1=android&field0-0-2=short_desc&type0-0-2=substring&value0-0-2=android&field0-0-3=status_whiteboard&type0-0-3=substring&value0-0-3=android&query_format=advanced&order=bugs.priority,bugs.bug_status%2Cbugs.bug_id&query_based_on= -P1 _ noLoop() is broken (draw is never called) -P1 _ http://dev.processing.org/bugs/show_bug.cgi?id=1467 -P1 _ app not pausing or closing when switching to another activity -P1 _ http://dev.processing.org/bugs/show_bug.cgi?id=1404 - *---jdf accepts-- | P1 _ get stdout and stderr from the emulator/device | P1 _ http://dev.processing.org/bugs/show_bug.cgi?id=1381