Something like the following should do it:
public static Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());
private Integer pendingAction;
private Boolean isActionPending = false;
private final Long TIMEOUT = 2000; //2 seconds
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (isActionPending) {
//TODO: better error handling
return false;
}
isActionPending = true;
pendingAction = item.getItemId();
new Thread( new Runnable() {
@Override
public void run() {
Thread.sleep(TIMEOUT);
MAIN_HANDLER.post(
new Runnable() {
@Override
public void run() {
onDoPendingAction();
}
}
);
}
}).start();
}
public void onDoPendingAction() {
if (!isPending ) {
return; //event was canceled
}
switch(pendingAction) {
case R.id.some_menu_action:
//Whatever you would do.
break;
/* other actions */
}
//TODO: something to indicate teh action finished.
}
public void cancelPendingAction() {
if (isPending) {
isPending = false;
//TODO: something to indicate it canceled.
}
}
Add a gesture detector to capture the TWO_SWIPE_DOWN event and call cancelPendingAction(); if you detect it. Get gesture detector code here.
https://developers.google.com/glass/develop/gdk/input/touch