1

I want to design a menu with option "yes" and "no".

It looks like the share option in native Glassware, when people touch "share" in their menu, Glass asks users to choose "facebook" or "Google+".

I want do design my menu with the same function and record users' choice as the input of other functions.

But I'm quite new to Android so I'm not quite clear about how to do this.

I Googled and found some similar questions:

I think it is some kind of nested menu but this question says there should not be nested in Glass.

Can you create more than one level of nested timeline cards on Glass?

and there is another similar solution

http://www.androidhive.info/2014/10/how-to-create-google-glass-options-menu/

but it uses more than one activity in the program and it is suitable for a more complicated operation than "yes"/"no" choice.

So I think I run and searched in a wrong way about the nested menu. Could anyone give me a final answer whether I can implement this operation or not. If can, what is its exact name so I can Google the implement method.

Thanks

Community
  • 1
  • 1
lanyusea
  • 143
  • 2
  • 14

2 Answers2

1

You should try to take advantage of what Google Glass can do; in this case, I would suggest you to use speech recognition for a simple Yes or No user response like this --

UI Diagram

(Live card)--> app launcher
|                      |
Share                  Stop
 | onGesture activate    |
 | voice recognition    terminate the app
 | to take user input
 onActivityResult()
   if it's "facebook" then go share on FB
   if it's "Google plus" then go share on G+

Here is the reference to Google Glass Developers Website - Voice Recognition

The section has a pretty easy-to-understand tutorial on how to implement voice recognition.

Below is a sample UI diagram of my Glass app. The first menu item takes voice commands and ask the user to confirm whether or not it is correct: For instance, ask user "Did you say 'carrot'? " and take input as either 'yes' or 'no' to determine the following action.

enter image description here

Finally, if you like, take a look at my HelloWorld Glass sample project for some ideas on the implementation. The direct link to the project hosted on Google Code is here: https://code.google.com/p/hello-world-google-glass/source/browse/#git%2FHelloWorld

Community
  • 1
  • 1
display name
  • 4,165
  • 2
  • 27
  • 52
  • Hi IsabelHM, thanks for your answer. I have a question about Voice Recognition but not sure whether it worth asking. I checked the official document and found that I need to set onCreateOptionsMenu() for voice command. But I have already done that in advance to set up normal menu. If I includes the voice command inside, the voice command will show when user click to enter menu. But I don't want this, I want a separated voice menu. Should I redo onCreateOptionsMenu() every time I enter/leave `ok glass` or is there any other way to solve this. Thanks! – lanyusea Jan 14 '15 at 19:59
  • What I did was adding a menu option as "Command Prototype" which starts the activity taking voice input and onActivityResult() if the command matches the option of (let's say) "Open shopping list", then I set the selected option menu id to "Shopping List" (which as you can see on the screenshot is the second menu option). Therefore, a user can access the Shopping List either with voice command or by clicking on it. What you want to implement in the voice rec. activity is to ask "Are you trying to XXX?" and get user input as "Yes" or "No". Let me know if you have any questions. – display name Jan 14 '15 at 22:16
  • Thanks for your reply! So the voice command must exist in the menu list and I cannot set up a voice command that is not a menu item directly. (e.g. I want "ok glass, take a picture" in my Glassware but there is not a TAKE PICTURE in clicking menu) – lanyusea Jan 15 '15 at 02:20
  • voice command that starts with "ok glass" is not allowed in your app besides opening the app (and the app name has to be approved when published to use as voice command) as far as I remember. In terms of taking an action like open camera, I don't think you need to add it to the menu list like what I did as long as you start an activity using immersion. If you get it to work and implement differently, let me know. :) Good luck! – display name Jan 15 '15 at 04:26
  • Thanks, I will try to find a way. :) – lanyusea Jan 15 '15 at 05:54
0

Please take a look at this official documentation by Google about how to add menu to the Glass app, will give you a direction of how to proceed with designing menu options for glass, without having to follow a lot of steps:

  • If you want to add the yes/no options in the Glass activities create menu resources and then display them on a user action, such as a tap when your activity has focus.
  • Please note that Glass menus don't support checkable items.
  • For each menu item, provide a 50 × 50 pixel menu item icon.

Here is a code snippet for OK option:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:id="@+id/Ok_menu_item"
    android:title="@string/Ok"                <!-- imperative verb -->
    android:icon="@drawable/ic_done_50" />   <!-- white in color on
                                                 transparent background
                                                 -->
   </menu>

The callbacks in the Menu are handled in the following manner:

  • onCreateOptionsMenu() inflates the XML menu resource.
  • onPrepareOptionsMenu() shows or hides menu items if required. For example, you can show different menu items based on what users are doing.
  • onOptionsItemSelected() handles user selection.

Here is a small code snippet of Java code:

    public class MyActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

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

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // Implement if needed
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection. Menu items typically start another
        // activity, start a service, or broadcast another intent.
        switch (item.getItemId()) {
            case R.id.stop:
                startActivity(new Intent(this,
                StopStopWatchActivity.class));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}

To display the menu, call openOptionsMenu() when required, such as a tap on the touchpad. The following examples detects a tap gesture on an activity and then calls openOptionsMenu().

    public class MainActivity extends Activity {
    // ...
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
          if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
              openOptionsMenu();
              return true;
          }
          return super.onKeyDown(keyCode, event);
    }
}

Hope this would help!!

AniV
  • 3,997
  • 1
  • 12
  • 17