在玻璃活卡的两个手指轻拍

时间:2015-01-28 23:14:11

标签: android google-glass google-gdk

如何在现场卡上捕获两个手指点按。我知道我可以用setAction打开一个菜单,但是我想要捕获更多。

目前:

public class MyApp extends Service {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    MainServer.singleton(this).updateStatus(MainServer.ONLINE);
    if (mLiveCard == null) {
        mLiveCard = new LiveCard(this, LIVE_CARD_TAG);
        Intent menuIntent = new Intent(this, LiveCardMenuActivity.class);
        mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
        ....
    }
}
...
}

1 个答案:

答案 0 :(得分:1)

GestureDetector定义为私有全局变量,然后在onCreate()方法中初始化它,捕获手势Gesture.TWO_TAP。这是看起来像:

public class SampleActivity extends Activity {
    private GestureDetector gestureDetector;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        createGestureDetector(this);
    }


    private GestureDetector createGestureDetector(Context context) {
    GestureDetector gestureDetector = new GestureDetector(context);
        gestureDetector.setBaseListener( new GestureDetector.BaseListener() {
            @Override
            public boolean onGesture(Gesture gesture) {
                if (gesture == Gesture.TWO_TAP) {
                    // do whatever you want on tap with two fingers
                    return true;
                }
                return false;
            }
        });
        return gestureDetector;
    }

    /*
     * Send generic motion events to the gesture detector
     */
    @Override
    public boolean onGenericMotionEvent(MotionEvent event) {
        if (mGestureDetector != null) {
            return mGestureDetector.onMotionEvent(event);
        }
        return false;
    }
}

就这么简单!您可以在Google Glass here上详细了解GestureDetector s。