use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.
the class OsmandDevelopmentPlugin method registerWidget.
private void registerWidget(MapActivity activity) {
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
final OsmandMapTileView mv = activity.getMapView();
if (mapInfoLayer != null && mapInfoLayer.getSideWidget(FPSTextInfoWidget.class) == null) {
FPSTextInfoWidget fps = new FPSTextInfoWidget(mv, activity);
mapInfoLayer.registerSideWidget(fps, R.drawable.ic_action_fps, R.string.map_widget_fps_info, "fps", false, 50);
mapInfoLayer.recreateControls();
}
}
use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.
the class ConfigureMapMenu method createRenderingProperty.
private ContextMenuItem createRenderingProperty(final ContextMenuAdapter adapter, final MapActivity activity, @DrawableRes final int icon, final RenderingRuleProperty p) {
final OsmandMapTileView view = activity.getMapView();
String propertyName = SettingsActivity.getStringPropertyName(view.getContext(), p.getAttrName(), p.getName());
final String propertyDescr = SettingsActivity.getStringPropertyDescription(view.getContext(), p.getAttrName(), p.getName());
if (p.isBoolean()) {
final OsmandSettings.CommonPreference<Boolean> pref = view.getApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName());
return ContextMenuItem.createBuilder(propertyName).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
pref.set(!pref.get());
refreshMapComplete(activity);
return false;
}
}).setSelected(pref.get()).createItem();
} else {
final OsmandSettings.CommonPreference<String> pref = view.getApplication().getSettings().getCustomRenderProperty(p.getAttrName());
final String descr;
if (!Algorithms.isEmpty(pref.get())) {
descr = SettingsActivity.getStringPropertyValue(activity, pref.get());
} else {
descr = SettingsActivity.getStringPropertyValue(view.getContext(), p.getDefaultValueDescription());
}
ContextMenuItem.ItemBuilder builder = ContextMenuItem.createBuilder(propertyName).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, final int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(propertyDescr);
int i = Arrays.asList(p.getPossibleValues()).indexOf(pref.get());
if (i >= 0) {
i++;
} else if (Algorithms.isEmpty(pref.get())) {
i = 0;
}
String[] possibleValuesString = new String[p.getPossibleValues().length + 1];
possibleValuesString[0] = SettingsActivity.getStringPropertyValue(view.getContext(), p.getDefaultValueDescription());
for (int j = 0; j < p.getPossibleValues().length; j++) {
possibleValuesString[j + 1] = SettingsActivity.getStringPropertyValue(view.getContext(), p.getPossibleValues()[j]);
}
b.setSingleChoiceItems(possibleValuesString, i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
pref.set("");
} else {
pref.set(p.getPossibleValues()[which - 1]);
}
refreshMapComplete(activity);
String description = SettingsActivity.getStringPropertyValue(activity, pref.get());
adapter.getItem(pos).setDescription(description);
dialog.dismiss();
}
});
b.setNegativeButton(R.string.shared_string_dismiss, null);
b.show();
return false;
}
}).setDescription(descr).setLayout(R.layout.list_item_single_line_descrition_narrow);
if (icon != 0) {
builder.setIcon(icon);
}
return builder.createItem();
}
}
use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.
the class DashboardOnMap method updateDownloadBtn.
private void updateDownloadBtn() {
Button btn = (Button) dashboardView.findViewById(R.id.map_download_button);
String filter = null;
String txt = "";
OsmandMapTileView mv = mapActivity.getMapView();
if (mv != null && !mapActivity.getMyApplication().isApplicationInitializing()) {
if (mv.getZoom() < 11 && !mapActivity.getMyApplication().getResourceManager().containsBasemap()) {
filter = "basemap";
txt = mapActivity.getString(R.string.shared_string_download) + " " + mapActivity.getString(R.string.base_world_map);
} else {
DownloadedRegionsLayer dl = mv.getLayerByClass(DownloadedRegionsLayer.class);
if (dl != null) {
StringBuilder btnName = new StringBuilder();
filter = dl.getFilter(btnName);
txt = btnName.toString();
}
}
}
btn.setText(txt);
btn.setVisibility(filter == null ? View.GONE : View.VISIBLE);
final String f = filter;
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideDashboard(false);
final Intent intent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getDownloadIndexActivity());
if (f != null && !f.equals("basemap")) {
intent.putExtra(DownloadActivity.FILTER_KEY, f);
}
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
mapActivity.startActivity(intent);
}
});
scheduleDownloadButtonCheck();
}
use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin 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) {
int[] viewCoordinates = AndroidUtils.getCenterViewCoordinates(view);
if (itemId == R.string.layer_overlay) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.OVERLAY_MAP, viewCoordinates);
return false;
} else if (itemId == R.string.layer_underlay) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.UNDERLAY_MAP, viewCoordinates);
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();
switch(itemId) {
case R.string.layer_overlay:
toggleUnderlayState(mapActivity, RasterMapType.OVERLAY, new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
ContextMenuItem item = adapter.getItem(pos);
String overlayMapDescr = settings.MAP_OVERLAY.get();
boolean hasOverlayDescription = overlayMapDescr != null;
overlayMapDescr = hasOverlayDescription ? overlayMapDescr : mapActivity.getString(R.string.shared_string_none);
item.setDescription(overlayMapDescr);
item.setSelected(hasOverlayDescription);
item.setColorRes(hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
});
return false;
case R.string.layer_underlay:
toggleUnderlayState(mapActivity, RasterMapType.UNDERLAY, new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
ContextMenuItem item = adapter.getItem(pos);
String underlayMapDescr = settings.MAP_UNDERLAY.get();
boolean hasUnderlayDescription = underlayMapDescr != null;
underlayMapDescr = hasUnderlayDescription ? underlayMapDescr : mapActivity.getString(R.string.shared_string_none);
item.setDescription(underlayMapDescr);
item.setSelected(hasUnderlayDescription);
item.setColorRes(hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
hidePolygonsPref.set(hasUnderlayDescription);
RasterMapMenu.refreshMapComplete(mapActivity);
}
});
return false;
}
return true;
}
};
if (overlayLayer.getMap() == null) {
settings.MAP_OVERLAY.set(null);
settings.MAP_OVERLAY_PREVIOUS.set(null);
}
if (underlayLayer.getMap() == null) {
settings.MAP_UNDERLAY.set(null);
settings.MAP_UNDERLAY_PREVIOUS.set(null);
}
String overlayMapDescr = settings.MAP_OVERLAY.get();
boolean hasOverlayDescription = overlayMapDescr != null;
overlayMapDescr = hasOverlayDescription ? overlayMapDescr : mapActivity.getString(R.string.shared_string_none);
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_overlay, mapActivity).setDescription(overlayMapDescr).setSelected(hasOverlayDescription).setColor(hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_layer_top_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(14).createItem());
String underlayMapDescr = settings.MAP_UNDERLAY.get();
boolean hasUnderlayDescription = underlayMapDescr != null;
underlayMapDescr = hasUnderlayDescription ? underlayMapDescr : mapActivity.getString(R.string.shared_string_none);
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_underlay, mapActivity).setDescription(underlayMapDescr).setSelected(hasUnderlayDescription).setColor(hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_layer_bottom_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(15).createItem());
}
use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method registerMapContextMenuActions.
@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, Object selectedObj) {
final OsmandMapTileView mapView = mapActivity.getMapView();
if (mapView.getMainLayer() instanceof MapTileLayer) {
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
if (resId == R.string.context_menu_item_update_map) {
mapActivity.getMapActions().reloadTile(mapView.getZoom(), latitude, longitude);
} else if (resId == R.string.shared_string_download_map) {
DownloadTilesDialog dlg = new DownloadTilesDialog(mapActivity, (OsmandApplication) mapActivity.getApplication(), mapView);
dlg.openDialog();
}
return true;
}
};
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_update_map, mapActivity).setIcon(R.drawable.ic_action_refresh_dark).setOrder(UPDATE_MAP_ITEM_ORDER).setListener(listener).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_download_map, mapActivity).setIcon(R.drawable.ic_action_import).setOrder(DOWNLOAD_MAP_ITEM_ORDER).setListener(listener).createItem());
}
}
Aggregations