简体   繁体   English

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

[英]Tapping / Swiping not detected in Android Studio Google Glass emulator

I'm running an emulator for google glass as seen here, works pretty flawlessly by showing settings, main display and even my activity (which I pretend to be an interactive static card). 我正在运行一个用于Google Glass的模拟器,如此处所示,它通过显示设置,主显示甚至我的活动(我伪装成交互式静态卡)来完美地工作。

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

I've seen that the motion gestures are captured using onKeyUp or onKeyDown events but neither are working and I don't understand why. 我已经看到动作手势是使用onKeyUponKeyDown事件捕获的,但是它们都不起作用,我也不知道为什么。

Here is my code. 这是我的代码。

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

Can someone help me on this one? 有人可以帮我吗? Tyvm! Tyvm!

Try calling setFocusable(true) on your content view. 尝试在内容视图上调用setFocusable(true)

Though I don't know much about how this emulator works, this is how you might get this working for standard Android. 尽管我对这个模拟器的工作原理并不了解,但是您可以通过这种方式使它在标准Android上正常工作。

You're using onKeyUp() when you need to be using onKeyDown() . 当您需要使用onKeyDown()时,便在使用onKeyUp() onKeyDown() Here's an example I'm using in my Glass project (but I have a physical Google Glass, not using an emulator): 这是我在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 Maybe this is an issue with the emulator? 编辑也许这是模拟器的问题? I doubt it though but you can test this theory by creating some dummy Android project for a phone/phone emulator that is known to work. 我对此表示怀疑,但是您可以通过为已知有效的电话/电话模拟器创建一些虚拟的Android项目来测试该理论。 If this snippet doesn't even work for the other Android emulation then maybe its something else? 如果此代码段甚至无法用于其他Android仿真,那么可能还有其他功能吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM