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

This is an old revision of the document!


Slide Menu

You can swipe left to close this menu.

swipeMenu.js
var layMenu,lst,txe;
//Called when application is started.
function OnStart()
{
    app.SetOrientation("Portrait");
    app.EnableBackKey(false);
    //container layout
    var layMain=app.CreateLayout("Absolute");
    layMain.SetBackColor("#ff224422");
    layMain.SetPosition(0,0,1,1);
    app.AddLayout(layMain);
    var lay=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);
    lay.AddChild(btnMnu);
    txe =app.CreateTextEdit("aaaaa\nbbbbb",0.9,0.8);
    txe.SetMargins(0.05,0.02,0,0)
    txe.SetBackColor("#ff888888");
    lay.AddChild(txe);
    layMain.AddChild(lay);
 
   //Create menu layout
    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);
    lst.SetOnTouch(lst_OnTouch);
    lst.SetList(null);
    lst.AddItem("Hello","World","/Sys/Img/Add.png");
    lst.AddItem("Another","Item","/Sys/Img/Bulb.png");
    lst.AddItem("Three","","video");
    lst.AddItem("Four","","audio");
    layMenu.AddChild( lst );
    //create swiper image
    var img=app.CreateImage(null,0.8,0.8);
    img.downX=0
    img.SetOnTouch(swipeTest);
    layMenu.AddChild(img);
 
    //Add layout to app.    
    layMain.AddChild( layMenu );
}
 
function mnuAnimate()
{
    if(layMenu.GetVisibility()==="Hide")
       layMenu.Animate("SlideFromLeft");
    else
       layMenu.Animate("SlideToLeft");
}
 
function swipeTest(ev)
{
    if(ev.action==="Down")
    {
        this.downX=ev.X;
    }
    if(ev.action==="Up")
    {
        if(ev.X-this.downX < -0.1)
           layMenu.Animate("SlideToLeft");
        else 
           app.SimulateTouch(lst,ev.X,ev.Y);
    }
}
 
function lst_OnTouch( title, body, image, index )
{
  var s = txe.GetText()+"\n"+title;
  txe.SetText(s);
  app.ShowPopup(title+" added")
}
 
function OnBack()
{
   if(layMenu.GetVisibility()==="Show")
      layMenu.Animate("SlideToLeft");
   else app.Exit();
}
sample_code/slide_menu.1443167943.txt.gz · Last modified: 2015/09/25 15:59 (external edit)