Remove the second hotspot but still remain in the second hotspot
Hi moagrius,
I got a small issue here which is I added 2 hotspot (first and second) into tileview. After I remove the second hotspot, as I thought I can tap on first hotspot but still remain in second tileview although I'm using the removeHotSpot() to remove the second hotspot. I have to add back the first hotspot then only can use back the first hotspot.
Is that the correct way for me to add back the first hotspot? It seem like redundant to do that...
i'm not clear on your question - can you try to restate simply, or with bullet points? specifically this line is confusing:
as I thought I can tap on first hotspot but still remain in second tileview
Sounds like you have 2 TileView instances?
Sorry to make you confusing.
I have only one TileView instance. I created and added a hot spot (first hot spot) to the tileview. After that I created and added another hot spot (second hot spot) to the tileview. Both the hotspot handle different task. After I done the task in second hot spot, I wish to get back to first hotspot. So, I use removeHotSpot() to remove second hot spot. I wan to know which hotspot Im dealing with so I put in Log.d() to track which hotspot currently dealing with. I realise that I'm dealing with second hot spot. (The second hot spot suppose to removed after I use removeHotSpot() to remove it) In order to get back to first hotspot, I use addHotSpot() to add the first hot spot to tileview.
Is that the correct way to get back to first hotspot after remove second hot spot?
I'm not sure what you mean by "get back to first hotspot", but yes, removeHotSpot should remove the HotSpot instance you pass. It's simply a LinkedList, and removeHotSpot passes that directly. See the source for more details:
TileView.removeHotSpot delegates to HotSPotManager.removeHotSpot: https://github.com/moagrius/TileView/blob/master/tileview/src/main/java/com/qozix/tileview/TileView.java#L610
... which in turn delegates to LinkedList.remove:
https://github.com/moagrius/TileView/blob/master/tileview/src/main/java/com/qozix/tileview/hotspots/HotSpotManager.java#L27
Here is the sample code.
TileView tileView = getTileView(); tileView.setSize(5000, 5000);
//First hotspot HotSpot firstHS = new HotSpot(); firstHS.setTag(this); firstHS.set(new Rect(0, 0, 7600, 7600)); firstHS.setHotSpotTapListener(new HotSpot.HotSpotTapListener(){
@Override public void onHotSpotTap(HotSpot hotSpot, int x, int y) { Log.d("Second Hot Spot", "second hot spot clicked."); } });
tileView.addHotSpot(firstHS);
//Second hotspot HotSpot secondHS = new HotSpot(); secondHS.setTag(this); secondHS.set(new Rect(0, 0, 7600, 7600)); secondHS.setHotSpotTapListener(new HotSpot.HotSpotTapListener() {
@Override public void onHotSpotTap(HotSpot hotSpot, int x, int y) { Log.d("Second Hot Spot", "second hot spot clicked."); } });
tileView.addHotSpot(secondHS);
tileView.removeHotSpot(secondHS);
After I remove secondHS, I still get access to secondHS TapListener. I wish to get back to first hotspot, so I use addHotSpot() to add the firstHS again then only I able to access it, but it seem redundant since I never remove firstHS. Is that any better way to do this?
Good catch. So the problem is that both HotSpots have the same Region, so when you remove the second one (from the LinkedList behind the scenes), remove uses equals to find the thing to remove. While Region uses a native (C) method to compare duplicates (via equals), I suspect it just checks the dimensions, so we're getting a false positive.
I should probably override HotSpot.equals to either check if the instance is the same entity (this == obj), or at least check the Region and the HotSpotTapListener.
I should be able to get that done fairly soon (within a couple days), a short-term fix would be to have the Regions be slightly different (e.g., 1 pixel larger or smaller on either axis).
HTH, I'll leave this issue open until I commit a patch and a new version, and thanks for the catch!
ok, no problem. Thanks for your reply and help.
This is corrected in 2.0.8
Thanks for catching and posting.