需要EyeGesture和EyeGestureManager清晰度

时间:2014-12-10 16:18:33

标签: java android google-glass android-logcat google-gdk

Google审核小组要求使用glasseware:

  

如果没有用户的期望,请将屏幕调暗   正在寻找

     

这与Glass的“现在和现在”体验一致。   如果没有期望,玻璃器皿应该总是调暗屏幕   用户正在看它。理想情况下,它的行为就像时间轴一样   15秒后变暗。用户可以通过查找“重新”重新屏幕。

     

更新:如果用户未查看结果设置   卡片滚动,调暗屏幕。

这暗示使用EyeGestureGlass Develop Page上似乎没有提及{<1}}。

经过一些搜索,我发现this EyeGesture library (github) this stackoverflow post (Google Glass Eye Gesture Crashing (EyeGestureLib)) this revised EyeGesture library (github)似乎不再有效(并且在4个月内未更新+)。

使用the revised EyeGesture library

提出的接受答案(来自stackoverflow帖子)

还提到了(在stackoverflow帖子中 - 作为评论):

  

基本上,您正在尝试公开Glass中存在的类   环境本身,但不是通过官方API。通过声明   这些存根类(没有实现任何方法)和   将它们放入com.google.android.glass.eye包中,我们就是   允许我们的代码使用这些未实现的类进行编译。在   运行时,系统具有这些类的实现和   应用程序将使用系统的实现。

