-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLCAndroidBatteryLibExp.lcb
595 lines (463 loc) · 21.9 KB
/
LCAndroidBatteryLibExp.lcb
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
library com.livecode.library.androidbattery
use com.livecode.foreign
use com.livecode.java
metadata title is "Android Battery Library"
metadata author is "LiveCode"
metadata version is "1.0.0"library com.livecode.library.androidbattery
use com.livecode.foreign
use com.livecode.java
metadata title is "Android Battery Library"
metadata author is "LiveCode"
metadata version is "1.0.0"
foreign handler ClassForName(in pClass as JString) returns JObject binds to "java:java.lang.Class>forName(Ljava/lang/String;)Ljava/lang/Class;!static"
foreign handler GetCurrentApplicationMethod(in pActivityThread as JObject, in pMethod as JString, in pParams as optional JObject) returns JObject binds to "java:java.lang.Class>getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"
foreign handler MethodInvoke(in pMethod as JObject, in pInstance as optional JObject, in pParams as optional JObject) returns JObject binds to "java:java.lang.reflect.Method>invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"
foreign handler GetIntentFilter(in pAction as JString) returns JObject binds to "java:android.content.IntentFilter>new(Ljava/lang/String;)"
foreign handler ApplicationRegisterReceiver(in pContext as JObject, in pObj as optional JObject, in pFilter as JObject) returns JObject binds to "java:android.content.Context>registerReceiver(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;"
foreign handler GetIntentValueInt(in pIntent as JObject, in pWhich as JString, in pDefault as CInt) returns CInt binds to "java:android.content.Intent>getIntExtra(Ljava/lang/String;I)I"
foreign handler GetIntentValueStr(in pIntent as JObject, in pWhich as JString, in pDefault as CInt) returns JString binds to "java:android.content.Intent>getStringExtra(Ljava/lang/String;I)Ljava/lang/String;"
--- https://developer.android.com/reference/android/os/BatteryManager.html
/**
Summary: Get an Android device battery's current charge percentage
Description:
Retreives the charged percentage amount as an integer from the Android OS BatteryManager
*/
public handler GetBatteryPercentage() returns Number
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tLevel as Integer
put GetIntentValueInt(tIntent, StringToJString("level"), -1) into tLevel
variable tScale as Integer
put GetIntentValueInt(tIntent, StringToJString("scale"), -1) into tScale
return tLevel / tScale * 100
end unsafe
end handler
/**
Summary: Retreives a string indicating if an Android device is connected to a charging source
and if so the charger type as well.
Description:
Retreives the plugged state from the Android OS BatteryManager as a string that indicates
if the Android device is connected to a charging source and if it is the charger type as well.
The returned value will be a string containing one of the following items:
Unplugged,Plugged AC,Plugged USB,Wireless Charging,Unknown State Number
*/
public handler GetBatteryPlugged() returns String
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tPlugInt as Integer
variable tRetStr as String
put GetIntentValueInt(tIntent, StringToJString("plugged"), -1) into tPlugInt
if tPlugInt = 0 then
put "Unplugged" into tRetStr
else if tPlugInt = 1 then
put "Plugged AC" into tRetStr
else if tPlugInt = 2 then
put "Plugged USB" into tRetStr
else if tPlugInt = 4 then
put "Wireless Charging" into tRetStr
else
put "Unknown State " & tPlugInt into tRetStr
end if
return tRetStr
end unsafe
end handler
/**
Summary: Retreives a string indicating if the Android device's battery is charging, discharging, or full
Description:
Retreives the battery status from the Android OS BatteryManager as a string that indicates
if the Android device's battery is charging, discharging, or full.
If the state cannot be determined it will indicate the unknown state and
possibly include the integer that was returned by the BatteryManager.
The returned value will be a string containing one of the following items:
Status:Charging,Status:Discharging,Status:Full,Status:Unknown,Status:Unknown Number
*/
public handler GetBatteryStatus() returns String
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tStatusInt as Integer
variable tRetStr as String
put GetIntentValueInt(tIntent, StringToJString("status"), -1) into tStatusInt
if tStatusInt = 1 then
put "Status:Unknown" into tRetStr
else if tStatusInt = 2 then
put "Status:Charging" into tRetStr
else if tStatusInt = 3 then
put "Status:Discharging" into tRetStr
else if tStatusInt = 5 then
put "Status:Full" into tRetStr
else
put "Status:Unknown " & tStatusInt into tRetStr
end if
return tRetStr
end unsafe
end handler
/**
Summary: Retreives a string indicating the health of an Android device's battery.
Description:
Retreives the battery health information from the Android OS BatteryManager
and returns it as a string
The returned value will contain one of the following items:
Health:Good,Health:Overheat,Health:Cold,Health:OverVoltage,Health:Dead,Health:Failing,Health:Unknown
*/
public handler GetBatteryHealth() returns String
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tHealthInt as Integer
variable tRetStr as String
put GetIntentValueInt(tIntent, StringToJString("health"), -1) into tHealthInt
if tHealthInt = 2 then
put "Health:Good" into tRetStr
else if tHealthInt = 3 then
put "Health:Overheat" into tRetStr
else if tHealthInt = 7 then
put "Health:Cold" into tRetStr
else if tHealthInt = 5 then
put "Health:OverVoltage" into tRetStr
else if tHealthInt = 4 then
put "Health:Dead" into tRetStr
else if tHealthInt = 6 then
put "Health:Failing" into tRetStr
else
put "Health:Unknown " & tHealthInt into tRetStr
end if
return tRetStr
end unsafe
end handler
/**
Summary: Retreives a string indicating Android device's battery technology type.
Description:
Retreives the battery technology type information from the Android OS BatteryManager
and returns it as a string
*/
public handler GetBatteryTechnology() returns String
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tTechStr as JString
put GetIntentValueStr(tIntent, StringToJString("technology"), -1) into tTechStr
return StringFromJString(tTechStr)
end unsafe
end handler
/**
Summary: Retreives an integer that is the voltage level of a Android device's charging source.
Description:
Retreives an integer that is the voltage level of a Android device's charging source.
*/
public handler GetBatteryVoltage() returns Number
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tVoltInt as Integer
put GetIntentValueInt(tIntent, StringToJString("voltage"), -1) into tVoltInt
return tVoltInt
end unsafe
end handler
end library
foreign handler ClassForName(in pClass as JString) returns JObject binds to "java:java.lang.Class>forName(Ljava/lang/String;)Ljava/lang/Class;!static"
foreign handler GetCurrentApplicationMethod(in pActivityThread as JObject, in pMethod as JString, in pParams as optional JObject) returns JObject binds to "java:java.lang.Class>getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"
foreign handler MethodInvoke(in pMethod as JObject, in pInstance as optional JObject, in pParams as optional JObject) returns JObject binds to "java:java.lang.reflect.Method>invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"
foreign handler GetIntentFilter(in pAction as JString) returns JObject binds to "java:android.content.IntentFilter>new(Ljava/lang/String;)"
foreign handler ApplicationRegisterReceiver(in pContext as JObject, in pObj as optional JObject, in pFilter as JObject) returns JObject binds to "java:android.content.Context>registerReceiver(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;"
foreign handler GetIntentValueInt(in pIntent as JObject, in pWhich as JString, in pDefault as CInt) returns CInt binds to "java:android.content.Intent>getIntExtra(Ljava/lang/String;I)I"
foreign handler GetIntentValueStr(in pIntent as JObject, in pWhich as JString, in pDefault as CInt) returns JString binds to "java:android.content.Intent>getStringExtra(Ljava/lang/String;I)Ljava/lang/String;"
--- https://developer.android.com/reference/android/os/BatteryManager.html
/**
Summary: Get an Android device battery's current charge percentage
Description:
Retreives the charged percentage amount as an integer from the Android OS BatteryManager
*/
public handler GetBatteryPercentage() returns Number
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tLevel as Integer
put GetIntentValueInt(tIntent, StringToJString("level"), -1) into tLevel
variable tScale as Integer
put GetIntentValueInt(tIntent, StringToJString("scale"), -1) into tScale
return tLevel / tScale * 100
end unsafe
end handler
/**
Summary: Retreives a string indicating if an Android device is connected to a charging source
and if so the charger type as well.
Description:
Retreives the plugged state from the Android OS BatteryManager as a string that indicates
if the Android device is connected to a charging source and if it is the charger type as well.
The returned value will be a string containing one of the following items:
Unplugged,Plugged AC,Plugged USB,Wireless Charging,Unknown State Number
*/
public handler GetBatteryPlugged() returns String
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tPlugInt as Integer
variable tRetStr as String
put GetIntentValueInt(tIntent, StringToJString("plugged"), -1) into tPlugInt
if tPlugInt = 0 then
put "Unplugged" into tRetStr
else if tPlugInt = 1 then
put "Plugged AC" into tRetStr
else if tPlugInt = 2 then
put "Plugged USB" into tRetStr
else if tPlugInt = 4 then
put "Wireless Charging" into tRetStr
else
put "Unknown State " & tPlugInt into tRetStr
end if
return tRetStr
end unsafe
end handler
/**
Summary: Retreives a string indicating if the Android device's battery is charging, discharging, or full
Description:
Retreives the battery status from the Android OS BatteryManager as a string that indicates
if the Android device's battery is charging, discharging, or full.
If the state cannot be determined it will indicate the unknown state and
possibly include the integer that was returned by the BatteryManager.
The returned value will be a string containing one of the following items:
Status:Charging,Status:Discharging,Status:Full,Status:Unknown,Status:Unknown Number
*/
public handler GetBatteryStatus() returns String
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tStatusInt as Integer
variable tRetStr as String
put GetIntentValueInt(tIntent, StringToJString("status"), -1) into tStatusInt
if tStatusInt = 1 then
put "Status:Unknown" into tRetStr
else if tStatusInt = 2 then
put "Status:Charging" into tRetStr
else if tStatusInt = 3 then
put "Status:Discharging" into tRetStr
else if tStatusInt = 5 then
put "Status:Full" into tRetStr
else
put "Status:Unknown " & tStatusInt into tRetStr
end if
return tRetStr
end unsafe
end handler
/**
Summary: Retreives a string indicating the health of an Android device's battery.
Description:
Retreives the battery health information from the Android OS BatteryManager
and returns it as a string
The returned value will contain one of the following items:
Health:Good,Health:Overheat,Health:Cold,Health:OverVoltage,Health:Dead,Health:Failing,Health:Unknown
*/
public handler GetBatteryHealth() returns String
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tHealthInt as Integer
variable tRetStr as String
put GetIntentValueInt(tIntent, StringToJString("health"), -1) into tHealthInt
if tHealthInt = 2 then
put "Health:Good" into tRetStr
else if tHealthInt = 3 then
put "Health:Overheat" into tRetStr
else if tHealthInt = 7 then
put "Health:Cold" into tRetStr
else if tHealthInt = 5 then
put "Health:OverVoltage" into tRetStr
else if tHealthInt = 4 then
put "Health:Dead" into tRetStr
else if tHealthInt = 6 then
put "Health:Failing" into tRetStr
else
put "Health:Unknown " & tHealthInt into tRetStr
end if
return tRetStr
end unsafe
end handler
/**
Summary: Retreives a string indicating Android device's battery technology type.
Description:
Retreives the battery technology type information from the Android OS BatteryManager
and returns it as a string
*/
public handler GetBatteryTechnology() returns String
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tTechStr as String
put GetIntentValueStr(tIntent, StringToJString("technology"), -1) into tTechStr
return tTechStr
end unsafe
end handler
/**
Summary: Retreives an integer that is the voltage level of a Android device's charging source.
Description:
Retreives an integer that is the voltage level of a Android device's charging source.
*/
public handler GetBatteryVoltage() returns Number
unsafe
// Get the application context. We rely on an undocumented
// method to get this 'statically' at the moment.
variable tClass as JObject
put ClassForName(StringToJString("android.app.ActivityThread")) into tClass
variable tMethod as JObject
put GetCurrentApplicationMethod(tClass, StringToJString("currentApplication"), nothing) into tMethod
variable tContext as JObject
put MethodInvoke(tMethod, nothing, nothing) into tContext
// Get an intent filter for the battery changed intent
variable tFilter as JObject
put GetIntentFilter(StringToJString("android.intent.action.BATTERY_CHANGED")) into tFilter
// Get the intent
variable tIntent as JObject
put ApplicationRegisterReceiver(tContext, nothing, tFilter) into tIntent
// Get the relevant values from the intent.
variable tVoltInt as Integer
put GetIntentValueInt(tIntent, StringToJString("voltage"), -1) into tVoltInt
return tVoltInt
end unsafe
end handler
end library