Raster map: synchronized model with view.
This commit is contained in:
parent
7bd6f9a54a
commit
4803a08245
3 changed files with 54 additions and 25 deletions
|
@ -8,6 +8,7 @@ import android.support.v7.app.AlertDialog;
|
|||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.core.android.MapRendererContext;
|
||||
|
@ -38,7 +39,6 @@ import net.osmand.util.Algorithms;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -73,14 +73,6 @@ public class ConfigureMapMenu {
|
|||
});
|
||||
createLayersItems(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;
|
||||
}
|
||||
|
@ -649,5 +641,4 @@ public class ConfigureMapMenu {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,9 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivityLayers;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.views.GPXLayer;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.RouteLayer;
|
||||
|
||||
public class RasterMapMenu {
|
||||
private static final String TAG = "RasterMapMenu";
|
||||
|
@ -26,7 +28,7 @@ public class RasterMapMenu {
|
|||
return adapter;
|
||||
}
|
||||
|
||||
private static void createLayersItems(ContextMenuAdapter adapter,
|
||||
private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter,
|
||||
final MapActivity mapActivity,
|
||||
final OsmandRasterMapsPlugin.RasterMapType type) {
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
|
@ -59,7 +61,8 @@ public class RasterMapMenu {
|
|||
}
|
||||
|
||||
@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 + ")");
|
||||
if (itemId == R.string.shared_string_show) {
|
||||
MapActivityLayers mapLayers = mapActivity.getMapLayers();
|
||||
|
@ -68,14 +71,21 @@ public class RasterMapMenu {
|
|||
} else {
|
||||
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) {
|
||||
hidePolygonsPref.set(!isChecked);
|
||||
refreshMapComplete(mapActivity);
|
||||
}
|
||||
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()) +"] ";
|
||||
ContextMenuAdapter.OnIntegerValueChangedListener integerListener =
|
||||
new ContextMenuAdapter.OnIntegerValueChangedListener() {
|
||||
|
@ -88,9 +98,23 @@ public class RasterMapMenu {
|
|||
};
|
||||
// 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!
|
||||
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();
|
||||
adapter.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(mapTypeString).layout(R.layout.two_line_list_item).description(mapTypePreference.get()).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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
|||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
|
@ -146,9 +147,10 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
public void selectMapOverlayLayer(final OsmandMapTileView mapView,
|
||||
final CommonPreference<String> mapPref,
|
||||
final MapActivity activity) {
|
||||
public void selectMapOverlayLayer(@NonNull final OsmandMapTileView mapView,
|
||||
@NonNull final CommonPreference<String> mapPref,
|
||||
@NonNull final MapActivity activity,
|
||||
@Nullable final OnMapSelectedCallback callback) {
|
||||
final OsmandSettings settings = app.getSettings();
|
||||
final MapActivityLayers layers = activity.getMapLayers();
|
||||
Map<String, String> entriesMap = settings.getTileSourceEntries();
|
||||
|
@ -174,9 +176,12 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
if (object == null) {
|
||||
if (count == 1) {
|
||||
mapPref.set(template.getName());
|
||||
if (callback != null) {
|
||||
callback.onMapSelected();
|
||||
}
|
||||
updateMapLayers(mapView, mapPref, layers);
|
||||
} else {
|
||||
selectMapOverlayLayer(mapView, mapPref, activity);
|
||||
selectMapOverlayLayer(mapView, mapPref, activity, null);
|
||||
}
|
||||
} else {
|
||||
count++;
|
||||
|
@ -192,6 +197,9 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
});
|
||||
} else {
|
||||
mapPref.set(keys.get(which));
|
||||
if (callback != null) {
|
||||
callback.onMapSelected();
|
||||
}
|
||||
updateMapLayers(mapView, mapPref, layers);
|
||||
}
|
||||
dialog.dismiss();
|
||||
|
@ -422,7 +430,9 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
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();
|
||||
CommonPreference<String> mapTypePreference;
|
||||
ITileSource map;
|
||||
|
@ -436,11 +446,11 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
|
||||
if (map != null) {
|
||||
mapTypePreference.set(null);
|
||||
callback.onMapSelected();
|
||||
MapActivityLayers mapLayers = mapActivity.getMapLayers();
|
||||
updateMapLayers(mapView, null, mapLayers);
|
||||
} else {
|
||||
selectMapOverlayLayer(mapView, mapTypePreference,
|
||||
mapActivity);
|
||||
selectMapOverlayLayer(mapView, mapTypePreference, mapActivity, callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -448,4 +458,8 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
|||
OVERLAY,
|
||||
UNDERLAY
|
||||
}
|
||||
|
||||
public interface OnMapSelectedCallback {
|
||||
void onMapSelected();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue