Merge pull request #10756 from osmandapp/mapillary_plugin
Mapillary plugin
This commit is contained in:
commit
7adaddd9a0
6 changed files with 125 additions and 45 deletions
|
@ -69,6 +69,7 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class OsmandPlugin {
|
||||
|
@ -211,10 +212,16 @@ public abstract class OsmandPlugin {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected List<ImageCard> getContextMenuImageCards(@Nullable GetImageCardsListener listener) {
|
||||
protected List<ImageCard> getContextMenuImageCards(@NonNull Map<String, String> params,
|
||||
@Nullable Map<String, String> additionalParams,
|
||||
@Nullable GetImageCardsListener listener) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected ImageCard createContextMenuImageCard(@NonNull JSONObject imageObject) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin was installed
|
||||
*/
|
||||
|
@ -273,9 +280,9 @@ public abstract class OsmandPlugin {
|
|||
|
||||
allPlugins.clear();
|
||||
|
||||
enableHiddenPlugin(app, enabledPlugins, new MapillaryPlugin(app));
|
||||
enableHiddenPlugin(app, enabledPlugins, new WikipediaPlugin(app));
|
||||
|
||||
allPlugins.add(new MapillaryPlugin(app));
|
||||
allPlugins.add(new OsmandRasterMapsPlugin(app));
|
||||
allPlugins.add(new OsmandMonitoringPlugin(app));
|
||||
checkMarketPlugin(app, enabledPlugins, new SRTMPlugin(app));
|
||||
|
@ -875,12 +882,23 @@ public abstract class OsmandPlugin {
|
|||
return collection;
|
||||
}
|
||||
|
||||
public static void populateContextMenuImageCards(@NonNull List<ImageCard> imageCards, @Nullable GetImageCardsListener listener) {
|
||||
for (OsmandPlugin p : getEnabledPlugins()) {
|
||||
imageCards.addAll(p.getContextMenuImageCards(listener));
|
||||
public static void populateContextMenuImageCards(@NonNull List<ImageCard> imageCards, @NonNull Map<String, String> params,
|
||||
@Nullable Map<String, String> additionalParams, @Nullable GetImageCardsListener listener) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
imageCards.addAll(plugin.getContextMenuImageCards(params, additionalParams, listener));
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageCard createImageCardForJson(@NonNull JSONObject imageObject) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
ImageCard imageCard = plugin.createContextMenuImageCard(imageObject);
|
||||
if (imageCard != null) {
|
||||
return imageCard;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isPackageInstalled(String packageInfo, Context ctx) {
|
||||
if (packageInfo == null) {
|
||||
return false;
|
||||
|
|
|
@ -63,7 +63,6 @@ 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;
|
||||
import net.osmand.plus.openplacereviews.OpenPlaceReviewsPlugin;
|
||||
import net.osmand.plus.openplacereviews.OprStartFragment;
|
||||
import net.osmand.plus.osmedit.opr.OpenDBAPI;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
|
@ -502,7 +501,7 @@ public class MenuBuilder {
|
|||
public void run() {
|
||||
if (AndroidUtils.isActivityNotDestroyed(mapActivity)) {
|
||||
try {
|
||||
ImageCard imageCard = OpenPlaceReviewsPlugin.createCardOpr(mapActivity, new JSONObject(response));
|
||||
ImageCard imageCard = OsmandPlugin.createImageCardForJson(new JSONObject(response));
|
||||
if (imageCard != null) {
|
||||
addImageCard(imageCard);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import net.osmand.AndroidNetworkUtils;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -27,9 +26,6 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapillary.MapillaryContributeCard;
|
||||
import net.osmand.plus.mapillary.MapillaryImageCard;
|
||||
import net.osmand.plus.wikimedia.WikiImageHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -47,10 +43,11 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.osmand.plus.mapillary.MapillaryPlugin.TYPE_MAPILLARY_CONTRIBUTE;
|
||||
import static net.osmand.plus.mapillary.MapillaryPlugin.TYPE_MAPILLARY_PHOTO;
|
||||
|
||||
public abstract class ImageCard extends AbstractCard {
|
||||
|
||||
public static String TYPE_MAPILLARY_PHOTO = "mapillary-photo";
|
||||
public static String TYPE_MAPILLARY_CONTRIBUTE = "mapillary-contribute";
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(ImageCard.class);
|
||||
protected String type;
|
||||
|
@ -182,11 +179,7 @@ public abstract class ImageCard extends AbstractCard {
|
|||
try {
|
||||
if (imageObject.has("type")) {
|
||||
String type = imageObject.getString("type");
|
||||
if (TYPE_MAPILLARY_PHOTO.equals(type)) {
|
||||
imageCard = new MapillaryImageCard(mapActivity, imageObject);
|
||||
} else if (TYPE_MAPILLARY_CONTRIBUTE.equals(type)) {
|
||||
imageCard = new MapillaryContributeCard(mapActivity, imageObject);
|
||||
} else {
|
||||
if (!TYPE_MAPILLARY_CONTRIBUTE.equals(type) && !TYPE_MAPILLARY_PHOTO.equals(type)) {
|
||||
imageCard = new UrlImageCard(mapActivity, imageObject);
|
||||
}
|
||||
}
|
||||
|
@ -419,7 +412,7 @@ public abstract class ImageCard extends AbstractCard {
|
|||
}
|
||||
|
||||
public GetImageCardsTask(@NonNull MapActivity mapActivity, LatLon latLon,
|
||||
@Nullable Map<String, String> params, GetImageCardsListener listener) {
|
||||
@Nullable Map<String, String> params, GetImageCardsListener listener) {
|
||||
this.mapActivity = mapActivity;
|
||||
this.app = mapActivity.getMyApplication();
|
||||
this.latLon = latLon;
|
||||
|
@ -428,10 +421,9 @@ public abstract class ImageCard extends AbstractCard {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<ImageCard> doInBackground(Void... params) {
|
||||
protected List<ImageCard> doInBackground(Void... voids) {
|
||||
TrafficStats.setThreadStatsTag(GET_IMAGE_CARD_THREAD_ID);
|
||||
List<ImageCard> result = new ArrayList<>();
|
||||
OsmandPlugin.populateContextMenuImageCards(result, listener);
|
||||
try {
|
||||
final Map<String, String> pms = new LinkedHashMap<>();
|
||||
pms.put("lat", "" + (float) latLon.getLatitude());
|
||||
|
@ -448,19 +440,8 @@ public abstract class ImageCard extends AbstractCard {
|
|||
if (!Algorithms.isEmpty(preferredLang)) {
|
||||
pms.put("lang", preferredLang);
|
||||
}
|
||||
if (this.params != null) {
|
||||
String wikidataId = this.params.get(Amenity.WIKIDATA);
|
||||
if (wikidataId != null) {
|
||||
this.params.remove(Amenity.WIKIDATA);
|
||||
WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, result);
|
||||
}
|
||||
String wikimediaContent = this.params.get(Amenity.WIKIMEDIA_COMMONS);
|
||||
if (wikimediaContent != null) {
|
||||
this.params.remove(Amenity.WIKIMEDIA_COMMONS);
|
||||
WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, result);
|
||||
}
|
||||
pms.putAll(this.params);
|
||||
}
|
||||
OsmandPlugin.populateContextMenuImageCards(result, pms, params, listener);
|
||||
|
||||
String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms,
|
||||
"Requesting location images...", false, false);
|
||||
|
||||
|
@ -472,7 +453,10 @@ public abstract class ImageCard extends AbstractCard {
|
|||
try {
|
||||
JSONObject imageObject = (JSONObject) images.get(i);
|
||||
if (imageObject != JSONObject.NULL) {
|
||||
ImageCard imageCard = ImageCard.createCard(mapActivity, imageObject);
|
||||
ImageCard imageCard = OsmandPlugin.createImageCardForJson(imageObject);
|
||||
if (imageCard == null) {
|
||||
imageCard = ImageCard.createCard(mapActivity, imageObject);
|
||||
}
|
||||
if (imageCard != null) {
|
||||
result.add(imageCard);
|
||||
}
|
||||
|
|
|
@ -17,27 +17,34 @@ import androidx.appcompat.widget.SwitchCompat;
|
|||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.map.TileSourceManager;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivityLayers;
|
||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||
import net.osmand.plus.dashboard.DashboardOnMap;
|
||||
import net.osmand.plus.views.layers.MapInfoLayer;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
|
||||
import net.osmand.plus.openplacereviews.OpenPlaceReviewsPlugin;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.layers.MapInfoLayer;
|
||||
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
|
||||
import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -47,11 +54,18 @@ import static net.osmand.plus.ContextMenuAdapter.makeDeleteAction;
|
|||
|
||||
public class MapillaryPlugin extends OsmandPlugin {
|
||||
|
||||
public static String TYPE_MAPILLARY_PHOTO = "mapillary-photo";
|
||||
public static String TYPE_MAPILLARY_CONTRIBUTE = "mapillary-contribute";
|
||||
|
||||
public static final String ID = "osmand.mapillary";
|
||||
private static final String MAPILLARY_PACKAGE_ID = "app.mapillary";
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(OpenPlaceReviewsPlugin.class);
|
||||
|
||||
private OsmandSettings settings;
|
||||
|
||||
private MapActivity mapActivity;
|
||||
|
||||
private MapillaryRasterLayer rasterLayer;
|
||||
private MapillaryVectorLayer vectorLayer;
|
||||
private TextInfoWidget mapillaryControl;
|
||||
|
@ -62,11 +76,6 @@ public class MapillaryPlugin extends OsmandPlugin {
|
|||
settings = app.getSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLogoResourceId() {
|
||||
return R.drawable.ic_action_mapillary;
|
||||
|
@ -228,6 +237,41 @@ public class MapillaryPlugin extends OsmandPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImageCard createContextMenuImageCard(@NonNull JSONObject imageObject) {
|
||||
ImageCard imageCard = null;
|
||||
if (mapActivity != null) {
|
||||
try {
|
||||
if (imageObject.has("type")) {
|
||||
String type = imageObject.getString("type");
|
||||
if (TYPE_MAPILLARY_PHOTO.equals(type)) {
|
||||
imageCard = new MapillaryImageCard(mapActivity, imageObject);
|
||||
} else if (TYPE_MAPILLARY_CONTRIBUTE.equals(type)) {
|
||||
imageCard = new MapillaryContributeCard(mapActivity, imageObject);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
return imageCard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mapActivityResume(MapActivity activity) {
|
||||
this.mapActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mapActivityResumeOnTop(MapActivity activity) {
|
||||
this.mapActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mapActivityPause(MapActivity activity) {
|
||||
this.mapActivity = null;
|
||||
}
|
||||
|
||||
public static boolean openMapillary(FragmentActivity activity, String imageKey) {
|
||||
boolean success = false;
|
||||
OsmandApplication app = (OsmandApplication) activity.getApplication();
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.openplacereviews;
|
|||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.AndroidNetworkUtils;
|
||||
|
@ -25,6 +26,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class OpenPlaceReviewsPlugin extends OsmandPlugin {
|
||||
|
||||
|
@ -85,7 +87,9 @@ public class OpenPlaceReviewsPlugin extends OsmandPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<ImageCard> getContextMenuImageCards(@Nullable GetImageCardsListener listener) {
|
||||
protected List<ImageCard> getContextMenuImageCards(@NonNull Map<String, String> params,
|
||||
@Nullable Map<String, String> additionalParams,
|
||||
@Nullable GetImageCardsListener listener) {
|
||||
List<ImageCard> imageCards = new ArrayList<>();
|
||||
if (mapActivity != null) {
|
||||
Object object = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObject();
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.view.View;
|
|||
import android.widget.ArrayAdapter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
|
@ -24,6 +25,8 @@ import net.osmand.plus.download.DownloadActivity;
|
|||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.download.DownloadResources;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.search.QuickSearchDialogFragment;
|
||||
|
@ -32,8 +35,9 @@ import net.osmand.plus.search.listitems.QuickSearchBannerListItem;
|
|||
import net.osmand.plus.search.listitems.QuickSearchFreeBannerListItem;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.views.layers.DownloadedRegionsLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.layers.DownloadedRegionsLayer;
|
||||
import net.osmand.plus.wikimedia.WikiImageHelper;
|
||||
import net.osmand.search.core.ObjectType;
|
||||
import net.osmand.search.core.SearchPhrase;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -42,6 +46,7 @@ import java.io.IOException;
|
|||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID;
|
||||
|
@ -91,6 +96,11 @@ public class WikipediaPlugin extends OsmandPlugin {
|
|||
this.mapActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mapActivityResumeOnTop(MapActivity activity) {
|
||||
this.mapActivity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mapActivityPause(MapActivity activity) {
|
||||
this.mapActivity = null;
|
||||
|
@ -435,4 +445,25 @@ public class WikipediaPlugin extends OsmandPlugin {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ImageCard> getContextMenuImageCards(@NonNull Map<String, String> params, @Nullable Map<String, String> additionalParams, @Nullable GetImageCardsListener listener) {
|
||||
List<ImageCard> imageCards = new ArrayList<>();
|
||||
if (mapActivity != null) {
|
||||
if (additionalParams != null) {
|
||||
String wikidataId = additionalParams.get(Amenity.WIKIDATA);
|
||||
if (wikidataId != null) {
|
||||
additionalParams.remove(Amenity.WIKIDATA);
|
||||
WikiImageHelper.addWikidataImageCards(mapActivity, wikidataId, imageCards);
|
||||
}
|
||||
String wikimediaContent = additionalParams.get(Amenity.WIKIMEDIA_COMMONS);
|
||||
if (wikimediaContent != null) {
|
||||
additionalParams.remove(Amenity.WIKIMEDIA_COMMONS);
|
||||
WikiImageHelper.addWikimediaImageCards(mapActivity, wikimediaContent, imageCards);
|
||||
}
|
||||
params.putAll(additionalParams);
|
||||
}
|
||||
}
|
||||
return imageCards;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue