Created
August 17, 2014 01:32
-
-
Save terrytowne/6f4530fdc95a2f5ebf80 to your computer and use it in GitHub Desktop.
Disable double tap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelpWebView extends WebView { | |
private GestureDetector gestureDetector; | |
private AtomicBoolean mPreventAction = new AtomicBoolean(false); | |
private AtomicLong mPreventActionTime = new AtomicLong(0); | |
public HelpWebView(Context context) { | |
super(context); | |
gestureDetector = new GestureDetector(context, new GestureListener()); | |
} | |
public HelpWebView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
gestureDetector = new GestureDetector(context, new GestureListener()); | |
} | |
public HelpWebView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
gestureDetector = new GestureDetector(context, new GestureListener()); | |
} | |
public HelpWebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { | |
super(context, attrs, defStyle, privateBrowsing); | |
gestureDetector = new GestureDetector(context, new GestureListener()); | |
} | |
@Override | |
public boolean onTouchEvent(MotionEvent event) { | |
int index = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; | |
int pointId = event.getPointerId(index); | |
// just use one(first) finger, prevent double tap with two and more fingers | |
if (pointId == 0){ | |
gestureDetector.onTouchEvent(event); | |
if (mPreventAction.get()){ | |
if (System.currentTimeMillis() - mPreventActionTime.get() > ViewConfiguration.getDoubleTapTimeout()){ | |
mPreventAction.set(false); | |
} else { | |
return true; | |
} | |
} | |
return super.onTouchEvent(event); | |
} else { | |
return true; | |
} | |
} | |
private class GestureListener extends GestureDetector.SimpleOnGestureListener { | |
@Override | |
public boolean onDoubleTap(MotionEvent e) { | |
mPreventAction.set(true); | |
mPreventActionTime.set(System.currentTimeMillis()); | |
return true; | |
} | |
@Override | |
public boolean onDoubleTapEvent(MotionEvent e) { | |
mPreventAction.set(true); | |
mPreventActionTime.set(System.currentTimeMillis()); | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment