use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.
the class DashOsmEditsFragment method setupEditings.
private void setupEditings() {
View mainView = getView();
assert mainView != null;
if (plugin == null) {
mainView.setVisibility(View.GONE);
return;
}
ArrayList<OsmPoint> dataPoints = new ArrayList<>();
getOsmPoints(dataPoints);
if (dataPoints.size() == 0) {
mainView.setVisibility(View.GONE);
return;
} else {
mainView.setVisibility(View.VISIBLE);
DashboardOnMap.handleNumberOfRows(dataPoints, getMyApplication().getSettings(), ROW_NUMBER_TAG);
}
LinearLayout osmLayout = (LinearLayout) mainView.findViewById(R.id.items);
osmLayout.removeAllViews();
for (final OsmPoint point : dataPoints) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.note, null, false);
OsmEditsFragment.getOsmEditView(view, point, getMyApplication());
ImageButton send = (ImageButton) view.findViewById(R.id.play);
send.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_export));
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (point.getGroup() == OsmPoint.Group.POI) {
selectedPoint = point;
if (getMyApplication().getOsmOAuthHelper().isLogged()) {
SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[] { point });
} else {
LoginBottomSheetFragment.showInstance(getActivity().getSupportFragmentManager(), DashOsmEditsFragment.this);
}
} else {
SendOsmNoteBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[] { point });
}
}
});
view.findViewById(R.id.options).setVisibility(View.GONE);
view.findViewById(R.id.divider).setVisibility(View.VISIBLE);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean poi = point.getGroup() == OsmPoint.Group.POI;
String name = poi ? ((OpenstreetmapPoint) point).getName() : ((OsmNotesPoint) point).getText();
getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(), 15, new PointDescription(poi ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG, name), true, // $NON-NLS-1$
point);
MapActivity.launchMapActivityMoveToTop(getActivity());
}
});
osmLayout.addView(view);
}
}
use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.
the class OsmEditsAdapter method getIcon.
private Drawable getIcon(OsmPoint point) {
if (point.getGroup() == OsmPoint.Group.POI) {
OpenstreetmapPoint osmPoint = (OpenstreetmapPoint) point;
int iconResId = 0;
String poiTranslation = osmPoint.getEntity().getTag(Entity.POI_TYPE_TAG);
if (poiTranslation != null) {
Map<String, PoiType> poiTypeMap = app.getPoiTypes().getAllTranslatedNames(false);
PoiType poiType = poiTypeMap.get(poiTranslation.toLowerCase());
if (poiType != null) {
String id = null;
if (RenderingIcons.containsBigIcon(poiType.getIconKeyName())) {
id = poiType.getIconKeyName();
} else if (RenderingIcons.containsBigIcon(poiType.getOsmTag() + "_" + poiType.getOsmValue())) {
id = poiType.getOsmTag() + "_" + poiType.getOsmValue();
}
if (id != null) {
iconResId = RenderingIcons.getBigIconResourceId(id);
}
}
}
if (iconResId == 0) {
iconResId = R.drawable.ic_action_info_dark;
}
int colorResId = R.color.color_distance;
if (point.getAction() == OsmPoint.Action.CREATE) {
colorResId = R.color.color_osm_edit_create;
} else if (point.getAction() == OsmPoint.Action.MODIFY) {
colorResId = R.color.color_osm_edit_modify;
} else if (point.getAction() == OsmPoint.Action.DELETE) {
colorResId = R.color.color_osm_edit_delete;
} else if (point.getAction() == OsmPoint.Action.REOPEN) {
colorResId = R.color.color_osm_edit_modify;
}
return app.getUIUtilities().getIcon(iconResId, colorResId);
} else if (point.getGroup() == OsmPoint.Group.BUG) {
return app.getUIUtilities().getIcon(R.drawable.ic_action_osm_note_add, R.color.color_distance);
}
return null;
}
use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.
the class OsmEditingPlugin method getEditName.
public static String getEditName(OsmPoint point) {
String prefix = getPrefix(point);
String name = getName(point);
if (point.getGroup() == OsmPoint.Group.POI) {
String subtype = "";
if (!Algorithms.isEmpty(((OpenstreetmapPoint) point).getSubtype())) {
subtype = " (" + ((OpenstreetmapPoint) point).getSubtype() + ") ";
}
return prefix + subtype + name;
} else if (point.getGroup() == OsmPoint.Group.BUG) {
return prefix + name;
} else {
return prefix;
}
}
use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.
the class EditPoiDialogFragment method save.
public void save() {
Entity original = editPoiData.getEntity();
final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
Entity entity;
if (original instanceof Node) {
entity = new Node(original.getLatitude(), original.getLongitude(), original.getId());
} else if (original instanceof Way) {
entity = new Way(original.getId(), ((Way) original).getNodeIds(), original.getLatitude(), original.getLongitude());
} else {
return;
}
Action action = entity.getId() < 0 ? Action.CREATE : Action.MODIFY;
for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue()) && !tag.getKey().equals(POI_TYPE_TAG)) {
entity.putTagNoLC(tag.getKey(), tag.getValue());
}
}
String poiTypeTag = editPoiData.getTagValues().get(POI_TYPE_TAG);
String comment = "";
if (poiTypeTag != null) {
final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(poiTypeTag.trim().toLowerCase());
if (poiType != null) {
entity.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue());
entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag());
if (poiType.getOsmTag2() != null) {
entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getOsmTag2());
}
if (poiType.getEditOsmTag2() != null) {
entity.putTagNoLC(poiType.getEditOsmTag2(), poiType.getEditOsmValue2());
entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag2());
}
} else if (!Algorithms.isEmpty(poiTypeTag)) {
PoiCategory category = editPoiData.getPoiCategory();
if (category != null) {
entity.putTagNoLC(category.getDefaultTag(), poiTypeTag);
}
}
if (offlineEdit && !Algorithms.isEmpty(poiTypeTag)) {
entity.putTagNoLC(POI_TYPE_TAG, poiTypeTag);
}
String actionString = action == Action.CREATE ? getString(R.string.default_changeset_add) : getString(R.string.default_changeset_edit);
comment = actionString + " " + poiTypeTag;
}
commitEntity(action, entity, mOpenstreetmapUtil.getEntityInfo(entity.getId()), comment, false, result -> {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (result != null) {
if (offlineEdit) {
List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
if (getActivity() instanceof MapActivity && points.size() > 0) {
OsmPoint point = points.get(points.size() - 1);
MapActivity mapActivity = (MapActivity) getActivity();
mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin.getOsmEditsLayer(mapActivity).getObjectName(point), point);
mapActivity.getMapLayers().getContextMenuLayer().updateContextMenu();
}
}
if (getActivity() instanceof MapActivity) {
((MapActivity) getActivity()).getMapView().refreshMap(true);
}
dismissAllowingStateLoss();
} else {
mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
Button saveButton = view.findViewById(R.id.saveButton);
saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil ? R.string.shared_string_upload : R.string.shared_string_save);
}
return false;
}, getActivity(), mOpenstreetmapUtil, action == Action.MODIFY ? editPoiData.getChangedTags() : null);
}
use of net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint in project Osmand by osmandapp.
the class EditPoiDialogFragment method showEditInstance.
public static void showEditInstance(final MapObject mapObject, final AppCompatActivity activity) {
final OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin == null) {
return;
}
final OsmandApplication app = ((OsmandApplication) activity.getApplication());
final OpenstreetmapUtil openstreetmapUtilToLoad = app.getSettings().isInternetConnectionAvailable(true) ? plugin.getPoiModificationRemoteUtil() : plugin.getPoiModificationLocalUtil();
new AsyncTask<Void, Void, Entity>() {
@Override
protected Entity doInBackground(Void... params) {
return openstreetmapUtilToLoad.loadEntity(mapObject);
}
@Override
protected void onPostExecute(Entity entity) {
if (entity != null) {
Entity existingOsmEditEntity = getExistingOsmEditEntity(plugin, entity.getId());
Entity entityToEdit = existingOsmEditEntity != null ? existingOsmEditEntity : entity;
EditPoiDialogFragment fragment = EditPoiDialogFragment.createInstance(entityToEdit, false);
fragment.show(activity.getSupportFragmentManager(), TAG);
} else {
Toast.makeText(activity, activity.getString(R.string.poi_cannot_be_found), Toast.LENGTH_LONG).show();
}
}
@Nullable
private Entity getExistingOsmEditEntity(@NonNull OsmEditingPlugin osmEditingPlugin, long entityId) {
List<OpenstreetmapPoint> osmEdits = osmEditingPlugin.getDBPOI().getOpenstreetmapPoints();
for (OpenstreetmapPoint osmEdit : osmEdits) {
if (osmEdit.getId() == entityId && osmEdit.getAction() == Action.MODIFY) {
return osmEdit.getEntity();
}
}
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Aggregations