回到向左滑动不是在谷歌眼镜活动工作 [英] Back Swipe not working in Google Glass Activity

查看:141
本文介绍了回到向左滑动不是在谷歌眼镜活动工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为谷歌眼镜的一项基本活动,但不会允许我使用标准的向下滑动即可返回堆栈中的previous活动。我试着给活动的焦点与此code:

I've created a basic activity for Google Glass, but it will not allow me to use the standard down swipe to go back in the stack to the previous activity. I've tried giving the activity focus with this code:

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.layout_orienation_detection_activity);

    mView = getWindow().getDecorView().findViewById(android.R.id.content);
    mView.setFocusable(true);
    mView.setFocusableInTouchMode(true);
}

@Override
protected void onStart() {
    super.onStart();

    mGestureDetector = createGestureDetector(this);

    serviceIntent = new Intent(this, SensorService.class);
    startService(serviceIntent);

    mView.requestFocus();
}

我也尝试创建使用的onkeydown()方法,我自己倒刷卡功能,我已经尝试创建为TAP和SWIPE_DOWN手势检测,然后将完成(),以各自的回调。我的手势和重点检测code看起来完全一样,上的 https://developers.google.com/glass/develop/gdk/touch ,但仍没有工作。我想这不应该是必要的,反正,因为玻璃的标准回刷卡应该反正工作。

I've also tried creating my own down swipe features using the onKeyDown() method, and I've tried creating a Gesture detector for both TAP and SWIPE_DOWN, and then adding finish() to their respective callbacks. My gesture and key detector code looks exactly the same as the code on the Google Developers site at https://developers.google.com/glass/develop/gdk/touch, but still nothing works. I figure this shouldn't be necessary anyways, as Glass's standard back swipe ought to work anyways.

我不知道这有什么关系呢,但我的活动开始的服务。

I don't know if this has anything to do with it, but my activity starts a service.

此外,有时它的工作原理我第一次安装应用程序后,但随后停止之后立即工作。

Also, sometimes it works the first time after I install the application, but then it stops working immediately after that.

有没有人有任何想法,问题是什么?它不得不关闭玻璃设备或等待屏幕以退出活动超时非常令人沮丧。

Does anyone have any ideas as to what the problem is? It's very frustrating having to turn off the glass device or wait for the screen to timeout in order to exit the activity.

编辑:问题是从活动启动的服务,因为当我删除从我的活动startService(意向)调用,向下刷卡工作的罚款。因此,如何我还可以运行后台服务,而且还能够降低刷卡?

The problem is with starting a service from the activity, as when I deleted the startService(intent) call from my activity, the down swiping worked fine. So how can I still run the background service, but also be able to down swipe?

推荐答案

欢迎对谷歌玻璃做的事情 - 在没有一切正常,因为它应该。我有问题摆,但已经找到了一些一些解决方法。无论哪种方式,设置第一手势检测是棘手的,当我这样做是为了。我会为您提供我现在在一个玻璃应用我做了运行两个工作方案。

Welcome to doing things on Google Glass -- where not everything works as it should. I've had a slew of issues, but have found some workarounds for some. Either way, setting up the first gesture detection was tricky when I did it to. I'll provide you two working options I have right now running in a glass app I made.

通过的onkeydown():

Via onKeyDown():

    import android.view.KeyEvent;

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if( keyCode == KeyEvent.KEYCODE_BACK ) {
            // handles swipe down
            return true;
        }
        else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
            // handles tap
            return true;
        }
        return false;
    }

设置手势检测是麻烦,但它看起来像你缺少你从什么张贴了很多code的。下面是我在应用手势检测,现在的工作,生病仅包括相关位:

Setting up gesture detection is trickier, but it looks like you're missing a lot of code from what you posted. Here's what I have working right now in the app for gesture detection, Ill include just the relevant bits:

    import android.view.MotionEvent;

    import com.google.android.glass.touchpad.Gesture;
    import com.google.android.glass.touchpad.GestureDetector;

    private GestureDetector mGestureDetector;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //instantiate the gesture detector
        mGestureDetector = createGestureDetector(this);
    }

    // Actually create the gesture detector
    private GestureDetector createGestureDetector(Context context) {
        GestureDetector gestureDetector = new GestureDetector(context);
        gestureDetector.setBaseListener( new GestureDetector.BaseListener() {
            @Override
            public boolean onGesture(Gesture gesture) {
                if (gesture == Gesture.SWIPE_RIGHT) { 
                    // pickup right swipe
                    return true;
                } else if (gesture == Gesture.SWIPE_LEFT) {                         
                    // pickup left swipe
                    return true;
                } else if (gesture == Gesture.SWIPE_DOWN) {
                    // pickup down swipe
                    return true;
                } else if (gesture == Gesture.TAP) {
                    // pickup tap
                    return true;
                }
                return false;
            }
        });
        return gestureDetector;
    }

    //Send generic motion events to the gesture detector
    @Override
    public boolean onGenericMotionEvent(MotionEvent event) {
        if (mGestureDetector != null) {
            return mGestureDetector.onMotionEvent(event);
        }
        return false;
    }

至于你说这句话的:

As far as you saying this:

    Also, sometimes it works the first time after I install the application, but then it stops working immediately after that.

我也经历过,我现在还在试图解决类似的问题。它很难解决,虽然不知道更多。您是否尝试过更新玻璃上的固件?检查其最新的,否则还有什么是您在code在做什么?也许你有杂耍状态信息什么的,如果你的活动之间切换的问题?只是一个猜测。

I have experienced similar problems that I'm still currently trying to resolve. Its hard to troubleshoot that though without knowing more. Have you tried updating the firmware on the Glass? Check that its up to date, otherwise what else are you doing in the code? Maybe you have an issue juggling state information or something if you're switching between activities? Just a guess..

注意:手势检测和左,右刷卡的玻璃被打破,如果你正在做一个MediaPlayer的osmething例如关键事件。我们创建了一块code的VideoView,只能检测向下滑动,然后点击,没有别的,但我们遇到此在是利用VideoView / MediaPlayer的code块时,只。

Note: Gesture detection and Key Events for left and right swipes are broken on Glass if you're doing osmething with a MediaPlayer for example. We create a VideoView in a piece of code, and can only detect swipe down and tap and nothing else but we experience this ONLY when in a block of code that is utilizing VideoView/MediaPlayer.

这篇关于回到向左滑动不是在谷歌眼镜活动工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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