1
votes

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

2

2 Answers

1
votes

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

0
votes

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!!