Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Google Glass Development Kit (GDK) #997

Closed
aaalaniz opened this issue Mar 11, 2014 · 2 comments
Closed

Support Google Glass Development Kit (GDK) #997

aaalaniz opened this issue Mar 11, 2014 · 2 comments

Comments

@aaalaniz
Copy link

I am trying to shadow some objects from the GDK. I did not have any luck at first, but after modifying isFromAndroidSdk(ClassInfo classInfo) in Setup.java to...

  public boolean isFromAndroidSdk(ClassInfo classInfo) {
    String className = classInfo.getName();
    return className.startsWith("android.")
        || className.startsWith("libcore.")
        || className.startsWith("dalvik.")
        || className.startsWith("com.android.internal.")
        || className.startsWith("com.google.android.maps.")
        || className.startsWith("com.google.android.gms.")

        // Added this line
        || className.startsWith("com.google.android.glass.")

        || className.startsWith("dalvik.system.")
        || className.startsWith("org.apache.http.impl.client.DefaultRequestDirector");
  }

...I was able to at least shadow GestureDetecture with the following:

package io.pristine.glass.camcorder.shadows;

import android.content.Context;
import android.view.MotionEvent;
import com.google.android.glass.touchpad.GestureDetector;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

import static com.google.android.glass.touchpad.GestureDetector.BaseListener;
import static com.google.android.glass.touchpad.GestureDetector.FingerListener;
import static com.google.android.glass.touchpad.GestureDetector.ScrollListener;
import static com.google.android.glass.touchpad.GestureDetector.TwoFingerScrollListener;

@Implements(GestureDetector.class)
public class ShadowGlassGestureDetector {
    private Context context;
    private GestureDetector.BaseListener baseListener;
    private GestureDetector.FingerListener fingerListener;
    private GestureDetector.ScrollListener scrollListener;
    private GestureDetector.TwoFingerScrollListener twoFingerScrollListener;
    private boolean alwaysConsumeEvents;

    public void __constructor__(Context context) {
        this.context = context;
    }

    @Implementation
    public GestureDetector setBaseListener(BaseListener listener) {
        this.baseListener = listener;

        return null;
    }

    @Implementation
    public GestureDetector setFingerListener(FingerListener listener) {
        this.fingerListener = listener;

        return null;
    }

    @Implementation
    public GestureDetector setScrollListener(ScrollListener listener) {
        this.scrollListener = listener;

        return null;
    }

    @Implementation
    public GestureDetector setTwoFingerScrollListener(TwoFingerScrollListener listener) {
        this.twoFingerScrollListener = listener;

        return null;
    }

    @Implementation
    public GestureDetector setAlwaysConsumeEvents(boolean enabled) {
        this.alwaysConsumeEvents = enabled;

        return null;
    }

    @Implementation
    public boolean onMotionEvent(MotionEvent event) {
        return false;
    }
}

Now I'm having issues trying to shadow CardScrollView. This is my shadow file class:

import android.content.Context;
import android.util.AttributeSet;
import com.google.android.glass.widget.CardScrollView;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowAdapterView;

@Implements(CardScrollView.class)
public class ShadowCardScrollView extends ShadowAdapterView {
    private Context context;
    private AttributeSet attrs;
    private int defStyle;
    private boolean shouldShowCardSeen;
    private boolean activated;
    private boolean settled;

    public void __constructor__(Context context) {
        __constructor__(context, null);
    }

    public void __constructor__(Context context, AttributeSet attrs) {
        __constructor__(context, attrs, 0);
    }

    public void __constructor__(Context context, AttributeSet attrs, int defStyle) {
        __constructor__(context, attrs, 0, true);
    }

    public void __constructor__(Context context, AttributeSet attrs, int defStyle, boolean shouldShowCardSeen) {
        this.context = context;
        this.attrs = attrs;
        this.defStyle = defStyle;
        this.shouldShowCardSeen = shouldShowCardSeen;
    }

    @Implementation
    public final void activate() {
        this.activated = true;
    }

    @Implementation
    public final void deactivate() {
        this.activated = false;
    }
}

I realize all the methods for CardScrollView are not implemented but I can't seem to get Robolectric to just instantiate the view without NPE. I dug around the source code more and found that "get" inside ViewConfiguration.java is getting a null Context. I've been stuck on this for a while and can't seem to get any further. I appreciate any help and let me know if I can provide any other information. (Below is the output from the current failure)

java.lang.NullPointerException
    at org.robolectric.shadows.ShadowViewConfiguration.setup(ShadowViewConfiguration.java:75)
    at org.robolectric.shadows.ShadowViewConfiguration.get(ShadowViewConfiguration.java:92)
    at android.view.ViewConfiguration.get(ViewConfiguration.java)
    at android.view.View.__constructor__(View.java:3264)
    at android.view.View.<init>(View.java:3252)
    at android.view.View.<init>(View.java:3315)
    at android.view.ViewGroup.<init>(ViewGroup.java:457)
    at android.widget.AdapterView.<init>(AdapterView.java:235)
    at com.google.android.glass.widget.CardScrollView.<init>(CardScrollView.java:8)
@aaalaniz
Copy link
Author

Also, the problematic line of code is essentially this inside onCreate in my activity.

        SubclassOfCardScrollView cardScrollView = new SubClassOfCardScrollView(this);

Where "SubclassOfCardScrollView" is a pretty barebones subclass of CardScrollView that I use for my view.

@erd erd changed the title Can't Shadow Google Glass Development Kit (GDK) Support Google Glass Development Kit (GDK) Apr 24, 2015
@jaredsburrows
Copy link
Contributor

@aaalaniz @erd Since Google Glass is no longer support by Google(http://www.google.com/glass/start/), can we close this?

@erd erd closed this as completed Jul 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants