0

I would like know how to list all available contextual commands on card, where the "Ok, glass" is at footer and ready to accepting the commands. My app has more than 10 contextual commands and the user might not remember all the commands.

My code below will just show "Ok glass" as footer and nothing above the footer. However, the list of commands will be shown right after the "Ok glass" command. I would like to have the list and "ok glass" to be shown at the same time.

Please advise.

public class MenuActivity extends Activity {


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

        // Requests a voice menu on this activity. As for any other
        // window feature, be sure to request this before
        // setContentView() is called
        getWindow().requestFeature(WindowUtils.FEATURE_VOICE_COMMANDS);           
        setContentView(R.layout.start);
    }

    @Override
    public boolean onCreatePanelMenu(int featureId, Menu menu) {
        if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS||
                featureId == Window.FEATURE_OPTIONS_PANEL) {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
        // Pass through to super to setup touch menu.
        return super.onCreatePanelMenu(featureId, menu);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS||
            featureId == Window.FEATURE_OPTIONS_PANEL) {

            switch (item.getItemId()) {
                case R.id.Atrig_menu_item:
                    // handle A trigger          
                    break;
                case R.id.Btrig_menu_item:
                    // handle B trigger
                    break;
                case R.id.Ctrig_menu_item:
                    // handle C trigger
                    break;
                case R.id.Dtrig_menu_item:
                    // handle D trigger
                    break;
                case R.id.Etrig_menu_item:
                    // handle E trigger
                    this.finish();                
                default:
                    return true;
            }
            return true;
        }
        // Good practice to pass through to super if not handled
        return super.onMenuItemSelected(featureId, item);
    }

}

1 Answers1

0

In XE 21, you can't change the behaviour of the Contextual voice command.

If you want to show all the option available, before activate the Contextual Voice command by saying "Ok Glass", you will have to create a layout showing the content of your menu R.menu.main.

But even if you create a layout with all the item in your R.menu.main, when you say "Ok Glass" in your app, the contextual voice command will display your menu again.

The best would be to show some text or information in your principal layout which is R.layout.start, then let the Contextual Voice command show the menu when the user say "Ok glass".

Here is a link to show you how to build a simple layout : Tutorial Linear Layout

Pull
  • 2,236
  • 2
  • 16
  • 32
  • Currently, the card is blank with "Ok, glass" footer only. I'm now thinking to just show some text and picture above the "Ok, glass" footer instead of populating the menu since it will somehow will be display after the user say "Ok, glass". May i know how can i do that with the code above? – Kok Cheow Yeoh Sep 24 '14 at 13:53
  • Indeed it is better to let the Contextual voice command show the menu, no need to do it yourself. I will update my answer and explain how populate your view – Pull Sep 24 '14 at 15:29