-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathSensorManagerModule.java
More file actions
188 lines (157 loc) · 4.86 KB
/
SensorManagerModule.java
File metadata and controls
188 lines (157 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package com.sensormanager;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import android.util.Log;
public class SensorManagerModule extends ReactContextBaseJavaModule {
private static final String REACT_CLASS = "SensorManager";
private AccelerometerRecord mAccelerometerRecord = null;
private GyroscopeRecord mGyroscopeRecord = null;
private MagnetometerRecord mMagnetometerRecord = null;
private StepCounterRecord mStepCounterRecord = null;
private ThermometerRecord mThermometerRecord = null;
private MotionValueRecord mMotionValueRecord = null;
private OrientationRecord mOrientationRecord = null;
private ProximityRecord mProximityRecord = null;
private LightSensorRecord mLightSensorRecord = null;
private GravityRecord mGravityRecord = null;
private ReactApplicationContext mReactContext;
@Override
public String getName() {
return REACT_CLASS;
}
public SensorManagerModule(ReactApplicationContext reactContext) {
super(reactContext);
mReactContext = reactContext;
}
@ReactMethod
public int startAccelerometer(int delay) {
if (mAccelerometerRecord == null)
mAccelerometerRecord = new AccelerometerRecord(mReactContext);
return (mAccelerometerRecord.start(delay));
}
@ReactMethod
public void stopAccelerometer() {
if (mAccelerometerRecord != null)
mAccelerometerRecord.stop();
}
@ReactMethod
public int startGyroscope(int delay) {
if (mGyroscopeRecord == null)
mGyroscopeRecord = new GyroscopeRecord(mReactContext);
return (mGyroscopeRecord.start(delay));
}
@ReactMethod
public void stopGyroscope() {
if (mGyroscopeRecord != null)
mGyroscopeRecord.stop();
}
@ReactMethod
public int startMagnetometer(int delay) {
if (mMagnetometerRecord == null)
mMagnetometerRecord = new MagnetometerRecord(mReactContext);
return (mMagnetometerRecord.start(delay));
}
@ReactMethod
public void stopMagnetometer() {
if (mMagnetometerRecord != null)
mMagnetometerRecord.stop();
}
@ReactMethod
public int startStepCounter(int delay) {
if (mStepCounterRecord == null)
mStepCounterRecord = new StepCounterRecord(mReactContext);
return (mStepCounterRecord.start(delay));
}
@ReactMethod
public void stopStepCounter() {
if (mStepCounterRecord != null)
mStepCounterRecord.stop();
}
@ReactMethod
public int startThermometer(int delay) {
if (mThermometerRecord == null)
mThermometerRecord = new ThermometerRecord(mReactContext);
return (mThermometerRecord.start(delay));
}
@ReactMethod
public void stopThermometer() {
if (mThermometerRecord != null)
mThermometerRecord.stop();
}
@ReactMethod
public int startMotionValue(int delay) {
if (mMotionValueRecord == null)
mMotionValueRecord = new MotionValueRecord(mReactContext);
return (mMotionValueRecord.start(delay));
}
@ReactMethod
public void stopMotionValue() {
if (mMotionValueRecord != null)
mMotionValueRecord.stop();
}
@ReactMethod
public int startOrientation(int delay) {
if (mOrientationRecord == null)
mOrientationRecord = new OrientationRecord(mReactContext);
return (mOrientationRecord.start(delay));
}
@ReactMethod
public void stopOrientation() {
if (mOrientationRecord != null)
mOrientationRecord.stop();
}
@ReactMethod
public int startProximity(int delay) {
if (mProximityRecord == null)
mProximityRecord = new ProximityRecord(mReactContext);
return (mProximityRecord.start(delay));
}
@ReactMethod
public void stopProximity() {
if (mProximityRecord != null)
mProximityRecord.stop();
}
@ReactMethod
public int startLightSensor(int delay) {
if(mLightSensorRecord == null)
mLightSensorRecord = new LightSensorRecord(mReactContext);
return (mLightSensorRecord.start(delay));
}
@ReactMethod
public void stopLightSensor() {
if(mLightSensorRecord != null)
mLightSensorRecord.stop();
}
@ReactMethod
public int startGravity(int delay) {
if (mGravityRecord == null)
mGravityRecord = new GravityRecord(mReactContext);
return (mGravityRecord.start(delay));
}
@ReactMethod
public void stopGravity() {
if (mGravityRecord != null)
mGravityRecord.stop();
}
/*
@Override
public ReactBarcodeScannerView createViewInstance(ThemedReactContext context) {
}
@Override
public void onDropViewInstance(ReactBarcodeScannerView view) {
}
@Override
public void onHostResume() {
}
@Override
public void onHostPause() {
}
@Override
public void onHostDestroy() {
}
*/
}