Droidscript

Droidscript is an android app used to create android apps using javascript

Droidscript Samples

DroidScript

DroidScript is a javascript IDE for android that enables one to build android applications in a more simpler way using JavaScript. After you complete coding your droidscript apps you need to purchase app builder plugin in order to convert them to android applications
I will provide some examples and functions for use to build droidscript applications
You will first need to go through droidscript tutorial to get started with the basics of Droidscript.

Samples

Your First App

This sample shows a popup message and also vibrate when button is button clicked.
 //Called when application is started. 
function OnStart() 
{ 
 //Create a layout with objects vertically centered. 
 lay = app.CreateLayout( "linear", "VCenter,FillXY" ); 

 //Create image 1/5 of screen width and correct aspect ratio. 
 img = app.CreateImage( "/Sys/Img/Hello.png", 0.2, -1 ); 
 lay.AddChild( img ); 
 
 //Create a button 1/3 of screen width and 1/10 screen height. 
 btn = app.CreateButton( "Press Me", 0.3, 0.1 ); 
 btn.SetMargins( 0, 0.05, 0, 0 ); 
 lay.AddChild( btn ); 
 
 //Set function to call when button pressed. 
 btn.SetOnTouch( btn_OnTouch ); 
 
 //Add layout to app. 
 app.AddLayout( lay ); 
} 

//Called when user touches our button. 
function btn_OnTouch() 
{ 
 //Show a popup message. 
 app.ShowPopup( "Hello World!" ); 
 
 //Vibrate phone with a pattern (in milliseconds). 
 //pause,vibrate,pause,vibrate... 
 app.Vibrate( "0,100,30,100,50,300" ); 
} 
 

Battery Level

This sample shows battery level with a notification
 
//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()
}
 

Filter

This Sample shows how to filter items from a list item
 app.ShowProgress("Loading..."+app.GetInternalFolder())
//List Files and folders on the sdcard

var myArray = app.ListFolder(app.GetInternalFolder()).sort();
//Called when application is started.
function OnStart()
{
    app.ShowProgress("Loading..."+app.GetInternalFolder())
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear", "TopCenter,FillXY" );    

    //Create a text label and add it to layout.
    txt = app.CreateTextEdit( "",1,.1,"Center,Singleline" );
    txt.SetTextSize( 32 );
    txt.SetHint("filter")
    txt.SetOnChange(change)
    lay.AddChild( txt );
    //Create Check Box
    chk =app.CreateCheckBox("Case insensitive")
    lay.AddChild(chk)
    //Create List
    lst = app.CreateList(myArray,1,null)
    lst.SetOnTouch(tch)
    lay.AddChild(lst)
    //Add layout to app.    
    app.AddLayout( lay );
    app.HideProgress();
}

function change(){
if(chk.GetChecked()){insens()}
else{sens()}

}

function tch(it){
if(app.IsFolder(app.GetInternalFolder()+"/"+it)){app.ShowPopup(it,"Short,Bottom")}
else{
app.OpenFile(app.GetInternalFolder()+"/"+it,null,"Select Application")
}
}

function sens(){
peo = []
s =""
text= txt.GetText()
for(i=0;i<myArray.length;i++){
if(myArray[i].indexOf(text)!=-1){
 peo.push(myArray[i])}
}    
lst.SetList(peo)
}
function insens() {
peo = []
s =""
text= txt.GetText().toLowerCase()
for(i=0;i<myArray.length;i++){
if(myArray[i].toLowerCase().indexOf(text)!=-1){
 peo.push(myArray[i])}
}    
lst.SetList(peo)
}

Digital Clock

This shows a digital Clock to show date and time

