From a3b1a04cbde8284656fc6b1eb72a9ffe5488d1de Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 1 Aug 2015 22:45:21 +0200 Subject: [PATCH] Fix weak listeners --- OsmAnd/src/net/osmand/plus/ApplicationMode.java | 9 +++++---- .../osmand/plus/rastermaps/OsmandRasterMapsPlugin.java | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/ApplicationMode.java index 0a6944a6cb..db06ec6a9c 100644 --- a/OsmAnd/src/net/osmand/plus/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/ApplicationMode.java @@ -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 listener; private ApplicationMode(int key, String stringKey) { this.key = key; @@ -162,14 +163,14 @@ public class ApplicationMode { public static List values(OsmandSettings settings) { if (cachedFilteredValues.isEmpty()) { - if (!listenerRegistered) { - settings.AVAILABLE_APP_MODES.addListener(new StateChangedListener() { + if (listener == null) { + listener = new StateChangedListener() { @Override public void stateChanged(String change) { cachedFilteredValues = new ArrayList(); } - }); - listenerRegistered = true; + }; + settings.AVAILABLE_APP_MODES.addListener(listener); } String available = settings.AVAILABLE_APP_MODES.get(); cachedFilteredValues = new ArrayList(); diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index da4a876ccc..041064578b 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -47,6 +47,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { private MapTileLayer overlayLayer; private MapTileLayer underlayLayer; + private StateChangedListener 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() { + overlayLayerListener = new StateChangedListener() { @Override public void stateChanged(Integer change) { overlayLayer.setAlpha(change); } - }); + }; + // mapView.addLayer(overlayLayer, 0.7f); + settings.MAP_OVERLAY_TRANSPARENCY.addListener(overlayLayerListener); } @Override