Fix weak listeners

This commit is contained in:
Victor Shcherb 2015-08-01 22:45:21 +02:00
parent c7167cc468
commit a3b1a04cbd
2 changed files with 10 additions and 7 deletions

View file

@ -154,6 +154,7 @@ public class ApplicationMode {
private int arrivalDistance = 90;
private int bearingIcon = R.drawable.map_pedestrian_bearing;
private int locationIcon = R.drawable.map_pedestrian_location;
private static StateChangedListener<String> listener;
private ApplicationMode(int key, String stringKey) {
this.key = key;
@ -162,14 +163,14 @@ public class ApplicationMode {
public static List<ApplicationMode> values(OsmandSettings settings) {
if (cachedFilteredValues.isEmpty()) {
if (!listenerRegistered) {
settings.AVAILABLE_APP_MODES.addListener(new StateChangedListener<String>() {
if (listener == null) {
listener = new StateChangedListener<String>() {
@Override
public void stateChanged(String change) {
cachedFilteredValues = new ArrayList<ApplicationMode>();
}
});
listenerRegistered = true;
};
settings.AVAILABLE_APP_MODES.addListener(listener);
}
String available = settings.AVAILABLE_APP_MODES.get();
cachedFilteredValues = new ArrayList<ApplicationMode>();

View file

@ -47,6 +47,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
private MapTileLayer overlayLayer;
private MapTileLayer underlayLayer;
private StateChangedListener<Integer> overlayLayerListener;
public OsmandRasterMapsPlugin(OsmandApplication app) {
this.app = app;
@ -84,13 +85,14 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
underlayLayer = new MapTileLayer(false);
// mapView.addLayer(underlayLayer, -0.5f);
overlayLayer = new MapTileLayer(false);
// mapView.addLayer(overlayLayer, 0.7f);
settings.MAP_OVERLAY_TRANSPARENCY.addListener(new StateChangedListener<Integer>() {
overlayLayerListener = new StateChangedListener<Integer>() {
@Override
public void stateChanged(Integer change) {
overlayLayer.setAlpha(change);
}
});
};
// mapView.addLayer(overlayLayer, 0.7f);
settings.MAP_OVERLAY_TRANSPARENCY.addListener(overlayLayerListener);
}
@Override