Handling onTouchEvent inside a view that also responds to onTouchEvent (used to work in OSMdroid 3.0.2)

StackOverflow https://stackoverflow.com/questions/6819543

  •  26-10-2019
  •  | 
  •  

Question

I am currently using osmdroid jar 3.0.1, and I have a MapView inside a "Dragable Space" (a view that you can swipe between screens). I have a bar at the bottom that lets the user swipe between the spaces, and if the touch event occurs outside that area, I call mapView.onTouchEvent(event).

This used to work well in 3.0.1, but I tried in osmdroid 3.0.4, and it only appears to work for vertical movement (which I suspect is related to some touch slop setting).

Here is the code from my Dragable Space view.

@Override
public boolean onTouchEvent(MotionEvent event) {
    // Check if the current space is the Map space and we are over the map
    // difference is the Y value between the top and bottom of the map area.
    if (this.mCurrentScreen == 1
                    && event.getY() >= topY && event.getY() <= difference){
            Log.d(TAG, "touch received inside Map Area");
            // Pass the event directly to the mapView.
            return mOsmv.onTouchEvent(event);
    }
    Log.d(TAG, "touch received outside Map Area");
    return super.onTouchEvent(event);
}

Although this is nasty (the view has to be passed an instance of the map), it did work fine in versions 3.0.1 and 3.0.2. However, since 3.0.3 it no longer works.

Is there a better way to pass touch events to the osmdroid map now?

I have a demo project that illustrates this problem. The full eclipse project is on github.

You can change the build path to use a 3.0.1 or 3.0.2 jar, and the map scrolls around correctly inside the larger space, but changing to 3.0.3 or 3.0.4 and any sideways movement is ignored.

Any guidance would be greatly appreciated.

PS, this is a cross post from the OSMdroid list. I hope there are a few more readers here.

Was it helpful?

Solution

The problem was that MapView.onTouchEvent was renamed to MapView.dispatchTouchEvent between versions 3.0.2 and 3.0.3

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top