var menu;
//Called when application is started.
function OnStart()
{
app.EnableBackKey(false);
//Create a layout with objects vertically centered.
var lay = app.CreateLayout( "linear", "VCenter,FillXY" );
//Create a button to launch the menu
var btn = app.CreateButton( "Show Menu", 0.6, 0.1 );
btn.SetOnTouch( showMenu );
lay.AddChild( btn );
//Add layout to app.
app.AddLayout( lay );
//create a menu dialog.
menu = createMenu("Exit");
menu.SetList("Exit,Model,OSversion");
}
//Create a menu dialog
function createMenu(list)
{
//Create dialog window.
var dlg = app.CreateDialog( "Menu" );
//Create a layout for dialog.
var layDlg = app.CreateLayout( "linear", "vertical,fillxy,left" );
layDlg.SetPadding( 0.02, 0, 0.02, 0.02 );
dlg.AddLayout( layDlg );
//Create a list control and add to dialog
var lstDlg = app.CreateList( list, 0.8, 0.6 );
lstDlg.SetTextSize( 22 );
lstDlg.SetTextColor( "#dddddd" );
lstDlg.SetOnTouch( OnMenu );
layDlg.AddChild( lstDlg );
//need a SetList function for changes to menu
dlg.SetList=function(lst)
{
lstDlg.SetList(lst)
}
//GetList function useful for adding to menu
dlg.GetList=function()
{
return lstDlg.GetList(",")
}
return dlg
}
function showMenu()
{
menu.Show();
}
//Handle list item selection.
function OnMenu( item )
{
//Hide the dialog window.
menu.Hide();
if(item==null)
{
showMenu();
return;
}
switch(item)
{
case "Exit":
app.Exit();
break;
case "Model":
app.ShowPopup(app.GetModel());
break;
case "OSversion":
app.ShowPopup("API level "+app.GetOSVersion());
break;
default:
app.Alert(item+" is not a valid option");
}
}
function OnBack()
{
showMenu();
}