From e6f515543bb455bfd31731ef8f35d73e8a83d576 Mon Sep 17 00:00:00 2001 From: benfry Date: Mon, 26 Jul 2010 13:30:33 +0000 Subject: [PATCH] lots of in-practice tweaks with making android more usable --- android/core/src/processing/core/PApplet.java | 45 +++++++++++++++++-- .../core/src/processing/core/PConstants.java | 11 +++-- android/core/src/processing/core/PFont.java | 1 - .../core/src/processing/core/PGraphics.java | 1 - android/todo.txt | 23 ++++++++++ .../app/tools/android/Manifest.java | 7 +++ 6 files changed, 78 insertions(+), 10 deletions(-) diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index 534444f50..7e90f3680 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -2016,10 +2016,10 @@ public class PApplet extends Activity implements PConstants, Runnable { // which is a problem if the space bar or tab key are used. key = (char) event.getUnicodeChar(); // if not mappable to a unicode character, instead mark as coded key - if (key == 0) { + if (key == 0 || key == 0xFFFF) { // System.out.println(" key is coded"); key = CODED; - } else { +// } else { // System.out.println(" key is unicode"); } @@ -2039,8 +2039,8 @@ public class PApplet extends Activity implements PConstants, Runnable { // set key to zero (or something besides the "ESC"). // println(event); if (action == KeyEvent.ACTION_DOWN) { - if (key == KeyEvent.KEYCODE_BACK) { -// println("KEYCODE_BACK, calling exit()"); + if (keyCode == KeyEvent.KEYCODE_BACK) { + println("KEYCODE_BACK, calling exit()"); exit(); } } @@ -2422,6 +2422,43 @@ public class PApplet extends Activity implements PConstants, Runnable { } } + + + ////////////////////////////////////////////////////////////// + + + public void method(String name) { +// final Object o = this; +// final Class c = getClass(); + try { + Method method = getClass().getMethod(name, new Class[] {}); + method.invoke(this, new Object[] { }); + + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.getTargetException().printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("There is no public " + name + "() method " + + "in the class " + getClass().getName()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public void thread(final String name) { + Thread later = new Thread() { + public void run() { + method(name); + } + }; + later.start(); + } + + ////////////////////////////////////////////////////////////// diff --git a/android/core/src/processing/core/PConstants.java b/android/core/src/processing/core/PConstants.java index 7928fac9d..c779efb6b 100644 --- a/android/core/src/processing/core/PConstants.java +++ b/android/core/src/processing/core/PConstants.java @@ -444,15 +444,18 @@ public interface PConstants { static final int CODED = 0xffff; // key will be CODED and keyCode will be this value -// static final int UP = KeyEvent.VK_UP; -// static final int DOWN = KeyEvent.VK_DOWN; -// static final int LEFT = KeyEvent.VK_LEFT; -// static final int RIGHT = KeyEvent.VK_RIGHT; static final int UP = KeyEvent.KEYCODE_DPAD_UP; static final int DOWN = KeyEvent.KEYCODE_DPAD_DOWN; static final int LEFT = KeyEvent.KEYCODE_DPAD_LEFT; static final int RIGHT = KeyEvent.KEYCODE_DPAD_RIGHT; + // These seem essential for most sketches, so they're included. + // Others can be found in the KeyEvent reference: + // http://developer.android.com/reference/android/view/KeyEvent.html + static final int BACK = KeyEvent.KEYCODE_BACK; + static final int MENU = KeyEvent.KEYCODE_MENU; + static final int DPAD = KeyEvent.KEYCODE_DPAD_CENTER; + // key will be CODED and keyCode will be this value // static final int ALT = KeyEvent.VK_ALT; diff --git a/android/core/src/processing/core/PFont.java b/android/core/src/processing/core/PFont.java index 7df872f62..a2a34a33d 100644 --- a/android/core/src/processing/core/PFont.java +++ b/android/core/src/processing/core/PFont.java @@ -265,7 +265,6 @@ public class PFont implements PConstants { descent = PApplet.round(lazyPaint.descent()); } } - PApplet.println("ascent/descent = " + ascent + " " + descent); } diff --git a/android/core/src/processing/core/PGraphics.java b/android/core/src/processing/core/PGraphics.java index 87ec51421..fb756d078 100644 --- a/android/core/src/processing/core/PGraphics.java +++ b/android/core/src/processing/core/PGraphics.java @@ -2467,7 +2467,6 @@ public class PGraphics extends PImage implements PConstants { } */ textSize(which.size); - PApplet.println("size should be " + which.size); } else { throw new RuntimeException(ERROR_TEXTFONT_NULL_PFONT); diff --git a/android/todo.txt b/android/todo.txt index 7494bd7fd..49b472a72 100644 --- a/android/todo.txt +++ b/android/todo.txt @@ -29,6 +29,20 @@ X http://code.google.com/p/processing/issues/detail?id=221 X change skewX/Y to shearX/Y _ need updated reference for this +http://developer.android.com/reference/android/view/KeyEvent.html +key == KeyEvent.KEYCODE_BACK (why not keyCode?) + +included +KEYCODE_MENU +KEYCODE_BACK +KEYCODE_DPAD_CENTER --> DPAD? + +not included +KEYCODE_VOLUME_DOWN +KEYCODE_VOLUME_UP +KEYCODE_CAMERA +KEYCODE_HOME + P1 _ exceptions with StreamPump and adb devices on osx and linux P1 _ http://dev.processing.org/bugs/show_bug.cgi?id=1545 P1 _ http://dev.processing.org/bugs/show_bug.cgi?id=1527 @@ -43,8 +57,14 @@ P3 _ example sketch added to bug report P3 _ http://dev.processing.org/bugs/show_bug.cgi?id=1472 P3 _ http://code.google.com/p/processing/issues/detail?id=232 +_ seems to have problems on 64-bit windows +_ removing local version of java helped someone fix it + _ remove 'import processing.opengl.*' in the preprocessor? +_ may need to add screen orientation as a built-in function +_ fairly common to use, and otherwise needs an obscure import + _ additional manifest gui necessary: _ icons are apparently important _ android:icon and android:label in @@ -333,6 +353,9 @@ _ or programmatically specify: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); +get the dpi of the screen +http://developer.android.com/reference/android/util/DisplayMetrics.html + _ show/hide the virtual keyboard InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); diff --git a/android/tool/src/processing/app/tools/android/Manifest.java b/android/tool/src/processing/app/tools/android/Manifest.java index 4959298c8..0ac8d077d 100644 --- a/android/tool/src/processing/app/tools/android/Manifest.java +++ b/android/tool/src/processing/app/tools/android/Manifest.java @@ -133,8 +133,15 @@ public class Manifest { writer.println(""); + // for now including this... we're wiring to a particular SDK version anyway... writer.println(" "); // writer.println(" "); // insert sdk version