This shows you the differences between two versions of the page.
sample_code:about_dialog [2015/01/25 14:17] octazid Created |
sample_code:about_dialog [2015/01/25 22:32] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======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. | ||
- | |||
- | <code Javascript 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, | ||
- | { | ||
- | var self = this; | ||
- | this.dlg = app.CreateDialog(" | ||
- | this.lay = app.CreateLayout( " | ||
- | this.txt = app.CreateWebView(infowidth, | ||
- | this.txt.SetBackColor(backcolor); | ||
- | this.txt.LoadHtml(information); | ||
- | this.txt.SetMargins(0, | ||
- | this.txt.parent = self; | ||
- | this.lay.AddChild(this.txt); | ||
- | this.btnlay = app.CreateLayout( " | ||
- | this.dlgbtn = app.CreateButton(" | ||
- | 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(" | ||
- | 2. Create a Button to call the Dialog and add it to the layout | ||
- | btn = app.CreateButton( " | ||
- | btn.SetOnTouch(CreateAboutDlg); | ||
- | lay.AddChild( btn ); | ||
- | 3. Write a function to call the Dialog | ||
- | function CreateAboutDlg() | ||
- | { | ||
- | var txt = app.ReadFile(" | ||
- | DlgAbout = new AboutDialog(txt, | ||
- | DlgAbout.Show(); | ||
- | } | ||
- | Or you can use this Example. | ||
- | <code Javascript exampleapp.js> | ||
- | //Called when application is started. | ||
- | |||
- | function OnStart() | ||
- | { | ||
- | app.LoadScript(" | ||
- | lay = app.CreateLayout( " | ||
- | btn = app.CreateButton( " | ||
- | btn.SetOnTouch(CreateAboutDlg); | ||
- | lay.AddChild( btn ); | ||
- | app.AddLayout( lay ); | ||
- | } | ||
- | |||
- | |||
- | function CreateAboutDlg() | ||
- | { | ||
- | var txt = app.ReadFile(" | ||
- | DlgAbout = new AboutDialog(txt, | ||
- | DlgAbout.Show(); | ||
- | } | ||
- | </ |