Merge pull request #10533 from osmandapp/share_address_poi_type
Share address. Nearby POI
This commit is contained in:
commit
e9d0a379b8
6 changed files with 126 additions and 46 deletions
|
@ -11,6 +11,8 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
|
||||
<string name="copy_address">Copy address</string>
|
||||
<string name="message_error_recheck_parameters">Error, recheck parameters</string>
|
||||
<string name="routing_engine_vehicle_type_car">Car</string>
|
||||
<string name="routing_engine_vehicle_type_bike">Bike</string>
|
||||
|
@ -4026,5 +4028,4 @@
|
|||
<string name="routing_attr_freeride_policy_description">\'Freeride\' and \'Off-piste\' are unofficial routes and passages. Typically ungroomed, unmaintained and not checked in the evening. Enter at your own risk.</string>
|
||||
<string name="voice_prompts_timetable">Voice prompts times</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -29,20 +29,29 @@ import android.widget.ImageView;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.plus.*;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.ActivityResultListener;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
|
@ -51,6 +60,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder;
|
|||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
|
||||
import net.osmand.plus.openplacereviews.AddPhotosBottomSheetDialogFragment;
|
||||
import net.osmand.plus.openplacereviews.OPRConstants;
|
||||
|
@ -65,6 +75,7 @@ import net.osmand.plus.widgets.TextViewEx;
|
|||
import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.openplacereviews.opendb.util.exception.FailedVerificationException;
|
||||
|
||||
|
@ -72,7 +83,13 @@ import java.io.BufferedInputStream;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
|
||||
|
||||
|
@ -91,13 +108,15 @@ public class MenuBuilder {
|
|||
private boolean firstRow;
|
||||
protected boolean matchWidthDivider;
|
||||
protected boolean light;
|
||||
private long objectId;
|
||||
private Amenity amenity;
|
||||
private LatLon latLon;
|
||||
private boolean hidden;
|
||||
private boolean showTitleIfTruncated = true;
|
||||
private boolean showNearestWiki = false;
|
||||
private boolean showNearestPoi = false;
|
||||
private boolean showOnlinePhotos = true;
|
||||
protected List<Amenity> nearestWiki = new ArrayList<>();
|
||||
protected List<Amenity> nearestPoi = new ArrayList<>();
|
||||
private List<OsmandPlugin> menuPlugins = new ArrayList<>();
|
||||
@Nullable
|
||||
private CardsRowBuilder onlinePhotoCardsRow;
|
||||
|
@ -208,10 +227,18 @@ public class MenuBuilder {
|
|||
return showNearestWiki;
|
||||
}
|
||||
|
||||
public boolean isShowNearestPoi() {
|
||||
return showNearestPoi;
|
||||
}
|
||||
|
||||
public void setShowNearestWiki(boolean showNearestWiki) {
|
||||
this.showNearestWiki = showNearestWiki;
|
||||
}
|
||||
|
||||
public void setShowNearestPoi(boolean showNearestPoi) {
|
||||
this.showNearestPoi = showNearestPoi;
|
||||
}
|
||||
|
||||
public void setShowTitleIfTruncated(boolean showTitleIfTruncated) {
|
||||
this.showTitleIfTruncated = showTitleIfTruncated;
|
||||
}
|
||||
|
@ -224,9 +251,8 @@ public class MenuBuilder {
|
|||
this.showOnlinePhotos = showOnlinePhotos;
|
||||
}
|
||||
|
||||
public void setShowNearestWiki(boolean showNearestWiki, long objectId) {
|
||||
this.objectId = objectId;
|
||||
this.showNearestWiki = showNearestWiki;
|
||||
public void setAmenity(Amenity amenity) {
|
||||
this.amenity = amenity;
|
||||
}
|
||||
|
||||
public void addMenuPlugin(OsmandPlugin plugin) {
|
||||
|
@ -246,6 +272,7 @@ public class MenuBuilder {
|
|||
buildTitleRow(view);
|
||||
}
|
||||
buildNearestWikiRow(view);
|
||||
buildNearestPoiRow(view);
|
||||
if (needBuildPlainMenuItems()) {
|
||||
buildPlainMenuItems(view);
|
||||
}
|
||||
|
@ -325,10 +352,20 @@ public class MenuBuilder {
|
|||
}
|
||||
|
||||
protected void buildNearestWikiRow(View view) {
|
||||
if (processNearestWiki() && nearestWiki.size() > 0) {
|
||||
buildRow(view, R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", 0,
|
||||
true, getCollapsableWikiView(view.getContext(), true),
|
||||
false, 0, false, null, false);
|
||||
buildNearestRow(view, nearestWiki, processNearestWiki(),
|
||||
R.drawable.ic_action_wikipedia, app.getString(R.string.wiki_around));
|
||||
}
|
||||
|
||||
protected void buildNearestPoiRow(View view) {
|
||||
buildNearestRow(view, nearestPoi, processNearestPoi(),
|
||||
nearestPoi.isEmpty() ? 0 : AmenityMenuController.getRightIconId(nearestPoi.get(0)),
|
||||
app.getString(R.string.speak_poi));
|
||||
}
|
||||
|
||||
protected void buildNearestRow(View view, List<Amenity> nearestAmenities, boolean process, int iconId, String text) {
|
||||
if (process && nearestAmenities.size() > 0) {
|
||||
buildRow(view, iconId, null, text + " (" + nearestAmenities.size() + ")", 0, true,
|
||||
getCollapsableView(view.getContext(), true, nearestAmenities), false, 0, false, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1118,20 +1155,23 @@ public class MenuBuilder {
|
|||
return new CollapsableView(textView, this, collapsed);
|
||||
}
|
||||
|
||||
protected CollapsableView getCollapsableWikiView(Context context, boolean collapsed) {
|
||||
protected CollapsableView getCollapsableView(Context context, boolean collapsed, List<Amenity> nearestAmenities) {
|
||||
LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
|
||||
|
||||
for (final Amenity wiki : nearestWiki) {
|
||||
for (final Amenity poi : nearestAmenities) {
|
||||
TextViewEx button = buildButtonInCollapsableView(context, false, false);
|
||||
String name = wiki.getName(preferredMapAppLang, transliterateNames);
|
||||
String name = poi.getName(preferredMapAppLang, transliterateNames);
|
||||
if (Algorithms.isBlank(name)) {
|
||||
name = AmenityMenuController.getTypeStr(poi);
|
||||
}
|
||||
button.setText(name);
|
||||
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LatLon latLon = new LatLon(wiki.getLocation().getLatitude(), wiki.getLocation().getLongitude());
|
||||
PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(wiki);
|
||||
mapActivity.getContextMenu().show(latLon, pointDescription, wiki);
|
||||
LatLon latLon = new LatLon(poi.getLocation().getLatitude(), poi.getLocation().getLongitude());
|
||||
PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(poi);
|
||||
mapActivity.getContextMenu().show(latLon, pointDescription, poi);
|
||||
}
|
||||
});
|
||||
view.addView(button);
|
||||
|
@ -1191,35 +1231,48 @@ public class MenuBuilder {
|
|||
}
|
||||
|
||||
protected boolean processNearestWiki() {
|
||||
if (showNearestWiki && latLon != null) {
|
||||
QuadRect rect = MapUtils.calculateLatLonBbox(
|
||||
latLon.getLatitude(), latLon.getLongitude(), 250);
|
||||
PoiUIFilter wikiPoiFilter = app.getPoiFilters().getTopWikiPoiFilter();
|
||||
|
||||
nearestWiki = getAmenities(rect, wikiPoiFilter);
|
||||
|
||||
Collections.sort(nearestWiki, new Comparator<Amenity>() {
|
||||
|
||||
@Override
|
||||
public int compare(Amenity o1, Amenity o2) {
|
||||
double d1 = MapUtils.getDistance(latLon, o1.getLocation());
|
||||
double d2 = MapUtils.getDistance(latLon, o2.getLocation());
|
||||
return Double.compare(d1, d2);
|
||||
}
|
||||
});
|
||||
Long id = objectId;
|
||||
List<Amenity> wikiList = new ArrayList<>();
|
||||
for (Amenity wiki : nearestWiki) {
|
||||
if (wiki.getId().equals(id)) {
|
||||
wikiList.add(wiki);
|
||||
}
|
||||
if (showNearestWiki && latLon != null && amenity != null) {
|
||||
PoiUIFilter filter = app.getPoiFilters().getTopWikiPoiFilter();
|
||||
if (filter != null) {
|
||||
nearestWiki = getSortedAmenities(filter, latLon);
|
||||
return true;
|
||||
}
|
||||
nearestWiki.removeAll(wikiList);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean processNearestPoi() {
|
||||
if (showNearestPoi && latLon != null && amenity != null) {
|
||||
PoiCategory pc = amenity.getType();
|
||||
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
|
||||
PoiUIFilter filter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + pt.getKeyName());
|
||||
if (filter != null) {
|
||||
nearestPoi = getSortedAmenities(filter, latLon);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<Amenity> getSortedAmenities(PoiUIFilter filter, final LatLon latLon) {
|
||||
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 250);
|
||||
|
||||
List<Amenity> nearestAmenities = getAmenities(rect, filter);
|
||||
nearestAmenities.remove(amenity);
|
||||
|
||||
Collections.sort(nearestAmenities, new Comparator<Amenity>() {
|
||||
|
||||
@Override
|
||||
public int compare(Amenity o1, Amenity o2) {
|
||||
double d1 = MapUtils.getDistance(latLon, o1.getLocation());
|
||||
double d2 = MapUtils.getDistance(latLon, o2.getLocation());
|
||||
return Double.compare(d1, d2);
|
||||
}
|
||||
});
|
||||
|
||||
return nearestAmenities;
|
||||
}
|
||||
|
||||
private List<Amenity> getAmenities(QuadRect rect, PoiUIFilter wikiPoiFilter) {
|
||||
return wikiPoiFilter.searchAmenities(rect.top, rect.left,
|
||||
rect.bottom, rect.right, -1, null);
|
||||
|
|
|
@ -35,6 +35,7 @@ import net.osmand.plus.helpers.FontCache;
|
|||
import net.osmand.plus.helpers.enums.MetricsConstants;
|
||||
import net.osmand.plus.mapcontextmenu.CollapsableView;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.views.layers.POIMapLayer;
|
||||
|
@ -78,7 +79,9 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
public AmenityMenuBuilder(@NonNull MapActivity mapActivity, final @NonNull Amenity amenity) {
|
||||
super(mapActivity);
|
||||
this.amenity = amenity;
|
||||
setShowNearestWiki(true, amenity.getId());
|
||||
setAmenity(amenity);
|
||||
setShowNearestWiki(true);
|
||||
setShowNearestPoi(!amenity.getType().isWiki());
|
||||
metricSystem = mapActivity.getMyApplication().getSettings().METRIC_SYSTEM.get();
|
||||
}
|
||||
|
||||
|
@ -86,6 +89,10 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
protected void buildNearestWikiRow(View view) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildNearestPoiRow(View view) {
|
||||
}
|
||||
|
||||
private void buildRow(View view, int iconId, String text, String textPrefix,
|
||||
boolean collapsable, final CollapsableView collapsableView,
|
||||
int textColor, boolean isWiki, boolean isText, boolean needLinks,
|
||||
|
@ -664,11 +671,19 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
if (processNearestWiki() && nearestWiki.size() > 0) {
|
||||
AmenityInfoRow wikiInfo = new AmenityInfoRow(
|
||||
"nearest_wiki", R.drawable.ic_plugin_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", true,
|
||||
getCollapsableWikiView(view.getContext(), true),
|
||||
getCollapsableView(view.getContext(), true, nearestWiki),
|
||||
0, false, false, false, 1000, null, false, false, false, 0);
|
||||
buildAmenityRow(view, wikiInfo);
|
||||
}
|
||||
|
||||
if (processNearestPoi() && nearestPoi.size() > 0) {
|
||||
AmenityInfoRow poiInfo = new AmenityInfoRow(
|
||||
"nearest_poi", AmenityMenuController.getRightIconId(amenity), null, app.getString(R.string.speak_poi) + " (" + nearestPoi.size() + ")", true,
|
||||
getCollapsableView(view.getContext(), true, nearestPoi),
|
||||
0, false, false, false, 1000, null, false, false, false, 0);
|
||||
buildAmenityRow(view, poiInfo);
|
||||
}
|
||||
|
||||
if (osmEditingEnabled && amenity.getId() != null
|
||||
&& amenity.getId() > 0 &&
|
||||
(amenity.getId() % 2 == 0 || (amenity.getId() >> 1) < Integer.MAX_VALUE)) {
|
||||
|
|
|
@ -59,9 +59,9 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void buildNearestWikiRow(View view) {
|
||||
protected void buildNearestRow(View view, List<Amenity> nearestAmenities, boolean process, int iconId, String text) {
|
||||
if (originObject == null || !(originObject instanceof Amenity)) {
|
||||
super.buildNearestWikiRow(view);
|
||||
super.buildNearestRow(view, nearestAmenities, process, iconId, text);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ public class AmenityMenuController extends MenuController {
|
|||
return getRightIconId(amenity);
|
||||
}
|
||||
|
||||
private static int getRightIconId(Amenity amenity) {
|
||||
public static int getRightIconId(Amenity amenity) {
|
||||
String id = null;
|
||||
PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
|
||||
if (st != null) {
|
||||
|
|
|
@ -36,6 +36,7 @@ public class ShareMenu extends BaseMenuController {
|
|||
public enum ShareItem {
|
||||
MESSAGE(R.drawable.ic_action_message, R.string.shared_string_send),
|
||||
CLIPBOARD(R.drawable.ic_action_copy, R.string.shared_string_copy),
|
||||
ADDRESS(R.drawable.ic_action_copy, R.string.copy_address),
|
||||
NAME(R.drawable.ic_action_copy, R.string.copy_location_name),
|
||||
COORDINATES(R.drawable.ic_action_copy, R.string.copy_coordinates),
|
||||
GEO(R.drawable.ic_world_globe_dark, R.string.share_geo),
|
||||
|
@ -66,6 +67,7 @@ public class ShareMenu extends BaseMenuController {
|
|||
List<ShareItem> list = new LinkedList<>();
|
||||
list.add(ShareItem.MESSAGE);
|
||||
list.add(ShareItem.CLIPBOARD);
|
||||
list.add(ShareItem.ADDRESS);
|
||||
list.add(ShareItem.NAME);
|
||||
list.add(ShareItem.COORDINATES);
|
||||
list.add(ShareItem.GEO);
|
||||
|
@ -121,6 +123,15 @@ public class ShareMenu extends BaseMenuController {
|
|||
case CLIPBOARD:
|
||||
ShareDialog.sendToClipboard(mapActivity, sms);
|
||||
break;
|
||||
case ADDRESS:
|
||||
if (!Algorithms.isEmpty(address)) {
|
||||
ShareDialog.sendToClipboard(mapActivity, address);
|
||||
} else {
|
||||
Toast.makeText(mapActivity,
|
||||
R.string.no_address_found,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
break;
|
||||
case NAME:
|
||||
if (!Algorithms.isEmpty(title)) {
|
||||
ShareDialog.sendToClipboard(mapActivity, title);
|
||||
|
|
Loading…
Reference in a new issue