====== Differences ====== This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
script_battery_charging_state [2015/01/23 09:49] pierrox Add polling loop |
script_battery_charging_state [2015/03/15 13:23] (current) jappie Script-name and tag-name |
||
|---|---|---|---|
| Line 8: | Line 8: | ||
| 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 | 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 "Lightning Action - Do Nothing" to run this script, it'll be dynamic label where the script show battery state. Give it name "batv". | + | * Create shortcut "Lightning Action - Do Nothing" to run this script. |
| + | * Disable Icon | ||
| + | * Set 'BattStatus-resume' script to event resume | ||
| + | * Set 'BattStatus-pause' script to event pause | ||
| - | Also assign the two scripts below to item resume and pause events. | + | This version edited by Pierre to minimize resource usage + updated without user intervention, |
| - | How to assign: Long tap on shortcut >> Customize Item >> More... >> "+" tab >> Resumed >> Run a script [choose the resume script]. Repeat these steps for "Paused". | + | The old version can be found here: https://www.dropbox.com/s/c0hews7f01b7l01/_AJS_script_oldBATSTATE.txt?dl=0 |
| - | + | :) | |
| - | 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 ====== | ||
| - | ======= Item resume script ======= | + | ======= BattStatus-resume ======= |
| <code> | <code> | ||
| LL.bindClass("android.os.BatteryManager"); | LL.bindClass("android.os.BatteryManager"); | ||
| Line 65: | Line 56: | ||
| item.setLabel(batstat); | item.setLabel(batstat); | ||
| - | item.setTag(setTimeout(refresh, PERIOD)); | + | item.setTag("battSt", setTimeout(refresh, PERIOD)); |
| } | } | ||
| Line 71: | Line 62: | ||
| </code> | </code> | ||
| - | ======= Item pause script ======= | + | ======= BattStatus-pause ======= |
| <code> | <code> | ||
| // important: preserve the battery life and clear timeouts when the item is paused to avoid useless background activity | // important: preserve the battery life and clear timeouts when the item is paused to avoid useless background activity | ||
| - | var id = LL.getEvent().getItem().getTag(); | + | var id = LL.getEvent().getItem().getTag("battSt"); |
| if(id != null) { | if(id != null) { | ||
| clearTimeout(parseInt(id)); | clearTimeout(parseInt(id)); | ||
| } | } | ||
| </code> | </code> | ||