User Tools

Site Tools


sample_code:battery_level

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sample_code:battery_level [2016/07/23 10:21]
titus Battery Level
sample_code:battery_level [2016/08/29 14:16]
Line 1: Line 1:
-**Battery Level** 
- 
-This is a simple app that displays battery level and also notifies it on the notification bar. 
- 
-<code JavaScript> 
- 
-//Called when application is started. 
-function OnStart() 
-{ 
-    app.SetDebugEnabled(false) 
-    //Create a layout with objects vertically centered. 
-    lay = app.CreateLayout( "linear", "VCenter,FillXY" );     
-    batt = app.GetBatteryLevel() 
-    bat = batt*100+"%" 
-    //Change Color according to battery level 
-    if(batt<.1){lay.SetBackColor("#44ff9999")} 
-    else if(batt<.5){lay.SetBackColor("#7799ff99") } 
-    else if(batt<90){ lay.SetBackColor("#cc9999ff" )} 
-    else{ lay.SetBackColor("#ff99ffff")} 
-    //Create a text label and add it to layout. 
-    txt = app.CreateText( bat ); 
-    txt.SetTextSize( 45 ); 
-    lay.AddChild( txt ); 
-    setInterval("battery()",5000) 
-    //Add layout to app.     
-    app.AddLayout( lay ); 
-  
- 
-    //Notify battery Level 
-    notify1 = app.CreateNotification();  
-    notify1.SetMessage( "Battery Level is " +bat, "Battery Level",bat ); 
-    notify1.SetLights( "#00ffff", 500, 500 );  
-    notify1.Notify() 
- 
-} 
-function battery(){ 
-batt = app.GetBatteryLevel() 
-    bat = batt*100+"%" 
-txt.SetText(bat) 
-notify1.SetMessage( "Battery Level is " +bat, "Battery Level",bat); 
- notify1.Notify() 
-} 
-</code> 
- 
  
sample_code/battery_level.txt · Last modified: 2016/08/29 14:16 (external edit)