Merge pull request #763 from Meibes/feature/MapScaleBarLayer/onDetach

MapScaleBarLayer: add onDetach-method to free resources automatically
This commit is contained in:
Emux
2020-01-26 18:12:58 +02:00
committed by GitHub
4 changed files with 9 additions and 24 deletions

View File

@@ -42,7 +42,6 @@ public class GettingStarted extends Activity {
private static final String MAP_FILE = "berlin.map"; private static final String MAP_FILE = "berlin.map";
private MapView mapView; private MapView mapView;
private MapScaleBar mapScaleBar;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@@ -69,7 +68,7 @@ public class GettingStarted extends Activity {
mapView.map().setTheme(VtmThemes.DEFAULT); mapView.map().setTheme(VtmThemes.DEFAULT);
// Scale bar // Scale bar
mapScaleBar = new DefaultMapScaleBar(mapView.map()); MapScaleBar mapScaleBar = new DefaultMapScaleBar(mapView.map());
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mapView.map(), mapScaleBar); MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mapView.map(), mapScaleBar);
mapScaleBarLayer.getRenderer().setPosition(GLViewport.Position.BOTTOM_LEFT); mapScaleBarLayer.getRenderer().setPosition(GLViewport.Position.BOTTOM_LEFT);
mapScaleBarLayer.getRenderer().setOffset(5 * CanvasAdapter.getScale(), 0); mapScaleBarLayer.getRenderer().setOffset(5 * CanvasAdapter.getScale(), 0);
@@ -94,8 +93,6 @@ public class GettingStarted extends Activity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
if (mapScaleBar != null)
mapScaleBar.destroy();
mapView.onDestroy(); mapView.onDestroy();
super.onDestroy(); super.onDestroy();
} }

View File

@@ -65,7 +65,6 @@ public class MapsforgeActivity extends MapActivity {
private static final Tag SEA_TAG = new Tag("natural", "sea"); private static final Tag SEA_TAG = new Tag("natural", "sea");
private TileGridLayer mGridLayer; private TileGridLayer mGridLayer;
private DefaultMapScaleBar mMapScaleBar;
private Menu mMenu; private Menu mMenu;
private boolean mS3db; private boolean mS3db;
private VectorTileLayer mTileLayer; private VectorTileLayer mTileLayer;
@@ -93,14 +92,6 @@ public class MapsforgeActivity extends MapActivity {
SELECT_MAP_FILE); SELECT_MAP_FILE);
} }
@Override
protected void onDestroy() {
if (mMapScaleBar != null)
mMapScaleBar.destroy();
super.onDestroy();
}
public static class MapFilePicker extends FilePicker { public static class MapFilePicker extends FilePicker {
public MapFilePicker() { public MapFilePicker() {
setFileDisplayFilter(new FilterByFileExtension(".map")); setFileDisplayFilter(new FilterByFileExtension(".map"));
@@ -197,7 +188,7 @@ public class MapsforgeActivity extends MapActivity {
mMap.layers().add(new BuildingLayer(mMap, mTileLayer)); mMap.layers().add(new BuildingLayer(mMap, mTileLayer));
mMap.layers().add(new LabelLayer(mMap, mTileLayer)); mMap.layers().add(new LabelLayer(mMap, mTileLayer));
mMapScaleBar = new DefaultMapScaleBar(mMap); DefaultMapScaleBar mMapScaleBar = new DefaultMapScaleBar(mMap);
mMapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH); mMapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
mMapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE); mMapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
mMapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE); mMapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);

View File

@@ -38,7 +38,6 @@ import org.oscim.theme.ThemeLoader;
import org.oscim.theme.VtmThemes; import org.oscim.theme.VtmThemes;
public class SimpleMapActivity extends BaseMapActivity { public class SimpleMapActivity extends BaseMapActivity {
private DefaultMapScaleBar mapScaleBar;
BuildingLayer mBuildingLayer; BuildingLayer mBuildingLayer;
private boolean mShadow; private boolean mShadow;
@@ -71,7 +70,7 @@ public class SimpleMapActivity extends BaseMapActivity {
groupLayer.layers.add(new LabelLayer(mMap, mBaseLayer)); groupLayer.layers.add(new LabelLayer(mMap, mBaseLayer));
mMap.layers().add(groupLayer); mMap.layers().add(groupLayer);
mapScaleBar = new DefaultMapScaleBar(mMap); DefaultMapScaleBar mapScaleBar = new DefaultMapScaleBar(mMap);
mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH); mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE); mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE); mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
@@ -86,14 +85,6 @@ public class SimpleMapActivity extends BaseMapActivity {
mMap.setTheme(VtmThemes.DEFAULT); mMap.setTheme(VtmThemes.DEFAULT);
} }
@Override
protected void onDestroy() {
if (mapScaleBar != null)
mapScaleBar.destroy();
super.onDestroy();
}
void runTheMonkey() { void runTheMonkey() {
themes[0] = ThemeLoader.load(VtmThemes.DEFAULT); themes[0] = ThemeLoader.load(VtmThemes.DEFAULT);
themes[1] = ThemeLoader.load(VtmThemes.OSMARENDER); themes[1] = ThemeLoader.load(VtmThemes.OSMARENDER);

View File

@@ -62,4 +62,10 @@ public class MapScaleBarLayer extends Layer implements Map.UpdateListener {
mapScaleBar.redrawNeeded = false; mapScaleBar.redrawNeeded = false;
} }
@Override
public void onDetach() {
super.onDetach();
mapScaleBar.destroy();
}
} }