package org.osmdroid.samplefragments.layouts; import android.content.Context; import android.os.Handler; import android.util.AttributeSet; import android.view.MotionEvent; import org.osmdroid.tileprovider.MapTileProviderBase; import org.osmdroid.views.MapView; /** * The only delta with this class vs the standard mapview is that it overcomes some of the issues * with the map view being inside of some kind of container which allows scrolling, such as * scroll view * recycler/card view * * * created on 1/3/2017. * * @author Alex O'Ree */ public class CustomMapView extends MapView { public CustomMapView(Context context, MapTileProviderBase tileProvider, Handler tileRequestCompleteHandler, AttributeSet attrs) { super(context, tileProvider, tileRequestCompleteHandler, attrs); } public CustomMapView(Context context, MapTileProviderBase tileProvider, Handler tileRequestCompleteHandler, AttributeSet attrs, boolean hardwareAccelerated) { super(context, tileProvider, tileRequestCompleteHandler, attrs, hardwareAccelerated); } public CustomMapView(Context context, AttributeSet attrs) { super(context, attrs); } public CustomMapView(Context context) { super(context); } public CustomMapView(Context context, MapTileProviderBase aTileProvider) { super(context, aTileProvider); } public CustomMapView(Context context, MapTileProviderBase aTileProvider, Handler tileRequestCompleteHandler) { super(context, aTileProvider, tileRequestCompleteHandler); } @Override public boolean onTouchEvent(MotionEvent ev) { int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: // Disallow ScrollView to intercept touch events. this.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: // Allow ScrollView to intercept touch events. this.getParent().requestDisallowInterceptTouchEvent(false); break; } // Handle MapView's touch events. return super.onTouchEvent(ev); } }