Top Commentators

  • Two guys and a Beer - Episode 85
  • Jam Session 2
  • Two guys and a Beer - Episode 84

Double click/tap detection on android's MapView

If there is a cleaner way to do it, please share :)
1. Override the default MapView with your own implementation;
2. Override the onInterceptTouchEvent method;
3. Check if the last event was also a click and happened close by (say in the last 250ms);
  3.1. If so,  it’s a double tap; do whatever you want (in this case I zoom in on the last clicked point);
  3.2. If not, ignore :)
Here’s the code:
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import com.google.android.maps.MapView;
public class MyMapView extends MapView {
private long lastTouchTime = -1;
public MyMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
long thisTime = System.currentTimeMillis();
if (thisTime – lastTouchTime < 250) {
// Double tap
this.getController().zoomInFixing((int) ev.getX(),
(int) ev.getY());
lastTouchTime = -1;
} else {
// Too slow :)
lastTouchTime = thisTime;
}
}

return super.onInterceptTouchEvent(ev);
}
}

Posted via email from nocivus’ ramblings

Related:

  1. Double click/tap detection on android’s MapView If there is a cleaner way to do it, please...
  2. Android location provider mock So, yeah, I resumed playing around with android, this time...

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>