@capawesome/capacitor-gyroscope 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CapawesomeCapacitorGyroscope.podspec +17 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +28 -0
  4. package/README.md +333 -0
  5. package/android/build.gradle +58 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/Gyroscope.java +97 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/GyroscopePlugin.java +152 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/Measurement.java +28 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/interfaces/Callback.java +5 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/interfaces/EmptyCallback.java +5 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/interfaces/NonEmptyResultCallback.java +7 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/interfaces/Result.java +7 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/results/GetMeasurementResult.java +21 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/results/IsAvailableResult.java +20 -0
  16. package/android/src/main/res/.gitkeep +0 -0
  17. package/dist/docs.json +358 -0
  18. package/dist/esm/definitions.d.ts +112 -0
  19. package/dist/esm/definitions.js +2 -0
  20. package/dist/esm/definitions.js.map +1 -0
  21. package/dist/esm/index.d.ts +4 -0
  22. package/dist/esm/index.js +7 -0
  23. package/dist/esm/index.js.map +1 -0
  24. package/dist/esm/web.d.ts +18 -0
  25. package/dist/esm/web.js +125 -0
  26. package/dist/esm/web.js.map +1 -0
  27. package/dist/plugin.cjs.js +139 -0
  28. package/dist/plugin.cjs.js.map +1 -0
  29. package/dist/plugin.js +142 -0
  30. package/dist/plugin.js.map +1 -0
  31. package/ios/Plugin/Classes/Measurement.swift +24 -0
  32. package/ios/Plugin/Classes/Results/IsAvailableResult.swift +15 -0
  33. package/ios/Plugin/Enums/CustomError.swift +20 -0
  34. package/ios/Plugin/Gyroscope.swift +87 -0
  35. package/ios/Plugin/GyroscopePlugin.swift +116 -0
  36. package/ios/Plugin/Info.plist +24 -0
  37. package/ios/Plugin/Protocols/Result.swift +5 -0
  38. package/package.json +91 -0
