【问题标题】:Tapping / Swiping not detected in Android Studio Google Glass emulator在 Android Studio Google Glass 模拟器中未检测到点击/滑动
【发布时间】:2014-08-13 18:52:05
【问题描述】:

我正在运行一个用于谷歌眼镜的模拟器,如图所示,通过显示设置、主显示甚至我的活动(我假装是一个交互式静态卡片),它工作得非常完美。

http://mobilevangelist.com/2014/01/02/gdk-and-the-android-emulator/

我发现运动手势是使用 onKeyUponKeyDown 事件捕获的,但两者都不起作用我不明白为什么。

这是我的代码。

public class LiveCardMenuActivity extends Activity {

    private TextView textView;

    @Override //isn't catching a thing, even with onKeyDown (mouse taps or slides in the emulator)
    public boolean onKeyUp(int keycode, KeyEvent event){
        Log.d("tag","keyUp");
        if(keycode == KeyEvent.KEYCODE_DPAD_CENTER){
            Log.d("tag","keypadcenter");
            textView.setText("tap");
        }else if(keycode == KeyEvent.KEYCODE_BACK){
            Log.d("tag","swipedown");
            textView.setText("down");
        }
        return true;
    }

    @Override
    public void onAttachedToWindow() {
            super.onAttachedToWindow();
            setContentView(R.layout.live_card); 
            //does successfully, I can see the layout in the emulator
           //and I can swipe it to the left (returning to the main display successfully)
            textView = (TextView) findViewById(R.id.textView);
            Log.d("tag","attached to window");
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_stop:
                // Stop the service which will unpublish the live card.
                stopService(new Intent(this, LiveCardService.class));
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public void onOptionsMenuClosed(Menu menu) {
        super.onOptionsMenuClosed(menu);
        // Nothing else to do, finish the Activity.
        finish();
    }
}

有人可以帮我解决这个问题吗?特维姆!

【问题讨论】:

    标签: java android google-glass gesture


    【解决方案1】:

    尝试在您的内容视图上调用setFocusable(true)

    虽然我不太了解此模拟器的工作原理,但您可以通过以下方式使其适用于标准 Android。

    【讨论】:

      【解决方案2】:

      当您需要使用onKeyDown() 时,您正在使用onKeyUp()。这是我在 Glass 项目中使用的示例(但我有一个物理 Google Glass,不使用模拟器):

      public boolean onKeyDown(int keyCode, KeyEvent event) {
          switch( keyCode ) {
              case KeyEvent.KEYCODE_DPAD_CENTER:
                  Log.e("GESTURE_EVENT", "PostVideoActivity.onKeyDown() TAP/KEYCODE_DPAD_CENTER");
                  // DO SOMETHING
                  return true;
              case KeyEvent.KEYCODE_BACK:
                  Log.e("GESTURE_EVENT", "PostVideoActivity.onKeyDown() SWIPE/KEYCODE_BACK");
                  // DO SOMETHING
                  return true;
              default:
                  Log.wtf("GESTURE_EVENT", "PostVideoActivity.onKeyDown() DEFAULT -- SHOULDNT BE HERE!");
                  return false;
          }
      }
      

      edit 也许这是模拟器的问题?虽然我对此表示怀疑,但您可以通过为已知可以工作的电话/电话模拟器创建一些虚拟 Android 项目来测试这个理论。如果这个 sn-p 甚至不适用于其他 Android 仿真,那么它可能是别的什么?

      【讨论】:

        猜你喜欢
        • 2017-04-02
        • 2019-01-17
        • 2021-08-28
        • 2018-12-18
        • 2021-07-25
        • 1970-01-01
        • 2017-11-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多