use of net.osmand.plus.activities.MapActivityLayers in project Osmand by osmandapp.
the class RasterMapMenu method createLayersItems.
private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity, final RasterMapType type) {
final OsmandApplication app = mapActivity.getMyApplication();
final OsmandSettings settings = app.getSettings();
final OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
assert plugin != null;
final OsmandSettings.CommonPreference<Integer> mapTransparencyPreference;
final OsmandSettings.CommonPreference<String> mapTypePreference;
final OsmandSettings.CommonPreference<String> exMapTypePreference;
final LayerTransparencySeekbarMode currentMapTypeSeekbarMode = type == RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.UNDERLAY;
@StringRes final int mapTypeString;
@StringRes final int mapTypeStringTransparency;
if (type == RasterMapType.OVERLAY) {
mapTransparencyPreference = settings.MAP_OVERLAY_TRANSPARENCY;
mapTypePreference = settings.MAP_OVERLAY;
exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS;
mapTypeString = R.string.map_overlay;
mapTypeStringTransparency = R.string.overlay_transparency;
} else if (type == RasterMapType.UNDERLAY) {
mapTransparencyPreference = settings.MAP_TRANSPARENCY;
mapTypePreference = settings.MAP_UNDERLAY;
exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS;
mapTypeString = R.string.map_underlay;
mapTypeStringTransparency = R.string.map_transparency;
} else {
throw new RuntimeException("Unexpected raster map type");
}
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
String mapTypeDescr = mapTypePreference.get();
final boolean selected = mapTypeDescr != null;
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
final OnMapSelectedCallback onMapSelectedCallback = new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
if (type == RasterMapType.UNDERLAY && !canceled && !selected) {
hidePolygonsPref.set(true);
refreshMapComplete(mapActivity);
} else if (type == RasterMapType.UNDERLAY && !canceled && mapTypePreference.get() == null) {
hidePolygonsPref.set(false);
refreshMapComplete(mapActivity);
}
mapActivity.getDashboard().refreshContent(true);
}
};
final MapActivityLayers mapLayers = mapActivity.getMapLayers();
ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
if (itemId == mapTypeString) {
if (selected) {
plugin.selectMapOverlayLayer(mapActivity.getMapView(), mapTypePreference, exMapTypePreference, true, mapActivity, onMapSelectedCallback);
}
return false;
}
return super.onRowItemClick(adapter, view, itemId, pos);
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, final int itemId, final int pos, final boolean isChecked, int[] viewCoordinates) {
if (itemId == toggleActionStringId) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
refreshMapComplete(mapActivity);
}
});
} else if (itemId == R.string.show_polygons) {
hidePolygonsPref.set(!isChecked);
refreshMapComplete(mapActivity);
} else if (itemId == R.string.show_transparency_seekbar) {
settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(isChecked ? currentMapTypeSeekbarMode : LayerTransparencySeekbarMode.OFF);
if (isChecked) {
mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
} else {
mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference);
}
mapLayers.getMapControlsLayer().setTransparencyBarEnabled(isChecked);
}
return false;
}
};
mapTypeDescr = selected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).hideDivider(true).setListener(l).setSelected(selected).createItem());
if (selected) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeString, mapActivity).hideDivider(true).setListener(l).setLayout(R.layout.list_item_icon_and_menu_wide).setDescription(mapTypeDescr).createItem());
ContextMenuAdapter.OnIntegerValueChangedListener integerListener = new ContextMenuAdapter.OnIntegerValueChangedListener() {
@Override
public boolean onIntegerValueChangedListener(int newValue) {
mapTransparencyPreference.set(newValue);
mapActivity.getMapView().refreshMap();
return false;
}
};
// android:max="255" in layout is expected
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeStringTransparency, mapActivity).hideDivider(true).setLayout(R.layout.list_item_progress).setIcon(R.drawable.ic_action_opacity).setProgress(mapTransparencyPreference.get()).setListener(l).setIntegerListener(integerListener).createItem());
if (type == RasterMapType.UNDERLAY) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_polygons, mapActivity).hideDivider(true).setListener(l).setSelected(!hidePolygonsPref.get()).createItem());
}
Boolean transparencySwitchState = isSeekbarVisible(app, type);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_transparency_seekbar, mapActivity).hideDivider(true).setListener(l).setSelected(transparencySwitchState).createItem());
}
}
use of net.osmand.plus.activities.MapActivityLayers in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method selectMapOverlayLayer.
public void selectMapOverlayLayer(@NonNull final OsmandMapTileView mapView, @NonNull final CommonPreference<String> mapPref, @NonNull final CommonPreference<String> exMapPref, boolean force, @NonNull final MapActivity activity, @Nullable final OnMapSelectedCallback callback) {
final MapActivityLayers layers = activity.getMapLayers();
if (!force && exMapPref.get() != null) {
mapPref.set(exMapPref.get());
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, mapPref, layers);
return;
}
final OsmandSettings settings = app.getSettings();
Map<String, String> entriesMap = settings.getTileSourceEntries();
final ArrayList<String> keys = new ArrayList<>(entriesMap.keySet());
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final String[] items = new String[entriesMap.size() + 1];
int i = 0;
for (String it : entriesMap.values()) {
items[i++] = it;
}
items[i] = app.getString(R.string.install_more);
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == items.length - 1) {
installMapLayers(activity, new ResultMatcher<TileSourceTemplate>() {
TileSourceTemplate template = null;
int count = 0;
@Override
public boolean publish(TileSourceTemplate object) {
if (object == null) {
if (count == 1) {
mapPref.set(template.getName());
exMapPref.set(template.getName());
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, mapPref, layers);
} else {
selectMapOverlayLayer(mapView, mapPref, exMapPref, false, activity, null);
}
} else {
count++;
template = object;
}
return false;
}
@Override
public boolean isCancelled() {
return false;
}
});
} else {
mapPref.set(keys.get(which));
exMapPref.set(keys.get(which));
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, mapPref, layers);
}
dialog.dismiss();
}
}).setNegativeButton(R.string.shared_string_cancel, null).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (callback != null) {
callback.onMapSelected(true);
}
}
});
builder.show();
}
use of net.osmand.plus.activities.MapActivityLayers in project Osmand by osmandapp.
the class MapillaryPlugin method registerLayerContextMenuActions.
@Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
if (itemId == R.string.mapillary) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAPILLARY, AndroidUtils.getCenterViewCoordinates(view));
return false;
}
return true;
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
if (itemId == R.string.mapillary) {
OsmandMapTileView mapView = mapActivity.getMapView();
MapActivityLayers mapLayers = mapActivity.getMapLayers();
settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
updateMapLayers(mapView, mapLayers, false);
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setSelected(settings.SHOW_MAPILLARY.get());
item.setColorRes(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
}
return false;
}
};
if (rasterLayer.getMap() == null) {
settings.SHOW_MAPILLARY.set(false);
}
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.mapillary, mapActivity).setSelected(settings.SHOW_MAPILLARY.get()).setColor(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_mapillary).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(11).createItem());
}
use of net.osmand.plus.activities.MapActivityLayers in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method toggleUnderlayState.
public void toggleUnderlayState(@NonNull MapActivity mapActivity, @NonNull RasterMapType type, @Nullable OnMapSelectedCallback callback) {
OsmandMapTileView mapView = mapActivity.getMapView();
CommonPreference<String> mapTypePreference;
CommonPreference<String> exMapTypePreference;
OsmandSettings.CommonPreference<Integer> mapTransparencyPreference;
ITileSource map;
if (type == RasterMapType.OVERLAY) {
mapTransparencyPreference = settings.MAP_OVERLAY_TRANSPARENCY;
mapTypePreference = settings.MAP_OVERLAY;
exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS;
map = overlayLayer.getMap();
} else {
// Underlay expected
mapTransparencyPreference = settings.MAP_TRANSPARENCY;
mapTypePreference = settings.MAP_UNDERLAY;
exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS;
map = underlayLayer.getMap();
}
boolean isChecked = map == null;
boolean showSeekbar = isChecked && RasterMapMenu.isSeekbarVisible(app, type);
boolean hideSeekbar = !isChecked && RasterMapMenu.isSeekbarVisible(app, type);
MapActivityLayers mapLayers = mapActivity.getMapLayers();
CommonPreference<LayerTransparencySeekbarMode> seekbarModePref = settings.LAYER_TRANSPARENCY_SEEKBAR_MODE;
if (showSeekbar) {
mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
mapLayers.getMapControlsLayer().setTransparencyBarEnabled(true);
if (seekbarModePref.get() == LayerTransparencySeekbarMode.UNDEFINED) {
final OsmandSettings.LayerTransparencySeekbarMode currentMapTypeSeekbarMode = type == OsmandRasterMapsPlugin.RasterMapType.OVERLAY ? OsmandSettings.LayerTransparencySeekbarMode.OVERLAY : OsmandSettings.LayerTransparencySeekbarMode.UNDERLAY;
seekbarModePref.set(currentMapTypeSeekbarMode);
}
} else if (hideSeekbar) {
mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference);
mapLayers.getMapControlsLayer().setTransparencyBarEnabled(false);
}
if (map != null) {
mapTypePreference.set(null);
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, null, mapLayers);
} else {
selectMapOverlayLayer(mapView, mapTypePreference, exMapTypePreference, false, mapActivity, callback);
}
}
Aggregations