java - Android Studio Google Glass 模拟器中未检测到点击/滑动

标签 java android google-glass gesture

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

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();
    }
}

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

最佳答案

尝试在内容 View 上调用 setFocusable(true)

虽然我不太了解这个模拟器的工作原理,但这就是您如何让它在标准 Android 上工作的方法。

关于java - Android Studio Google Glass 模拟器中未检测到点击/滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25293966/

相关文章:

java - 如果用户关闭浏览器,如何自动结束 session

java - Web 服务是否应该记录响应数据(如果是,在哪个级别)?

java - Elasticsearch High Level Rest Client - 带有类型(子)字段的 Java map - 日期、数字等

java - 如何获取属性名称而不是属性值?

java - RecyclerView 中的多个 TextView。怎么做?

Java保证回调顺序执行

google-glass - 哪个语音命令具有优先权?

android - 从 RAW 资源在 TextView 中加载文本

java - EyeGesture和EyeGestureManager需要清晰

google-glass - 使用 Glass 进行身份验证