2

I'm trying to capture touchpad data from within an IME on google glass. Following roughly the example given in the GDK docs, I've added the following to my top level view for my IME.

However none of these methods are ever triggered, so I don't get any touchpad data. In the meantime the activity (immersion) that I am in continues to get data from both dispatchGenericMotionEvent() and onGenericMotionEvent()

Any thoughts on why I can't access this data in the IME? I can get onKeyDown events within the InputMethodService no problem, but they don't give me access to all the touchpad gestures/controls I would like to use. InputMethodService also has a onGenericMotionEvent() method, but only API level 17 which is not helpful for glass which is API level 15 only.

public class TopLevelView extends LinearLayout {

    public TopLevelView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setFocusable(true);
        setFocusableInTouchMode(true);
    }

    public TopLevelView(Context context) {
        this(context, null);
    }

    @Override
    public void onAttachedToWindow() {
        requestFocus(); //returns true, isFocused() also returns true
    }

    @Override
    protected void onDetachedFromWindow() {

    }

    /* Methods I normally get touch pad data from in a regular activity/view */

    public boolean dispatchGenericMotionEvent(MotionEvent event) {
        Log.d("TopLevelView", "dispatchGenericMotionEvent");
        return super.dispatchGenericMotionEvent(event);
    }

    public boolean onGenericMotionEvent(MotionEvent event) {
        Log.d("TopLevelView", "onGenericMotionEvent");
        return super.onGenericMotionEvent(event);
    }

    public boolean dispatchGenericFocusedEvent(MotionEvent event) {
        Log.d("TopLevelView", "dispatchGenericFocusedEvent");
        return super.dispatchGenericFocusedEvent(event);
    }

    /* The kitchen sink */

    public boolean onTouchEvent(MotionEvent e) {
        Log.d("TopLevelView", "onTouch");
        return false;
    }

    public boolean dispatchTouchEvent(MotionEvent event) {
        Log.d("TopLevelView", "dispatchTouchEvent");
        return false;
    }

    public boolean onHoverEvent(MotionEvent event) {
        Log.d("TopLevelView", "onHoverEvent");
        return false;
    }

    public boolean onTrackballEvent(MotionEvent event) {
        Log.d("TopLevelView", "onTrackballEvent");
        return false;
    }

    public boolean dispatchGenericPointerEvent(MotionEvent event) {
        Log.d("TopLevelView", "dispatchGenericPointerEvent");
        return false;
    }

    public boolean dispatchHoverEvent(MotionEvent event)     {
        Log.d("TopLevelView", "dispatchHoverEvent");
        return false;
    }

    public boolean dispatchTrackballEvent(MotionEvent event) {
        Log.d("TopLevelView", "dispatchTrackballEvent");
        return false;
    }

    public boolean dispatchUnhandledMove(View focused, int direction) {
        Log.d("TopLevelView", "dispatchUnhandledMove");
        return false;
    }

    public boolean onFilterTouchEventForSecurity(MotionEvent event) {
        Log.d("TopLevelView", "onFilterTouchEventForSecurity");
        return false;
    }

}
mimming
  • 13,974
  • 3
  • 45
  • 74
Sparky
  • 327
  • 2
  • 9
  • 1
    I've spoken with some devs from the Glass team. They told me it was probably not possible currently. Apparently managing the focus such that these events get passed to the IME is very cumbersome/inconvenient. In general they don't recommend try to build IMEs for Glass. Instead they suggest you build a separate activity which is called with `startActivityForResult(intent, "STRING");` and returns the result of the user input. This kind of design is probably also more consistent with the design guidelines for Glass. – Sparky Feb 23 '14 at 22:08

0 Answers0