react-native-flic2 2.0.0-beta.1 → 2.0.0-beta.11
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/README.md +85 -22
- package/ios/Flic2.mm +12 -12
- package/lib/module/NativeFlic2.js.map +1 -1
- package/lib/module/index.js +6 -14
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeFlic2.d.ts +14 -49
- package/lib/typescript/src/NativeFlic2.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +17 -52
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +23 -23
- package/src/NativeFlic2.ts +30 -28
- package/src/index.ts +18 -40
- package/android/build.gradle +0 -81
- package/android/gradle.properties +0 -5
- package/android/src/main/AndroidManifest.xml +0 -27
- package/android/src/main/java/com/flic2/Flic2ButtonListener.kt +0 -128
- package/android/src/main/java/com/flic2/Flic2Converter.kt +0 -103
- package/android/src/main/java/com/flic2/Flic2Module.kt +0 -481
- package/android/src/main/java/com/flic2/Flic2Package.kt +0 -33
- package/android/src/main/java/com/flic2/Flic2Service.kt +0 -112
- package/lib/module/index.bak.js +0 -161
- package/lib/module/index.bak.js.map +0 -1
- package/lib/typescript/src/index.bak.d.ts +0 -1
- package/lib/typescript/src/index.bak.d.ts.map +0 -1
- package/src/index.bak.tsx +0 -159
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAoB,EAClB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,cAAM,KAAK;IAET,OAAO,CAAC,yBAAyB,CAAkB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAoB,EAClB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,cAAM,KAAK;IAET,OAAO,CAAC,yBAAyB,CAAkB;IAE5C,YAAY,EAAE,YAAY,CAAC;QAChC,WAAW,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;QAC1C,kBAAkB,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;QAC7D,gBAAgB,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC;KAC1D,CAAC,CAAC;IAEH;;;;;OAKG;;IAqBH;;;;OAIG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBxC;;;;OAIG;IACI,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC;;;;OAIG;IACI,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAMhC;;OAEG;IACI,aAAa,IAAI,IAAI;IAM5B;;;;OAIG;IACI,aAAa,IAAI,OAAO;IAM/B;;;;OAIG;IACI,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9C;;;;OAIG;IACI,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjD;;;;OAIG;IACI,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAMxC;;;;OAIG;IACI,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAMrC;;;;;OAKG;IACI,YAAY,CACjB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC;IAOhB;;;;;OAKG;IACI,aAAa,CAClB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,UAAU,CAAC;IAMtB;;;;;OAKG;IACI,gBAAgB,CACrB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,UAAU,CAAC;IAMtB;;;;;;OAMG;IACI,oBAAoB,CACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,UAAU,CAAC;IAMtB;;;;;;OAMG;IACI,oBAAoB,CACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,UAAU,CAAC;IAMtB;;;;;;OAMG;IACI,iBAAiB,CACtB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC;IAMtB;;;;OAIG;IACI,UAAU,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAM1C;;;;;OAKG;IACU,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAShE;;;;;;OAMG;IACU,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAe7D;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAM1B;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAsB3B;;;;OAIG;IACH,OAAO,CAAC,0BAA0B;IAMlC;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;CAMjC;;AAGD,wBAA2B;AAG3B,mBAAmB,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-flic2",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.11",
|
|
4
4
|
"description": "React Native Flic plugin made with the Flic2 SDK (unofficial)",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -57,31 +57,31 @@
|
|
|
57
57
|
"registry": "https://registry.npmjs.org/"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@eslint/compat": "
|
|
61
|
-
"@eslint/eslintrc": "
|
|
62
|
-
"@eslint/js": "
|
|
63
|
-
"@evilmartians/lefthook": "
|
|
60
|
+
"@eslint/compat": "1.3.2",
|
|
61
|
+
"@eslint/eslintrc": "3.3.1",
|
|
62
|
+
"@eslint/js": "9.35.0",
|
|
63
|
+
"@evilmartians/lefthook": "1.12.3",
|
|
64
64
|
"@react-native-community/cli": "20.0.1",
|
|
65
65
|
"@react-native/babel-preset": "0.81.1",
|
|
66
|
-
"@react-native/eslint-config": "
|
|
67
|
-
"@release-it/conventional-changelog": "
|
|
68
|
-
"@types/react": "
|
|
69
|
-
"@typescript-eslint/eslint-plugin": "
|
|
70
|
-
"@typescript-eslint/parser": "
|
|
71
|
-
"del-cli": "
|
|
72
|
-
"eslint": "
|
|
73
|
-
"eslint-config-prettier": "
|
|
74
|
-
"eslint-plugin-ft-flow": "
|
|
75
|
-
"eslint-plugin-jest": "
|
|
76
|
-
"eslint-plugin-prettier": "
|
|
77
|
-
"eslint-plugin-react-native": "
|
|
78
|
-
"prettier": "
|
|
66
|
+
"@react-native/eslint-config": "0.81.1",
|
|
67
|
+
"@release-it/conventional-changelog": "10.0.1",
|
|
68
|
+
"@types/react": "19.1.0",
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "8.46.2",
|
|
70
|
+
"@typescript-eslint/parser": "8.46.2",
|
|
71
|
+
"del-cli": "6.0.0",
|
|
72
|
+
"eslint": "8.57.1",
|
|
73
|
+
"eslint-config-prettier": "10.1.8",
|
|
74
|
+
"eslint-plugin-ft-flow": "3.0.11",
|
|
75
|
+
"eslint-plugin-jest": "29.0.1",
|
|
76
|
+
"eslint-plugin-prettier": "5.5.4",
|
|
77
|
+
"eslint-plugin-react-native": "5.0.0",
|
|
78
|
+
"prettier": "3.6.2",
|
|
79
79
|
"react": "19.1.0",
|
|
80
80
|
"react-native": "0.81.1",
|
|
81
|
-
"react-native-builder-bob": "
|
|
82
|
-
"release-it": "
|
|
83
|
-
"turbo": "
|
|
84
|
-
"typescript": "
|
|
81
|
+
"react-native-builder-bob": "0.40.13",
|
|
82
|
+
"release-it": "19.0.4",
|
|
83
|
+
"turbo": "2.5.6",
|
|
84
|
+
"typescript": "5.9.2"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"react": "*",
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
"type": "modules",
|
|
137
137
|
"jsSrcsDir": "src",
|
|
138
138
|
"android": {
|
|
139
|
-
"javaPackageName": "
|
|
139
|
+
"javaPackageName": "nl.xguard.flic2"
|
|
140
140
|
}
|
|
141
141
|
},
|
|
142
142
|
"create-react-native-library": {
|
package/src/NativeFlic2.ts
CHANGED
|
@@ -46,22 +46,24 @@ export type ScanStatusChangeEvent = {
|
|
|
46
46
|
result?: ScanResult;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
export type ButtonEventName =
|
|
50
|
+
| 'discovered'
|
|
51
|
+
| 'connected'
|
|
52
|
+
| 'ready'
|
|
53
|
+
| 'disconnected'
|
|
54
|
+
| 'connectionFailed'
|
|
55
|
+
| 'buttonDown'
|
|
56
|
+
| 'buttonUp'
|
|
57
|
+
| 'click'
|
|
58
|
+
| 'doubleClick'
|
|
59
|
+
| 'hold'
|
|
60
|
+
| 'unpaired'
|
|
61
|
+
| 'batteryUpdate'
|
|
62
|
+
| 'nicknameUpdate';
|
|
63
|
+
|
|
49
64
|
export type ButtonEvent = {
|
|
50
65
|
uuid: string;
|
|
51
|
-
event:
|
|
52
|
-
| 'discovered'
|
|
53
|
-
| 'connected'
|
|
54
|
-
| 'ready'
|
|
55
|
-
| 'disconnected'
|
|
56
|
-
| 'connectionFailed'
|
|
57
|
-
| 'buttonDown'
|
|
58
|
-
| 'buttonUp'
|
|
59
|
-
| 'click'
|
|
60
|
-
| 'doubleClick'
|
|
61
|
-
| 'hold'
|
|
62
|
-
| 'unpaired'
|
|
63
|
-
| 'batteryUpdate'
|
|
64
|
-
| 'nicknameUpdate';
|
|
66
|
+
event: ButtonEventName;
|
|
65
67
|
queued?: boolean;
|
|
66
68
|
age?: number;
|
|
67
69
|
nickname?: string;
|
|
@@ -133,33 +135,33 @@ export interface Spec extends TurboModule {
|
|
|
133
135
|
// Manager methods
|
|
134
136
|
initialize(
|
|
135
137
|
background: boolean
|
|
136
|
-
): Promise<
|
|
138
|
+
): Promise<void>;
|
|
137
139
|
getButtons(): Promise<FlicButton[]>;
|
|
138
|
-
scanForButtons(): Promise<
|
|
139
|
-
stopScan(): Promise<
|
|
140
|
-
forgetButton(uuid: string): Promise<
|
|
141
|
-
connectAllKnownButtons(): Promise<
|
|
142
|
-
disconnectAllKnownButtons(): Promise<
|
|
143
|
-
forgetAllButtons(): Promise<
|
|
140
|
+
scanForButtons(): Promise<void>;
|
|
141
|
+
stopScan(): Promise<void>;
|
|
142
|
+
forgetButton(uuid: string): Promise<void>;
|
|
143
|
+
connectAllKnownButtons(): Promise<void>;
|
|
144
|
+
disconnectAllKnownButtons(): Promise<void>;
|
|
145
|
+
forgetAllButtons(): Promise<void>;
|
|
144
146
|
isScanning(): Promise<boolean>;
|
|
145
147
|
|
|
146
148
|
// Button methods
|
|
147
|
-
connectButton(uuid: string): Promise<
|
|
149
|
+
connectButton(uuid: string): Promise<FlicButton>;
|
|
148
150
|
disconnectButton(
|
|
149
151
|
uuid: string
|
|
150
|
-
): Promise<
|
|
152
|
+
): Promise<FlicButton>;
|
|
151
153
|
setTriggerMode(
|
|
152
154
|
uuid: string,
|
|
153
|
-
mode:
|
|
154
|
-
): Promise<
|
|
155
|
+
mode: number
|
|
156
|
+
): Promise<FlicButton>;
|
|
155
157
|
setLatencyMode(
|
|
156
158
|
uuid: string,
|
|
157
|
-
mode:
|
|
158
|
-
): Promise<
|
|
159
|
+
mode: number
|
|
160
|
+
): Promise<FlicButton>;
|
|
159
161
|
setNickname(
|
|
160
162
|
uuid: string,
|
|
161
163
|
nickname: string
|
|
162
|
-
): Promise<
|
|
164
|
+
): Promise<FlicButton>;
|
|
163
165
|
|
|
164
166
|
// Event emitters
|
|
165
167
|
readonly onManagerStateChange: CodegenTypes.EventEmitter<ManagerStateChangeEvent>;
|
package/src/index.ts
CHANGED
|
@@ -12,13 +12,10 @@ class Flic2 {
|
|
|
12
12
|
|
|
13
13
|
private isFlic2ManagerInitialized: boolean = false;
|
|
14
14
|
|
|
15
|
-
private sessionId: string;
|
|
16
|
-
|
|
17
15
|
public eventEmitter: TypedEmitter<{
|
|
18
16
|
buttonEvent: (event: ButtonEvent) => void;
|
|
19
17
|
managerStateChange: (event: ManagerStateChangeEvent) => void;
|
|
20
18
|
scanStatusChange: (event: ScanStatusChangeEvent) => void;
|
|
21
|
-
managerInitialized: () => void;
|
|
22
19
|
}>;
|
|
23
20
|
|
|
24
21
|
/**
|
|
@@ -29,11 +26,6 @@ class Flic2 {
|
|
|
29
26
|
*/
|
|
30
27
|
constructor() {
|
|
31
28
|
|
|
32
|
-
// generate a random session ID for the instance
|
|
33
|
-
this.sessionId = Math.random().toString(36).substring(2, 15);
|
|
34
|
-
|
|
35
|
-
console.log('Created new Flic2 instance with sessionId', this.sessionId);
|
|
36
|
-
|
|
37
29
|
// create event emitter
|
|
38
30
|
this.eventEmitter = new TypedEmitter<{
|
|
39
31
|
buttonEvent: (event: ButtonEvent) => void;
|
|
@@ -57,7 +49,7 @@ class Flic2 {
|
|
|
57
49
|
*
|
|
58
50
|
* @returns A promise that resolves when the Flic2 manager is initialized.
|
|
59
51
|
*/
|
|
60
|
-
public async initialize(): Promise<
|
|
52
|
+
public async initialize(): Promise<void> {
|
|
61
53
|
|
|
62
54
|
// check if the Flic2 manager is already initialized
|
|
63
55
|
if (this.isInitialized()) {
|
|
@@ -67,18 +59,10 @@ class Flic2 {
|
|
|
67
59
|
}
|
|
68
60
|
|
|
69
61
|
// initialize the Flic2 manager in background
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (!result.success) {
|
|
73
|
-
|
|
74
|
-
throw new Error(result.message);
|
|
75
|
-
|
|
76
|
-
}
|
|
62
|
+
await NativeFlic2.initialize(true);
|
|
77
63
|
|
|
78
64
|
this.onInitialized();
|
|
79
65
|
|
|
80
|
-
return true;
|
|
81
|
-
|
|
82
66
|
}
|
|
83
67
|
|
|
84
68
|
/**
|
|
@@ -86,7 +70,7 @@ class Flic2 {
|
|
|
86
70
|
*
|
|
87
71
|
* @returns A promise that resolves when the scan is started. Events will be emitted for the scan process.
|
|
88
72
|
*/
|
|
89
|
-
public startScan(): Promise<
|
|
73
|
+
public startScan(): Promise<void> {
|
|
90
74
|
|
|
91
75
|
return NativeFlic2.scanForButtons();
|
|
92
76
|
|
|
@@ -97,7 +81,7 @@ class Flic2 {
|
|
|
97
81
|
*
|
|
98
82
|
* @returns A promise that resolves when the scan is stopped.
|
|
99
83
|
*/
|
|
100
|
-
public stopScan(): Promise<
|
|
84
|
+
public stopScan(): Promise<void> {
|
|
101
85
|
|
|
102
86
|
return NativeFlic2.stopScan();
|
|
103
87
|
|
|
@@ -128,10 +112,7 @@ class Flic2 {
|
|
|
128
112
|
*
|
|
129
113
|
* @returns A promise that resolves when the all known buttons are connected.
|
|
130
114
|
*/
|
|
131
|
-
public connectAllKnownButtons(): Promise<{
|
|
132
|
-
success: boolean;
|
|
133
|
-
message: string;
|
|
134
|
-
}> {
|
|
115
|
+
public connectAllKnownButtons(): Promise<void> {
|
|
135
116
|
|
|
136
117
|
return NativeFlic2.connectAllKnownButtons();
|
|
137
118
|
|
|
@@ -142,10 +123,7 @@ class Flic2 {
|
|
|
142
123
|
*
|
|
143
124
|
* @returns A promise that resolves when the all known buttons are disconnected.
|
|
144
125
|
*/
|
|
145
|
-
public disconnectAllKnownButtons(): Promise<{
|
|
146
|
-
success: boolean;
|
|
147
|
-
message: string;
|
|
148
|
-
}> {
|
|
126
|
+
public disconnectAllKnownButtons(): Promise<void> {
|
|
149
127
|
|
|
150
128
|
return NativeFlic2.disconnectAllKnownButtons();
|
|
151
129
|
|
|
@@ -156,7 +134,7 @@ class Flic2 {
|
|
|
156
134
|
*
|
|
157
135
|
* @returns A promise that resolves when the all buttons are forgotten.
|
|
158
136
|
*/
|
|
159
|
-
public forgetAllButtons(): Promise<
|
|
137
|
+
public forgetAllButtons(): Promise<void> {
|
|
160
138
|
|
|
161
139
|
return NativeFlic2.forgetAllButtons();
|
|
162
140
|
|
|
@@ -181,7 +159,7 @@ class Flic2 {
|
|
|
181
159
|
*/
|
|
182
160
|
public forgetButton(
|
|
183
161
|
uuid: string
|
|
184
|
-
): Promise<
|
|
162
|
+
): Promise<void> {
|
|
185
163
|
|
|
186
164
|
return NativeFlic2.forgetButton(uuid);
|
|
187
165
|
|
|
@@ -192,11 +170,11 @@ class Flic2 {
|
|
|
192
170
|
* Connect a button.
|
|
193
171
|
*
|
|
194
172
|
* @param uuid - The UUID of the button to connect.
|
|
195
|
-
* @returns A promise that resolves
|
|
173
|
+
* @returns A promise that resolves with the button when the connection is initiated.
|
|
196
174
|
*/
|
|
197
175
|
public buttonConnect(
|
|
198
176
|
uuid: string
|
|
199
|
-
): Promise<
|
|
177
|
+
): Promise<FlicButton> {
|
|
200
178
|
|
|
201
179
|
return NativeFlic2.connectButton(uuid);
|
|
202
180
|
|
|
@@ -206,11 +184,11 @@ class Flic2 {
|
|
|
206
184
|
* Disconnect a button.
|
|
207
185
|
*
|
|
208
186
|
* @param uuid - The UUID of the button to disconnect.
|
|
209
|
-
* @returns A promise that resolves
|
|
187
|
+
* @returns A promise that resolves with the button when the disconnection is initiated.
|
|
210
188
|
*/
|
|
211
189
|
public buttonDisconnect(
|
|
212
190
|
uuid: string
|
|
213
|
-
): Promise<
|
|
191
|
+
): Promise<FlicButton> {
|
|
214
192
|
|
|
215
193
|
return NativeFlic2.disconnectButton(uuid);
|
|
216
194
|
|
|
@@ -221,12 +199,12 @@ class Flic2 {
|
|
|
221
199
|
*
|
|
222
200
|
* @param uuid - The UUID of the button to set the trigger mode of.
|
|
223
201
|
* @param mode - The trigger mode to set.
|
|
224
|
-
* @returns A promise that resolves when the trigger mode is set.
|
|
202
|
+
* @returns A promise that resolves with the button when the trigger mode is set.
|
|
225
203
|
*/
|
|
226
204
|
public buttonSetTriggerMode(
|
|
227
205
|
uuid: string,
|
|
228
206
|
mode: TriggerModeType
|
|
229
|
-
): Promise<
|
|
207
|
+
): Promise<FlicButton> {
|
|
230
208
|
|
|
231
209
|
return NativeFlic2.setTriggerMode(uuid, mode);
|
|
232
210
|
|
|
@@ -237,12 +215,12 @@ class Flic2 {
|
|
|
237
215
|
*
|
|
238
216
|
* @param uuid - The UUID of the button to set the latency mode of.
|
|
239
217
|
* @param mode - The latency mode to set.
|
|
240
|
-
* @returns A promise that resolves when the latency mode is set.
|
|
218
|
+
* @returns A promise that resolves with the button when the latency mode is set.
|
|
241
219
|
*/
|
|
242
220
|
public buttonSetLatencyMode(
|
|
243
221
|
uuid: string,
|
|
244
222
|
mode: LatencyModeType
|
|
245
|
-
): Promise<
|
|
223
|
+
): Promise<FlicButton> {
|
|
246
224
|
|
|
247
225
|
return NativeFlic2.setLatencyMode(uuid, mode);
|
|
248
226
|
|
|
@@ -253,12 +231,12 @@ class Flic2 {
|
|
|
253
231
|
*
|
|
254
232
|
* @param uuid - The UUID of the button to set the nickname of.
|
|
255
233
|
* @param nickname - The nickname to set.
|
|
256
|
-
* @returns A promise that resolves when the nickname is set.
|
|
234
|
+
* @returns A promise that resolves with the button when the nickname is set.
|
|
257
235
|
*/
|
|
258
236
|
public buttonSetNickname(
|
|
259
237
|
uuid: string,
|
|
260
238
|
nickname: string
|
|
261
|
-
): Promise<
|
|
239
|
+
): Promise<FlicButton> {
|
|
262
240
|
|
|
263
241
|
return NativeFlic2.setNickname(uuid, nickname);
|
|
264
242
|
|
package/android/build.gradle
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
buildscript {
|
|
2
|
-
ext.getExtOrDefault = {name ->
|
|
3
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Flic2_' + name]
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
repositories {
|
|
7
|
-
google()
|
|
8
|
-
mavenCentral()
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
dependencies {
|
|
12
|
-
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
-
// noinspection DifferentKotlinGradleVersion
|
|
14
|
-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
apply plugin: "com.android.library"
|
|
20
|
-
apply plugin: "kotlin-android"
|
|
21
|
-
|
|
22
|
-
apply plugin: "com.facebook.react"
|
|
23
|
-
|
|
24
|
-
def getExtOrIntegerDefault(name) {
|
|
25
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Flic2_" + name]).toInteger()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
android {
|
|
29
|
-
namespace "com.flic2"
|
|
30
|
-
|
|
31
|
-
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
|
-
|
|
33
|
-
defaultConfig {
|
|
34
|
-
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
35
|
-
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
buildFeatures {
|
|
39
|
-
buildConfig true
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
buildTypes {
|
|
43
|
-
release {
|
|
44
|
-
minifyEnabled false
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
lintOptions {
|
|
49
|
-
disable "GradleCompatible"
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
compileOptions {
|
|
53
|
-
sourceCompatibility JavaVersion.VERSION_1_8
|
|
54
|
-
targetCompatibility JavaVersion.VERSION_1_8
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
sourceSets {
|
|
58
|
-
main {
|
|
59
|
-
java.srcDirs += [
|
|
60
|
-
"generated/java",
|
|
61
|
-
"generated/jni"
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
repositories {
|
|
68
|
-
mavenCentral()
|
|
69
|
-
google()
|
|
70
|
-
maven { url 'https://jitpack.io' }
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
74
|
-
|
|
75
|
-
dependencies {
|
|
76
|
-
implementation "com.facebook.react:react-android"
|
|
77
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
78
|
-
implementation 'com.github.50ButtonsEach:flic2lib-android:1.+'
|
|
79
|
-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
|
|
80
|
-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3'
|
|
81
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
-
xmlns:tools="http://schemas.android.com/tools">
|
|
3
|
-
|
|
4
|
-
<!-- Bluetooth permissions for API < 31 -->
|
|
5
|
-
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
|
|
6
|
-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
|
|
7
|
-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
|
|
8
|
-
|
|
9
|
-
<!-- Bluetooth permissions for API >= 31 -->
|
|
10
|
-
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
|
|
11
|
-
android:usesPermissionFlags="neverForLocation"
|
|
12
|
-
tools:targetApi="s" />
|
|
13
|
-
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
|
14
|
-
|
|
15
|
-
<!-- Foreground service permission -->
|
|
16
|
-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
17
|
-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" />
|
|
18
|
-
|
|
19
|
-
<application>
|
|
20
|
-
<service
|
|
21
|
-
android:name=".Flic2Service"
|
|
22
|
-
android:enabled="true"
|
|
23
|
-
android:exported="false"
|
|
24
|
-
android:foregroundServiceType="connectedDevice" />
|
|
25
|
-
</application>
|
|
26
|
-
|
|
27
|
-
</manifest>
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
package com.flic2
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.Arguments
|
|
4
|
-
import com.facebook.react.bridge.WritableMap
|
|
5
|
-
import io.flic.flic2libandroid.BatteryLevel
|
|
6
|
-
import io.flic.flic2libandroid.Flic2Button
|
|
7
|
-
import io.flic.flic2libandroid.Flic2ButtonListener
|
|
8
|
-
|
|
9
|
-
class Flic2ButtonEventListener(
|
|
10
|
-
private val emitEvent: (WritableMap) -> Unit
|
|
11
|
-
) : Flic2ButtonListener() {
|
|
12
|
-
|
|
13
|
-
// Map Android library's onConnect() to emit "connected" (matches iOS)
|
|
14
|
-
override fun onConnect(button: Flic2Button) {
|
|
15
|
-
emitEvent(createButtonEvent(button, "connected"))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Map Android library's onReady() to emit "ready" (matches iOS)
|
|
19
|
-
override fun onReady(button: Flic2Button, timestamp: Long) {
|
|
20
|
-
emitEvent(createButtonEvent(button, "ready"))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Map Android library's onDisconnect() to emit "disconnected" (matches iOS)
|
|
24
|
-
override fun onDisconnect(button: Flic2Button) {
|
|
25
|
-
emitEvent(createButtonEvent(button, "disconnected"))
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Map Android library's onFailure() to emit "connectionFailed" (matches iOS)
|
|
29
|
-
override fun onFailure(button: Flic2Button, errorCode: Int, subCode: Int) {
|
|
30
|
-
emitEvent(createButtonEvent(button, "connectionFailed").apply {
|
|
31
|
-
putMap("error", Arguments.createMap().apply {
|
|
32
|
-
putInt("code", errorCode)
|
|
33
|
-
putInt("subCode", subCode)
|
|
34
|
-
putString("message", "Connection failed: code=$errorCode, subCode=$subCode")
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
override fun onButtonUpOrDown(
|
|
40
|
-
button: Flic2Button,
|
|
41
|
-
wasQueued: Boolean,
|
|
42
|
-
lastQueued: Boolean,
|
|
43
|
-
timestamp: Long,
|
|
44
|
-
isUp: Boolean,
|
|
45
|
-
isDown: Boolean
|
|
46
|
-
) {
|
|
47
|
-
val event = if (isDown) "buttonDown" else "buttonUp"
|
|
48
|
-
emitEvent(createButtonEvent(button, event).apply {
|
|
49
|
-
putBoolean("queued", wasQueued)
|
|
50
|
-
putDouble("age", System.currentTimeMillis() - timestamp.toDouble())
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Android library calls ALL applicable callback methods, causing duplicate events.
|
|
55
|
-
// Only onButtonSingleOrDoubleClickOrHold should emit events to match iOS behavior.
|
|
56
|
-
override fun onButtonClickOrHold(
|
|
57
|
-
button: Flic2Button,
|
|
58
|
-
wasQueued: Boolean,
|
|
59
|
-
lastQueued: Boolean,
|
|
60
|
-
timestamp: Long,
|
|
61
|
-
isClick: Boolean,
|
|
62
|
-
isHold: Boolean
|
|
63
|
-
) {
|
|
64
|
-
// Intentionally empty - events are handled by onButtonSingleOrDoubleClickOrHold
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Android library calls ALL applicable callback methods, causing duplicate events.
|
|
68
|
-
// Only onButtonSingleOrDoubleClickOrHold should emit events to match iOS behavior.
|
|
69
|
-
override fun onButtonSingleOrDoubleClick(
|
|
70
|
-
button: Flic2Button,
|
|
71
|
-
wasQueued: Boolean,
|
|
72
|
-
lastQueued: Boolean,
|
|
73
|
-
timestamp: Long,
|
|
74
|
-
isSingleClick: Boolean,
|
|
75
|
-
isDoubleClick: Boolean
|
|
76
|
-
) {
|
|
77
|
-
// Intentionally empty - events are handled by onButtonSingleOrDoubleClickOrHold
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
override fun onButtonSingleOrDoubleClickOrHold(
|
|
81
|
-
button: Flic2Button,
|
|
82
|
-
wasQueued: Boolean,
|
|
83
|
-
lastQueued: Boolean,
|
|
84
|
-
timestamp: Long,
|
|
85
|
-
isSingleClick: Boolean,
|
|
86
|
-
isDoubleClick: Boolean,
|
|
87
|
-
isHold: Boolean
|
|
88
|
-
) {
|
|
89
|
-
val event = when {
|
|
90
|
-
isSingleClick -> "click"
|
|
91
|
-
isDoubleClick -> "doubleClick"
|
|
92
|
-
isHold -> "hold"
|
|
93
|
-
else -> "unknown"
|
|
94
|
-
}
|
|
95
|
-
emitEvent(createButtonEvent(button, event).apply {
|
|
96
|
-
putBoolean("queued", wasQueued)
|
|
97
|
-
putDouble("age", System.currentTimeMillis() - timestamp.toDouble())
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Map Android library's onUnpaired() to emit "unpaired" (matches iOS)
|
|
102
|
-
override fun onUnpaired(button: Flic2Button) {
|
|
103
|
-
emitEvent(createButtonEvent(button, "unpaired"))
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Map Android library's onBatteryLevelUpdated() to emit "batteryUpdate" (matches iOS)
|
|
107
|
-
override fun onBatteryLevelUpdated(button: Flic2Button, level: BatteryLevel) {
|
|
108
|
-
emitEvent(createButtonEvent(button, "batteryUpdate").apply {
|
|
109
|
-
putDouble("voltage", level.voltage.toDouble())
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Map Android library's onNameUpdated() to emit "nicknameUpdate" (matches iOS)
|
|
114
|
-
override fun onNameUpdated(button: Flic2Button, newName: String) {
|
|
115
|
-
emitEvent(createButtonEvent(button, "nicknameUpdate").apply {
|
|
116
|
-
putString("nickname", newName)
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private fun createButtonEvent(button: Flic2Button, event: String): WritableMap {
|
|
121
|
-
return Arguments.createMap().apply {
|
|
122
|
-
putString("uuid", button.uuid)
|
|
123
|
-
putString("event", event)
|
|
124
|
-
putMap("button", Flic2Converter.buttonToMap(button))
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|