====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
script_template [2015/01/21 09:01] ajasei [How to use the script] |
script_template [2015/05/05 20:27] (current) trianguloy |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== About the script ====== | ====== About the script ====== | ||
- | * Purpose : Show battery "charging" or "discharging" state | + | * Purpose : explain what the script does |
- | * Author : Abednego JS ( https://plus.google.com/u/0/118095355037125433304 ) | + | * Author : who wrote this script |
- | * Link: https://plus.google.com/u/0/118095355037125433304/posts/UXfaG9YQyqX | + | * Link: if needed, you may add a link here |
====== How to use the script ====== | ====== How to use the script ====== | ||
- | This script will NOT showing anything when the power cable unplugged, just change the batstat value (in variable declaration or onReceive function) to change this. :D | + | Explain everything needed to use the script, whether some item configuration need to be done before, on which event to trigger the script, and so on |
- | + | ||
- | Create shortcut to run this script, it'll be dynamic label where the script show battery state. Give it name "batv". | + | |
- | + | ||
- | Also assign script to running when displaying the page where "batv" placed (follow this step if user want to see battery state updated/checked when access spesific page instad of checking the state everytime). | + | |
- | How to assign: Lightning Setting >> Current desktop >> Event & Actions >> Resumed >> Run a script [choose this script]. | + | |
- | + | ||
- | Dictionary: | + | |
- | + | ||
- | var: | + | |
- | + | ||
- | item (get LLX item), batcon (get LLX context), batstat ( String value to edit the "batv" label), curd (get current page), curi (get "batv"); | + | |
- | ifilter (filtering android intent), batterystatus (intent where activity to change batstat's value executed), text (temporary place used as bridge between batstat value to "batv" label); | + | |
- | etc (status, isCharging, chargePlug, usbCharge, acCharge they're variable used to change batstat's value) | + | |
- | + | ||
- | function: | + | |
- | + | ||
- | onReceive(context, intent) = function to change batstat's value; | + | |
- | manref () = function to manual update "batv" label | + | |
====== Script code ====== | ====== Script code ====== | ||
- | <code> | + | <sxh javascript> |
- | LL.bindClass("android.os.BatteryManager"); | + | |
- | LL.bindClass("android.content.BroadcastReceiver"); | + | |
- | LL.bindClass("android.content.Intent"); | + | |
- | LL.bindClass("android.content.Context"); | + | |
- | LL.bindClass("android.content.IntentFilter"); | + | |
- | + | ||
- | var item = LL.getEvent().getItem(); | + | |
- | var batstat = ""; | + | |
- | var batcon = LL.getContext(); | + | |
- | var curd = LL.getCurrentDesktop(); | + | |
- | var curi = curd.getItemByName("batv"); | + | |
- | + | ||
- | + | ||
- | var ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); | + | |
- | var batteryStatus = batcon.registerReceiver(null, ifilter); | + | |
- | + | ||
- | function onReceive(context, intent) { | + | |
- | var status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); | + | |
- | var isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || | + | |
- | status == BatteryManager.BATTERY_STATUS_FULL; | + | |
- | + | ||
- | var chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); | + | |
- | var usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; | + | |
- | var acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; | + | |
- | + | ||
- | if (isCharging) | + | |
- | { | + | |
- | if (usbCharge) | + | |
- | { | + | |
- | batstat = "usb charging . . ."; | + | |
- | }else | + | |
- | { | + | |
- | batstat = "AC charging . . ."; | + | |
- | } | + | |
- | }else | + | |
- | { | + | |
- | batstat = ""; | + | |
- | } | + | |
- | + | ||
- | + | ||
- | } | + | |
- | function manref() { | + | //New tag, line completion and colors. |
- | var text = batstat; | + | //The previous one was <code> script(); </code> |
- | curi.setLabel(text); | + | //remove those lines and write here your script |
- | } | + | yourJavaScriptCodeHere(); |
- | onReceive(LL.getContext(), batteryStatus); | + | </sxh> |
- | manref(); | + | |
- | </code> | + |