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

inputbox

Dialog to get a string from the user.

inbox.js
var inbox, txt;
function OnStart()
{
  var lay = app.CreateLayout( "linear", "VCenter,FillXY" );  
  txt = app.CreateText( "Hello" );
  txt.SetTextSize( 32 );
  lay.AddChild( txt );
  var ask = app.CreateButton( "Ask for some text" );
  ask.SetOnTouch( ask_OnTouch );
  lay.AddChild( ask );
  app.AddLayout( lay );  
 
  inbox = inputBox("What is your name?", gotInput,"Name",0.9);
}
 
function ask_OnTouch()
{
    //inbox.SetText("");
    //inbox.Show();
    inbox.ShowWithKeyboard();
}
 
function gotInput()
{
  txt.SetText( this.GetText() );
}
 
// This function returns an input dialog
// title (optional) dialog title, suppressed if empty
// okCallback (required) function called when Ok touched
// hint (optional) empty string displays no hint
// width (optional) 0 to 1 used when creating TextBox
function inputBox(title, okCallback, hint, width)
{
    var options = "NoCancel"
    title = title || "";
    hint = hint || "Your text";
    //suppress title line if no title - pass " " to override
    if( title==="") options += ",NoTitle";
 
    // create dialog
    var dlg = app.CreateDialog( title,options  );
    var lay = app.CreateLayout( "Linear", "" );
    dlg.AddLayout( lay );
 
    // add controls
    var edt = app.CreateTextEdit( "", width );
    edt.SetHint( hint );
    lay.AddChild( edt );
    var layBtn = app.CreateLayout( "Linear", "Horizontal" );
    lay.AddChild( layBtn );
    var btnCancel = app.CreateButton( "Cancel",-1,-1,"custom" );
    btnCancel.SetOnTouch( function(){dlg.Dismiss();} );
    layBtn.AddChild( btnCancel );
    var btnOk = app.CreateButton( "Ok",-1,-1,"custom" );
    layBtn.AddChild( btnOk );    
    btnOk.SetOnTouch( function(){okCallback.call(edt);dlg.Dismiss()} );
 
    // public functions
    dlg.ShowKeyboard = function(  )
    {edt.Focus();app.ShowKeyboard( edt );}
 
    dlg.SetText = function(txt){edt.SetText(txt);}
 
    dlg.ShowWithKeyboard=function()
    {setTimeout(dlg.ShowKeyboard, 100);dlg.Show();}
 
    // 
    return dlg
}
sample_code/inputbox.txt · Last modified: 2017/02/17 05:04 by stevegarman