Raster map: synchronized model with view.

This commit is contained in:
GaidamakUA 2016-02-10 11:22:37 +02:00
parent 7bd6f9a54a
commit 4803a08245
3 changed files with 54 additions and 25 deletions

View file

@ -8,6 +8,7 @@ import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.core.android.MapRendererContext; import net.osmand.core.android.MapRendererContext;
@ -38,7 +39,6 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -73,14 +73,6 @@ public class ConfigureMapMenu {
}); });
createLayersItems(adapter, ma); createLayersItems(adapter, ma);
createRenderingAttributeItems(adapter, ma); createRenderingAttributeItems(adapter, ma);
// adapter.item(R.string.layer_map_appearance).
// iconColor(R.drawable.ic_configure_screen_dark).listen(new OnContextMenuClick() {
// @Override
// public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
// ma.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN);
// return false;
// }
// }).reg();
return adapter; return adapter;
} }
@ -649,5 +641,4 @@ public class ConfigureMapMenu {
} }
} }
} }
} }

View file

@ -13,7 +13,9 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.views.GPXLayer;
import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.RouteLayer;
public class RasterMapMenu { public class RasterMapMenu {
private static final String TAG = "RasterMapMenu"; private static final String TAG = "RasterMapMenu";
@ -26,7 +28,7 @@ public class RasterMapMenu {
return adapter; return adapter;
} }
private static void createLayersItems(ContextMenuAdapter adapter, private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter,
final MapActivity mapActivity, final MapActivity mapActivity,
final OsmandRasterMapsPlugin.RasterMapType type) { final OsmandRasterMapsPlugin.RasterMapType type) {
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
@ -59,7 +61,8 @@ public class RasterMapMenu {
} }
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(final ArrayAdapter<?> adapter,
int itemId, int pos, boolean isChecked) {
Log.v(TAG, "onContextMenuClick(" + "adapter=" + adapter + ", itemId=" + itemId + ", pos=" + pos + ", isChecked=" + isChecked + ")"); Log.v(TAG, "onContextMenuClick(" + "adapter=" + adapter + ", itemId=" + itemId + ", pos=" + pos + ", isChecked=" + isChecked + ")");
if (itemId == R.string.shared_string_show) { if (itemId == R.string.shared_string_show) {
MapActivityLayers mapLayers = mapActivity.getMapLayers(); MapActivityLayers mapLayers = mapActivity.getMapLayers();
@ -68,14 +71,21 @@ public class RasterMapMenu {
} else { } else {
mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference); mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference);
} }
plugin.toggleUnderlayState(mapActivity, type); plugin.toggleUnderlayState(mapActivity, type, new OsmandRasterMapsPlugin.OnMapSelectedCallback() {
@Override
public void onMapSelected() {
mapActivity.getDashboard().refreshContent(true);
}
});
} else if (itemId == R.string.show_polygons) { } else if (itemId == R.string.show_polygons) {
hidePolygonsPref.set(!isChecked); hidePolygonsPref.set(!isChecked);
refreshMapComplete(mapActivity);
} }
return false; return false;
} }
}; };
adapter.item(R.string.shared_string_show).listen(l).selected(rasterMapLayer != null && rasterMapLayer.getMap() != null ? 1 : 0).reg(); int selected = mapTypePreference.get() != null ? 1 : 0;
contextMenuAdapter.item(R.string.shared_string_show).listen(l).selected(selected).reg();
// String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] "; // String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] ";
ContextMenuAdapter.OnIntegerValueChangedListener integerListener = ContextMenuAdapter.OnIntegerValueChangedListener integerListener =
new ContextMenuAdapter.OnIntegerValueChangedListener() { new ContextMenuAdapter.OnIntegerValueChangedListener() {
@ -88,9 +98,23 @@ public class RasterMapMenu {
}; };
// android:max="255" in layout is expected // android:max="255" in layout is expected
// Please note this does not modify the transparency of the underlay map, but of the base map, of course! // Please note this does not modify the transparency of the underlay map, but of the base map, of course!
adapter.item(R.string.map_transparency).layout(R.layout.progress_list_item) contextMenuAdapter.item(R.string.map_transparency).layout(R.layout.progress_list_item)
.progress(mapTransparencyPreference.get()).listenInteger(integerListener).reg(); .progress(mapTransparencyPreference.get()).listenInteger(integerListener).reg();
adapter.item(mapTypeString).layout(R.layout.two_line_list_item).description(mapTypePreference.get()).reg(); contextMenuAdapter.item(mapTypeString).layout(R.layout.two_line_list_item).description(mapTypePreference.get()).reg();
adapter.item(R.string.show_polygons).listen(l).selected(hidePolygonsPref.get() ? 0 : 1).reg(); contextMenuAdapter.item(R.string.show_polygons).listen(l).selected(hidePolygonsPref.get() ? 0 : 1).reg();
}
private static void refreshMapComplete(final MapActivity activity) {
activity.getMyApplication().getResourceManager().getRenderer().clearCache();
activity.updateMapSettings();
GPXLayer gpx = activity.getMapView().getLayerByClass(GPXLayer.class);
if(gpx != null) {
gpx.updateLayerStyle();
}
RouteLayer rte = activity.getMapView().getLayerByClass(RouteLayer.class);
if(rte != null) {
rte.updateLayerStyle();
}
activity.getMapView().refreshMap(true);
} }
} }

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -146,9 +147,10 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
} }
} }
public void selectMapOverlayLayer(final OsmandMapTileView mapView, public void selectMapOverlayLayer(@NonNull final OsmandMapTileView mapView,
final CommonPreference<String> mapPref, @NonNull final CommonPreference<String> mapPref,
final MapActivity activity) { @NonNull final MapActivity activity,
@Nullable final OnMapSelectedCallback callback) {
final OsmandSettings settings = app.getSettings(); final OsmandSettings settings = app.getSettings();
final MapActivityLayers layers = activity.getMapLayers(); final MapActivityLayers layers = activity.getMapLayers();
Map<String, String> entriesMap = settings.getTileSourceEntries(); Map<String, String> entriesMap = settings.getTileSourceEntries();
@ -174,9 +176,12 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
if (object == null) { if (object == null) {
if (count == 1) { if (count == 1) {
mapPref.set(template.getName()); mapPref.set(template.getName());
if (callback != null) {
callback.onMapSelected();
}
updateMapLayers(mapView, mapPref, layers); updateMapLayers(mapView, mapPref, layers);
} else { } else {
selectMapOverlayLayer(mapView, mapPref, activity); selectMapOverlayLayer(mapView, mapPref, activity, null);
} }
} else { } else {
count++; count++;
@ -192,6 +197,9 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
}); });
} else { } else {
mapPref.set(keys.get(which)); mapPref.set(keys.get(which));
if (callback != null) {
callback.onMapSelected();
}
updateMapLayers(mapView, mapPref, layers); updateMapLayers(mapView, mapPref, layers);
} }
dialog.dismiss(); dialog.dismiss();
@ -422,7 +430,9 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
return overlayLayer; return overlayLayer;
} }
public void toggleUnderlayState(@NonNull MapActivity mapActivity, @NonNull RasterMapType type) { public void toggleUnderlayState(@NonNull MapActivity mapActivity,
@NonNull RasterMapType type,
@Nullable OnMapSelectedCallback callback) {
OsmandMapTileView mapView = mapActivity.getMapView(); OsmandMapTileView mapView = mapActivity.getMapView();
CommonPreference<String> mapTypePreference; CommonPreference<String> mapTypePreference;
ITileSource map; ITileSource map;
@ -436,11 +446,11 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
if (map != null) { if (map != null) {
mapTypePreference.set(null); mapTypePreference.set(null);
callback.onMapSelected();
MapActivityLayers mapLayers = mapActivity.getMapLayers(); MapActivityLayers mapLayers = mapActivity.getMapLayers();
updateMapLayers(mapView, null, mapLayers); updateMapLayers(mapView, null, mapLayers);
} else { } else {
selectMapOverlayLayer(mapView, mapTypePreference, selectMapOverlayLayer(mapView, mapTypePreference, mapActivity, callback);
mapActivity);
} }
} }
@ -448,4 +458,8 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
OVERLAY, OVERLAY,
UNDERLAY UNDERLAY
} }
public interface OnMapSelectedCallback {
void onMapSelected();
}
} }