public void updateType(Amenity amenity) { poiTypeEditText.setText(amenity.getSubType()); poiTypeTextInputLayout.setHint(amenity.getType().getTranslation()); setAdapterForPoiTypeEditText(); poiTypeEditText.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(final View v, MotionEvent event) { final EditText editText = (EditText) v; final int DRAWABLE_RIGHT = 2; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getX() >= (editText.getRight() - editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width() - editText.getPaddingRight())) { if (editPoiData.amenity.getType() != null) { DialogFragment dialogFragment = PoiSubTypeDialogFragment.createInstance(editPoiData.amenity); dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment"); } return true; } } return false; } }); }
public void getAmenityFromPoint(PointF point, List<? super Amenity> am) { if (objects != null) { int ex = (int) point.x; int ey = (int) point.y; int compare = getRadiusPoi(view.getZoom()); int radius = getRadiusPoi(view.getZoom()) * 3 / 2; try { for (int i = 0; i < objects.size(); i++) { Amenity n = objects.get(i); int x = view.getRotatedMapXForPoint( n.getLocation().getLatitude(), n.getLocation().getLongitude()); int y = view.getRotatedMapYForPoint( n.getLocation().getLatitude(), n.getLocation().getLongitude()); if (Math.abs(x - ex) <= compare && Math.abs(y - ey) <= compare) { compare = radius; am.add(n); } } } catch (IndexOutOfBoundsException e) { // that's really rare case, but is much efficient than introduce synchronized block } } }
public Drawable getDrawable(Context uiCtx, OsmandApplication app) { if (type == POI) { Amenity amenity = ((AmenityLocationPoint) point).a; PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType()); if (st != null) { if (RenderingIcons.containsBigIcon(st.getIconKeyName())) { return uiCtx .getResources() .getDrawable(RenderingIcons.getBigIconResourceId(st.getIconKeyName())); } else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) { return uiCtx .getResources() .getDrawable( RenderingIcons.getBigIconResourceId(st.getOsmTag() + "_" + st.getOsmValue())); } } return null; } else if (type == TARGETS) { int i = !((TargetPoint) point).intermediate ? R.drawable.list_destination : R.drawable.list_intermediate; return uiCtx.getResources().getDrawable(i); } else if (type == FAVORITES || type == WAYPOINTS) { return FavoriteImageDrawable.getOrCreate(uiCtx, point.getColor(), false); } else if (type == ALARMS) { // assign alarm list icons manually for now if (((AlarmInfo) point).getType().toString() == "SPEED_CAMERA") { return uiCtx.getResources().getDrawable(R.drawable.mx_highway_speed_camera); } else if (((AlarmInfo) point).getType().toString() == "BORDER_CONTROL") { return uiCtx.getResources().getDrawable(R.drawable.mx_barrier_border_control); } else if (((AlarmInfo) point).getType().toString() == "RAILWAY") { if (app.getSettings().DRIVING_REGION.get().americanSigns) { return uiCtx.getResources().getDrawable(R.drawable.list_warnings_railways_us); } else { return uiCtx.getResources().getDrawable(R.drawable.list_warnings_railways); } } else if (((AlarmInfo) point).getType().toString() == "TRAFFIC_CALMING") { if (app.getSettings().DRIVING_REGION.get().americanSigns) { return uiCtx.getResources().getDrawable(R.drawable.list_warnings_traffic_calming_us); } else { return uiCtx.getResources().getDrawable(R.drawable.list_warnings_traffic_calming); } } else if (((AlarmInfo) point).getType().toString() == "TOLL_BOOTH") { return uiCtx.getResources().getDrawable(R.drawable.mx_toll_booth); } else if (((AlarmInfo) point).getType().toString() == "STOP") { return uiCtx.getResources().getDrawable(R.drawable.list_stop); } else if (((AlarmInfo) point).getType().toString() == "PEDESTRIAN") { if (app.getSettings().DRIVING_REGION.get().americanSigns) { return uiCtx.getResources().getDrawable(R.drawable.list_warnings_pedestrian_us); } else { return uiCtx.getResources().getDrawable(R.drawable.list_warnings_pedestrian); } } else { return null; } } else { return null; } }
public static EditPoiDialogFragment createAddPoiInstance( double latitude, double longitude, OsmandApplication application) { Node node = new Node(latitude, longitude, -1); Amenity amenity; amenity = new Amenity(); amenity.setType(application.getPoiTypes().getOtherPoiCategory()); amenity.setSubType(""); amenity.setAdditionalInfo(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(), ""); return createInstance(node, amenity); }
private void showDescriptionDialog(Amenity a) { Builder bs = new AlertDialog.Builder(view.getContext()); bs.setTitle( OsmAndFormatter.getPoiSimpleFormat( a, view.getContext(), view.getSettings().USE_ENGLISH_NAMES.get())); bs.setMessage(a.getDescription()); bs.show(); }
private StringBuilder buildPoiInformation(StringBuilder res, Amenity n) { String format = OsmAndFormatter.getPoiSimpleFormat( n, view.getContext(), view.getSettings().USE_ENGLISH_NAMES.get()); res.append(" " + format); if (n.getOpeningHours() != null) { res.append("\n") .append(view.getContext().getString(R.string.opening_hours)) .append(" : ") .append(n.getOpeningHours()); // $NON-NLS-1$ //$NON-NLS-2$ } if (n.getPhone() != null) { res.append("\n") .append(view.getContext().getString(R.string.phone)) .append(" : ") .append(n.getPhone()); // $NON-NLS-1$ //$NON-NLS-2$ } if (n.getSite() != null && n.getType() != AmenityType.OSMWIKI) { res.append("\n") .append(view.getContext().getString(R.string.website)) .append(" : ") .append(n.getSite()); // $NON-NLS-1$ //$NON-NLS-2$ } return res; }
protected void calculatePoi( RouteCalculationResult route, List<LocationPointWrapper> locationPoints) { PoiUIFilter pf = getPoiFilter(); if (pf != null) { final List<Location> locs = route.getImmutableAllLocations(); List<Amenity> amenities = pf.searchAmenitiesOnThePath(locs, poiSearchDeviationRadius); for (Amenity a : amenities) { AmenityRoutePoint rp = a.getRoutePoint(); int i = locs.indexOf(rp.pointA); if (i >= 0) { LocationPointWrapper lwp = new LocationPointWrapper( route, POI, new AmenityLocationPoint(a), (float) rp.deviateDistance, i); lwp.setAnnounce(announcePOI()); locationPoints.add(lwp); } } } }
public static String getPoiStringWithoutType(Amenity amenity, boolean en) { String type = SpecialPhrases.getSpecialPhrase(amenity.getSubType()); String n = amenity.getName(en); if (type == null) { type = amenity.getSubType(); } if (n.indexOf(type) != -1) { // type is contained in name e.g. // n = "Bakery the Corner" // type = "Bakery" // no need to repeat this return n; } if (n.length() == 0) { return type; } return type + " " + n; // $NON-NLS-1$ }
@Override public Node loadNode(Amenity n) { if (n.getId() % 2 == 1) { // that's way id return null; } long nodeId = n.getId() >> 1; try { String res = sendRequest( SITE_API + "api/0.6/node/" + nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$ if (res != null) { OsmBaseStorage st = new OsmBaseStorage(); st.parseOSM( new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); // $NON-NLS-1$ EntityId id = new Entity.EntityId(EntityType.NODE, nodeId); Node entity = (Node) st.getRegisteredEntities().get(id); entityInfo = st.getRegisteredEntityInfo().get(id); // check whether this is node (because id of node could be the same as relation) if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) { return entity; } return null; } } catch (IOException e) { log.error("Loading node failed " + nodeId, e); // $NON-NLS-1$ AccessibleToast.makeText( ctx, ctx.getResources().getString(R.string.error_io_error), Toast.LENGTH_LONG) .show(); } catch (SAXException e) { log.error("Loading node failed " + nodeId, e); // $NON-NLS-1$ AccessibleToast.makeText( ctx, ctx.getResources().getString(R.string.error_io_error), Toast.LENGTH_LONG) .show(); } return null; }
@Override public OnClickListener getActionListener(List<String> actionsList, Object o) { final Amenity a = (Amenity) o; int ind = 0; final int phoneIndex = a.getPhone() != null ? ind++ : -1; final int siteIndex = a.getSite() != null ? ind++ : -1; final int descriptionIndex = a.getDescription() != null ? ind++ : -1; if (a.getPhone() != null) { actionsList.add(this.view.getResources().getString(R.string.poi_context_menu_call)); } if (a.getSite() != null) { actionsList.add(this.view.getResources().getString(R.string.poi_context_menu_website)); } if (a.getDescription() != null) { actionsList.add( this.view.getResources().getString(R.string.poi_context_menu_showdescription)); } final int modifyInd = ind++; actionsList.add(this.view.getResources().getString(R.string.poi_context_menu_modify)); final int deleteInd = ind++; actionsList.add(this.view.getResources().getString(R.string.poi_context_menu_delete)); final EditingPOIActivity edit = activity.getPoiActions(); return new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == modifyInd) { edit.showEditDialog(a); } else if (which == deleteInd) { edit.showDeleteDialog(a); } else if (which == phoneIndex) { try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("tel:" + a.getPhone())); // $NON-NLS-1$ view.getContext().startActivity(intent); } catch (RuntimeException e) { log.error("Failed to invoke call", e); // $NON-NLS-1$ AccessibleToast.makeText(view.getContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } else if (which == siteIndex) { try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(a.getSite())); view.getContext().startActivity(intent); } catch (RuntimeException e) { log.error("Failed to invoke call", e); // $NON-NLS-1$ AccessibleToast.makeText(view.getContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } else if (which == descriptionIndex) { showDescriptionDialog(a); } else { } } }; }
@Override public Node loadNode(Amenity n) { if (n.getId() % 2 == 1) { // that's way id return null; } long nodeId = n.getId() >> 1; // EntityId id = new Entity.EntityId(EntityType.NODE, nodeId); Node entity = new Node(n.getLocation().getLatitude(), n.getLocation().getLongitude(), nodeId); Map<AmenityType, Map<String, String>> typeNameToTagVal = MapRenderingTypes.getDefault().getAmenityTypeNameToTagVal(); AmenityType type = n.getType(); String tag = type.getDefaultTag(); String subType = n.getSubType(); String val = subType; if (typeNameToTagVal.containsKey(type)) { Map<String, String> map = typeNameToTagVal.get(type); if (map.containsKey(subType)) { String res = map.get(subType); if (res != null) { int i = res.indexOf(' '); if (i != -1) { tag = res.substring(0, i); val = res.substring(i + 1); } else { tag = res; } } } } entity.putTag(tag, val); entity.putTag(OSMTagKey.NAME.getValue(), n.getName()); entity.putTag(OSMTagKey.OPENING_HOURS.getValue(), n.getOpeningHours()); // check whether this is node (because id of node could be the same as relation) if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) { return entity; } return null; }
@Override public void buildInternal(View view) { boolean hasWiki = false; MapPoiTypes poiTypes = app.getPoiTypes(); String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get(); if (Algorithms.isEmpty(preferredLang)) { preferredLang = app.getLanguage(); } List<AmenityDescription> descriptions = new LinkedList<>(); for (Map.Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) { int iconId; Drawable icon = null; int textColor = 0; String key = e.getKey(); String vl = e.getValue(); String textPrefix = ""; boolean isWiki = false; boolean isText = false; boolean needLinks = !"population".equals(key); if (amenity.getType().isWiki()) { if (!hasWiki) { iconId = R.drawable.ic_action_note_dark; String lng = amenity.getContentSelected("content", preferredLang, "en"); if (Algorithms.isEmpty(lng)) { lng = "en"; } final String langSelected = lng; String content = amenity.getDescription(langSelected); vl = Html.fromHtml(content).toString(); if (vl.length() > 300) { vl = vl.substring(0, 300); } hasWiki = true; isWiki = true; } else { continue; } } else if (key.startsWith("name:")) { continue; } else if (Amenity.OPENING_HOURS.equals(key)) { iconId = R.drawable.ic_action_time; OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours()); if (rs != null) { Calendar inst = Calendar.getInstance(); inst.setTimeInMillis(System.currentTimeMillis()); boolean opened = rs.isOpenedForTime(inst); if (opened) { textColor = R.color.color_ok; } else { textColor = R.color.color_invalid; } } } else if (Amenity.PHONE.equals(key)) { iconId = R.drawable.ic_action_call_dark; } else if (Amenity.WEBSITE.equals(key)) { iconId = R.drawable.ic_world_globe_dark; vl = vl.replace(' ', '_'); } else { if (Amenity.DESCRIPTION.equals(key)) { iconId = R.drawable.ic_action_note_dark; } else { iconId = R.drawable.ic_action_info_dark; } AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(key); if (pt != null) { PoiType pType = (PoiType) pt; if (pType.getParentType() != null && pType.getParentType() instanceof PoiType) { icon = getRowIcon( view.getContext(), ((PoiType) pType.getParentType()).getOsmTag() + "_" + pType.getOsmTag().replace(':', '_') + "_" + pType.getOsmValue()); } if (!pType.isText()) { vl = pType.getTranslation(); } else { isText = true; iconId = R.drawable.ic_action_note_dark; textPrefix = pType.getTranslation(); vl = amenity.unzipContent(e.getValue()); } } else { textPrefix = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey()); vl = amenity.unzipContent(e.getValue()); } } if (isText && iconId == R.drawable.ic_action_note_dark) { descriptions.add(new AmenityDescription(key, textPrefix, vl)); } else if (icon != null) { buildRow(view, icon, vl, textPrefix, textColor, isWiki, isText, needLinks); } else { buildRow(view, iconId, vl, textPrefix, textColor, isWiki, isText, needLinks); } } String langSuffix = ":" + preferredLang; AmenityDescription descInPrefLang = null; for (AmenityDescription desc : descriptions) { if (desc.key.length() > langSuffix.length() && desc.key .substring(desc.key.length() - langSuffix.length(), desc.key.length()) .equals(langSuffix)) { descInPrefLang = desc; break; } } if (descInPrefLang != null) { descriptions.remove(descInPrefLang); descriptions.add(0, descInPrefLang); } for (AmenityDescription desc : descriptions) { buildRow( view, R.drawable.ic_action_note_dark, desc.text, desc.textPrefix, 0, false, true, true); } }
@Override public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, DrawSettings nightMode) { if (view.getZoom() >= startZoom) { objects.clear(); resourceManager.searchAmenitiesAsync( latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, view.getZoom(), filter, objects); int r = getRadiusPoi(view.getZoom()); for (Amenity o : objects) { int x = view.getRotatedMapXForPoint( o.getLocation().getLatitude(), o.getLocation().getLongitude()); int y = view.getRotatedMapYForPoint( o.getLocation().getLatitude(), o.getLocation().getLongitude()); canvas.drawCircle(x, y, r, pointAltUI); canvas.drawCircle(x, y, r, point); String id = null; if (RenderingIcons.containsIcon(o.getSubType())) { id = o.getSubType(); } else if (RenderingIcons.containsIcon( o.getType().getDefaultTag() + "_" + o.getSubType())) { id = o.getType().getDefaultTag() + "_" + o.getSubType(); } if (id != null) { Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id); if (bmp != null) { canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon); } } } if (view.getSettings().SHOW_POI_LABEL.get()) { TIntHashSet set = new TIntHashSet(); for (Amenity o : objects) { int x = view.getRotatedMapXForPoint( o.getLocation().getLatitude(), o.getLocation().getLongitude()); int y = view.getRotatedMapYForPoint( o.getLocation().getLatitude(), o.getLocation().getLongitude()); int tx = view.getMapXForPoint(o.getLocation().getLongitude()); int ty = view.getMapYForPoint(o.getLocation().getLatitude()); String name = o.getName(view.getSettings().USE_ENGLISH_NAMES.get()); if (name != null && name.length() > 0) { int lines = 0; while (lines < TEXT_LINES) { if (set.contains(division(tx, ty, 0, lines)) || set.contains(division(tx, ty, -1, lines)) || set.contains(division(tx, ty, +1, lines))) { break; } lines++; } if (lines == 0) { // drawWrappedText(canvas, "...", paintTextIcon.getTextSize(), x, y + r + 2 + // paintTextIcon.getTextSize() / 2, 1); } else { drawWrappedText( canvas, name, paintTextIcon.getTextSize(), x, y + r + 2 + paintTextIcon.getTextSize() / 2, lines); while (lines > 0) { set.add(division(tx, ty, 1, lines - 1)); set.add(division(tx, ty, -1, lines - 1)); set.add(division(tx, ty, 0, lines - 1)); lines--; } } } } } } }
@Override public double getLongitude() { return a.getLocation().getLongitude(); }
public static String getPoiSimpleFormat(Amenity amenity, Context ctx, boolean en) { return toPublicString(amenity.getType(), ctx) + " : " + getPoiStringWithoutType(amenity, en); // $NON-NLS-1$ }