Skip to content

Commit fdf4955

Browse files
committed
updated sensor examples
1 parent 151f373 commit fdf4955

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

examples/Sensors/Accelerometer/Accelerometer.pde

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ public void accelerationEvent(float x, float y, float z) {
4646
ay = y;
4747
az = z;
4848
redraw();
49-
}
49+
}

examples/Sensors/Accelerometer/AccelerometerManager.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import processing.core.PApplet;
2+
13
import java.lang.reflect.*;
24
import java.util.List;
35

@@ -32,11 +34,12 @@ public class AccelerometerManager {
3234
/** indicates whether or not Accelerometer Sensor is running */
3335
private boolean running = false;
3436

35-
Context context;
36-
37+
PApplet parent;
38+
Context context;
3739

38-
public AccelerometerManager(Context parent) {
39-
this.context = parent;
40+
public AccelerometerManager(PApplet parent) {
41+
this.parent = parent;
42+
this.context = parent.getActivity();
4043

4144
try {
4245
shakeEventMethod =
@@ -57,8 +60,8 @@ public AccelerometerManager(Context parent) {
5760
}
5861

5962

60-
public AccelerometerManager(Context context, int threshold, int interval) {
61-
this(context);
63+
public AccelerometerManager(PApplet parent, int threshold, int interval) {
64+
this(parent);
6265
this.threshold = threshold;
6366
this.interval = interval;
6467
}
@@ -211,7 +214,7 @@ public void onSensorChanged(SensorEvent event) {
211214
// listener.onShake(force);
212215
if (shakeEventMethod != null) {
213216
try {
214-
shakeEventMethod.invoke(context, new Object[] { new Float(force) });
217+
shakeEventMethod.invoke(parent, new Object[] { new Float(force) });
215218
} catch (Exception e) {
216219
e.printStackTrace();
217220
shakeEventMethod = null;
@@ -230,13 +233,12 @@ public void onSensorChanged(SensorEvent event) {
230233
// listener.onAccelerationChanged(x, y, z);
231234
if (accelerationEventMethod != null) {
232235
try {
233-
accelerationEventMethod.invoke(context, new Object[] { x, y, z });
236+
accelerationEventMethod.invoke(parent, new Object[] { x, y, z });
234237
} catch (Exception e) {
235238
e.printStackTrace();
236239
accelerationEventMethod = null;
237240
}
238241
}
239242
}
240243
};
241-
}
242-
244+
}

examples/Sensors/Compass/CompassManager.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import processing.core.PApplet;
2+
13
import java.lang.reflect.*;
24
import java.util.List;
35

@@ -18,11 +20,12 @@ public class CompassManager {
1820
private Boolean supported;
1921
private boolean running = false;
2022

23+
PApplet parent;
2124
Context context;
22-
23-
24-
public CompassManager(Context parent) {
25-
this.context = parent;
25+
26+
public CompassManager(PApplet parent) {
27+
this.parent = parent;
28+
this.context = parent.getActivity();
2629

2730
try {
2831
compassEventMethod =
@@ -118,7 +121,7 @@ public void onSensorChanged(SensorEvent event) {
118121

119122
if (compassEventMethod != null) {
120123
try {
121-
compassEventMethod.invoke(context, new Object[] { x, y, z });
124+
compassEventMethod.invoke(parent, new Object[] { x, y, z });
122125
} catch (Exception e) {
123126
e.printStackTrace();
124127
compassEventMethod = null;
@@ -127,13 +130,12 @@ public void onSensorChanged(SensorEvent event) {
127130

128131
if (directionEventMethod != null) {
129132
try {
130-
directionEventMethod.invoke(context, new Object[] { (float) (-x * Math.PI / 180) });
133+
directionEventMethod.invoke(parent, new Object[] { (float) (-x * Math.PI / 180) });
131134
} catch (Exception e) {
132135
e.printStackTrace();
133136
directionEventMethod = null;
134137
}
135138
}
136139
}
137140
};
138-
}
139-
141+
}

0 commit comments

Comments
 (0)