DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


Sidebar

News

Version1.42 is out since December 2nd 2016


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:slide_menu

Slide Menu

You can swipe left to close this menu.

swipeMenu.js
var layMenu,txe;
//Called when application is started.
function OnStart()
{
    app.SetOrientation("Portrait");
    app.EnableBackKey(false);
 
    //container layout
    var layApp=app.CreateLayout("Absolute");
    layApp.SetBackColor("#ff224422");
    layApp.SetPosition(0,0,1,1);
    app.AddLayout(layApp);
 
    //home layout
    var layHome=app.CreateLayout("Linear","Left,FillXY");
    var btnMnu;
    if(app.GetDSVersion()>1.25)
    {
       btnMnu=app.CreateButton("[fa-bars]", -1, -1, "fontawesome,custom");
       btnMnu.SetStyle( "#77bb77", "#559955", 15, "#449944",2,0 );
    }
    else
       btnMnu=app.CreateButton("[fa-bars]", -1, -1, "fontawesome,alum");
    btnMnu.SetOnTouch(mnuAnimate);
    layHome.AddChild(btnMnu);
    txe =app.CreateTextEdit("aaaaa\nbbbbb",0.9,0.8);
    txe.SetMargins(0.05,0.02,0,0)
    txe.SetBackColor("#ff888888");
    layHome.AddChild(txe);
    layApp.AddChild(layHome);
 
   //Create menu layout
    layMenu = getSlideMenu(menu_OnTouch, menu_SwipeTest);    
    layMenu.SetPosition(0,0.08);
    //Populate menu list
    layMenu.AddItem("Hello","World","/Sys/Img/Add.png");
    layMenu.AddItem("Another","Item","/Sys/Img/Bulb.png");
    layMenu.AddItem("Three","","video");
    layMenu.AddItem("Four","","audio");
 
    //Add layout to app.    
    layApp.AddChild( layMenu );
}
 
function mnuAnimate()
{
    if(layMenu.GetVisibility()==="Hide")
       layMenu.Show();
    else
       layMenu.Hide();
}
 
function OnBack()
{
   if(layMenu.GetVisibility()==="Show")
      layMenu.Animate("SlideToLeft");
   else app.Exit();
}
 
//catch hardware menu button
function OnMenu( item )
{    
    if(item==null) mnuAnimate();
}
 
function getSlideMenu(onTouch, swipeTest)
{
//Create menu layout
    var lst
    var layMenu = app.CreateLayout( "Absolute", "" );    
    layMenu.SetPosition(0,0.08);
    layMenu.SetBackColor("#ff66aa66");
    layMenu.SetVisibility("Hide")
    //Create menu list
    lst = app.CreateList( "" ,0.8,0.8);
    if(onTouch) lst.SetOnTouch(onTouch);
    lst.SetList(null);
    layMenu.AddChild( lst );
    //create swiper image
    var img=app.CreateImage(null,0.8,0.8);
    img.menu=lst;
    img.downX=0;
    if(swipeTest) img.SetOnTouch(swipeTest);
    layMenu.AddChild(img);
 
    //public methods
    img.Hide=function()
    {
         layMenu.Hide();
    }
    layMenu.Show=function()
    {
         this.Animate("SlideFromLeft");
    }
    layMenu.Hide=function()
    {
         this.Animate("SlidetoLeft");
    }
    layMenu.AddItem=function( title,body,image )
    {
        lst.AddItem( title,body,image );
    }
    layMenu.Setlist=function( list,delim )
    {
        lst.SetList( list,delim )
    }
    return layMenu
}
 
// callback function for menu selection
function menu_OnTouch( title, body, image, index )
{
  var s = txe.GetText()+"\n"+title;
  txe.SetText(s);
  app.ShowPopup(title+" added")
}
 
// callback function to swipe close menu
function menu_SwipeTest(ev)
{
    if(ev.action==="Down")
    {
        this.downX=ev.X;
    }
    if(ev.action==="Up")
    {
        if(ev.X-this.downX < -0.1)
           this.Hide();
        else 
           app.SimulateTouch(this.menu,ev.X,ev.Y);
    }
}
sample_code/slide_menu.txt · Last modified: 2016/01/02 05:07 by 1.127.48.14