User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

sample_code:battery_level

Battery Level

This is a simple app that displays battery level and also notifies it on the notification bar. Here is the spk.

//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()
}

Home»Sample Code

sample_code/battery_level.txt · Last modified: 2016/08/29 14:16 (external edit)