use of net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode 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.OsmandSettings.LayerTransparencySeekbarMode in project Osmand by osmandapp.
the class RasterMapMenu method isSeekbarVisible.
@NonNull
public static Boolean isSeekbarVisible(OsmandApplication app, RasterMapType type) {
final OsmandSettings.LayerTransparencySeekbarMode currentMapTypeSeekbarMode = type == RasterMapType.OVERLAY ? OsmandSettings.LayerTransparencySeekbarMode.OVERLAY : OsmandSettings.LayerTransparencySeekbarMode.UNDERLAY;
LayerTransparencySeekbarMode seekbarMode = app.getSettings().LAYER_TRANSPARENCY_SEEKBAR_MODE.get();
return seekbarMode == LayerTransparencySeekbarMode.UNDEFINED || seekbarMode == currentMapTypeSeekbarMode;
}
use of net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode in project Osmand by osmandapp.
the class MapControlsLayer method initTransparencyBar.
// /////////////// Transparency bar /////////////////////////
private void initTransparencyBar() {
transparencyBarLayout = (LinearLayout) mapActivity.findViewById(R.id.map_transparency_layout);
transparencyBar = (SeekBar) mapActivity.findViewById(R.id.map_transparency_seekbar);
transparencyBar.setMax(255);
if (transparencySetting != null) {
transparencyBar.setProgress(transparencySetting.get());
transparencyBarLayout.setVisibility(View.VISIBLE);
} else {
transparencyBarLayout.setVisibility(View.GONE);
}
transparencyBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (transparencySetting != null) {
transparencySetting.set(progress);
mapActivity.getMapView().refreshMap();
}
}
});
ImageButton imageButton = (ImageButton) mapActivity.findViewById(R.id.map_transparency_hide);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
transparencyBarLayout.setVisibility(View.GONE);
settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(LayerTransparencySeekbarMode.OFF);
hideTransparencyBar(transparencySetting);
}
});
LayerTransparencySeekbarMode seekbarMode = settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.get();
if (seekbarMode == LayerTransparencySeekbarMode.OVERLAY && settings.MAP_OVERLAY.get() != null) {
showTransparencyBar(settings.MAP_OVERLAY_TRANSPARENCY);
setTransparencyBarEnabled(true);
} else if (seekbarMode == LayerTransparencySeekbarMode.UNDERLAY && settings.MAP_UNDERLAY.get() != null) {
showTransparencyBar(settings.MAP_TRANSPARENCY);
setTransparencyBarEnabled(true);
}
}
use of net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode 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