//Called when application is started.
function OnStart()
{
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear", "VCenter,FillXY" ); 
    lay.SetBackColor("#dd665544")   
    //Create a text label and add it to layout.
    txtd = app.CreateText( "Digital Clock" );
    txtd.SetTextSize( 45 );
    txtd.SetMargins(0,0,0,0.03)
    lay.AddChild( txtd );
     //Create Text
  text = app.CreateText( "" );
    text.SetTextSize( 25 );
    lay.AddChild( text );
    //Create a text label and add it to layout.
    txt = app.CreateText( "" );
    txt.SetTextSize( 32 );
    lay.AddChild( txt );
    
    //Add layout to app.    
    app.AddLayout( lay );
setInterval("Clock()",1000)
}
function Clock() 
{ 
  var day =["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
 var today = new Date();
    var y = today.getFullYear()
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    var mi = today.getMilliseconds();
    var mon =today.getMonth()
 var d = today.getDay()
var mon = today.getMonth()+1
var dt = today.getDate()
text.SetText(day[d]+" "+dt+"/"+mon+"/"+y)

if(s<10&&m<10&&h<10){
     txt.SetText("0"+h+":"+"0"+m+":"+"0"+s)
  }
else{

 if(s<10&&h<10){
     txt.SetText("0"+h+":"+m+":"+"0"+s)
  }
else if(h<10&&m<10){
     txt.SetText("0"+h+":"+"0"+m+":"+s)
  }
else if(m<10&&s<10){
   
     txt.SetText(h+":"+"0"+m+":"+"0"+s)
  }
else{
if(h<10){
     txt.SetText("0"+h+":"+m+":"+s)
  }
else if(m<10){
  
     txt.SetText(h+":"+"0"+m+":"+s)
  }

else if(s<10){
     txt.SetText(h+":"+m+":"+"0"+s)
  }

else{
txt.SetText(h+":"+m+":"+s)
    }
  }
 }
}

Simple Audio player

This sample shows how to create a simple Audio player
var s = 5
//You can change this to your own music folder.
var musicFolder= "/sdcard/MYT DOCS/C/audio/instruments"
function OnStart()
{
//Create Layout
  lay = app.CreateLayout( "Linear" ,"FillXY,VCenter");
//Buttons
  btn = app.CreateButton( "Play", 0.2, 0.1 );
  btn.SetOnTouch(A);
  lay.AddChild( btn );

   btn2 = app.CreateButton( "Pause", 0.2, 0.1 );
  btn2.SetOnTouch( B );
  lay.AddChild( btn2 );

   btn3 = app.CreateButton( "Stop", 0.2, 0.1 );
  btn3.SetOnTouch( C );
  lay.AddChild( btn3 );

   btn4 = app.CreateButton( "Seek", 0.2, 0.1 );
  btn4.SetOnTouch( D );
  lay.AddChild( btn4 );

   btn5 = app.CreateButton( "Close", 0.2, 0.1 );
  btn5.SetOnTouch( E );
  lay.AddChild( btn5 );
   
//SeekBar
  skb = app.CreateSeekBar( 0.8 );
  
  skb.SetValue( 0.5 );
  skb.SetOnTouch( skb_OnTouch );
  lay.AddChild( skb );

    lay2 = app.CreateLayout( "Linear","VCenter" );
  
    //Create music list. 
    spin = app.CreateSpinner( "[none]" ); 
    spin.SetSize( 1 ); 
    spin.SetOnTouch( spn_OnTouch ); 
    lay2.AddChild( spin );
   
    //Find mp3 files on internal sdcard . 
    mp3List = app.ListFolder( musicFolder ); 
    spin.SetList( mp3List ); 

  app.AddLayout( lay );
  app.AddLayout( lay2 );
   
  player = app.CreateMediaPlayer();
  player.SetOnReady(f);
  player.SetFile(musicFolder+"/"+spin.GetText()); 
  app.ShowPopup(spin.GetText())
  
  //Start timer to update seek bar every second. 
    setInterval( "Update()", 1000 ); 
  
 
 
}
  
//Handle file select. 
function spn_OnTouch( i ) 
{ 
    player.SetFile(musicFolder+"/" + spin.GetText()); 
} 

//When ready to play
function f()  {
player.Play()
var y = player.GetDuration()
app.Vibrate("1,50")
skb.SetRange(y)
}
function A()
{
  
  player.Play();
}

function player_OnComplete()
{
  app.ShowPopup( "OnComplete" );
}


function B()
{
  
  player.Pause();
}


function C()
{
  
  player.Stop();
}

function D()
{
  s = player.GetPosition()+20
  player.SeekTo(s);
}


function E()
{
  
  player.Close();
}


function s(i) {
spin.GetText(i)
}

function skb_OnTouch( value )
{  player.SeekTo(value)
 
 var m = player.GetPosition();
}



//Update seek bar. 
function Update() 
{ 
    prog = player.GetPosition(); 
     skb.SetValue( prog ); 
} 

Proximity Sensor

Your phone resists you from touching it

//Called when application is started.
function OnStart()
{
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear","VCenter,FillXY" );   
   
    //Create a text label and add it to layout.
    txt = app.CreateText( "Place your hand near your front speaker" );
    txt.SetTextSize( 12 );
    lay.AddChild( txt );
     //Create and start accelerometer sensor. 
    //(in fast mode with no minimum change value). 
    sns = app.CreateSensor( "Proximity", "Fast" ); 
    
    sns.SetMinChange( 0 ); 
    sns.Start(); 
    sns.SetOnChange(update)
    
    //Add layout to app.    

    app.AddLayout( lay );
  
  
}
function update(x,y,z)   {
if(x==0){app.Vibrate("1,11,55,45"); app.ShowPopup("Don't touch me");
  app.TextToSpeech( "Don't touch me!", 1.0, 1.0 );
}
}
Categories
Top Apps
External
Contact


Free Web Hosting