Need help from someone with a menu button.

141 views
Skip to first unread message

Steve Garman

unread,
Apr 6, 2015, 10:41:21 AM4/6/15
to androi...@googlegroups.com
I have been trying to change my menu system slightly but I do not have any android device with a menu button.

I would be really grateful if someone with a phone or tablet that has a menu button would test the code below for me and see if the menu button displays the menu.

On my devices, both the button on the screen and the back button bring up the menu but I am not at all sure whether my technique for detecting the menu button is valid.

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();
}



Timo Octazid

unread,
Apr 6, 2015, 10:44:46 AM4/6/15
to androi...@googlegroups.com
Hi,
I will test it later on my other device at home.
Many Greetings
Timo

Steve Garman

unread,
Apr 6, 2015, 3:30:56 PM4/6/15
to androi...@googlegroups.com
Thanks Timo,

That will be very helpful.

Timo Octazid

unread,
Apr 6, 2015, 3:51:57 PM4/6/15
to androi...@googlegroups.com
Steve, your menu pops up on every button (hardware: back and menu button and on your software button)
By the way, its a nice solution for a bigger menu. I think I will use it in my apps.
Many Greetings
Timo

Steve Garman

unread,
Apr 6, 2015, 3:58:22 PM4/6/15
to androi...@googlegroups.com
Thanks for that Timo.

I found I needed a more prominent menu on my phone in a project I'm working on with lots of options.

Hopefully I can just rely on the hardware buttons and not need a title bar with a menu button.

Fernando Remor

unread,
Jun 5, 2015, 10:41:46 PM6/5/15
to androi...@googlegroups.com
Im test too and its ok. The same Timo Octazid say:  your menu pops up on every button (hardware: back and menu button and on your software button) .
Reply all
Reply to author
Forward
0 new messages