Reputation: 2842
How do I capture a two finger tap on a live card. I know I can open a menu with setAction, but I would like to capture more than that.
Currently:
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));
....
}
}
...
}
Upvotes: 0
Views: 61
Reputation: 8338
Define a GestureDetector
as a private, global variable, then initialize it in your onCreate()
method, catching the gesture Gesture.TWO_TAP
. This is what that looks like:
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;
}
}
It's that simple! You can read more about GestureDetector
s on Google Glass here.
Upvotes: 1