Created
February 8, 2012 14:17
-
-
Save jgilfelt/1769883 to your computer and use it in GitHub Desktop.
Android - MapView implementing double tap to zoom
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 DoubleTapZoomMapView extends MapView { | |
private static final long TIME_INITIAL = -1; | |
private static final long TIME_DOUBLE_TAP = 250; | |
private long lastTouchTime = TIME_INITIAL; | |
public DoubleTapZoomMapView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public DoubleTapZoomMapView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
public DoubleTapZoomMapView(Context context, String apiKey) { | |
super(context, apiKey); | |
} | |
@Override | |
public boolean onInterceptTouchEvent(MotionEvent ev) { | |
if (ev.getAction() == MotionEvent.ACTION_DOWN) { | |
long thisTime = System.currentTimeMillis(); | |
if (thisTime - lastTouchTime <= TIME_DOUBLE_TAP) { | |
this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY()); | |
lastTouchTime = TIME_INITIAL; | |
} else { | |
lastTouchTime = thisTime; | |
} | |
} | |
return super.onInterceptTouchEvent(ev); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What we have to use instead of getcontroller() in Google Maps V2?