以编程方式填充上下文"ok玻璃"框.菜单 [英] Programmatically populated contextual "ok glass" menu

查看:32
本文介绍了以编程方式填充上下文"ok玻璃"框.菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以以编程方式在我的玻璃器皿中填充自定义"ok玻璃"菜单吗?

Is there any way to populate the custom "ok glass" menu in my glassware programmatically?

我有一个应用程序,用户可以沉浸其中并主要通过语音命令与系统交互.沉浸式显示一个CardScrollView,显示不同的数据集.这些设置是通过与电话通话的蓝牙服务动态添加和删除的,玻璃单元无法事先知道将出现什么新设置.

I have an application where the user will be in an immersion and interact with the system mainly by voice commands. The immersion consists of a CardScrollView displaying different sets of data. These sets are added and removed dynamically from a bluetooth service talking to a phone and the glass unit can't know in advance what new sets will appear.

我希望用户能够在语音菜单中列出所有当前设置,然后从中选择要切换到的设置.例如,如果我目前拥有A,B,C和D组,则我希望用户能够说好的玻璃杯,去进行设置",请参阅带有A,B,C和D的子菜单,然后说"C"以切换到视图中的设置C.

What I want the user to be able to do is to list all current sets in the voice menu and from there choose which set to switch to. For example, if I at the moment have the sets A, B, C and D, I want the user to be able to say "ok glass, go to set", see a sub menu with A, B, C and D and then say for example "C" to switch to set C in the view.

这有可能吗?

该玻璃器皿将在完全不连接MyGlass的封闭环境中运行,因此具有开发许可的菜单自定义语音命令不是问题.

The glassware is going to run in a closed environment with no connection to MyGlass at all, so custom voice commands for the menu with the development permission is not a problem.

推荐答案

据我了解,您希望应用程序在用户讲话时已经在运行.如果正确,那么您可以使用上下文语音命令.我相信您可以随时通过覆盖onPreparePanel重新填充菜单.

From what I understand you want you application to be already running when the user speaks. If this is correct then you can simply implement a custom menu with contextual voice commands. I believe you can always repopulate the menu just before it is being shown by overriding onPreparePanel.

我还没有测试过,但是从指南中猜测是这样的:

I haven't tested it but guessing from the guide something like:

  @Override
  public boolean onPreparePanel(int featureId, View view, Menu menu) {
    if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS) {
      menu.clear();
      for (MyMenuItem item : mCurrentMenuItems) {
        menu.add(Menu.NONE, item.getId(), Menu.NONE, item.getTitle());
      }
    }
    return super.onPreparePanel(featureId, view, menu);
  }

  @Override
  public boolean onMenuItemSelected(int featureId, MenuItem item) {
    if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS) {
      switch (item.getItemId()) {
        case MENU_ITEM_A:
          // do something
          break;
        default:
          return true;
      }
      return true;
    }
    return super.onMenuItemSelected(featureId, item);
  }

MyMenuItem将是一个简单的类,其中包含项的唯一ID及其标题. mCurrentMenuItems是当前要显示的项目列表.例如,您可以使用后台服务更改其内容.

MyMenuItem would be a simple class which holds a unique id of an item and its title. mCurrentMenuItems is a list of items to be shown at the moment. You can change its content using a background service, for example.

这篇关于以编程方式填充上下文"ok玻璃"框.菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