@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.
- package/CapawesomeCapacitorGyroscope.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +333 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/Gyroscope.java +97 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/GyroscopePlugin.java +152 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/Measurement.java +28 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/interfaces/Result.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/results/GetMeasurementResult.java +21 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/gyroscope/classes/results/IsAvailableResult.java +20 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +358 -0
- package/dist/esm/definitions.d.ts +112 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +18 -0
- package/dist/esm/web.js +125 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +139 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +142 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Measurement.swift +24 -0
- package/ios/Plugin/Classes/Results/IsAvailableResult.swift +15 -0
- package/ios/Plugin/Enums/CustomError.swift +20 -0
- package/ios/Plugin/Gyroscope.swift +87 -0
- package/ios/Plugin/GyroscopePlugin.swift +116 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +91 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapawesomeCapacitorGyroscope'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robin Genz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapawesomeCapacitorGyroscope",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapawesomeCapacitorGyroscope",
|
|
10
|
+
targets: ["GyroscopePlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "GyroscopePlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Plugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "GyroscopePluginTests",
|
|
25
|
+
dependencies: ["GyroscopePlugin"],
|
|
26
|
+
path: "ios/PluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# @capawesome/capacitor-gyroscope
|
|
2
|
+
|
|
3
|
+
Capacitor plugin to read the device's gyroscope sensor.
|
|
4
|
+
|
|
5
|
+
<div class="capawesome-z29o10a">
|
|
6
|
+
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
|
+
</a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
We are proud to offer one of the most complete and feature-rich Capacitor plugins for gyroscope measurements. Here are some of the key features:
|
|
14
|
+
|
|
15
|
+
- 🖥️ **Cross-platform**: Supports Android and iOS.
|
|
16
|
+
- ⚡ **Real-time measurements**: Continuous gyroscope data with event listeners.
|
|
17
|
+
- 📊 **Rotation rate**: Accurate x, y, and z-axis rotation rate in rad/s.
|
|
18
|
+
- 🔒 **Permission handling**: Built-in permission management for sensor access.
|
|
19
|
+
- 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
20
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
21
|
+
- 🔗 **Compatibility**: Works alongside the [Accelerometer](https://capawesome.io/plugins/accelerometer/), [Barometer](https://capawesome.io/plugins/barometer/) and [Pedometer](https://capawesome.io/plugins/pedometer/) plugins.
|
|
22
|
+
|
|
23
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
24
|
+
|
|
25
|
+
## Newsletter
|
|
26
|
+
|
|
27
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
28
|
+
|
|
29
|
+
## Compatibility
|
|
30
|
+
|
|
31
|
+
| Plugin Version | Capacitor Version | Status |
|
|
32
|
+
| -------------- | ----------------- | -------------- |
|
|
33
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
38
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Then use the following prompt:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-gyroscope` plugin in my project.
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install @capawesome/capacitor-gyroscope
|
|
54
|
+
npx cap sync
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Android
|
|
58
|
+
|
|
59
|
+
#### Proguard
|
|
60
|
+
|
|
61
|
+
If you are using Proguard, you need to add the following rules to your `proguard-rules.pro` file:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
-keep class io.capawesome.capacitorjs.plugins.** { *; }
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### iOS
|
|
68
|
+
|
|
69
|
+
#### Privacy Descriptions
|
|
70
|
+
|
|
71
|
+
Add the `NSMotionUsageDescription` key to the `ios/App/App/Info.plist` file, which tells the user why your app needs access to the device's motion data:
|
|
72
|
+
|
|
73
|
+
```xml
|
|
74
|
+
<key>NSMotionUsageDescription</key>
|
|
75
|
+
<string>The app needs to access the motion activity.</string>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Configuration
|
|
79
|
+
|
|
80
|
+
No configuration required for this plugin.
|
|
81
|
+
|
|
82
|
+
## Usage
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { Gyroscope } from '@capawesome/capacitor-gyroscope';
|
|
86
|
+
|
|
87
|
+
const getMeasurement = async () => {
|
|
88
|
+
const measurement = await Gyroscope.getMeasurement();
|
|
89
|
+
console.log('X: ', measurement.x);
|
|
90
|
+
console.log('Y: ', measurement.y);
|
|
91
|
+
console.log('Z: ', measurement.z);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const isAvailable = async () => {
|
|
95
|
+
const result = await Gyroscope.isAvailable();
|
|
96
|
+
return result.isAvailable;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const startMeasurementUpdates = async () => {
|
|
100
|
+
await Gyroscope.addListener('measurement', measurement => {
|
|
101
|
+
console.log('X: ', measurement.x);
|
|
102
|
+
console.log('Y: ', measurement.y);
|
|
103
|
+
console.log('Z: ', measurement.z);
|
|
104
|
+
});
|
|
105
|
+
await Gyroscope.startMeasurementUpdates();
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const stopMeasurementUpdates = async () => {
|
|
109
|
+
await Gyroscope.stopMeasurementUpdates();
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const checkPermissions = async () => {
|
|
113
|
+
const result = await Gyroscope.checkPermissions();
|
|
114
|
+
return result;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const requestPermissions = async () => {
|
|
118
|
+
const result = await Gyroscope.requestPermissions();
|
|
119
|
+
return result;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const removeAllListeners = async () => {
|
|
123
|
+
await Gyroscope.removeAllListeners();
|
|
124
|
+
};
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## API
|
|
128
|
+
|
|
129
|
+
<docgen-index>
|
|
130
|
+
|
|
131
|
+
* [`addListener('measurement', ...)`](#addlistenermeasurement-)
|
|
132
|
+
* [`checkPermissions()`](#checkpermissions)
|
|
133
|
+
* [`getMeasurement()`](#getmeasurement)
|
|
134
|
+
* [`isAvailable()`](#isavailable)
|
|
135
|
+
* [`removeAllListeners()`](#removealllisteners)
|
|
136
|
+
* [`requestPermissions()`](#requestpermissions)
|
|
137
|
+
* [`startMeasurementUpdates()`](#startmeasurementupdates)
|
|
138
|
+
* [`stopMeasurementUpdates()`](#stopmeasurementupdates)
|
|
139
|
+
* [Interfaces](#interfaces)
|
|
140
|
+
* [Type Aliases](#type-aliases)
|
|
141
|
+
|
|
142
|
+
</docgen-index>
|
|
143
|
+
|
|
144
|
+
<docgen-api>
|
|
145
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
146
|
+
|
|
147
|
+
### addListener('measurement', ...)
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Called when a new measurement is available.
|
|
154
|
+
|
|
155
|
+
Only available on Android and iOS.
|
|
156
|
+
|
|
157
|
+
| Param | Type |
|
|
158
|
+
| ------------------ | ----------------------------------------------------------------------- |
|
|
159
|
+
| **`eventName`** | <code>'measurement'</code> |
|
|
160
|
+
| **`listenerFunc`** | <code>(event: <a href="#measurement">Measurement</a>) => void</code> |
|
|
161
|
+
|
|
162
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
163
|
+
|
|
164
|
+
**Since:** 0.1.0
|
|
165
|
+
|
|
166
|
+
--------------------
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
### checkPermissions()
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
checkPermissions() => Promise<PermissionStatus>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Check if the app has permission to access the gyroscope sensor.
|
|
176
|
+
|
|
177
|
+
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
178
|
+
|
|
179
|
+
**Since:** 0.1.0
|
|
180
|
+
|
|
181
|
+
--------------------
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
### getMeasurement()
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
getMeasurement() => Promise<GetMeasurementResult>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Get the latest measurement.
|
|
191
|
+
|
|
192
|
+
This method returns the most recent measurement from the gyroscope sensor.
|
|
193
|
+
|
|
194
|
+
**Returns:** <code>Promise<<a href="#measurement">Measurement</a>></code>
|
|
195
|
+
|
|
196
|
+
**Since:** 0.1.0
|
|
197
|
+
|
|
198
|
+
--------------------
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
### isAvailable()
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
isAvailable() => Promise<IsAvailableResult>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Check if the gyroscope sensor is available on the device.
|
|
208
|
+
|
|
209
|
+
**Returns:** <code>Promise<<a href="#isavailableresult">IsAvailableResult</a>></code>
|
|
210
|
+
|
|
211
|
+
**Since:** 0.1.0
|
|
212
|
+
|
|
213
|
+
--------------------
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
### removeAllListeners()
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
removeAllListeners() => Promise<void>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Remove all listeners for this plugin.
|
|
223
|
+
|
|
224
|
+
**Since:** 0.1.0
|
|
225
|
+
|
|
226
|
+
--------------------
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
### requestPermissions()
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
requestPermissions() => Promise<PermissionStatus>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Request permission to access the gyroscope sensor.
|
|
236
|
+
|
|
237
|
+
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
238
|
+
|
|
239
|
+
**Since:** 0.1.0
|
|
240
|
+
|
|
241
|
+
--------------------
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
### startMeasurementUpdates()
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
startMeasurementUpdates() => Promise<void>
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Start emitting `measurement` events.
|
|
251
|
+
|
|
252
|
+
**Since:** 0.1.0
|
|
253
|
+
|
|
254
|
+
--------------------
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
### stopMeasurementUpdates()
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
stopMeasurementUpdates() => Promise<void>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Stop emitting `measurement` events.
|
|
264
|
+
|
|
265
|
+
**Since:** 0.1.0
|
|
266
|
+
|
|
267
|
+
--------------------
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
### Interfaces
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
#### PluginListenerHandle
|
|
274
|
+
|
|
275
|
+
| Prop | Type |
|
|
276
|
+
| ------------ | ----------------------------------------- |
|
|
277
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
#### Measurement
|
|
281
|
+
|
|
282
|
+
| Prop | Type | Description | Since |
|
|
283
|
+
| ------- | ------------------- | ------------------------------------------------------------------ | ----- |
|
|
284
|
+
| **`x`** | <code>number</code> | The rotation rate around the x-axis in radians per second (rad/s). | 0.1.0 |
|
|
285
|
+
| **`y`** | <code>number</code> | The rotation rate around the y-axis in radians per second (rad/s). | 0.1.0 |
|
|
286
|
+
| **`z`** | <code>number</code> | The rotation rate around the z-axis in radians per second (rad/s). | 0.1.0 |
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
#### PermissionStatus
|
|
290
|
+
|
|
291
|
+
| Prop | Type | Description | Since |
|
|
292
|
+
| --------------- | ----------------------------------------------------------------------------- | ---------------------------------------------- | ----- |
|
|
293
|
+
| **`gyroscope`** | <code><a href="#gyroscopepermissionstate">GyroscopePermissionState</a></code> | The permission status of the gyroscope sensor. | 0.1.0 |
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
#### IsAvailableResult
|
|
297
|
+
|
|
298
|
+
| Prop | Type | Description | Since |
|
|
299
|
+
| ----------------- | -------------------- | -------------------------------------------------------- | ----- |
|
|
300
|
+
| **`isAvailable`** | <code>boolean</code> | Whether the gyroscope sensor is available on the device. | 0.1.0 |
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
### Type Aliases
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
#### MeasurementEvent
|
|
307
|
+
|
|
308
|
+
<code><a href="#measurement">Measurement</a></code>
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
#### GyroscopePermissionState
|
|
312
|
+
|
|
313
|
+
<code><a href="#permissionstate">PermissionState</a> | 'limited'</code>
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
#### PermissionState
|
|
317
|
+
|
|
318
|
+
<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
#### GetMeasurementResult
|
|
322
|
+
|
|
323
|
+
<code><a href="#measurement">Measurement</a></code>
|
|
324
|
+
|
|
325
|
+
</docgen-api>
|
|
326
|
+
|
|
327
|
+
## Changelog
|
|
328
|
+
|
|
329
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/gyroscope/CHANGELOG.md).
|
|
330
|
+
|
|
331
|
+
## License
|
|
332
|
+
|
|
333
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/gyroscope/LICENSE).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace = "io.capawesome.capacitorjs.plugins.gyroscope"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError = false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.gyroscope;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.hardware.Sensor;
|
|
5
|
+
import android.hardware.SensorEvent;
|
|
6
|
+
import android.hardware.SensorEventListener;
|
|
7
|
+
import android.hardware.SensorManager;
|
|
8
|
+
import androidx.annotation.NonNull;
|
|
9
|
+
import androidx.annotation.Nullable;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.gyroscope.classes.Measurement;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces.EmptyCallback;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.gyroscope.classes.interfaces.NonEmptyResultCallback;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.gyroscope.classes.results.GetMeasurementResult;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.gyroscope.classes.results.IsAvailableResult;
|
|
15
|
+
|
|
16
|
+
public class Gyroscope {
|
|
17
|
+
|
|
18
|
+
@NonNull
|
|
19
|
+
private final GyroscopePlugin plugin;
|
|
20
|
+
|
|
21
|
+
private boolean isRunning = false;
|
|
22
|
+
|
|
23
|
+
@Nullable
|
|
24
|
+
private SensorEventListener sensorEventListener;
|
|
25
|
+
|
|
26
|
+
public Gyroscope(@NonNull GyroscopePlugin plugin) {
|
|
27
|
+
this.plugin = plugin;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public void getMeasurement(@NonNull NonEmptyResultCallback<GetMeasurementResult> callback) throws Exception {
|
|
31
|
+
SensorManager sensorManager = (SensorManager) plugin.getContext().getSystemService(Context.SENSOR_SERVICE);
|
|
32
|
+
Sensor gyroscopeSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
|
|
33
|
+
|
|
34
|
+
if (gyroscopeSensor == null) {
|
|
35
|
+
throw new Exception(GyroscopePlugin.ERROR_GYROSCOPE_UNAVAILABLE);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
final SensorEventListener listener = new SensorEventListener() {
|
|
39
|
+
@Override
|
|
40
|
+
public void onSensorChanged(SensorEvent event) {
|
|
41
|
+
sensorManager.unregisterListener(this);
|
|
42
|
+
Measurement measurement = new Measurement(event);
|
|
43
|
+
callback.success(new GetMeasurementResult(measurement));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Override
|
|
47
|
+
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
sensorManager.registerListener(listener, gyroscopeSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public void isAvailable(@NonNull NonEmptyResultCallback<IsAvailableResult> callback) {
|
|
54
|
+
SensorManager sensorManager = (SensorManager) plugin.getContext().getSystemService(Context.SENSOR_SERVICE);
|
|
55
|
+
Sensor gyroscopeSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
|
|
56
|
+
boolean isAvailable = gyroscopeSensor != null;
|
|
57
|
+
callback.success(new IsAvailableResult(isAvailable));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public void startMeasurementUpdates(@NonNull EmptyCallback callback) {
|
|
61
|
+
if (isRunning) {
|
|
62
|
+
callback.success();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
SensorManager sensorManager = (SensorManager) plugin.getContext().getSystemService(Context.SENSOR_SERVICE);
|
|
67
|
+
Sensor gyroscopeSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
|
|
68
|
+
if (gyroscopeSensor == null) {
|
|
69
|
+
callback.error(new Exception(GyroscopePlugin.ERROR_GYROSCOPE_UNAVAILABLE));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
sensorEventListener = new SensorEventListener() {
|
|
74
|
+
@Override
|
|
75
|
+
public void onSensorChanged(SensorEvent event) {
|
|
76
|
+
Measurement measurement = new Measurement(event);
|
|
77
|
+
plugin.notifyMeasurementEventListeners(measurement);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Override
|
|
81
|
+
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
sensorManager.registerListener(sensorEventListener, gyroscopeSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
|
85
|
+
isRunning = true;
|
|
86
|
+
callback.success();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public void stopMeasurementUpdates(@Nullable EmptyCallback callback) {
|
|
90
|
+
SensorManager sensorManager = (SensorManager) plugin.getContext().getSystemService(Context.SENSOR_SERVICE);
|
|
91
|
+
sensorManager.unregisterListener(sensorEventListener);
|
|
92
|
+
isRunning = false;
|
|
93
|
+
if (callback != null) {
|
|
94
|
+
callback.success();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|