mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
add a couple examples, organizing todo
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
AccelerometerManager accel;
|
||||
float ax, ay, az;
|
||||
|
||||
|
||||
void setup() {
|
||||
accel = new AccelerometerManager(this);
|
||||
orientation(PORTRAIT);
|
||||
noLoop();
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
fill(255);
|
||||
textSize(70);
|
||||
textAlign(CENTER, CENTER);
|
||||
text("x: " + nf(ax, 1, 2) + "\n" +
|
||||
"y: " + nf(ay, 1, 2) + "\n" +
|
||||
"z: " + nf(az, 1, 2),
|
||||
0, 0, width, height);
|
||||
}
|
||||
|
||||
|
||||
public void resume() {
|
||||
if (accel != null) {
|
||||
accel.resume();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void pause() {
|
||||
if (accel != null) {
|
||||
accel.pause();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void shakeEvent(float force) {
|
||||
println("shake : " + force);
|
||||
}
|
||||
|
||||
|
||||
public void accelerationEvent(float x, float y, float z) {
|
||||
// println("acceleration: " + x + ", " + y + ", " + z);
|
||||
ax = x;
|
||||
ay = y;
|
||||
az = z;
|
||||
redraw();
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
import java.lang.reflect.*;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
|
||||
|
||||
/**
|
||||
* Android Accelerometer Sensor Manager Archetype
|
||||
* @author antoine vianey
|
||||
* under GPL v3 : http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*/
|
||||
public class AccelerometerManager {
|
||||
/** Accuracy configuration */
|
||||
private float threshold = 0.2f;
|
||||
private int interval = 1000;
|
||||
|
||||
private Sensor sensor;
|
||||
private SensorManager sensorManager;
|
||||
// you could use an OrientationListener array instead
|
||||
// if you plans to use more than one listener
|
||||
// private AccelerometerListener listener;
|
||||
|
||||
Method shakeEventMethod;
|
||||
Method accelerationEventMethod;
|
||||
|
||||
/** indicates whether or not Accelerometer Sensor is supported */
|
||||
private Boolean supported;
|
||||
/** indicates whether or not Accelerometer Sensor is running */
|
||||
private boolean running = false;
|
||||
|
||||
Context context;
|
||||
|
||||
|
||||
public AccelerometerManager(Context parent) {
|
||||
this.context = parent;
|
||||
|
||||
try {
|
||||
shakeEventMethod =
|
||||
parent.getClass().getMethod("shakeEvent", new Class[] { Float.TYPE });
|
||||
} catch (Exception e) {
|
||||
// no such method, or an error.. which is fine, just ignore
|
||||
}
|
||||
|
||||
try {
|
||||
accelerationEventMethod =
|
||||
parent.getClass().getMethod("accelerationEvent", new Class[] { Float.TYPE, Float.TYPE, Float.TYPE });
|
||||
} catch (Exception e) {
|
||||
// no such method, or an error.. which is fine, just ignore
|
||||
}
|
||||
// System.out.println("shakeEventMethod is " + shakeEventMethod);
|
||||
// System.out.println("accelerationEventMethod is " + accelerationEventMethod);
|
||||
resume();
|
||||
}
|
||||
|
||||
|
||||
public AccelerometerManager(Context context, int threshold, int interval) {
|
||||
this(context);
|
||||
this.threshold = threshold;
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
|
||||
public void resume() {
|
||||
if (isSupported()) {
|
||||
startListening();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void pause() {
|
||||
if (isListening()) {
|
||||
stopListening();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the manager is listening to orientation changes
|
||||
*/
|
||||
public boolean isListening() {
|
||||
return running;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unregisters listeners
|
||||
*/
|
||||
public void stopListening() {
|
||||
running = false;
|
||||
try {
|
||||
if (sensorManager != null && sensorEventListener != null) {
|
||||
sensorManager.unregisterListener(sensorEventListener);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if at least one Accelerometer sensor is available
|
||||
*/
|
||||
public boolean isSupported() {
|
||||
if (supported == null) {
|
||||
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||
List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
|
||||
supported = new Boolean(sensors.size() > 0);
|
||||
}
|
||||
return supported;
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * Configure the listener for shaking
|
||||
// * @param threshold
|
||||
// * minimum acceleration variation for considering shaking
|
||||
// * @param interval
|
||||
// * minimum interval between to shake events
|
||||
// */
|
||||
// public static void configure(int threshold, int interval) {
|
||||
// AccelerometerManager.threshold = threshold;
|
||||
// AccelerometerManager.interval = interval;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Registers a listener and start listening
|
||||
* @param accelerometerListener callback for accelerometer events
|
||||
*/
|
||||
public void startListening() {
|
||||
// AccelerometerListener accelerometerListener = (AccelerometerListener) context;
|
||||
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||
List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
|
||||
if (sensors.size() > 0) {
|
||||
sensor = sensors.get(0);
|
||||
running = sensorManager.registerListener(sensorEventListener, sensor, SensorManager.SENSOR_DELAY_GAME);
|
||||
// listener = accelerometerListener;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * Configures threshold and interval
|
||||
// * And registers a listener and start listening
|
||||
// * @param accelerometerListener
|
||||
// * callback for accelerometer events
|
||||
// * @param threshold
|
||||
// * minimum acceleration variation for considering shaking
|
||||
// * @param interval
|
||||
// * minimum interval between to shake events
|
||||
// */
|
||||
// public void startListening(int threshold, int interval) {
|
||||
// configure(threshold, interval);
|
||||
// startListening();
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* The listener that listen to events from the accelerometer listener
|
||||
*/
|
||||
//private static SensorEventListener sensorEventListener = new SensorEventListener() {
|
||||
private SensorEventListener sensorEventListener = new SensorEventListener() {
|
||||
private long now = 0;
|
||||
private long timeDiff = 0;
|
||||
private long lastUpdate = 0;
|
||||
private long lastShake = 0;
|
||||
|
||||
private float x = 0;
|
||||
private float y = 0;
|
||||
private float z = 0;
|
||||
private float lastX = 0;
|
||||
private float lastY = 0;
|
||||
private float lastZ = 0;
|
||||
private float force = 0;
|
||||
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
}
|
||||
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
// use the event timestamp as reference
|
||||
// so the manager precision won't depends
|
||||
// on the AccelerometerListener implementation
|
||||
// processing time
|
||||
now = event.timestamp;
|
||||
|
||||
x = event.values[0];
|
||||
y = event.values[1];
|
||||
z = event.values[2];
|
||||
|
||||
// if not interesting in shake events
|
||||
// just remove the whole if then else bloc
|
||||
if (lastUpdate == 0) {
|
||||
lastUpdate = now;
|
||||
lastShake = now;
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
lastZ = z;
|
||||
|
||||
} else {
|
||||
timeDiff = now - lastUpdate;
|
||||
if (timeDiff > 0) {
|
||||
force = Math.abs(x + y + z - lastX - lastY - lastZ)
|
||||
/ timeDiff;
|
||||
if (force > threshold) {
|
||||
if (now - lastShake >= interval) {
|
||||
// trigger shake event
|
||||
// listener.onShake(force);
|
||||
if (shakeEventMethod != null) {
|
||||
try {
|
||||
shakeEventMethod.invoke(context, new Object[] { new Float(force) });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
shakeEventMethod = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
lastShake = now;
|
||||
}
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
lastZ = z;
|
||||
lastUpdate = now;
|
||||
}
|
||||
}
|
||||
// trigger change event
|
||||
// listener.onAccelerationChanged(x, y, z);
|
||||
if (accelerationEventMethod != null) {
|
||||
try {
|
||||
accelerationEventMethod.invoke(context, new Object[] { x, y, z });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
accelerationEventMethod = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
CompassManager compass;
|
||||
float direction;
|
||||
|
||||
|
||||
void setup() {
|
||||
compass = new CompassManager(this);
|
||||
}
|
||||
|
||||
|
||||
void pause() {
|
||||
if (compass != null) compass.pause();
|
||||
}
|
||||
|
||||
|
||||
void resume() {
|
||||
if (compass != null) compass.resume();
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
fill(192, 0, 0);
|
||||
noStroke();
|
||||
|
||||
translate(width/2, height/2);
|
||||
scale(2);
|
||||
rotate(direction);
|
||||
beginShape();
|
||||
vertex(0, -50);
|
||||
vertex(-20, 60);
|
||||
vertex(0, 50);
|
||||
vertex(20, 60);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
|
||||
|
||||
void directionEvent(float newDirection) {
|
||||
direction = newDirection;
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import java.lang.reflect.*;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
|
||||
|
||||
public class CompassManager {
|
||||
private Sensor sensor;
|
||||
private SensorManager sensorManager;
|
||||
|
||||
Method compassEventMethod;
|
||||
Method directionEventMethod;
|
||||
|
||||
private Boolean supported;
|
||||
private boolean running = false;
|
||||
|
||||
Context context;
|
||||
|
||||
|
||||
public CompassManager(Context parent) {
|
||||
this.context = parent;
|
||||
|
||||
try {
|
||||
compassEventMethod =
|
||||
parent.getClass().getMethod("compassEvent", new Class[] { Float.TYPE, Float.TYPE, Float.TYPE });
|
||||
} catch (Exception e) {
|
||||
// no such method, or an error.. which is fine, just ignore
|
||||
}
|
||||
try {
|
||||
directionEventMethod =
|
||||
parent.getClass().getMethod("directionEvent", new Class[] { Float.TYPE });
|
||||
} catch (Exception e) {
|
||||
// no such method, or an error.. which is fine, just ignore
|
||||
}
|
||||
// System.out.println("directionEventMethod is " + directionEventMethod);
|
||||
|
||||
resume();
|
||||
}
|
||||
|
||||
|
||||
public void resume() {
|
||||
if (isSupported()) {
|
||||
startListening();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void pause() {
|
||||
if (isListening()) {
|
||||
stopListening();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the manager is listening to orientation changes
|
||||
*/
|
||||
public boolean isListening() {
|
||||
return running;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unregisters listeners
|
||||
*/
|
||||
public void stopListening() {
|
||||
running = false;
|
||||
try {
|
||||
if (sensorManager != null && sensorEventListener != null) {
|
||||
sensorManager.unregisterListener(sensorEventListener);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if at least one Accelerometer sensor is available
|
||||
*/
|
||||
public boolean isSupported() {
|
||||
if (supported == null) {
|
||||
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||
List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
|
||||
supported = new Boolean(sensors.size() > 0);
|
||||
}
|
||||
return supported;
|
||||
}
|
||||
|
||||
|
||||
public void startListening() {
|
||||
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||
List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
|
||||
if (sensors.size() > 0) {
|
||||
sensor = sensors.get(0);
|
||||
running = sensorManager.registerListener(sensorEventListener, sensor, SensorManager.SENSOR_DELAY_GAME);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The listener that listen to events from the accelerometer listener
|
||||
*/
|
||||
private SensorEventListener sensorEventListener = new SensorEventListener() {
|
||||
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
// ignored for now
|
||||
}
|
||||
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
float x = event.values[0];
|
||||
float y = event.values[1];
|
||||
float z = event.values[2];
|
||||
|
||||
if (compassEventMethod != null) {
|
||||
try {
|
||||
compassEventMethod.invoke(context, new Object[] { x, y, z });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
compassEventMethod = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (directionEventMethod != null) {
|
||||
try {
|
||||
directionEventMethod.invoke(context, new Object[] { (float) (-x * Math.PI / 180) });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
directionEventMethod = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+32
-33
@@ -11,17 +11,38 @@ X http://forum.processing.org/topic/ant-rules-r3-xml-209-395-error#25080000000
|
||||
X just delete ~/.android/debug.keystore
|
||||
X .java files are reported with Syntax Error with the Android build 0191
|
||||
X http://code.google.com/p/processing/issues/detail?id=404
|
||||
X implement mode switching for android/java/etc
|
||||
X save state re: whether sketches are android or java mode (or others?)
|
||||
X http://dev.processing.org/bugs/show_bug.cgi?id=1380
|
||||
X http://code.google.com/p/processing/issues/detail?id=202
|
||||
X android mode is currently per-editor (and clunky)
|
||||
X http://dev.processing.org/bugs/show_bug.cgi?id=1379
|
||||
X http://code.google.com/p/processing/issues/detail?id=201
|
||||
|
||||
_ pause/resume trickiness with interactive apps
|
||||
_ can we serialize objects (even if slow?)
|
||||
_ add pause() and resume() methods to PApplet
|
||||
_ register(this, "pause") -> libs will need pause events on android
|
||||
_ add registered methods again
|
||||
_ need to figure out generic event queueing first
|
||||
_ may need a different subset of methods, and introduce new ones
|
||||
_ that will be usable on both android and desktop
|
||||
_ dispose() was calling disposeMethods.handle(), but they're null
|
||||
_ possible major issue with sketches not quitting out of run() when in bg
|
||||
_ pause needs to actually kill the thread
|
||||
_ returning from pause needs to reset the clock
|
||||
_ this is currently draining batteries
|
||||
_ thread is continually running - 'inside handleDraw()' running continually
|
||||
_ inside run() it shouldn't still be going
|
||||
|
||||
_ need sizeChanged() method...
|
||||
_ also add the param to the xml file saying that it can deal w/ rotation
|
||||
|
||||
_ when returning to android application, sometimes screen stays black
|
||||
_ http://code.google.com/p/processing/issues/detail?id=237
|
||||
Here's what is happening with the A2D renderer. When the user hits the home button, the Android framework calls PApplet.surfaceDestroyed(), which recycles the drawing surface by calling PGraphicsAndroid2D.dispose(). The surface is never recreated. The code path in PApplet.handleDraw() that reallocates the surface by calling PGraphicsAndroid2D.setSize() is missed because the dimensions of the sketch have not changed.
|
||||
Removing "bitmap.recycle()" from PGraphicsAndroid2D.dispose() fixes the problem.
|
||||
|
||||
_ need sizeChanged() method...
|
||||
_ also add the param to the xml file saying that it can deal w/ rotation
|
||||
|
||||
mess
|
||||
X implement mode switching for android/java/etc
|
||||
_ check out andres' changes for PShape
|
||||
_ ctrl-shift-r (run on device) is totally hosed
|
||||
adb devices
|
||||
@@ -32,17 +53,10 @@ adb devices
|
||||
error: protocol fault (no status)
|
||||
_ re: android libraries, from shawn van every
|
||||
The most powerful part were the libraries (and the ease with which they could be developed). Location, SMS, Camera/Video, Bluetooth (for Arduino integration) and PClient/PRequest were by far the most used. The ones that came with it, plus the ones from MJSoft were good though I ended up making a couple of very specific ones for my students: http://www.mobvcasting.com/wp/?cat=4
|
||||
_ adb -s HT91MLC00031 install -r sketchbook/Hue/android/bin/Hue-debug.apk
|
||||
_ pkg: /data/local/tmp/Hue-debug.apk
|
||||
_ Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]
|
||||
_ why does this result return 0?
|
||||
_ separate activity and view
|
||||
_ process trackball events (they're only deltas)
|
||||
_ handle repeat key events
|
||||
_ implement link()
|
||||
_ pause/resume trickiness with interactive apps
|
||||
_ can we serialize objects (even if slow?)
|
||||
_ add pause() and resume() methods to PApplet
|
||||
_ need to post android examples
|
||||
|
||||
_ try using the internal javac on windows and see if exceptions come through..
|
||||
@@ -80,16 +94,6 @@ _ need to do something to make it easier to do new screen sizes.
|
||||
_ sketches must be removed manually if the debug keystore changes
|
||||
_ http://code.google.com/p/processing/issues/detail?id=236
|
||||
|
||||
_ register(this, "pause") -> libs will need pause events on android
|
||||
_ add registered methods again
|
||||
_ need to figure out generic event queueing first
|
||||
_ may need a different subset of methods, and introduce new ones
|
||||
_ that will be usable on both android and desktop
|
||||
_ dispose() was calling disposeMethods.handle(), but they're null
|
||||
|
||||
_ thread is continually running - 'inside handleDraw()' running continually
|
||||
_ inside run() it shouldn't still be going
|
||||
|
||||
_ Error 336 Can't run any sketch.
|
||||
_ http://code.google.com/p/processing/issues/detail?id=393
|
||||
_ javac.exe not included with the download
|
||||
@@ -187,11 +191,6 @@ _ removing local version of java helped someone fix it
|
||||
_ don't let the keystore message show up in red
|
||||
_ Using keystore: /Users/fry/.android/debug.keystore
|
||||
|
||||
_ possible major issue with sketches not quitting out of run() when in bg
|
||||
_ pause needs to actually kill the thread
|
||||
_ returning from pause needs to reset the clock
|
||||
_ this is currently draining batteries
|
||||
|
||||
X look into touch event code, see if there's a good way to integrate
|
||||
_ make a decision on how to integrate touch event code
|
||||
|
||||
@@ -300,13 +299,9 @@ W/System.err( 242): at processing.core.PApplet.createOutput(PApplet.java:3677)
|
||||
|
||||
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
|
||||
P2 _ http://code.google.com/p/processing/issues/detail?id=206
|
||||
P2 _ implement method for selecting the AVD
|
||||
P2 _ http://dev.processing.org/bugs/show_bug.cgi?id=1390
|
||||
P2 _ android mode is currently per-editor (and clunky)
|
||||
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
|
||||
|
||||
DM _ compiler errors on Windows not appearing, nor highlighting the line number
|
||||
DM _ http://code.google.com/p/processing/issues/detail?id=253
|
||||
@@ -319,7 +314,11 @@ P3 _ --> implement selector to choose the default device for debugging
|
||||
P3 _ http://dev.processing.org/bugs/show_bug.cgi?id=1389
|
||||
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 _ adb -s HT91MLC00031 install -r sketchbook/Hue/android/bin/Hue-debug.apk
|
||||
P3 _ pkg: /data/local/tmp/Hue-debug.apk
|
||||
P3 _ Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]
|
||||
P3 _ why does this result return 0?
|
||||
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?
|
||||
|
||||
Reference in New Issue
Block a user