From 4fb9821a336d8063a8a26d7f3ebc662ce5257102 Mon Sep 17 00:00:00 2001 From: benfry Date: Fri, 26 Feb 2010 19:52:24 +0000 Subject: [PATCH] cleanups, now going after image loading and memory issues --- android/about.txt | 4 ++ android/core/src/processing/core/PApplet.java | 65 ++++++++++--------- .../processing/core/PGraphicsAndroid2D.java | 2 +- android/todo.txt | 45 +++++++++---- 4 files changed, 71 insertions(+), 45 deletions(-) diff --git a/android/about.txt b/android/about.txt index 853c28c9b..69f29a5dc 100644 --- a/android/about.txt +++ b/android/about.txt @@ -72,3 +72,7 @@ to compress the files itself. + Use screenWidth and screenHeight instead of screen.width and screen.height. + ++ To use the virtual keyboard, hold down the MENU key on the device. This + is an Android default, but some users might not be familiar with it. + diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index 2e12f4718..8c4b54697 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -25,6 +25,7 @@ package processing.core; import android.content.*; import android.content.res.AssetManager; +import android.content.res.Configuration; import android.graphics.*; import java.io.*; @@ -300,7 +301,10 @@ public class PApplet extends Activity implements PConstants, Runnable { * For Android, true if the activity has been paused. */ protected boolean paused; - + + protected SurfaceView surfaceView; + protected SurfaceHolder surfaceHolder; + /** * The Window object for Android. */ @@ -381,22 +385,10 @@ public class PApplet extends Activity implements PConstants, Runnable { ////////////////////////////////////////////////////////////// -// static final private int BACK_ID = Menu.FIRST; -// static final private int CLEAR_ID = Menu.FIRST + 1; -// private EditText mEditor; - - -// public BagelDroid() { -// } - -// SurfaceView surfaceView; - - /** Called with the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // println("PApplet.onCreate()"); Window window = getWindow(); @@ -409,12 +401,7 @@ public class PApplet extends Activity implements PConstants, Runnable { // This does the actual full screen work window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); - - // window size is -1 at this point, so no sense in using attrs -// final WindowManager.LayoutParams attrs = window.getAttributes(); -// println("window width = " + attrs.width); -// println("window height = " + attrs.height); - + DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels; @@ -427,7 +414,10 @@ public class PApplet extends Activity implements PConstants, Runnable { surfaceView = new SketchSurfaceView3D(this); } - window.setContentView(surfaceView); // attempt to fix full-screen + width = screenWidth; + height = screenHeight; + + window.setContentView(surfaceView); // set full screen // code below here formerly from init() @@ -447,6 +437,12 @@ public class PApplet extends Activity implements PConstants, Runnable { } + public void onConfigurationChanged(Configuration newConfig) { + System.out.println("configuration changed: " + newConfig); + super.onConfigurationChanged(newConfig); + } + + protected void onResume() { super.onResume(); @@ -504,10 +500,6 @@ public class PApplet extends Activity implements PConstants, Runnable { // ANDROID SURFACE VIEW - SurfaceView surfaceView; - SurfaceHolder surfaceHolder; - - public SurfaceHolder getSurfaceHolder() { //return surfaceView.getHolder(); return surfaceHolder; @@ -740,21 +732,25 @@ public class PApplet extends Activity implements PConstants, Runnable { ////////////////////////////////////////////////////////////// - /* public int sketchWidth() { - return DEFAULT_WIDTH; + return screenWidth; } public int sketchHeight() { - return DEFAULT_HEIGHT; + return screenHeight; } - */ public String sketchRenderer() { return A2D; } + + +// public int sketchOrientation() { +// return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; +// //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); +// } /** @@ -1223,9 +1219,13 @@ public class PApplet extends Activity implements PConstants, Runnable { public void handleDraw() { if (surfaceChanged) { - width = surfaceView.getWidth(); - height = surfaceView.getHeight(); - g.setSize(width, height); + int newWidth = surfaceView.getWidth(); + int newHeight = surfaceView.getHeight(); + if (newWidth != width || newHeight != height) { + width = newWidth; + height = newHeight; + g.setSize(width, height); + } surfaceChanged = false; // println("surfaceChanged true, resized to " + width + "x" + height); } @@ -2742,6 +2742,7 @@ public class PApplet extends Activity implements PConstants, Runnable { System.err.println("Could not find the image " + filename + "."); return null; } + long t = System.currentTimeMillis(); Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeStream(stream); @@ -2751,6 +2752,8 @@ public class PApplet extends Activity implements PConstants, Runnable { stream = null; } catch (IOException e) { } } + int much = (int) (System.currentTimeMillis() - t); + println("loadImage(" + filename + ") was " + nfc(much)); PImage image = new PImage(bitmap); image.parent = this; return image; diff --git a/android/core/src/processing/core/PGraphicsAndroid2D.java b/android/core/src/processing/core/PGraphicsAndroid2D.java index 6ea55b4e5..3125228bf 100644 --- a/android/core/src/processing/core/PGraphicsAndroid2D.java +++ b/android/core/src/processing/core/PGraphicsAndroid2D.java @@ -129,7 +129,7 @@ public class PGraphicsAndroid2D extends PGraphics { public void dispose() { - // called when paused. + bitmap.recycle(); } diff --git a/android/todo.txt b/android/todo.txt index 65b5cbef5..ccee237c9 100644 --- a/android/todo.txt +++ b/android/todo.txt @@ -5,16 +5,8 @@ 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 _ 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 - -_ if !looping, is it necessary to call redraw() in onResume()? - -_ prevent rotation of applications? (or require a certain orientation) +o if !looping, is it necessary to call redraw() in onResume()? +X doesn't appear to be, since it gets completely rebuilt cleaning @@ -37,8 +29,6 @@ _ ANDROID_SDK not getting set on OS X _ http://dev.processing.org/bugs/show_bug.cgi?id=1469 _ http://stackoverflow.com/questions/603785/environment-variables-in-mac-os-x -_ need to have single signature that can be reapplied -_ with different machines, users are required to remove signature _ library support also needs android manifest changes _ http://dev.processing.org/bugs/show_bug.cgi?id=1439 @@ -64,7 +54,8 @@ _ test createFont() _ gz files not allowed, need to remove the code from createInput() et al _ or maybe not, since could still come from a site or a File? -_ just can't come from the assets file.. okok +_ just can't come from the assets file.. +_ throw an error if a file in the 'data' dir ends with .gz _ add method to set the icon (and package name?) _ http://dev.processing.org/bugs/show_bug.cgi?id=1429 @@ -144,3 +135,31 @@ P3 _ http://dev.processing.org/bugs/show_bug.cgi?id=1406 P3 _ implement certificates (self-signed) for distribution P3 _ http://developer.android.com/guide/publishing/app-signing.html P3 _ http://dev.processing.org/bugs/show_bug.cgi?id=1430 +P3 _ if different machines, debug.keystore changes, requiring manual removal +P3 _ or find a way to do it automatically with processing +P3 _ can't keep it with the sketch, don't want to give away private key +P3 _ with different machines, users are required to remove signature +P3 _ add a method to remove an application if the debug key is different +P3 _ perhaps the first time an application is installed, remove it? +P3 _ http://dev.processing.org/bugs/show_bug.cgi?id=1481 +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 + + +POSSIBLE FEATURE EDITIONS + +_ prevent rotation of applications? (or require a certain orientation) +_ add to activity tag in the manifest: +android:configChanges="keyboardHidden|orientation" +android:screenOrientation="landscape" +_ or programmatically specify: +setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); +setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + +_ show/hide the virtual keyboard +InputMethodManager imm = + (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); +imm.showSoftInput(surfaceView, 0);