use of net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin in project Osmand by osmandapp.
the class OsmandAidlApi method registerShowSqliteDbFileReceiver.
private void registerShowSqliteDbFileReceiver(@NonNull MapActivity mapActivity) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
BroadcastReceiver showSqliteDbFileReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
OsmandSettings settings = app.getSettings();
String fileName = intent.getStringExtra(AIDL_FILE_NAME);
if (!Algorithms.isEmpty(fileName)) {
settings.MAP_OVERLAY.set(fileName);
settings.MAP_OVERLAY_PREVIOUS.set(fileName);
MapActivity mapActivity = mapActivityRef.get();
if (mapActivity != null) {
OsmandRasterMapsPlugin plugin = OsmandPlugin.getActivePlugin(OsmandRasterMapsPlugin.class);
if (plugin != null) {
plugin.updateMapLayers(mapActivity, mapActivity, settings.MAP_OVERLAY);
}
}
}
}
};
registerReceiver(showSqliteDbFileReceiver, mapActivity, AIDL_SHOW_SQLITEDB_FILE);
}
use of net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin 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.getPlugin(OsmandRasterMapsPlugin.class);
assert plugin != null;
final CommonPreference<Integer> mapTransparencyPreference;
final CommonPreference<String> mapTypePreference;
final CommonPreference<String> exMapTypePreference;
final LayerTransparencySeekbarMode currentMode = type == RasterMapType.OVERLAY ? OVERLAY : 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");
}
CommonPreference<Boolean> hidePolygonsPref = settings.getCustomRenderBooleanProperty("noPolygons");
CommonPreference<Boolean> hideWaterPolygonsPref = settings.getCustomRenderBooleanProperty("hideWaterPolygons");
String mapTypeDescr = mapTypePreference.get();
if (mapTypeDescr != null && mapTypeDescr.contains(".sqlitedb")) {
mapTypeDescr = mapTypeDescr.replaceFirst(".sqlitedb", "");
}
final boolean mapSelected = mapTypeDescr != null;
final int toggleActionStringId = mapSelected ? R.string.shared_string_on : R.string.shared_string_off;
final OnMapSelectedCallback onMapSelectedCallback = new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
mapActivity.getDashboard().refreshContent(true);
boolean refreshToHidePolygons = type == RasterMapType.UNDERLAY;
if (refreshToHidePolygons) {
mapActivity.refreshMapComplete();
}
}
};
final MapLayers 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 (mapSelected) {
plugin.selectMapOverlayLayer(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(() -> {
plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
mapActivity.refreshMapComplete();
});
} else if (itemId == R.string.show_polygons) {
hidePolygonsPref.set(!isChecked);
hideWaterPolygonsPref.set(!isChecked);
mapActivity.refreshMapComplete();
} else if (itemId == R.string.show_transparency_seekbar) {
updateTransparencyBarVisibility(isChecked);
} else if (itemId == R.string.show_parameter_seekbar) {
if (isChecked) {
settings.SHOW_MAP_LAYER_PARAMETER.set(true);
MapTileLayer overlayLayer = plugin.getOverlayLayer();
if (overlayLayer != null) {
mapLayers.getMapControlsLayer().showParameterBar(overlayLayer);
}
} else {
settings.SHOW_MAP_LAYER_PARAMETER.set(false);
mapLayers.getMapControlsLayer().hideParameterBar();
updateTransparencyBarVisibility(isSeekbarVisible(app, RasterMapType.OVERLAY));
}
}
return false;
}
private void updateTransparencyBarVisibility(boolean visible) {
if (visible) {
settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(currentMode);
mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
} else // if(settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.get() == currentMode)
{
settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(LayerTransparencySeekbarMode.OFF);
mapLayers.getMapControlsLayer().hideTransparencyBar();
}
}
};
mapTypeDescr = mapSelected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).hideDivider(true).setListener(l).setSelected(mapSelected).createItem());
if (mapSelected) {
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.getMapLayers().getMapControlsLayer().updateTransparencySliderValue();
mapActivity.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());
ITileSource oveplayMap = plugin.getOverlayLayer().getMap();
if (type == RasterMapType.OVERLAY && oveplayMap != null && oveplayMap.getParamType() != ParameterType.UNDEFINED) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_parameter_seekbar, mapActivity).hideDivider(true).setListener(l).setSelected(settings.SHOW_MAP_LAYER_PARAMETER.get()).createItem());
}
}
}
use of net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin in project Osmand by osmandapp.
the class OsmandPlugin method initPlugins.
public static void initPlugins(@NonNull OsmandApplication app) {
Set<String> enabledPlugins = app.getSettings().getEnabledPlugins();
allPlugins.clear();
allPlugins.add(new WikipediaPlugin(app));
allPlugins.add(new OsmandRasterMapsPlugin(app));
allPlugins.add(new OsmandMonitoringPlugin(app));
checkMarketPlugin(app, new SRTMPlugin(app));
checkMarketPlugin(app, new NauticalMapsPlugin(app));
checkMarketPlugin(app, new SkiMapsPlugin(app));
allPlugins.add(new AudioVideoNotesPlugin(app));
checkMarketPlugin(app, new ParkingPositionPlugin(app));
allPlugins.add(new OsmEditingPlugin(app));
allPlugins.add(new OpenPlaceReviewsPlugin(app));
allPlugins.add(new MapillaryPlugin(app));
allPlugins.add(new AccessibilityPlugin(app));
allPlugins.add(new OsmandDevelopmentPlugin(app));
loadCustomPlugins(app);
registerAppInitializingDependedProperties(app);
enablePluginsByDefault(app, enabledPlugins);
activatePlugins(app, enabledPlugins);
}
use of net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin in project Osmand by osmandapp.
the class OsmandAidlApi method registerHideSqliteDbFileReceiver.
private void registerHideSqliteDbFileReceiver(@NonNull MapActivity mapActivity) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
BroadcastReceiver hideSqliteDbFileReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
OsmandSettings settings = app.getSettings();
String fileName = intent.getStringExtra(AIDL_FILE_NAME);
if (!Algorithms.isEmpty(fileName) && fileName.equals(settings.MAP_OVERLAY.get())) {
settings.MAP_OVERLAY.set(null);
settings.MAP_OVERLAY_PREVIOUS.set(null);
MapActivity mapActivity = mapActivityRef.get();
if (mapActivity != null) {
OsmandRasterMapsPlugin plugin = OsmandPlugin.getActivePlugin(OsmandRasterMapsPlugin.class);
if (plugin != null) {
plugin.updateMapLayers(mapActivity, mapActivity, settings.MAP_OVERLAY);
}
}
}
}
};
registerReceiver(hideSqliteDbFileReceiver, mapActivity, AIDL_HIDE_SQLITEDB_FILE);
}
use of net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin in project Osmand by osmandapp.
the class SqliteTileImportTask method onPostExecute.
@Override
protected void onPostExecute(String error) {
hideProgress();
if (error == null) {
FragmentActivity activity = activityRef.get();
OsmandRasterMapsPlugin plugin = OsmandPlugin.getPlugin(OsmandRasterMapsPlugin.class);
OsmandPlugin.enablePluginIfNeeded(activity, app, plugin, true);
if (activity instanceof MapActivity) {
MapActivity mapActivity = (MapActivity) activity;
mapActivity.getMapLayers().selectMapLayer(mapActivity, true, null);
}
Toast.makeText(app, app.getString(R.string.map_imported_successfully), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(app, app.getString(R.string.map_import_error) + ": " + error, Toast.LENGTH_SHORT).show();
}
}
Aggregations