Blog über DroidScript - Android Apps mit Javascript entwickeln
Mit der "app.GetBatteryLevel()"-Methode lässt sich die Kapazität des Akkus ermitteln:
'use strict'; var lay; app.SetDebugEnabled(false); function OnStart() { lay = app.CreateLayout( "linear", "VCenter,FillXY" ); var ico = app.CreateText( "",-1,-1,'fontawesome'); ico.level = function(i){ if(i<10) i=0; else if(i<40) i=1; else if(i<61) i=2; else if(i<91) i=3; else i=4; ico.SetText('[fa-battery-'+i+']'); if(i===0) ico.SetTextColor( "#ff0000" ); else if(i>3) ico.SetTextColor( "#00ff00" ); else ico.SetTextColor( "#ffffff" ); }; ico.SetTextSize( 120 ); lay.AddChild(ico); lay.ico = ico; var msg = app.CreateText( "" ); msg.format = function (i){ this.SetText('Level: ' + i + '%'); }; msg.SetTextSize( 36 ); lay.AddChild(msg); lay.msg = msg; lay.setLevel = function(lv){ this.ico.level(lv); this.msg.format(lv); }; app.AddLayout( lay ); getLevel(); } function getLevel(){ lay.setLevel(app.GetBatteryLevel()*100); setTimeout(getLevel,1000); }
Keine Kommentare:
Kommentar veröffentlichen