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

About Dialog

First create a .js-File and save it as aboutdlg.js in a Droidscriptfolder where you need the file.
Then write the informations you want to display in the dialogbox on a seperate HTML-file.
Call it about.html and put the file in the same folder. So it is later easy to change the informations.

aboutdlg.js
/********************************************************************
 * About Dialog
=====================================================================
 * Creation date: 22-01-2015 by octazid
 * Last update: 22-01-2015 by octazid
=====================================================================
 * Simple dialog to show some things about the app
********************************************************************/
 
//*** AboutDialog class ***//
function AboutDialog(information, infowidth, infoheight, backcolor)
{
  var self = this;
  this.dlg = app.CreateDialog("About:");
  this.lay = app.CreateLayout( "linear", "FillXY" );
  this.txt = app.CreateWebView(infowidth, infoheight);
  this.txt.SetBackColor(backcolor);
  this.txt.LoadHtml(information);
  this.txt.SetMargins(0,0.01,0,0);
  this.txt.parent = self;
  this.lay.AddChild(this.txt);
  this.btnlay = app.CreateLayout( "Linear", "Horizontal,FillXY" );
  this.dlgbtn = app.CreateButton("OK", 0.45,-1);
  this.dlgbtn.parent = self;
  this.dlgbtn.SetOnTouch(dlgbtn_OnTouch);
  this.btnlay.AddChild(this.dlgbtn);
  this.lay.AddChild(this.btnlay);
  this.dlg.AddLayout(this.lay);
  this.Show = function(){self.dlg.Show();}
  this.Hide = function(){self.dlg.Hide();}
}//function AboutDialog()
 
 
// Called if button is touched
function dlgbtn_OnTouch()
{
    var par = this.parent;
    par.Hide();
}//function dlgbtn_OnTouch

In your app you have to do three things,

1. Load the Script with

  app.LoadScript("aboutdlg.js")

2. Create a Button to call the Dialog and add it to the layout

  btn = app.CreateButton( "About", 0.3, 0.1, "Alum" );
  btn.SetOnTouch(CreateAboutDlg);
  lay.AddChild( btn );

3. Write a function to call the Dialog

  function CreateAboutDlg()
  {
  var txt = app.ReadFile("about.html");
  DlgAbout = new AboutDialog(txt, -1, -1, "#ff222222");
  DlgAbout.Show();    
  }

Or you can use this Example.

exampleapp.js
//Called when application is started.
 
function OnStart()
{
    app.LoadScript("aboutdlg.js")      
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );    
    btn = app.CreateButton( "About", 0.3, 0.1, "Alum" );
    btn.SetOnTouch(CreateAboutDlg);
    lay.AddChild( btn );
    app.AddLayout( lay );    
} 
 
 
function CreateAboutDlg()
{
    var txt = app.ReadFile("about.html");
    DlgAbout = new AboutDialog(txt, -1, -1, "#ff222222");
    DlgAbout.Show();    
}
sample_code/about_dialog.txt · Last modified: 2015/01/25 22:32 (external edit)