Skip to content

Commit

Permalink
updated package
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Sep 5, 2023
1 parent 77fde98 commit 1599c3b
Show file tree
Hide file tree
Showing 9 changed files with 668 additions and 372 deletions.
8 changes: 7 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ ext {
}

buildscript {
ext {
kotlin_version = '1.9.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.0'
classpath 'com.android.tools.build:gradle:8.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'

android {
namespace "com.alwe.plugins.battery"
Expand Down Expand Up @@ -52,6 +57,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':capacitor-android')
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation 'androidx.core:core-ktx:1.10.1'
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
Expand Down
6 changes: 3 additions & 3 deletions android/src/main/java/com/alwe/plugins/battery/Battery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class Battery(
content.put("voltage", voltage)
content.put("amperage", amperage)
content.put("wattage", wattage)
content.put("health", BatteryHealth.fromInt(health))
content.put("status", BatteryStatus.fromInt(status))
content.put("chargeMode", BatteryChargeMode.fromInt(chargeMode))
content.put("health", BatteryHealth.fromInt(health)?.ordinal ?: 0)
content.put("status", BatteryStatus.fromInt(status)?.ordinal ?: 0)
content.put("chargeMode", BatteryChargeMode.fromInt(chargeMode)?.ordinal ?: 0)

this.notify("batteryChange", content, true)

Expand Down
11 changes: 8 additions & 3 deletions android/src/main/java/com/alwe/plugins/battery/BatteryPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import com.getcapacitor.annotation.CapacitorPlugin

@CapacitorPlugin(name = "Battery")
class BatteryPlugin : Plugin() {
private val implementation = Battery(::notifyListeners, context)
private var implementation: Battery? = null

override fun load() {
super.load()
implementation = Battery(::notifyListeners, context)
}

@PluginMethod
fun start(call: PluginCall) {
val res = implementation.start()
val res = implementation?.start()
call.resolve(res)
}

@PluginMethod
fun stop(call: PluginCall) {
implementation.stop()
implementation?.stop()
}
}
319 changes: 319 additions & 0 deletions dist/docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,319 @@
{
"api": {
"name": "BatteryPlugin",
"slug": "batteryplugin",
"docs": "",
"tags": [],
"methods": [
{
"name": "start",
"signature": "() => Promise<Battery | undefined>",
"parameters": [],
"returns": "Promise<Battery | undefined>",
"tags": [],
"docs": "",
"complexTypes": [
"Battery"
],
"slug": "start"
},
{
"name": "stop",
"signature": "() => Promise<void>",
"parameters": [],
"returns": "Promise<void>",
"tags": [],
"docs": "",
"complexTypes": [],
"slug": "stop"
},
{
"name": "addListener",
"signature": "(eventName: 'batteryChange', listenerFunc: (event: Battery) => void) => Promise<PluginListenerHandle>",
"parameters": [
{
"name": "eventName",
"docs": "",
"type": "'batteryChange'"
},
{
"name": "listenerFunc",
"docs": "",
"type": "(event: Battery) => void"
}
],
"returns": "Promise<PluginListenerHandle>",
"tags": [],
"docs": "",
"complexTypes": [
"PluginListenerHandle",
"Battery"
],
"slug": "addlistenerbatterychange"
},
{
"name": "removeAllListeners",
"signature": "() => Promise<void>",
"parameters": [],
"returns": "Promise<void>",
"tags": [],
"docs": "",
"complexTypes": [],
"slug": "removealllisteners"
}
],
"properties": []
},
"interfaces": [
{
"name": "Battery",
"slug": "battery",
"docs": "",
"tags": [],
"methods": [],
"properties": [
{
"name": "level",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "number"
},
{
"name": "hasBattery",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "boolean"
},
{
"name": "isCharging",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "boolean"
},
{
"name": "chargingTime",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "number | undefined"
},
{
"name": "dischargingTime",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "number | undefined"
},
{
"name": "currentCapacity",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "number | undefined"
},
{
"name": "totalCapacity",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "number | undefined"
},
{
"name": "realPercentage",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "number | undefined"
},
{
"name": "technology",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "string | undefined"
},
{
"name": "temperature",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "number | undefined"
},
{
"name": "voltage",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "number | undefined"
},
{
"name": "amperage",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "number | undefined"
},
{
"name": "wattage",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "number | undefined"
},
{
"name": "health",
"tags": [],
"docs": "",
"complexTypes": [
"BatteryHealth"
],
"type": "BatteryHealth"
},
{
"name": "status",
"tags": [],
"docs": "",
"complexTypes": [
"BatteryStatus"
],
"type": "BatteryStatus"
},
{
"name": "chargeMode",
"tags": [],
"docs": "",
"complexTypes": [
"BatteryChargeMode"
],
"type": "BatteryChargeMode"
}
]
},
{
"name": "PluginListenerHandle",
"slug": "pluginlistenerhandle",
"docs": "",
"tags": [],
"methods": [],
"properties": [
{
"name": "remove",
"tags": [],
"docs": "",
"complexTypes": [],
"type": "() => Promise<void>"
}
]
}
],
"enums": [
{
"name": "BatteryHealth",
"slug": "batteryhealth",
"members": [
{
"name": "UNKNOWN",
"tags": [],
"docs": ""
},
{
"name": "COLD",
"tags": [],
"docs": ""
},
{
"name": "DEAD",
"tags": [],
"docs": ""
},
{
"name": "GOOD",
"tags": [],
"docs": ""
},
{
"name": "OVERHEAT",
"tags": [],
"docs": ""
},
{
"name": "OVER_VOLTAGE",
"tags": [],
"docs": ""
},
{
"name": "FAILURE",
"tags": [],
"docs": ""
}
]
},
{
"name": "BatteryStatus",
"slug": "batterystatus",
"members": [
{
"name": "UNKNOWN",
"tags": [],
"docs": ""
},
{
"name": "NOT_CHARGING",
"tags": [],
"docs": ""
},
{
"name": "DISCHARGING",
"tags": [],
"docs": ""
},
{
"name": "CHARGING",
"tags": [],
"docs": ""
},
{
"name": "FULL",
"tags": [],
"docs": ""
}
]
},
{
"name": "BatteryChargeMode",
"slug": "batterychargemode",
"members": [
{
"name": "UNKNOWN",
"tags": [],
"docs": ""
},
{
"name": "AC",
"tags": [],
"docs": ""
},
{
"name": "USB",
"tags": [],
"docs": ""
},
{
"name": "DOCK",
"tags": [],
"docs": ""
},
{
"name": "WIRELESS",
"tags": [],
"docs": ""
}
]
}
],
"typeAliases": [],
"pluginConfigs": []
}
3 changes: 2 additions & 1 deletion dist/esm/web.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { WebPlugin } from '@capacitor/core';
import type { BatteryPlugin, Battery } from './definitions';
import { Battery } from './definitions';
import type { BatteryPlugin } from './definitions';
export declare class BatteryWeb extends WebPlugin implements BatteryPlugin {
private battery;
private controller;
Expand Down
Loading

0 comments on commit 1599c3b

Please sign in to comment.