Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 16af7145da60d6b9e8703e11f6714f68f3d6d65f Johan committed Jul 13, 2011
Showing with 1,975 additions and 0 deletions.
  1. BIN .DS_Store
  2. +242 −0 AccelerometerManager.java
  3. +23 −0 AndroidManifest.xml
  4. +140 −0 CompassManager.java
  5. +14 −0 android.110711.0041/AndroidManifest.xml
  6. BIN android.110711.0041/bin/classes.dex
  7. BIN android.110711.0041/bin/classes/processing/android/test/gps_example/R$attr.class
  8. BIN android.110711.0041/bin/classes/processing/android/test/gps_example/R$drawable.class
  9. BIN android.110711.0041/bin/classes/processing/android/test/gps_example/R$layout.class
  10. BIN android.110711.0041/bin/classes/processing/android/test/gps_example/R.class
  11. BIN ....110711.0041/bin/classes/processing/android/test/gps_example/gps_example$MyLocationListener.class
  12. BIN android.110711.0041/bin/classes/processing/android/test/gps_example/gps_example.class
  13. BIN android.110711.0041/bin/gps_example-debug-unaligned.apk
  14. BIN android.110711.0041/bin/gps_example-debug.apk
  15. BIN android.110711.0041/bin/gps_example.ap_
  16. +1 −0 android.110711.0041/build.properties
  17. +17 −0 android.110711.0041/build.xml
  18. +1 −0 android.110711.0041/default.properties
  19. +19 −0 android.110711.0041/gen/processing/android/test/gps_example/R.java
  20. BIN android.110711.0041/libs/processing-core.jar
  21. +1 −0 android.110711.0041/local.properties
  22. BIN android.110711.0041/res/drawable-hdpi/icon.png
  23. BIN android.110711.0041/res/drawable-ldpi/icon.png
  24. BIN android.110711.0041/res/drawable/icon.png
  25. +6 −0 android.110711.0041/res/layout/main.xml
  26. +112 −0 android.110711.0041/src/processing/android/test/gps_example/gps_example.java
  27. +23 −0 android/AndroidManifest.xml
  28. BIN android/assets/helpmefindmytwin01.wav
  29. BIN android/assets/helpmefindmytwin02.wav
  30. BIN android/assets/noise.wav
  31. BIN android/assets/old/findmytwin.wav
  32. BIN android/assets/old/pickmeup.wav
  33. BIN android/assets/old/thankyou.wav
  34. BIN android/assets/pleasepickmeup01.wav
  35. BIN android/assets/pleasepickmeup02.wav
  36. BIN android/assets/pleasepickmeup03.wav
  37. BIN android/assets/pleasepickmeup04.wav
  38. BIN android/assets/pleasepickmeup05.wav
  39. BIN android/assets/rightdirection01.wav
  40. BIN android/assets/rightdirection02.wav
  41. BIN android/assets/rightdirection03.wav
  42. BIN android/assets/rightdirection04.wav
  43. BIN android/assets/thankyou01.wav
  44. BIN android/assets/wrongdirection01.wav
  45. BIN android/bin/classes.dex
  46. BIN android/bin/classes/processing/android/test/mystbox2/AccelerometerManager$1.class
  47. BIN android/bin/classes/processing/android/test/mystbox2/AccelerometerManager.class
  48. BIN android/bin/classes/processing/android/test/mystbox2/CompassManager$1.class
  49. BIN android/bin/classes/processing/android/test/mystbox2/CompassManager.class
  50. BIN android/bin/classes/processing/android/test/mystbox2/R$attr.class
  51. BIN android/bin/classes/processing/android/test/mystbox2/R$drawable.class
  52. BIN android/bin/classes/processing/android/test/mystbox2/R$layout.class
  53. BIN android/bin/classes/processing/android/test/mystbox2/R.class
  54. BIN android/bin/classes/processing/android/test/mystbox2/mystbox2$Ball.class
  55. BIN android/bin/classes/processing/android/test/mystbox2/mystbox2$MyLocationListener.class
  56. BIN android/bin/classes/processing/android/test/mystbox2/mystbox2.class
  57. BIN android/bin/mystbox2-debug-unaligned.apk
  58. BIN android/bin/mystbox2-debug.apk
  59. BIN android/bin/mystbox2.ap_
  60. +1 −0 android/build.properties
  61. +17 −0 android/build.xml
  62. +1 −0 android/default.properties
  63. +19 −0 android/gen/processing/android/test/mystbox2/R.java
  64. BIN android/libs/apwidgets.jar
  65. BIN android/libs/processing-core.jar
  66. +1 −0 android/local.properties
  67. BIN android/res/drawable-hdpi/icon.png
  68. BIN android/res/drawable-ldpi/icon.png
  69. BIN android/res/drawable/icon.png
  70. +6 −0 android/res/layout/main.xml
  71. +242 −0 android/src/processing/android/test/mystbox2/AccelerometerManager.java
  72. +140 −0 android/src/processing/android/test/mystbox2/CompassManager.java
  73. +463 −0 android/src/processing/android/test/mystbox2/mystbox2.java
  74. +50 −0 ball.pde
  75. BIN code/apwidgets.jar
  76. BIN data/helpmefindmytwin01.wav
  77. BIN data/helpmefindmytwin02.wav
  78. BIN data/noise.wav
  79. BIN data/old/findmytwin.wav
  80. BIN data/old/pickmeup.wav
  81. BIN data/old/thankyou.wav
  82. BIN data/pleasepickmeup01.wav
  83. BIN data/pleasepickmeup02.wav
  84. BIN data/pleasepickmeup03.wav
  85. BIN data/pleasepickmeup04.wav
  86. BIN data/pleasepickmeup05.wav
  87. BIN data/rightdirection01.wav
  88. BIN data/rightdirection02.wav
  89. BIN data/rightdirection03.wav
  90. BIN data/rightdirection04.wav
  91. BIN data/thankyou01.wav
  92. BIN data/wrongdirection01.wav
  93. +392 −0 mystbox2.pde
  94. +44 −0 twin.pde
Binary file not shown.
@@ -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,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="">
+ <uses-sdk android:minSdkVersion="7"/>
+ <application android:debuggable="true" android:icon="@drawable/icon" android:label="">
+ <activity android:name="">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+ <uses-permission android:name="android.permission.HARDWARE_TEST"/>
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
+ <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
+ <uses-permission android:name="android.permission.READ_OWNER_DATA"/>
+ <uses-permission android:name="android.permission.WAKE_LOCK"/>
+ <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
+</manifest>
Oops, something went wrong.

0 comments on commit 16af714

Please sign in to comment.