4

I am trying to check Wink from Glass using the EyeGestureLib.

I created a new project and did exactly what the guy did with the sample project here.

The problem part of my code is below:

private EyeGestureManager mEyeGestureManager;
private EyeGestureListener mEyeGestureListener;

private EyeGesture target1 = EyeGesture.WINK;
private EyeGesture target2 = EyeGesture.DOUBLE_BLINK;

Inside onCreate, I have:

    mEyeGestureManager = EyeGestureManager.from(this);
    mEyeGestureListener = new EyeGestureListener();

    // print out each eye gesture is supported or not
    for (EyeGesture eg : EyeGesture.values()) {
        boolean supported = mEyeGestureManager.isSupported(eg);
        Log.d(TAG, eg.name() + ":" + supported);
    }

My program crashes immediately after opening. I realize that the problem is when it tries to access mEyeGestureManager. Any where in the code that uses mEyeGestureManager will make the program crash.According to what I observed, mEyeGestureManager is null even after mEyeGestureManager = EyeGestureManager.from(this);

When I change

mEyeGestureManager = EyeGestureManager.from(this);

to

mEyeGestureManager = new EyeGestureManager();

it stops crashing and mEyeGestureManager is no longer null but won't detect wink, or double wink.

My glass was running XE21 but I downgraded it to XE18.3 because my research shows that EyeGestureLib wont work properly on Glass version > XE18.3.

EyeGestures NOT working in 19.1

https://github.com/thorikawa/EyeGestureLib/issues/2

Now I have XE18.3 but it is not working. Wink is not working when I have mEyeGestureManager = new EyeGestureManager(); and I get:

Supported:﹕ BLINK:false
Supported:﹕ DOFF:false
Supported:﹕ DON:false
Supported:﹕ DOUBLE_BLINK:false
Supported:﹕ DOUBLE_WINK:false
Supported:﹕ LOOK_AT_SCREEN:false
Supported:﹕ LOOK_AWAY_FROM_SCREEN:false
Supported:﹕ WINK:false

But when I have:

mEyeGestureManager = EyeGestureManager.from(this);

it crashes right away.

I went and installed already compiled example "EyeGestureDemo-debug-1.1.apk" and that WORKED very well but mine does not.

What am I doing wrong? I have been trying to do this for 3 days now. Google doesn't have an official API for this but I don't want to wait till they release one. I need this for my school project ASAP. Anyone got any ideas of what might be the problem?

EDIT: CRASH LOG

12-02 09:39:54.347    3758-3758/com.inno.inno.glassplugin D/AndroidRuntime﹕ Shutting down VM
12-02 09:39:54.347    3758-3758/com.inno.inno.glassplugin W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41f78bd8)
12-02 09:39:54.363    3758-3758/com.inno.inno.glassplugin E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.inno.inno.glassplugin, PID: 3758
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.inno.inno.glassplugin/com.inno.inno.glassplugin.MainActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2235)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2285)
            at android.app.ActivityThread.access$800(ActivityThread.java:138)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:149)
            at android.app.ActivityThread.main(ActivityThread.java:5061)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.inno.inno.glassplugin.MainActivity.onCreate(MainActivity.java:92)
            at android.app.Activity.performCreate(Activity.java:5236)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1089)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2285)
            at android.app.ActivityThread.access$800(ActivityThread.java:138)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1236)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:149)
            at android.app.ActivityThread.main(ActivityThread.java:5061)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
            at dalvik.system.NativeStart.main(Native Method)
Community
  • 1
  • 1
Programmer
  • 121,791
  • 22
  • 236
  • 328

1 Answers1

2

The API has changed a long time ago (around XE 20 I think).

I had to do quite a bit of digging with reflection to figure out the workings of EyeGestureManager.

Here's my updated version, along with some sample code demonstrating usage: https://gist.github.com/victorkp/9094a6aea9db236a97f3

Victor KP
  • 437
  • 3
  • 10
  • Where and how is mEyeGestureListener defined? Can you provide a full example.Java? Thanks. – Programmer Dec 03 '14 at 19:41
  • And for mEyeGestureManager = EyeGestureManager.from(mContext);, Can I replace mContext with "this"? I don't know where you defined mContext and how it got initialized. – Programmer Dec 03 '14 at 19:49
  • Whoops forgot to replace that - yep, mContext is just a Context, so you'll be able to replace it with 'this' (assuming you're calling this code in an Activity or Service). – Victor KP Dec 04 '14 at 21:07
  • I updated both the EyeGesture.java and EyeGestureManager.java and my main class with your Example but it is still crashing. The problem is still the null pointer stuff. mEyeGestureManager is still null after mEyeGestureManager = EyeGestureManager.from(mContext); – Programmer Dec 05 '14 at 04:16
  • Interesting - I'll look into it. I guess I haven't tried that code on the latest update. I know that it worked before though. – Victor KP Dec 05 '14 at 17:14
  • Your code is now working. What happened is that I had to place the EyeGesture and EyeGestureManager in com.google.android.glass.eye package. I am very good at C++ and new to Java. Can you explain to me why this is a problem? It is fixed now but I don't understand why it would't work if not placed in com.google.android.glass.eye as mentioned here.https://github.com/prt2121/EyeGestureLib – Programmer Dec 06 '14 at 10:33
  • 1
    Ah, I suppose that I forgot to mention that. Basically, you're trying to expose classes that exist in the Glass environment itself, but not through the official APIs. By declaring these stub classes (none of the methods are implemented) and by putting them into the com.google.android.glass.eye package, we're allowing our code to compile with these unimplemented classes. At runtime, the system has implementations of those classes and the application will instead use the system's implementations. You may want to look into the notion of reflection. – Victor KP Dec 08 '14 at 17:37