@@ -0,0 +1,152 @@
1
+ package io.capawesome.capacitorjs.plugins.gyroscope;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+ import com.getcapacitor.JSObject;
6
+ import com.getcapacitor.Logger;
7
+ import com.getcapacitor.Plugin;
8
+ import com.getcapacitor.PluginCall;
9
+ import com.getcapacitor.PluginMethod;
10
+ import com.getcapacitor.annotation.CapacitorPlugin;
11
+ import io.capawesome.capacitorjs.plugins.gyroscope.classes.Measurement;
12
+ import io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces.EmptyCallback;
13
+ import io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces.NonEmptyResultCallback;
14
+ import io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces.Result;
15
+ import io.capawesome.capacitorjs.plugins.gyroscope.classes.results.GetMeasurementResult;
16
+ import io.capawesome.capacitorjs.plugins.gyroscope.classes.results.IsAvailableResult;
17
+
18
+ @CapacitorPlugin(name = "Gyroscope")
19
+ public class GyroscopePlugin extends Plugin {
20
+
21
+ public static final String ERROR_GYROSCOPE_UNAVAILABLE = "Not available on this device.";
22
+ public static final String ERROR_UNKNOWN_ERROR = "An unknown error has occurred.";
23
+ public static final String EVENT_MEASUREMENT = "measurement";
24
+ public static final String TAG = "GyroscopePlugin";
25
+
26
+ private final Gyroscope implementation = new Gyroscope(this);
27
+
28
+ @PluginMethod
29
+ public void checkPermissions(PluginCall call) {
30
+ JSObject result = new JSObject();
31
+ result.put("gyroscope", "granted");
32
+ call.resolve(result);
33
+ }
34
+
35
+ @PluginMethod
36
+ public void getMeasurement(PluginCall call) {
37
+ try {
38
+ NonEmptyResultCallback<GetMeasurementResult> callback = new NonEmptyResultCallback<>() {
39
+ @Override
40
+ public void success(@NonNull GetMeasurementResult result) {
41
+ resolveCall(call, result);
42
+ }
43
+
44
+ @Override
45
+ public void error(Exception exception) {
46
+ rejectCall(call, exception);
47
+ }
48
+ };
49
+
50
+ implementation.getMeasurement(callback);
51
+ } catch (Exception exception) {
52
+ rejectCall(call, exception);
53
+ }
54
+ }
55
+
56
+ @PluginMethod
57
+ public void isAvailable(PluginCall call) {
58
+ try {
59
+ NonEmptyResultCallback<IsAvailableResult> callback = new NonEmptyResultCallback<>() {
60
+ @Override
61
+ public void success(@NonNull IsAvailableResult result) {
62
+ resolveCall(call, result);
63
+ }
64
+
65
+ @Override
66
+ public void error(Exception exception) {
67
+ rejectCall(call, exception);
68
+ }
69
+ };
70
+
71
+ implementation.isAvailable(callback);
72
+ } catch (Exception exception) {
73
+ rejectCall(call, exception);
74
+ }
75
+ }
76
+
77
+ public void notifyMeasurementEventListeners(@NonNull Measurement measurement) {
78
+ notifyListeners(GyroscopePlugin.EVENT_MEASUREMENT, measurement.toJSObject());
79
+ }
80
+
81
+ @PluginMethod
82
+ public void removeAllListeners(PluginCall call) {
83
+ super.removeAllListeners(call);
84
+ implementation.stopMeasurementUpdates(null);
85
+ }
86
+
87
+ @PluginMethod
88
+ public void requestPermissions(PluginCall call) {
89
+ JSObject result = new JSObject();
90
+ result.put("gyroscope", "granted");
91
+ call.resolve(result);
92
+ }
93
+
94
+ @PluginMethod
95
+ public void startMeasurementUpdates(PluginCall call) {
96
+ try {
97
+ EmptyCallback callback = new EmptyCallback() {
98
+ @Override
99
+ public void success() {
100
+ resolveCall(call, null);
101
+ }
102
+
103
+ @Override
104
+ public void error(Exception exception) {
105
+ rejectCall(call, exception);
106
+ }
107
+ };
108
+
109
+ implementation.startMeasurementUpdates(callback);
110
+ } catch (Exception exception) {
111
+ rejectCall(call, exception);
112
+ }
113
+ }
114
+
115
+ @PluginMethod
116
+ public void stopMeasurementUpdates(PluginCall call) {
117
+ try {
118
+ EmptyCallback callback = new EmptyCallback() {
119
+ @Override
120
+ public void success() {
121
+ resolveCall(call, null);
122
+ }
123
+
124
+ @Override
125
+ public void error(Exception exception) {
126
+ rejectCall(call, exception);
127
+ }
128
+ };
129
+
130
+ implementation.stopMeasurementUpdates(callback);
131
+ } catch (Exception exception) {
132
+ rejectCall(call, exception);
133
+ }
134
+ }
135
+
136
+ private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
137
+ String message = exception.getMessage();
138
+ if (message == null) {
139
+ message = ERROR_UNKNOWN_ERROR;
140
+ }
141
+ Logger.error(TAG, message, exception);
142
+ call.reject(message);
143
+ }
144
+
145
+ private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
146
+ if (result == null) {
147
+ call.resolve();
148
+ } else {
149
+ call.resolve(result.toJSObject());
150
+ }
151
+ }
152
+ }
@@ -0,0 +1,28 @@
1
+ package io.capawesome.capacitorjs.plugins.gyroscope.classes;
2
+
3
+ import android.hardware.SensorEvent;
4
+ import androidx.annotation.NonNull;
5
+ import com.getcapacitor.JSObject;
6
+ import io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces.Result;
7
+
8
+ public class Measurement implements Result {
9
+
10
+ final double x;
11
+ final double y;
12
+ final double z;
13
+
14
+ public Measurement(@NonNull SensorEvent sensorEvent) {
15
+ this.x = Math.round(sensorEvent.values[0] * 100.0) / 100.0;
16
+ this.y = Math.round(sensorEvent.values[1] * 100.0) / 100.0;
17
+ this.z = Math.round(sensorEvent.values[2] * 100.0) / 100.0;
18
+ }
19
+
20
+ @Override
21
+ public JSObject toJSObject() {
22
+ JSObject result = new JSObject();
23
+ result.put("x", x);
24
+ result.put("y", y);
25
+ result.put("z", z);
26
+ return result;
27
+ }
28
+ }
@@ -0,0 +1,5 @@
1
+ package io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces;
2
+
3
+ public interface Callback {
4
+ void error(Exception exception);
5
+ }
@@ -0,0 +1,5 @@
1
+ package io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces;
2
+
3
+ public interface EmptyCallback extends Callback {
4
+ void success();
5
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ public interface NonEmptyResultCallback<T extends Result> extends Callback {
6
+ void success(@NonNull T result);
7
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces;
2
+
3
+ import com.getcapacitor.JSObject;
4
+
5
+ public interface Result {
6
+ JSObject toJSObject();
7
+ }
@@ -0,0 +1,21 @@
1
+ package io.capawesome.capacitorjs.plugins.gyroscope.classes.results;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.gyroscope.classes.Measurement;
6
+ import io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces.Result;
7
+
8
+ public class GetMeasurementResult implements Result {
9
+
10
+ @NonNull
11
+ private final Measurement measurement;
12
+
13
+ public GetMeasurementResult(@NonNull Measurement measurement) {
14
+ this.measurement = measurement;
15
+ }
16
+
17
+ @Override
18
+ public JSObject toJSObject() {
19
+ return measurement.toJSObject();
20
+ }
21
+ }
@@ -0,0 +1,20 @@
1
+ package io.capawesome.capacitorjs.plugins.gyroscope.classes.results;
2
+
3
+ import com.getcapacitor.JSObject;
4
+ import io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces.Result;
5
+
6
+ public class IsAvailableResult implements Result {
7
+
8
+ private final boolean isAvailable;
9
+
10
+ public IsAvailableResult(boolean isAvailable) {
11
+ this.isAvailable = isAvailable;
12
+ }
13
+
14
+ @Override
15
+ public JSObject toJSObject() {
16
+ JSObject result = new JSObject();
17
+ result.put("isAvailable", isAvailable);
18
+ return result;
19
+ }
20
+ }
File without changes
package/dist/docs.json ADDED
@@ -0,0 +1,358 @@
1
+ {
2
+ "api": {
3
+ "name": "GyroscopePlugin",
4
+ "slug": "gyroscopeplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "addListener",
10
+ "signature": "(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>",
11
+ "parameters": [
12
+ {
13
+ "name": "eventName",
14
+ "docs": "",
15
+ "type": "'measurement'"
16
+ },
17
+ {
18
+ "name": "listenerFunc",
19
+ "docs": "",
20
+ "type": "(event: Measurement) => void"
21
+ }
22
+ ],
23
+ "returns": "Promise<PluginListenerHandle>",
24
+ "tags": [
25
+ {
26
+ "name": "since",
27
+ "text": "0.1.0"
28
+ }
29
+ ],
30
+ "docs": "Called when a new measurement is available.\n\nOnly available on Android and iOS.",
31
+ "complexTypes": [
32
+ "PluginListenerHandle",
33
+ "MeasurementEvent"
34
+ ],
35
+ "slug": "addlistenermeasurement-"
36
+ },
37
+ {
38
+ "name": "checkPermissions",
39
+ "signature": "() => Promise<PermissionStatus>",
40
+ "parameters": [],
41
+ "returns": "Promise<PermissionStatus>",
42
+ "tags": [
43
+ {
44
+ "name": "since",
45
+ "text": "0.1.0"
46
+ }
47
+ ],
48
+ "docs": "Check if the app has permission to access the gyroscope sensor.",
49
+ "complexTypes": [
50
+ "PermissionStatus"
51
+ ],
52
+ "slug": "checkpermissions"
53
+ },
54
+ {
55
+ "name": "getMeasurement",
56
+ "signature": "() => Promise<GetMeasurementResult>",
57
+ "parameters": [],
58
+ "returns": "Promise<Measurement>",
59
+ "tags": [
60
+ {
61
+ "name": "since",
62
+ "text": "0.1.0"
63
+ }
64
+ ],
65
+ "docs": "Get the latest measurement.\n\nThis method returns the most recent measurement from the gyroscope sensor.",
66
+ "complexTypes": [
67
+ "Measurement",
68
+ "GetMeasurementResult"
69
+ ],
70
+ "slug": "getmeasurement"
71
+ },
72
+ {
73
+ "name": "isAvailable",
74
+ "signature": "() => Promise<IsAvailableResult>",
75
+ "parameters": [],
76
+ "returns": "Promise<IsAvailableResult>",
77
+ "tags": [
78
+ {
79
+ "name": "since",
80
+ "text": "0.1.0"
81
+ }
82
+ ],
83
+ "docs": "Check if the gyroscope sensor is available on the device.",
84
+ "complexTypes": [
85
+ "IsAvailableResult"
86
+ ],
87
+ "slug": "isavailable"
88
+ },
89
+ {
90
+ "name": "removeAllListeners",
91
+ "signature": "() => Promise<void>",
92
+ "parameters": [],
93
+ "returns": "Promise<void>",
94
+ "tags": [
95
+ {
96
+ "name": "since",
97
+ "text": "0.1.0"
98
+ }
99
+ ],
100
+ "docs": "Remove all listeners for this plugin.",
101
+ "complexTypes": [],
102
+ "slug": "removealllisteners"
103
+ },
104
+ {
105
+ "name": "requestPermissions",
106
+ "signature": "() => Promise<PermissionStatus>",
107
+ "parameters": [],
108
+ "returns": "Promise<PermissionStatus>",
109
+ "tags": [
110
+ {
111
+ "name": "since",
112
+ "text": "0.1.0"
113
+ }
114
+ ],
115
+ "docs": "Request permission to access the gyroscope sensor.",
116
+ "complexTypes": [
117
+ "PermissionStatus"
118
+ ],
119
+ "slug": "requestpermissions"
120
+ },
121
+ {
122
+ "name": "startMeasurementUpdates",
123
+ "signature": "() => Promise<void>",
124
+ "parameters": [],
125
+ "returns": "Promise<void>",
126
+ "tags": [
127
+ {
128
+ "name": "since",
129
+ "text": "0.1.0"
130
+ }
131
+ ],
132
+ "docs": "Start emitting `measurement` events.",
133
+ "complexTypes": [],
134
+ "slug": "startmeasurementupdates"
135
+ },
136
+ {
137
+ "name": "stopMeasurementUpdates",
138
+ "signature": "() => Promise<void>",
139
+ "parameters": [],
140
+ "returns": "Promise<void>",
141
+ "tags": [
142
+ {
143
+ "name": "since",
144
+ "text": "0.1.0"
145
+ }
146
+ ],
147
+ "docs": "Stop emitting `measurement` events.",
148
+ "complexTypes": [],
149
+ "slug": "stopmeasurementupdates"
150
+ }
151
+ ],
152
+ "properties": []
153
+ },
154
+ "interfaces": [
155
+ {
156
+ "name": "PluginListenerHandle",
157
+ "slug": "pluginlistenerhandle",
158
+ "docs": "",
159
+ "tags": [],
160
+ "methods": [],
161
+ "properties": [
162
+ {
163
+ "name": "remove",
164
+ "tags": [],
165
+ "docs": "",
166
+ "complexTypes": [],
167
+ "type": "() => Promise<void>"
168
+ }
169
+ ]
170
+ },
171
+ {
172
+ "name": "Measurement",
173
+ "slug": "measurement",
174
+ "docs": "",
175
+ "tags": [
176
+ {
177
+ "text": "0.1.0",
178
+ "name": "since"
179
+ }
180
+ ],
181
+ "methods": [],
182
+ "properties": [
183
+ {
184
+ "name": "x",
185
+ "tags": [
186
+ {
187
+ "text": "0.12",
188
+ "name": "example"
189
+ },
190
+ {
191
+ "text": "0.1.0",
192
+ "name": "since"
193
+ }
194
+ ],
195
+ "docs": "The rotation rate around the x-axis in radians per second (rad/s).",
196
+ "complexTypes": [],
197
+ "type": "number"
198
+ },
199
+ {
200
+ "name": "y",
201
+ "tags": [
202
+ {
203
+ "text": "0.12",
204
+ "name": "example"
205
+ },
206
+ {
207
+ "text": "0.1.0",
208
+ "name": "since"
209
+ }
210
+ ],
211
+ "docs": "The rotation rate around the y-axis in radians per second (rad/s).",
212
+ "complexTypes": [],
213
+ "type": "number"
214
+ },
215
+ {
216
+ "name": "z",
217
+ "tags": [
218
+ {
219
+ "text": "0.12",
220
+ "name": "example"
221
+ },
222
+ {
223
+ "text": "0.1.0",
224
+ "name": "since"
225
+ }
226
+ ],
227
+ "docs": "The rotation rate around the z-axis in radians per second (rad/s).",
228
+ "complexTypes": [],
229
+ "type": "number"
230
+ }
231
+ ]
232
+ },
233
+ {
234
+ "name": "PermissionStatus",
235
+ "slug": "permissionstatus",
236
+ "docs": "",
237
+ "tags": [
238
+ {
239
+ "text": "0.1.0",
240
+ "name": "since"
241
+ }
242
+ ],
243
+ "methods": [],
244
+ "properties": [
245
+ {
246
+ "name": "gyroscope",
247
+ "tags": [
248
+ {
249
+ "text": "0.1.0",
250
+ "name": "since"
251
+ }
252
+ ],
253
+ "docs": "The permission status of the gyroscope sensor.",
254
+ "complexTypes": [
255
+ "GyroscopePermissionState"
256
+ ],
257
+ "type": "GyroscopePermissionState"
258
+ }
259
+ ]
260
+ },
261
+ {
262
+ "name": "IsAvailableResult",
263
+ "slug": "isavailableresult",
264
+ "docs": "",
265
+ "tags": [
266
+ {
267
+ "text": "0.1.0",
268
+ "name": "since"
269
+ }
270
+ ],
271
+ "methods": [],
272
+ "properties": [
273
+ {
274
+ "name": "isAvailable",
275
+ "tags": [
276
+ {
277
+ "text": "0.1.0",
278
+ "name": "since"
279
+ }
280
+ ],
281
+ "docs": "Whether the gyroscope sensor is available on the device.",
282
+ "complexTypes": [],
283
+ "type": "boolean"
284
+ }
285
+ ]
286
+ }
287
+ ],
288
+ "enums": [],
289
+ "typeAliases": [
290
+ {
291
+ "name": "MeasurementEvent",
292
+ "slug": "measurementevent",
293
+ "docs": "",
294
+ "types": [
295
+ {
296
+ "text": "Measurement",
297
+ "complexTypes": [
298
+ "Measurement"
299
+ ]
300
+ }
301
+ ]
302
+ },
303
+ {
304
+ "name": "GyroscopePermissionState",
305
+ "slug": "gyroscopepermissionstate",
306
+ "docs": "",
307
+ "types": [
308
+ {
309
+ "text": "PermissionState",
310
+ "complexTypes": [
311
+ "PermissionState"
312
+ ]
313
+ },
314
+ {
315
+ "text": "'limited'",
316
+ "complexTypes": []
317
+ }
318
+ ]
319
+ },
320
+ {
321
+ "name": "PermissionState",
322
+ "slug": "permissionstate",
323
+ "docs": "",
324
+ "types": [
325
+ {
326
+ "text": "'prompt'",
327
+ "complexTypes": []
328
+ },
329
+ {
330
+ "text": "'prompt-with-rationale'",
331
+ "complexTypes": []
332
+ },
333
+ {
334
+ "text": "'granted'",
335
+ "complexTypes": []
336
+ },
337
+ {
338
+ "text": "'denied'",
339
+ "complexTypes": []
340
+ }
341
+ ]
342
+ },
343
+ {
344
+ "name": "GetMeasurementResult",
345
+ "slug": "getmeasurementresult",
346
+ "docs": "",
347
+ "types": [
348
+ {
349
+ "text": "Measurement",
350
+ "complexTypes": [
351
+ "Measurement"
352
+ ]
353
+ }
354
+ ]
355
+ }
356
+ ],
357
+ "pluginConfigs": []
358
+ }