以下是我的以下问题:

  1. EyeGesture会在什么时候(及时)出现一个官方API?
  2. 我尝试通过遵循提议的指南实现GestureDetector而没有任何运气。我能做错什么?
  3. 我有什么东西可以检测到吗?我知道,Override onGenericMotionEvent(MotionEvent event)需要com.google.android.glass EyeGesture,EyeGesture有类似内容吗?
  4. 以下是我目前正在做的事情:

    我有一个名为enum的软件包,在这个软件包中我有以下内容:

      {li> implements Parcelable EyeGestureManager class
    • GestureIds class

    我在主包中:

    • private void createEyeGestureDetector(ResultActivity resultActivity) { final GestureIds gestureIds = new GestureIds(); //The github guide didn't mention any class names for //mEyeGestureManager and mEyeGestureListener .. so I added some.. EyeGestureManager mEyeGestureManager = EyeGestureManager.from(resultActivity); EyeGestureManager.Listener mEyeGestureListener = new EyeGestureManager.Listener() { @Override public void onDetected(EyeGesture gesture) { Log.i("EyeGestureListener", "Gesture: " + gesture.getId()); int id = gesture.getId(); if(id == gestureIds.WINK_ID || id == gestureIds.DOUBLE_WINK_ID) { Log.d("EyeGesture", "Wink"); } else if (id == gestureIds.BLINK_ID || id == gestureIds.DOUBLE_BLINK_ID){ Log.d("EyeGesture", "Blink"); } else if (id == gestureIds.LOOK_AT_SCREEN_ID || id == gestureIds.LOOK_AWAY_FROM_SCREEN_ID) { Log.d("EyeGesture", "Screen"); } } }; } onCreate(这个与github不同,因为它是一个公共类,而不是私有的)

    在我的活动中,我有:

    //..
    super.onCreate(bundle);
    createEyeGestureDetector(this);
    //..
    

    for (EyeGesture eg : EyeGesture.values()) { boolean supported = mEyeGestureManager.isSupported(eg); Log.w("yupyup", eg.name() + ":" + supported); } 我有:

    12-10 18:40:51.252    2405-2405/com.google.android.glass.websurg.websurg W/yupyup﹕ WINK:true
    12-10 18:40:51.252    2405-2405/com.google.android.glass.websurg.websurg W/yupyup﹕ DOUBLE_WINK:false
    12-10 18:40:51.252    2405-2405/com.google.android.glass.websurg.websurg W/yupyup﹕ BLINK:false
    12-10 18:40:51.252    2405-2405/com.google.android.glass.websurg.websurg W/yupyup﹕ DOUBLE_BLINK:true
    12-10 18:40:51.260    2405-2405/com.google.android.glass.websurg.websurg W/yupyup﹕ DON:true
    12-10 18:40:51.268    2405-2405/com.google.android.glass.websurg.websurg W/yupyup﹕ DOFF:true
    12-10 18:40:51.268    2405-2405/com.google.android.glass.websurg.websurg W/yupyup﹕ LOOK_AT_SCREEN:true
    12-10 18:40:51.268    2405-2405/com.google.android.glass.websurg.websurg W/yupyup﹕ LOOK_AWAY_FROM_SCREEN:false
    

    更新Logcat:

    当我这样做时:

    @Override
    protected void onStart(){
        super.onStart();
        createEyeGestureDetector(this);
        for (EyeGesture eg : EyeGesture.values()) {
            boolean supported = mEyeGestureManager.isSupported(eg);
            Log.w("yupyup", eg.name() + ":" + supported);
        }
        mEyeGestureManager.register(EyeGesture.LOOK_AT_SCREEN, mEyeGestureListener);
        mEyeGestureManager.register(EyeGesture.LOOK_AWAY_FROM_SCREEN, mEyeGestureListener);
        mEyeGestureManager.register(EyeGesture.WINK, mEyeGestureListener);
    
    }
    

    我明白了:

    @Override
    protected void onStop(){
        mEyeGestureManager.unregister(EyeGesture.LOOK_AT_SCREEN, mEyeGestureListener);
        mEyeGestureManager.unregister(EyeGesture.LOOK_AWAY_FROM_SCREEN, mEyeGestureListener);
        mEyeGestureManager.unregister(EyeGesture.WINK, mEyeGestureListener);
        super.onStop();
    }
    

    我还添加了(来自第一个github链接):

    12-10 18:46:11.314    2553-2553/com.google.android.glass.websurg.websurg I/EyeGestureManager﹕ Removing listener: com.google.android.glass.websurg.websurg.ResultActivity$1@41b8b908 for eye gesture: LOOK_AT_SCREEN
    12-10 18:46:11.314    2553-2553/com.google.android.glass.websurg.websurg I/EyeGestureManager﹕ Removing listener: com.google.android.glass.websurg.websurg.ResultActivity$1@41b8b908 for eye gesture: LOOK_AWAY_FROM_SCREEN
    12-10 18:46:11.314    2553-2553/com.google.android.glass.websurg.websurg I/EyeGestureManager﹕ Removing listener: com.google.android.glass.websurg.websurg.ResultActivity$1@41b8b908 for eye gesture: WINK
    

    {{1}}

    这给了我:

    {{1}}

    然而,他们没有被检测到..甚至WINK,因为它似乎得到了支持。

1 个答案:

答案 0 :(得分:0)

从Google Glass Review团队获得回报。他们回应:

  

如果没有用户正在看的期望,请将屏幕调暗   它

     

这与Glass的“现在和现在”体验一致。   如果没有期望,玻璃器皿应该总是调暗屏幕   用户正在看它。理想情况下,它的行为就像时间轴一样   15秒后变暗。用户可以通过查找来“重新点亮”屏幕。

     

更新:如果用户没有查看中的结果集   卡片滚动,调暗屏幕。

是这样的:

  

平台处理这个问题,你是否以某种方式覆盖了这个问题   你在显示结果时拿着唤醒锁?

所以现在看来​​它并不打算直接使用EyeGesture,因为它可以自动执行(需要在此部分进行确认)。在任何情况下都没有必要尝试处理LOOK_AT_SCREEN,因为LOOK_AWAY_FROM_SCREEN未得到处理。

12-10 18:40:51.268    2405-2405/com.google.android.glass.websurg.websurg W/yupyup﹕ LOOK_AWAY_FROM_SCREEN:false

对于那些有兴趣处理Wink EyeGesture的人来说,根据我收集的一些信息(需要确认),可以正常运作。

想法是使用is来使用EyeGestureEyeGestureManager存根。它们几乎存在于环境中但不存在于API中。这意味着要访问它们,您需要创建运行时运行的子程序(至少我理解它的方式)。

在处理WINK EyeGesture时,有一个已知的错误。它会拍照。这可能是在Google Glass设置中导致的,其中在检测到眨眼时拍摄照片。 (需要确认)。

那么如何实际处理呢?

第1步:创建存根:

创建一个名为com.google.android.glass的包。在此包中创建两个类:EyeGestureEyeGestureManager

EyeGesture:

package com.google.android.glass.eye;

    import android.os.Parcel;
    import android.os.Parcelable;

    /**
     *  https://gist.github.com/victorkp/9094a6aea9db236a97f3E
     * 
     */
    public enum EyeGesture implements Parcelable {
        BLINK, DOFF, DON, DOUBLE_BLINK, DOUBLE_WINK, LOOK_AT_SCREEN, LOOK_AWAY_FROM_SCREEN, WINK;

        public int getId(){
            return -1;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {

        }
    }

EyeGestureManager:

package com.google.android.glass.eye;

import android.content.Context;

/**
 * 
 * If there are any updates required check: https://gist.github.com/victorkp/9094a6aea9db236a97f3
 * 
 */
public class EyeGestureManager {
    public static final int INFINITE_TIMEOUT = -1;
    public static final String SERVICE_NAME = "eye_gesture";

    public interface Listener {
        public void onDetected(EyeGesture gesture);
    }

    public static EyeGestureManager from(Context paramContext) {
        return null;
    }

    public void activateGazeLogging(boolean paramBoolean) {
    }

    public boolean applyAndSaveCalibration(EyeGesture paramEyeGesture) {
        return false;
    }

    public boolean clearCalibration(EyeGesture paramEyeGesture) {
        return false;
    }

    public void enableGazeService(boolean paramBoolean) {
    }

    public boolean endCalibrationInterval(EyeGesture paramEyeGesture) {
        return false;
    }

    public boolean isCalibrationComplete(EyeGesture paramEyeGesture) {
        return false;
    }

    public boolean isGazeLogging() {
        return false;
    }

    public boolean isRegistered() {
        return false;
    }

    public boolean isSupported(EyeGesture paramEyeGesture) {
        return false;
    }

    public boolean loadCalibration(EyeGesture paramEyeGesture) {
        return false;
    }

    public boolean register(EyeGesture gesture, EyeGestureManager.Listener listener){
        return false;
    }

    public boolean startCalibrationInterval(EyeGesture paramEyeGesture) {
        return false;
    }

    public boolean unregister(EyeGesture gesture, EyeGestureManager.Listener listener) {
        return false;
    }
}

太棒了,你有两个存根。你应该注意的第一件事是它们不是100%喜欢github链接中的那个。有些功能已被弃用,我保留了那些功能。 (我没有尝试过每一个)。

下一步是什么?嗯,你需要(不是真的,但如果你这样做更容易)创建GestureId类(是的,你可以把它放在任何你想要的地方)。

GestureId:

package com.google.android.glass.websurg.websurg;

import com.google.android.glass.eye.EyeGesture;

/**
 * 
 *
 * For updates check out: https://gist.github.com/victorkp/9094a6aea9db236a97f3
 * 
 *
 * 
 */
public class GestureIds {
    public int BLINK_ID;
    public int WINK_ID;
    public int DOUBLE_BLINK_ID;
    public int DOUBLE_WINK_ID;
    public int LOOK_AT_SCREEN_ID;
    public int LOOK_AWAY_FROM_SCREEN_ID;

    public GestureIds() {
        BLINK_ID = EyeGesture.BLINK.getId();
        WINK_ID = EyeGesture.WINK.getId();
        DOUBLE_BLINK_ID = EyeGesture.DOUBLE_BLINK.getId();
        DOUBLE_WINK_ID = EyeGesture.DOUBLE_WINK.getId();
        LOOK_AT_SCREEN_ID = EyeGesture.LOOK_AT_SCREEN.getId();
        LOOK_AWAY_FROM_SCREEN_ID = EyeGesture.LOOK_AWAY_FROM_SCREEN.getId();
    }
}

现在你已经拥有了所有课程。请记住,存根是在运行时可以正常工作的存根(至少我认为是因为我没有收到任何错误?

假设您有一个MainActivity并且想要添加EyeGesture:

private void createEyeGestureDetector(Context context) {
    mGestureIds = new GestureIds();
    mEyeGestureManager = EyeGestureManager.from(context);
    mEyeGestureListener = new EyeGestureManager.Listener() {
        @Override
        public void onDetected(EyeGesture gesture) {
            Log.w("EyeGestureListener", "Gesture: " + gesture.getId());
            int id = gesture.getId();
            if (id == mGestureIds.WINK_ID || id == mGestureIds.DOUBLE_WINK_ID) {
                Log.d("EyeGesture", "Wink");
            } else if (id == mGestureIds.BLINK_ID || id == mGestureIds.DOUBLE_BLINK_ID) {
                Log.d("EyeGesture", "Blink");
            } else if (id == mGestureIds.LOOK_AT_SCREEN_ID || id == mGestureIds.LOOK_AWAY_FROM_SCREEN_ID) {
                Log.d("EyeGesture", "Screen");
            }
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Log.w("detected", "omg detected");
                }
            });

        }
    };    
}

注意我还有一个run()。我添加了两个,因为一个github链接了它而另一个没有。试过这两个,似乎没有被发现。

你在onCreate()中调用了这个(上面的那个)函数; ,然后在你的onResume();

mEyeGestureManager.register(EyeGesture.LOOK_AT_SCREEN, mEyeGestureListener);
mEyeGestureManager.register(EyeGesture.LOOK_AWAY_FROM_SCREEN, mEyeGestureListener);
mEyeGestureManager.register(EyeGesture.WINK, mEyeGestureListener);

你的onPause():

mEyeGestureManager.unregister(EyeGesture.LOOK_AT_SCREEN, mEyeGestureListener);
        mEyeGestureManager.unregister(EyeGesture.LOOK_AWAY_FROM_SCREEN, mEyeGestureListener);
        mEyeGestureManager.unregister(EyeGesture.WINK, mEyeGestureListener);

现在所有这些似乎都有效(调用函数时没有错误,并显示日志说它们被调用(注意存根中没有日志))。

然而,我的谷歌眼镜似乎没有检测到EyeGesture。我很确定这一切都很好,或者我错过了一些小事。我不会接受它作为答案,因为它只回答了我的部分问题。请随意尝试一下,让我知道它是如何工作的。