moagrius / MapView

(Deprecated, prefer https://github.com/moagrius/TileView) Android widget roughly described as a hybrid between com.google.android.maps.MapView and iOS's CATiledLayer
http://moagrius.github.com/MapView/documentation
69 stars 35 forks source link

How to use HotSpot and HotSpotManager? #51

Closed smoothdvd closed 11 years ago

moagrius commented 11 years ago

You don't need to use either class directly, just use the addHotSpot method, which accepts a Rect that defines the area to watch and a View.OnClickListener to invoke.

Here's the signature: http://moagrius.github.io/MapView/documentation/com/qozix/mapview/MapView.html#addHotSpot(Rect, View.OnClickListener)

A simple example might look like this (untested):

Rect r = new Rect(0,0,100,100);  // 100px sqaure in top left corner
View.OnClickListener l = new View.OnClickListener(){
    @Override
    public void onClick(){
        Log.d("hola");
    }
};
mapViewInstance.addHotSpot(r, l);

Note that the listener is passed null, since there's no actual View. In practice, it's not terribly useful as written above - generally you'll probably want to subclass Rect, or use a Listener factory, otherwise there's no obvious way to tie a Rect to it's listener (as you might do with View.setTag). I'd like to expand this functionality in future releases, but for now that's what available. Feel free to hack.

smoothdvd commented 11 years ago

Thanks! And Why you use OnClickListener, will GestureDetector be better?

moagrius commented 11 years ago

OnClickListener is the more common, familiar interface - it's all emulated anyways - when a finger goes up on the container, a contains test is run against each Rect registered as a hotspot - on success, it's dispatched a fake click event with no parameters, so the entirety of the gesture is being handled elsewhere anyways.