0

I am trying to create a simple menu inside of a Glass application. It only consists of 4 items. I previously used ListView to accomplish this, and it worked perfectly. However, according to a number of different posts ListViews are on Google's bad list, so they gutted the functionality for it. I tried to use the workaround listed here

How to enable scrolling on a simpleadapter on Google Glass's firmware X16

But I had no luck implementing it, I also wanted to move away from ListViews as they are already off of the supported list of google and I don't want to have to force it.

So my question is, is there any other way to create a small menu for glass?

Community
  • 1
  • 1
Zarno
  • 47
  • 2

2 Answers2

0

did you already try creating an standard menu?, like this tutorial:

https://developers.google.com/glass/develop/gdk/immersions#creating_and_displaying_a_menu

You could find examples in the Timer and Charade examples:

https://developers.google.com/glass/samples/gdk

specifically in this activity: https://github.com/googleglass/gdk-timer-sample/blob/master/src/com/google/android/glass/sample/timer/MenuActivity.java

fpanizza
  • 1,589
  • 1
  • 8
  • 15
0

This is how I implemented it on my Google GLASS:

First of all, implement in your Activity the menu as you would do it on a normal Android app:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection.
        switch (item.getItemId()) {
            case R.id.menu_item_1:
                //Do what you want here
                return true;
            case R.id.menu_item_2:
                //Do what you want here
                return true;
            case R.id.menu_item_3:
                //Do what you want here
                return true;
            case R.id.menu_item_4:
                //Do what you want here
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

Then, implement the method onKeyDown, to make it open the menu when you are in the activity and you tap the touchpad:

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
      switch (keyCode) {
      // Handle tap events.
      case KeyEvent.KEYCODE_DPAD_CENTER:
      case KeyEvent.KEYCODE_ENTER:
          //Play default tap sound
          AudioManager audio = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
          audio.playSoundEffect(Sounds.TAP);
          //Open the menu
          openOptionsMenu();
        return true;
      default:
        return super.onKeyDown(keyCode, event);
      }
    }

This is how your menu layout should look like:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">   
    <item
        android:id="@+id/menu_item_1"
        android:title="@string/menu_item_1" />
    <item
        android:id="@+id/menu_item_2"
        android:title="@string/menu_item_2"/>
    <item
        android:id="@+id/menu_item_3"
        android:title="@string/menu_item_3"/>
    <item
        android:id="@+id/menu_item_4"
        android:title="@string/menu_item_4"
        android:icon="@drawable/menu_icon_4" />
</menu>

As you can see on item 4, you can also add icons to your menu.

Hope it helps :)

kodartcha
  • 1,063
  • 12
  • 23