Samples: use theme dispose function

This commit is contained in:
Emux
2020-12-28 12:04:17 +02:00
parent d446a3448b
commit 6bea801bf6
4 changed files with 36 additions and 23 deletions

View File

@@ -29,7 +29,6 @@ import org.oscim.scalebar.DefaultMapScaleBar;
import org.oscim.scalebar.MapScaleBar; import org.oscim.scalebar.MapScaleBar;
import org.oscim.scalebar.MapScaleBarLayer; import org.oscim.scalebar.MapScaleBarLayer;
import org.oscim.theme.IRenderTheme; import org.oscim.theme.IRenderTheme;
import org.oscim.theme.ThemeLoader;
import org.oscim.theme.VtmThemes; import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.mapfile.MapFileTileSource; import org.oscim.tiling.source.mapfile.MapFileTileSource;
@@ -90,8 +89,7 @@ public class GettingStarted extends Activity {
mapView.map().layers().add(new LabelLayer(mapView.map(), tileLayer)); mapView.map().layers().add(new LabelLayer(mapView.map(), tileLayer));
// Render theme // Render theme
theme = ThemeLoader.load(VtmThemes.DEFAULT); theme = mapView.map().setTheme(VtmThemes.DEFAULT);
mapView.map().setTheme(theme);
// Scale bar // Scale bar
MapScaleBar mapScaleBar = new DefaultMapScaleBar(mapView.map()); MapScaleBar mapScaleBar = new DefaultMapScaleBar(mapView.map());

View File

@@ -42,6 +42,7 @@ import org.oscim.renderer.BitmapRenderer;
import org.oscim.renderer.GLViewport; import org.oscim.renderer.GLViewport;
import org.oscim.renderer.bucket.RenderBuckets; import org.oscim.renderer.bucket.RenderBuckets;
import org.oscim.scalebar.*; import org.oscim.scalebar.*;
import org.oscim.theme.IRenderTheme;
import org.oscim.theme.ThemeFile; import org.oscim.theme.ThemeFile;
import org.oscim.theme.VtmThemes; import org.oscim.theme.VtmThemes;
import org.oscim.theme.styles.AreaStyle; import org.oscim.theme.styles.AreaStyle;
@@ -68,6 +69,7 @@ public class MapsforgeActivity extends MapActivity {
private TileGridLayer mGridLayer; private TileGridLayer mGridLayer;
private Menu mMenu; private Menu mMenu;
private final boolean mS3db; private final boolean mS3db;
IRenderTheme mTheme;
VectorTileLayer mTileLayer; VectorTileLayer mTileLayer;
public MapsforgeActivity() { public MapsforgeActivity() {
@@ -106,27 +108,37 @@ public class MapsforgeActivity extends MapActivity {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.theme_default: case R.id.theme_default:
mMap.setTheme(VtmThemes.DEFAULT); if (mTheme != null)
mTheme.dispose();
mTheme = mMap.setTheme(VtmThemes.DEFAULT);
item.setChecked(true); item.setChecked(true);
return true; return true;
case R.id.theme_osmarender: case R.id.theme_osmarender:
mMap.setTheme(VtmThemes.OSMARENDER); if (mTheme != null)
mTheme.dispose();
mTheme = mMap.setTheme(VtmThemes.OSMARENDER);
item.setChecked(true); item.setChecked(true);
return true; return true;
case R.id.theme_osmagray: case R.id.theme_osmagray:
mMap.setTheme(VtmThemes.OSMAGRAY); if (mTheme != null)
mTheme.dispose();
mTheme = mMap.setTheme(VtmThemes.OSMAGRAY);
item.setChecked(true); item.setChecked(true);
return true; return true;
case R.id.theme_tubes: case R.id.theme_tubes:
mMap.setTheme(VtmThemes.TRONRENDER); if (mTheme != null)
mTheme.dispose();
mTheme = mMap.setTheme(VtmThemes.TRONRENDER);
item.setChecked(true); item.setChecked(true);
return true; return true;
case R.id.theme_newtron: case R.id.theme_newtron:
mMap.setTheme(VtmThemes.NEWTRON); if (mTheme != null)
mTheme.dispose();
mTheme = mMap.setTheme(VtmThemes.NEWTRON);
item.setChecked(true); item.setChecked(true);
return true; return true;
@@ -230,12 +242,16 @@ public class MapsforgeActivity extends MapActivity {
}); });
} }
mMap.setTheme(theme); if (mTheme != null)
mTheme.dispose();
mTheme = mMap.setTheme(theme);
mMenu.findItem(R.id.theme_external).setChecked(true); mMenu.findItem(R.id.theme_external).setChecked(true);
} }
} }
protected void loadTheme(final String styleId) { protected void loadTheme(final String styleId) {
mMap.setTheme(VtmThemes.DEFAULT); if (mTheme != null)
mTheme.dispose();
mTheme = mMap.setTheme(VtmThemes.DEFAULT);
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2017 devemux86 * Copyright 2016-2020 devemux86
* *
* This program is free software: you can redistribute it and/or modify it under the * This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software * terms of the GNU Lesser General Public License as published by the Free Software
@@ -17,7 +17,6 @@ package org.oscim.android.test;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast; import android.widget.Toast;
import org.oscim.android.theme.AssetsRenderTheme; import org.oscim.android.theme.AssetsRenderTheme;
import org.oscim.theme.XmlRenderThemeMenuCallback; import org.oscim.theme.XmlRenderThemeMenuCallback;
import org.oscim.theme.XmlRenderThemeStyleLayer; import org.oscim.theme.XmlRenderThemeStyleLayer;
@@ -58,7 +57,9 @@ public class MapsforgeStyleActivity extends MapsforgeActivity {
@Override @Override
protected void loadTheme(final String styleId) { protected void loadTheme(final String styleId) {
mMap.setTheme(new AssetsRenderTheme(getAssets(), "", "vtm/stylemenu.xml", new XmlRenderThemeMenuCallback() { if (mTheme != null)
mTheme.dispose();
mTheme = mMap.setTheme(new AssetsRenderTheme(getAssets(), "", "vtm/stylemenu.xml", new XmlRenderThemeMenuCallback() {
@Override @Override
public Set<String> getCategories(XmlRenderThemeStyleMenu renderThemeStyleMenu) { public Set<String> getCategories(XmlRenderThemeStyleMenu renderThemeStyleMenu) {
// Use the selected style or the default // Use the selected style or the default

View File

@@ -2,7 +2,7 @@
* Copyright 2013 Hannes Janetzek * Copyright 2013 Hannes Janetzek
* Copyright 2016 Andrey Novikov * Copyright 2016 Andrey Novikov
* Copyright 2016 Stephan Leuschner * Copyright 2016 Stephan Leuschner
* Copyright 2016-2019 devemux86 * Copyright 2016-2020 devemux86
* Copyright 2016 Longri * Copyright 2016 Longri
* Copyright 2018 Gustl22 * Copyright 2018 Gustl22
* *
@@ -24,11 +24,7 @@ package org.oscim.map;
import org.oscim.core.BoundingBox; import org.oscim.core.BoundingBox;
import org.oscim.core.Box; import org.oscim.core.Box;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.event.Event; import org.oscim.event.*;
import org.oscim.event.EventDispatcher;
import org.oscim.event.EventListener;
import org.oscim.event.Gesture;
import org.oscim.event.MotionEvent;
import org.oscim.layers.AbstractMapEventLayer; import org.oscim.layers.AbstractMapEventLayer;
import org.oscim.layers.Layer; import org.oscim.layers.Layer;
import org.oscim.layers.MapEventLayer; import org.oscim.layers.MapEventLayer;
@@ -189,16 +185,18 @@ public abstract class Map implements TaskQueue {
* Utility function to set theme of base vector-layer and * Utility function to set theme of base vector-layer and
* use map background color from theme. * use map background color from theme.
*/ */
public void setTheme(ThemeFile theme) { public IRenderTheme setTheme(ThemeFile theme) {
setTheme(theme, false); return setTheme(theme, false);
} }
/** /**
* Utility function to set theme of base vector-layer, optionally * Utility function to set theme of base vector-layer, optionally
* to all vector layers and use map background color from theme. * to all vector layers and use map background color from theme.
*/ */
public void setTheme(ThemeFile theme, boolean allLayers) { public IRenderTheme setTheme(ThemeFile theme, boolean allLayers) {
setTheme(ThemeLoader.load(theme), allLayers); IRenderTheme renderTheme = ThemeLoader.load(theme);
setTheme(renderTheme, allLayers);
return renderTheme;
} }
public void setTheme(IRenderTheme theme) { public void setTheme(IRenderTheme theme) {