User Tools

Site Tools


script_template

**This is an old revision of the document!** ----

A PCRE internal error occured. This might be caused by a faulty plugin

====== About the script ====== * Purpose : show battery "charging" or "discharging" state * Author : Abednego JS ( https://plus.google.com/u/0/118095355037125433304 ) * Link: https://plus.google.com/u/0/118095355037125433304/posts/UXfaG9YQyqX ====== 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 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 ====== <code> 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() { var text = batstat; curi.setLabel(text); } onReceive(LL.getContext(), batteryStatus); manref(); </code>

script_template.1421830627.txt.gz · Last modified: 2015/01/21 08:57 by ajasei