触摸板MotionEvent来自GDK中的IME

时间:2014-02-02 10:57:50

标签: android google-glass google-gdk

我正在尝试从谷歌眼镜上的IME中捕获触摸板数据。在roughly the example given in the GDK docs之后,我已将以下内容添加到我的IME的顶级视图中。

但是这些方法都没有被触发,所以我没有得到任何触摸板数据。与此同时,我所处的活动(沉浸式)继续从dispatchGenericMotionEvent()和onGenericMotionEvent()获取数据

有关为什么我无法在IME中访问此数据的任何想法?我可以在InputMethodService中获取onKeyDown事件没问题,但是它们不允许我访问我想要使用的所有触摸板手势/控件。 InputMethodService也有onGenericMotionEvent()方法,但只有API级别17,对于仅为API级别15的玻璃没有帮助。

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;
    }

}

0 个答案:

没有答案