moagrius / TileView

TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.
MIT License
1.46k stars 337 forks source link

addCallout after onLongPress #458

Closed drshavit closed 6 years ago

drshavit commented 6 years ago

Hi,

I'm trying to add a callout after a long press:

@Override
    public void onLongPress(MotionEvent event)
    {
        float scale = getScale();
        double relX = getCoordinateTranslater().translateAndScaleAbsoluteToRelativeX(getScrollX() + event.getX(), scale);
        double relY = getCoordinateTranslater().translateAndScaleAbsoluteToRelativeY(getScrollY() + event.getY(), scale);
        callback.LongPress(relX, relY);
    }

then on the activity:

@Override
    public void LongPress(double x, double y)
    {
        HotSpotCallout hotSpotCallout = new HotSpotCallout(MapActivity.this); // just a view
        gis_map.addCallout(hotSpotCallout, x, y, 0f, 0f);
    }

After I long-press, the view is visibile, but then disappears right away. I use the same code on MarkerTapListener and the view stays visible after the tap, so my guess is that some other event is triggered that is causing the view to vanish. My guess was that it's onTouchEvent, so I tried setting a flag to true on onLongPress and then catch the ACTION_UP MotionEvent and return true so that the event will be consumed, but that did not change anything.

Any advice to help me with the actual event chain?

moagrius commented 6 years ago

so a callout is just like a marker but disappears on touch. you probably just want to use addMarker instead of addCallout.

if you look at the source for CalloutManager you'll see there's very little going on there.

drshavit commented 6 years ago

ok so I needed the callout functionality since I wanted the view to be removed after further interaction with the TileView.

So this is what I did:

@Override
    public void onLongPress(MotionEvent event)
    {
        longPressed = true;
        float scale = getScale();
        double relX = getCoordinateTranslater().translateAndScaleAbsoluteToRelativeX(getScrollX() + event.getX(), scale);
        double relY = getCoordinateTranslater().translateAndScaleAbsoluteToRelativeY(getScrollY() + event.getY(), scale);
        callback.LongPress(relX, relY);
    }
@Override
    public boolean onTouchEvent(MotionEvent event)
    {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_MOVE:
                if (longPressed)
                    return true;
                break;
            case MotionEvent.ACTION_UP:
                if (longPressed)
                {
                    longPressed = false;
                    return true;
                }
                break;
        }
        return super.onTouchEvent(event);
    }

Maybe you should consider adding it so that the callouts will have LongPress functionality, but not that important.

Thanks again!