Custom Yes-No-Dialog

(Sample posted by Chris Hopkin in the DroidScript Google Group)

If you want to show a popup window on exit, you could use a custom Dialog.
For example, this is a small app that pops up a custom dialog when the back button is pressed

custom_yes_no_dialog.js
//Called after application is started.
    function OnStart()
    {
        app.EnableBackKey( false );
        app.ShowPopup( "Touch the Back Button" );
    }
 
    function OnBack()
    {              
        //Create dialog window.
        dlgExit = app.CreateDialog( "Exit?" );
 
        //Create a layout for dialog.
        layDlg = app.CreateLayout( "Linear", "Horizontal,FillXY" );
        layDlg.SetPadding( 0.02, 0.02, 0.02, 0.02 );
        dlgExit.AddLayout( layDlg );
 
        var btnYes = app.CreateButton("[fa-check-circle] Yes", 0.3, -1, "FontAwesome");
        btnYes.SetTextSize( 24 );
        btnYes.SetOnTouch( btnYes_OnTouch );
        layDlg.AddChild( btnYes );
 
        var btnNo = app.CreateButton("[fa-times-circle] No", 0.3, -1, "FontAwesome");
        btnNo.SetOnTouch( btnNo_OnTouch );
        btnNo.SetTextSize( 24 );
        layDlg.AddChild( btnNo );
 
        //Show dialog.
        dlgExit.Show();
    }
 
    function btnYes_OnTouch()
    {
        dlgExit.Dismiss();
        app.Exit();
    }
 
    function btnNo_OnTouch()
    {
        dlgExit.Dismiss();
    }