forked from upstream-mirrors/OpenTracks
Fix bug so only one map overlap is displayed.
This commit is contained in:
@@ -27,7 +27,6 @@ import java.util.HashMap;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.WeakHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager for the external data listeners and their listening types.
|
* Manager for the external data listeners and their listening types.
|
||||||
@@ -77,13 +76,6 @@ class TrackDataListeners {
|
|||||||
private final Map<TrackDataListener, ListenerRegistration> registeredListeners =
|
private final Map<TrackDataListener, ListenerRegistration> registeredListeners =
|
||||||
new HashMap<TrackDataListener, ListenerRegistration>();
|
new HashMap<TrackDataListener, ListenerRegistration>();
|
||||||
|
|
||||||
/**
|
|
||||||
* Map of external paused listener to its registration details.
|
|
||||||
* This will automatically discard listeners which are GCed.
|
|
||||||
*/
|
|
||||||
private final WeakHashMap<TrackDataListener, ListenerRegistration> oldListeners =
|
|
||||||
new WeakHashMap<TrackDataListener, ListenerRegistration>();
|
|
||||||
|
|
||||||
/** Map of data type to external listeners interested in it. */
|
/** Map of data type to external listeners interested in it. */
|
||||||
private final Map<ListenerDataType, Set<TrackDataListener>> listenerSetsPerType =
|
private final Map<ListenerDataType, Set<TrackDataListener>> listenerSetsPerType =
|
||||||
new EnumMap<ListenerDataType, Set<TrackDataListener>>(ListenerDataType.class);
|
new EnumMap<ListenerDataType, Set<TrackDataListener>>(ListenerDataType.class);
|
||||||
@@ -109,10 +101,7 @@ class TrackDataListeners {
|
|||||||
throw new IllegalStateException("Listener already registered");
|
throw new IllegalStateException("Listener already registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
ListenerRegistration registration = oldListeners.remove(listener);
|
ListenerRegistration registration = new ListenerRegistration(listener, dataTypes);
|
||||||
if (registration == null) {
|
|
||||||
registration = new ListenerRegistration(listener, dataTypes);
|
|
||||||
}
|
|
||||||
registeredListeners.put(listener, registration);
|
registeredListeners.put(listener, registration);
|
||||||
|
|
||||||
for (ListenerDataType type : dataTypes) {
|
for (ListenerDataType type : dataTypes) {
|
||||||
@@ -142,17 +131,10 @@ class TrackDataListeners {
|
|||||||
for (ListenerDataType type : match.types) {
|
for (ListenerDataType type : match.types) {
|
||||||
listenerSetsPerType.get(type).remove(listener);
|
listenerSetsPerType.get(type).remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep it around in case it's re-registered soon
|
|
||||||
oldListeners.put(listener, match);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListenerRegistration getRegistration(TrackDataListener listener) {
|
public ListenerRegistration getRegistration(TrackDataListener listener) {
|
||||||
ListenerRegistration registration = registeredListeners.get(listener);
|
return registeredListeners.get(listener);
|
||||||
if (registration == null) {
|
|
||||||
registration = oldListeners.get(listener);
|
|
||||||
}
|
|
||||||
return registration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<TrackDataListener> getListenersFor(ListenerDataType type) {
|
public Set<TrackDataListener> getListenersFor(ListenerDataType type) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import com.google.android.apps.mytracks.util.LocationUtils;
|
|||||||
import com.google.android.maps.GeoPoint;
|
import com.google.android.maps.GeoPoint;
|
||||||
import com.google.android.maps.MapController;
|
import com.google.android.maps.MapController;
|
||||||
import com.google.android.maps.MapView;
|
import com.google.android.maps.MapView;
|
||||||
|
import com.google.android.maps.Overlay;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -52,6 +53,7 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fragment to display map to the user.
|
* A fragment to display map to the user.
|
||||||
@@ -89,8 +91,8 @@ public class MapFragment extends Fragment
|
|||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
private View mapViewContainer;
|
private View mapViewContainer;
|
||||||
private MapOverlay mapOverlay;
|
|
||||||
private MapView mapView;
|
private MapView mapView;
|
||||||
|
private MapOverlay mapOverlay;
|
||||||
private ImageButton myLocationImageButton;
|
private ImageButton myLocationImageButton;
|
||||||
private TextView messageTextView;
|
private TextView messageTextView;
|
||||||
|
|
||||||
@@ -104,14 +106,16 @@ public class MapFragment extends Fragment
|
|||||||
public View onCreateView(
|
public View onCreateView(
|
||||||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
mapViewContainer = ((TrackDetailActivity) getActivity()).getMapViewContainer();
|
mapViewContainer = ((TrackDetailActivity) getActivity()).getMapViewContainer();
|
||||||
|
mapView = (MapView) mapViewContainer.findViewById(R.id.map_view);
|
||||||
mapOverlay = new MapOverlay(getActivity());
|
mapOverlay = new MapOverlay(getActivity());
|
||||||
|
|
||||||
mapView = (MapView) mapViewContainer.findViewById(R.id.map_view);
|
List<Overlay> overlays = mapView.getOverlays();
|
||||||
|
overlays.clear();
|
||||||
|
overlays.add(mapOverlay);
|
||||||
|
|
||||||
mapView.requestFocus();
|
mapView.requestFocus();
|
||||||
mapView.setOnTouchListener(this);
|
mapView.setOnTouchListener(this);
|
||||||
mapView.setBuiltInZoomControls(true);
|
mapView.setBuiltInZoomControls(true);
|
||||||
mapView.getOverlays().add(mapOverlay);
|
|
||||||
myLocationImageButton = (ImageButton) mapViewContainer.findViewById(R.id.map_my_location);
|
myLocationImageButton = (ImageButton) mapViewContainer.findViewById(R.id.map_my_location);
|
||||||
myLocationImageButton.setOnClickListener(new View.OnClickListener() {
|
myLocationImageButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user