user2583660
user2583660

Reputation: 1

How to implement double click event handling into Android SDK source code [PhoneWindow.java]

I am trying to implement double click event handling into Android SDK (phoneWindow.java) for emulator hardkey. There i am able to see the click and longpress event handling but no idea about double click event handling into SDK source code.

Please help to implement this feature.

thanks

Upvotes: 0

Views: 598

Answers (2)

Ankit Aggarwal
Ankit Aggarwal

Reputation: 2405

This is a good site for performing double click... I used it and worked.

http://mobile.tutsplus.com/tutorials/android/android-gesture/

We should implement a GestureDetector and GestureListener.

private class GestureListener implements GestureDetector.OnGestureListener,  
        GestureDetector.OnDoubleTapListener {  
     PlayAreaView view;  
     public GestureListener(PlayAreaView view) {  
        this.view = view;  
     }  
}  

This should do the trick. Go through the tutorial and you would be able to implement it properly and also many other gestures :)

Cheers.

Upvotes: 1

Gabe Sechan
Gabe Sechan

Reputation: 93561

long lastClickTime = System.currentTimeMillis();
static final long MAX_DOUBLE_CLICK_TIME = 150;

boolean isDoubleClick(){
    boolean result = false;
    long now = System.currentTimeMillis();
    if(now - lastClickTime <MAX_DOUBLE_CLICK_TIME){
        result = true;
    }
    lastClickTime = now;
    return result;
}

Call that function in your onClick handler. It will return true for a double click.

Upvotes: 1

Related Questions