From 6027fce59c5159148aa53ac2b4aa921842de15f3 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 17 Oct 2017 11:37:03 +0300 Subject: [PATCH 01/10] Fix endless "looking up address" after adding map marker --- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 1f8023a472..ebd85e0527 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -769,6 +769,7 @@ public class MapMarkersHelper { mapMarkers.add(0, marker); addMarkerToGroup(marker); reorderActiveMarkersIfNeeded(); + lookupAddress(marker); } } } From daf2375f2ad0ab272faf10aa8b525a533a65deb4 Mon Sep 17 00:00:00 2001 From: Dmitriy Prodchenko Date: Tue, 17 Oct 2017 13:07:54 +0300 Subject: [PATCH 02/10] Update russian string. --- OsmAnd/res/values-ru/strings.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index 47445cf3ae..fccbc22bc7 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -2530,11 +2530,11 @@ Маркер перемещен в историю Маркер перемещен в действующие Указатель расстояния - • Полностью переработанные маркеры с рекомендациями и планированием маршрута + • Полностью переработанные маркеры карты, с направляющими линиями и планированием маршрута \n -\n• Инструмент измерения расстояния, предлагающий привязку к дороге и сохранение точек в качестве трека +\n• Инструмент измерения расстояния, с привязкой к дороге и сохранением точек в качестве трека \n -\n• OSM Live: исправления ошибок, обновление данных на сервере каждые 30 минут, обновления вносимые в навигацию +\n• OsmAnd Live: исправления ошибок, обновление данных на сервере каждые 30 минут, обновления учитываются в навигации \n \n Показать карту From c3a1c39775680c6e48e61dedb7752c9684306915 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 17 Oct 2017 13:09:03 +0300 Subject: [PATCH 03/10] Fix update query; fix opening of old markers --- OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java | 4 ++-- OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 93fdc99e77..dcab53a5cb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -30,7 +30,6 @@ import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.TargetPointsHelper.TargetPointChangedListener; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.mapcontextmenu.MenuController.ContextMenuToolbarController; import net.osmand.plus.mapcontextmenu.MenuController.MenuState; @@ -44,6 +43,7 @@ import net.osmand.plus.mapcontextmenu.editors.RtePtEditor; import net.osmand.plus.mapcontextmenu.editors.WptPtEditor; import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import net.osmand.plus.mapcontextmenu.other.ShareMenu; +import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.ContextMenuLayer; @@ -717,7 +717,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL if (pointDescription.isMapMarker()) { hide(); MapActivity.clearPrevActivityIntent(); - mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS); + MapMarkersDialogFragment.showInstance(mapActivity); } else { mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(), getPointDescriptionForMarker()); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index c6a7a27b51..19b7687f4e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -140,7 +140,7 @@ public class MapMarkersDbHelper { if (oldVersion < 10) { db.execSQL("ALTER TABLE " + MARKERS_TABLE_NAME + " ADD " + MARKERS_COL_SELECTED + " int"); db.execSQL("UPDATE " + MARKERS_TABLE_NAME + - " SET" + MARKERS_COL_SELECTED + " = ? " + + " SET " + MARKERS_COL_SELECTED + " = ? " + "WHERE " + MARKERS_COL_SELECTED + " IS NULL", new Object[]{0}); } } From d9643760ab42394e6dde683310939253f28d4cc7 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 17 Oct 2017 13:54:10 +0300 Subject: [PATCH 04/10] Fix condition --- OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index dcab53a5cb..843e268078 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -898,7 +898,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public PointDescription getPointDescriptionForMarker() { PointDescription pd = getPointDescriptionForTarget(); - if (Algorithms.isEmpty(pd.getName()) && !nameStr.equals(PointDescription.getAddressNotFoundStr(mapActivity))) { + if (Algorithms.isEmpty(pd.getName()) && !Algorithms.isEmpty(nameStr) + && !nameStr.equals(PointDescription.getAddressNotFoundStr(mapActivity))) { return new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, nameStr); } else { return pd; From cd7f33ed70b21890858cecaed81a9f928b229891 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 17 Oct 2017 14:28:32 +0300 Subject: [PATCH 05/10] Fix onUpgrade --- OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 19b7687f4e..4d6798e7a4 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -21,7 +21,7 @@ import java.util.Random; public class MapMarkersDbHelper { - private static final int DB_VERSION = 10; + private static final int DB_VERSION = 11; public static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; @@ -139,6 +139,8 @@ public class MapMarkersDbHelper { } if (oldVersion < 10) { db.execSQL("ALTER TABLE " + MARKERS_TABLE_NAME + " ADD " + MARKERS_COL_SELECTED + " int"); + } + if (oldVersion < 11) { db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_SELECTED + " = ? " + "WHERE " + MARKERS_COL_SELECTED + " IS NULL", new Object[]{0}); From dd72744c441209cefea1fb4026fbc773f182f57a Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Tue, 17 Oct 2017 15:43:43 +0300 Subject: [PATCH 06/10] Fix #4346 --- .../src/net/osmand/plus/OsmandSettings.java | 2 +- .../plus/mapcontextmenu/MenuBuilder.java | 17 +- .../builders/AmenityMenuBuilder.java | 26 ++- .../builders/cards/AbstractCard.java | 28 ++- .../builders/cards/ImageCard.java | 199 ++++++++++-------- .../builders/cards/UrlImageCard.java | 15 +- 6 files changed, 188 insertions(+), 99 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 73d25f1563..9c8fcf4d5e 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -920,7 +920,7 @@ public class OsmandSettings { public final OsmandPreference SHOW_MAPILLARY = new BooleanPreference("show_mapillary", false).makeGlobal(); public final OsmandPreference MAPILLARY_FIRST_DIALOG_SHOWN = new BooleanPreference("mapillary_first_dialog_shown", false).makeGlobal(); - public final OsmandPreference MAPILLARY_MENU_COLLAPSED = new BooleanPreference("mapillary_menu_collapsed", false).makeGlobal(); + public final OsmandPreference ONLINE_PHOTOS_ROW_COLLAPSED = new BooleanPreference("mapillary_menu_collapsed", false).makeGlobal(); public final OsmandPreference WEBGL_SUPPORTED = new BooleanPreference("webgl_supported", true).makeGlobal(); // this value string is synchronized with settings_pref.xml preference name diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index bfdf8c0c57..f58a4b72ec 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -53,6 +53,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import static android.util.TypedValue.COMPLEX_UNIT_DIP; @@ -344,7 +345,7 @@ public class MenuBuilder { onlinePhotoCardsRow = new CardsRowBuilder(this, view, false); onlinePhotoCardsRow.build(); CollapsableView collapsableView = new CollapsableView(onlinePhotoCardsRow.getContentView(), - app.getSettings().MAPILLARY_MENU_COLLAPSED); + app.getSettings().ONLINE_PHOTOS_ROW_COLLAPSED); collapsableView.setOnCollExpListener(new CollapsableView.OnCollExpListener() { @Override public void onCollapseExpand(boolean collapsed) { @@ -366,8 +367,13 @@ public class MenuBuilder { private void startLoadingImages(final MenuBuilder menuBuilder) { onlinePhotoCards = new ArrayList<>(); onlinePhotoCardsRow.setProgressCard(); - execute(new GetImageCardsTask(mapActivity, menuBuilder.getLatLon(), + execute(new GetImageCardsTask(mapActivity, menuBuilder.getLatLon(), getAdditionalCardParams(), new GetImageCardsListener() { + @Override + public void onPostProcess(List cardList) { + processOnlinePhotosCards(cardList); + } + @Override public void onFinish(List cardList) { if (!menuBuilder.isHidden()) { @@ -383,6 +389,13 @@ public class MenuBuilder { })); } + protected Map getAdditionalCardParams() { + return null; + } + + protected void processOnlinePhotosCards(List cardList) { + } + protected void buildInternal(View view) { } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 9a65b98354..8330458ee4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -38,6 +38,7 @@ import net.osmand.util.OpeningHoursParser; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -289,9 +290,13 @@ public class AmenityMenuBuilder extends MenuBuilder { String key = e.getKey(); String vl = e.getValue(); + if (key.equals("image") || key.equals("mapillary")) { + continue; + } + String textPrefix = ""; CollapsableView collapsableView = null; - boolean collapsable = false; + boolean collapsable = false; boolean isWiki = false; boolean isText = false; boolean isDescription = false; @@ -465,7 +470,7 @@ public class AmenityMenuBuilder extends MenuBuilder { if (processNearstWiki() && nearestWiki.size() > 0) { AmenityInfoRow wikiInfo = new AmenityInfoRow( - "nearest_wiki", R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size()+")", true, + "nearest_wiki", R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", true, getCollapsableWikiView(view.getContext(), true), 0, false, false, false, 1000, null, false, false); buildAmenityRow(view, wikiInfo); @@ -475,7 +480,7 @@ public class AmenityMenuBuilder extends MenuBuilder { boolean osmEditingEnabled = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null; if (osmEditingEnabled && amenity.getId() != null - && amenity.getId() > 0 && + && amenity.getId() > 0 && (amenity.getId() % 2 == 0 || (amenity.getId() >> 1) < Integer.MAX_VALUE)) { String link; if (amenity.getId() % 2 == 0) { @@ -506,6 +511,21 @@ public class AmenityMenuBuilder extends MenuBuilder { } } + @Override + protected Map getAdditionalCardParams() { + Map params = new HashMap<>(); + Map additionalInfo = amenity.getAdditionalInfo(); + String imageValue = additionalInfo.get("image"); + String mapillaryValue = additionalInfo.get("mapillary"); + if (!Algorithms.isEmpty(imageValue)) { + params.put("image", imageValue); + } + if (!Algorithms.isEmpty(mapillaryValue)) { + params.put("mapillary", mapillaryValue); + } + return params; + } + private static class AmenityInfoRow { private String key; private Drawable icon; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java index 1c265960f2..c0b9de5795 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java @@ -7,6 +7,8 @@ import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v7.widget.Toolbar; import android.util.TypedValue; @@ -51,8 +53,12 @@ public abstract class AbstractCard { @SuppressLint("SetJavaScriptEnabled") @SuppressWarnings("deprecation") - protected static void openUrl(Context ctx, OsmandApplication app, - String title, String url, boolean externalLink) { + protected static void openUrl(@NonNull Context ctx, + @NonNull OsmandApplication app, + @Nullable String title, + @NonNull String url, + boolean externalLink, + boolean hasImageUrl) { if (externalLink) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); @@ -84,12 +90,14 @@ public abstract class AbstractCard { final WebView wv = new WebView(ctx); WebSettings settings = wv.getSettings(); - /* - settings.setDefaultTextEncodingName("utf-8"); - settings.setBuiltInZoomControls(true); - settings.setDisplayZoomControls(false); - settings.setSupportZoom(true); + if (hasImageUrl) { + settings.setDefaultTextEncodingName("utf-8"); + settings.setBuiltInZoomControls(true); + settings.setDisplayZoomControls(false); + settings.setSupportZoom(true); + } + /* //Scale web view font size with system font size float scale = ctx.getResources().getConfiguration().fontScale; if (android.os.Build.VERSION.SDK_INT >= 14) { @@ -111,7 +119,11 @@ public abstract class AbstractCard { wv.setBackgroundColor(Color.argb(1, 0, 0, 0)); //wv.setScrollContainer(false); wv.getSettings().setJavaScriptEnabled(true); - wv.loadUrl(url); + if (hasImageUrl) { + wv.loadData("", "text/html", "UTF-8"); + } else { + wv.loadUrl(url); + } ll.addView(topBar); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java index 343a875060..e960ebd774 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -5,6 +5,7 @@ import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v7.widget.AppCompatButton; import android.view.View; import android.view.View.OnClickListener; @@ -38,29 +39,32 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import static java.text.DateFormat.FULL; - public abstract class ImageCard extends AbstractCard { - private String type; + public static String TYPE_MAPILLARY_PHOTO = "mapillary-photo"; + public static String TYPE_MAPILLARY_CONTRIBUTE = "mapillary-contribute"; + + protected String type; // Image location - private LatLon location; - // (optional) Image's camera angle in range [0, 360]. - private double ca = Double.NaN; - // Date When bitmap was captured. - private Date timestamp; - // Image key. - private String key; + protected LatLon location; + // (optional) Image's camera angle in range [0, 360] + protected double ca = Double.NaN; + // Date When bitmap was captured + protected Date timestamp; + // Image key + protected String key; + // Image title + protected String title; // User name - private String userName; + protected String userName; // Image viewer url - private String url; + protected String url; // Image bitmap url - private String imageUrl; + protected String imageUrl; // Image high resolution bitmap url - private String imageHiresUrl; + protected String imageHiresUrl; // true if external browser should to be opened, open webview otherwise - private boolean externalLink; + protected boolean externalLink; protected int topIconId; protected int buttonIconId; @@ -76,7 +80,8 @@ public abstract class ImageCard extends AbstractCard { protected OnClickListener onClickListener; protected OnClickListener onButtonClickListener; - private static final DateFormat DATE_FORMAT = SimpleDateFormat.getDateTimeInstance(FULL, FULL, Locale.US); //"yyyy-MM-dd'T'HH:mm:ss"); + private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); + private boolean downloading; private boolean downloaded; private Bitmap bitmap; @@ -85,75 +90,80 @@ public abstract class ImageCard extends AbstractCard { public ImageCard(MapActivity mapActivity, JSONObject imageObject) { super(mapActivity); - try { - if (imageObject.has("type")) { - this.type = imageObject.getString("type"); - } - if (imageObject.has("ca") && !imageObject.isNull("ca")) { - this.ca = imageObject.getDouble("ca"); - } - if (imageObject.has("lat") && imageObject.has("lon")) { - double latitude = imageObject.getDouble("lat"); - double longitude = imageObject.getDouble("lon"); - this.location = new LatLon(latitude, longitude); - } - if (imageObject.has("timestamp")) { - try { - this.timestamp = DATE_FORMAT.parse(imageObject.getString("timestamp")); - } catch (ParseException e) { - e.printStackTrace(); + if (imageObject != null) { + try { + if (imageObject.has("type")) { + this.type = imageObject.getString("type"); } - } - if (imageObject.has("key")) { - this.key = imageObject.getString("key"); - } - if (imageObject.has("username")) { - this.userName = imageObject.getString("username"); - } - if (imageObject.has("url")) { - this.url = imageObject.getString("url"); - } - if (imageObject.has("imageUrl")) { - this.imageUrl = imageObject.getString("imageUrl"); - } - if (imageObject.has("imageHiresUrl")) { - this.imageHiresUrl = imageObject.getString("imageHiresUrl"); - } - if (imageObject.has("externalLink") && !imageObject.isNull("externalLink")) { - this.externalLink = imageObject.getBoolean("externalLink"); - } - if (imageObject.has("topIcon") && !imageObject.isNull("topIcon")) { - this.topIconId = getDrawableId(imageObject.getString("topIcon")); - } - if (imageObject.has("buttonIcon") && !imageObject.isNull("buttonIcon")) { - this.buttonIconId = getDrawableId(imageObject.getString("buttonIcon")); - } - if (imageObject.has("buttonText") && !imageObject.isNull("buttonText")) { - this.buttonText = imageObject.getString("buttonText"); - } - if (imageObject.has("buttonIconColor") && !imageObject.isNull("buttonIconColor")) { - try { - this.buttonIconColor = Algorithms.parseColor(imageObject.getString("buttonIconColor")); - } catch (IllegalArgumentException e) { - e.printStackTrace(); + if (imageObject.has("ca") && !imageObject.isNull("ca")) { + this.ca = imageObject.getDouble("ca"); } - } - if (imageObject.has("buttonColor") && !imageObject.isNull("buttonColor")) { - try { - this.buttonColor = Algorithms.parseColor(imageObject.getString("buttonColor")); - } catch (IllegalArgumentException e) { - e.printStackTrace(); + if (imageObject.has("lat") && imageObject.has("lon")) { + double latitude = imageObject.getDouble("lat"); + double longitude = imageObject.getDouble("lon"); + this.location = new LatLon(latitude, longitude); } - } - if (imageObject.has("buttonTextColor") && !imageObject.isNull("buttonTextColor")) { - try { - this.buttonTextColor = Algorithms.parseColor(imageObject.getString("buttonTextColor")); - } catch (IllegalArgumentException e) { - e.printStackTrace(); + if (imageObject.has("timestamp")) { + try { + this.timestamp = DATE_FORMAT.parse(imageObject.getString("timestamp")); + } catch (ParseException e) { + e.printStackTrace(); + } } + if (imageObject.has("key")) { + this.key = imageObject.getString("key"); + } + if (imageObject.has("title")) { + this.title = imageObject.getString("title"); + } + if (imageObject.has("username")) { + this.userName = imageObject.getString("username"); + } + if (imageObject.has("url")) { + this.url = imageObject.getString("url"); + } + if (imageObject.has("imageUrl")) { + this.imageUrl = imageObject.getString("imageUrl"); + } + if (imageObject.has("imageHiresUrl")) { + this.imageHiresUrl = imageObject.getString("imageHiresUrl"); + } + if (imageObject.has("externalLink") && !imageObject.isNull("externalLink")) { + this.externalLink = imageObject.getBoolean("externalLink"); + } + if (imageObject.has("topIcon") && !imageObject.isNull("topIcon")) { + this.topIconId = getDrawableId(imageObject.getString("topIcon")); + } + if (imageObject.has("buttonIcon") && !imageObject.isNull("buttonIcon")) { + this.buttonIconId = getDrawableId(imageObject.getString("buttonIcon")); + } + if (imageObject.has("buttonText") && !imageObject.isNull("buttonText")) { + this.buttonText = imageObject.getString("buttonText"); + } + if (imageObject.has("buttonIconColor") && !imageObject.isNull("buttonIconColor")) { + try { + this.buttonIconColor = Algorithms.parseColor(imageObject.getString("buttonIconColor")); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + if (imageObject.has("buttonColor") && !imageObject.isNull("buttonColor")) { + try { + this.buttonColor = Algorithms.parseColor(imageObject.getString("buttonColor")); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + if (imageObject.has("buttonTextColor") && !imageObject.isNull("buttonTextColor")) { + try { + this.buttonTextColor = Algorithms.parseColor(imageObject.getString("buttonTextColor")); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); } } @@ -170,9 +180,9 @@ public abstract class ImageCard extends AbstractCard { try { if (imageObject.has("type")) { String type = imageObject.getString("type"); - if ("mapillary-photo".equals(type)) { + if (TYPE_MAPILLARY_PHOTO.equals(type)) { imageCard = new MapillaryImageCard(mapActivity, imageObject); - } else if ("mapillary-contribute".equals(type)) { + } else if (TYPE_MAPILLARY_CONTRIBUTE.equals(type)) { imageCard = new MapillaryContributeCard(mapActivity, imageObject); } else { imageCard = new UrlImageCard(mapActivity, imageObject); @@ -192,6 +202,10 @@ public abstract class ImageCard extends AbstractCard { return key; } + public String getTitle() { + return title; + } + public String getType() { return type; } @@ -302,9 +316,11 @@ public abstract class ImageCard extends AbstractCard { if (view != null) { ImageView image = (ImageView) view.findViewById(R.id.image); ImageView iconImageView = (ImageView) view.findViewById(R.id.icon); + TextView urlTextView = (TextView) view.findViewById(R.id.url); TextView watermarkTextView = (TextView) view.findViewById(R.id.watermark); ProgressBar progress = (ProgressBar) view.findViewById(R.id.progress); AppCompatButton button = (AppCompatButton) view.findViewById(R.id.button); + if (icon == null && topIconId != 0) { icon = getMyApplication().getIconsCache().getIcon(topIconId); } @@ -328,6 +344,12 @@ public abstract class ImageCard extends AbstractCard { } else { progress.setVisibility(View.GONE); image.setImageBitmap(bitmap); + if (bitmap == null) { + urlTextView.setVisibility(View.VISIBLE); + urlTextView.setText(getUrl()); + } else { + urlTextView.setVisibility(View.GONE); + } } if (onClickListener != null) { view.findViewById(R.id.image_card).setOnClickListener(new OnClickListener() { @@ -377,17 +399,22 @@ public abstract class ImageCard extends AbstractCard { private MapActivity mapActivity; private OsmandApplication app; private LatLon latLon; + private Map params; private GetImageCardsListener listener; private List result; public interface GetImageCardsListener { + void onPostProcess(List cardList); + void onFinish(List cardList); } - public GetImageCardsTask(@NonNull MapActivity mapActivity, LatLon latLon, GetImageCardsListener listener) { + public GetImageCardsTask(@NonNull MapActivity mapActivity, LatLon latLon, + @Nullable Map params, GetImageCardsListener listener) { this.mapActivity = mapActivity; this.app = mapActivity.getMyApplication(); this.latLon = latLon; + this.params = params; this.listener = listener; } @@ -410,6 +437,9 @@ public abstract class ImageCard extends AbstractCard { if (!Algorithms.isEmpty(preferredLang)) { pms.put("lang", preferredLang); } + if (this.params != null) { + pms.putAll(this.params); + } String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place.php", pms, "Requesting location images...", false, false); @@ -435,6 +465,9 @@ public abstract class ImageCard extends AbstractCard { } catch (Exception e) { e.printStackTrace(); } + if (listener != null) { + listener.onPostProcess(result); + } return result; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java index cae773173b..27d8525c04 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java @@ -12,11 +12,22 @@ public class UrlImageCard extends ImageCard { public UrlImageCard(MapActivity mapActivity, JSONObject imageObject) { super(mapActivity, imageObject); - if (!Algorithms.isEmpty(getUrl())) { + + final String url; + final boolean hasImageUrl; + if (Algorithms.isEmpty(getImageHiresUrl())) { + url = getUrl(); + hasImageUrl = false; + } else { + url = getImageHiresUrl(); + hasImageUrl = true; + } + + if (!Algorithms.isEmpty(url)) { OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(View v) { - openUrl(getMapActivity(), getMyApplication(), "", getUrl(), isExternalLink()); + openUrl(getMapActivity(), getMyApplication(), getTitle(), url, isExternalLink(), hasImageUrl); } }; if (!Algorithms.isEmpty(buttonText)) { From 67cd31df93b65ca0ffda3d4f602f2afadb0c15fc Mon Sep 17 00:00:00 2001 From: PaulStets Date: Tue, 17 Oct 2017 16:15:44 +0300 Subject: [PATCH 07/10] Fixed getRegionName and improved osmlive filename recognition --- .../src/net/osmand/binary/BinaryMapIndexReader.java | 12 ++++++++---- .../src/net/osmand/search/core/SearchPhrase.java | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java index 8b5f0bbdcc..325ec1540a 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java @@ -407,14 +407,18 @@ public class BinaryMapIndexReader { } String ls = rg.get(0); if (ls.lastIndexOf('_') != -1) { - if (ls.matches(".*([0-9]+_*){3}\\.obf")) { - Pattern osmDiffDateEnding = Pattern.compile("_([0-9]+_*){3}\\.obf"); + if (ls.matches("([a-zA-Z-]+_)+([0-9]+_){2}[0-9]+\\.obf")) { + Pattern osmDiffDateEnding = Pattern.compile("_([0-9]+_){2}[0-9]+\\.obf"); Matcher m = osmDiffDateEnding.matcher(ls); if (m.find()) { ls = ls.substring(0, m.start()); + if (ls.lastIndexOf('_') != -1) { + return ls.substring(0, ls.lastIndexOf('_')).replace('_', ' '); + } else { + return ls; + } + } - return ls.substring(0, ls.lastIndexOf('_')).replace('_', ' '); - } else { if (ls.contains(".")) { ls = ls.substring(0, ls.indexOf(".")); diff --git a/OsmAnd-java/src/net/osmand/search/core/SearchPhrase.java b/OsmAnd-java/src/net/osmand/search/core/SearchPhrase.java index e0eac2a796..d9da250e28 100644 --- a/OsmAnd-java/src/net/osmand/search/core/SearchPhrase.java +++ b/OsmAnd-java/src/net/osmand/search/core/SearchPhrase.java @@ -587,7 +587,8 @@ public class SearchPhrase { Iterator it = indexes.iterator(); while (it.hasNext()) { BinaryMapIndexReader r = it.next(); - if (r.getFile().getName().matches(".*([0-9]+_*){3}\\.obf")) { + String filename = r.getFile().getName(); + if (filename.matches("([a-zA-Z-]+_)+([0-9]+_){2}[0-9]+\\.obf")) { String currRegionName = r.getRegionName(); if (result.containsKey(currRegionName)) { result.get(currRegionName).add(r); From 0a9294bd0eeaeedfcea3c4630648a4cb7b45bc08 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 17 Oct 2017 14:53:15 +0300 Subject: [PATCH 08/10] Fix strings --- OsmAnd/res/values-tr/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values-tr/strings.xml b/OsmAnd/res/values-tr/strings.xml index 5a1d0362fc..73197b320a 100644 --- a/OsmAnd/res/values-tr/strings.xml +++ b/OsmAnd/res/values-tr/strings.xml @@ -1052,7 +1052,7 @@ kamyon - Şimdidosya ($1%s ) Yeni Geliş kopyalamak … + Şimdidosya (%s) Yeni Geliş kopyalamak … Yeni hedef (%s) için Osmand veri dosyaları kopyalanıyor … Yolbul tercihleri Öncelikli yönlendirme @@ -2008,7 +2008,7 @@ Kaydedilen her klibin uzunluğunu artık bu belirtilen zaman aralığı olmayacak Depolama boyutu Tüm kaydedilen kliplerin tarafından işgal edilebilir alan miktarı - Son harita değişikliği:% s + Son harita değişikliği: %s Saatlik Günlük Haftalık From 597419d7e13c78d4aff9727b35b07c6222e254a7 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 17 Oct 2017 18:57:22 +0300 Subject: [PATCH 09/10] Fix #4577 --- .../osmand/plus/mapcontextmenu/other/ShareMenuFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java index 48c58c6011..b969ae5076 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenuFragment.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -121,10 +122,9 @@ public class ShareMenuFragment extends Fragment implements OnItemClickListener { } public void dismissMenu() { + menu.getMapActivity().getSupportFragmentManager().popBackStackImmediate(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); if (menu.getMapActivity().getContextMenu().isVisible()) { menu.getMapActivity().getContextMenu().hide(); - } else { - menu.getMapActivity().getSupportFragmentManager().popBackStack(); } } } From dbb72952c7aafe91e4955348d89d82ab79df9a43 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Tue, 17 Oct 2017 20:47:38 +0300 Subject: [PATCH 10/10] Fix osm image/mapillary processing --- .../plus/mapcontextmenu/MenuBuilder.java | 12 ++++----- .../builders/AmenityMenuBuilder.java | 4 +-- .../builders/cards/AbstractCard.java | 8 ++++++ .../builders/cards/ImageCard.java | 16 +++++++----- .../builders/cards/UrlImageCard.java | 26 ++++++++++--------- 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index f58a4b72ec..022f9fdb98 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -42,7 +42,6 @@ import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard; 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.ImageCard.GetImageCardsTask.GetImageCardsListener; import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard; import net.osmand.plus.render.RenderingIcons; import net.osmand.util.Algorithms; @@ -56,6 +55,7 @@ import java.util.List; import java.util.Map; import static android.util.TypedValue.COMPLEX_UNIT_DIP; +import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.*; public class MenuBuilder { @@ -350,7 +350,7 @@ public class MenuBuilder { @Override public void onCollapseExpand(boolean collapsed) { if (!collapsed && onlinePhotoCards == null) { - startLoadingImages(MenuBuilder.this); + startLoadingImages(); } } }); @@ -360,14 +360,14 @@ public class MenuBuilder { if (needUpdateOnly && onlinePhotoCards != null) { onlinePhotoCardsRow.setCards(onlinePhotoCards); } else if (!collapsableView.isCollapsed()) { - startLoadingImages(this); + startLoadingImages(); } } - private void startLoadingImages(final MenuBuilder menuBuilder) { + private void startLoadingImages() { onlinePhotoCards = new ArrayList<>(); onlinePhotoCardsRow.setProgressCard(); - execute(new GetImageCardsTask(mapActivity, menuBuilder.getLatLon(), getAdditionalCardParams(), + execute(new GetImageCardsTask(mapActivity, getLatLon(), getAdditionalCardParams(), new GetImageCardsListener() { @Override public void onPostProcess(List cardList) { @@ -376,7 +376,7 @@ public class MenuBuilder { @Override public void onFinish(List cardList) { - if (!menuBuilder.isHidden()) { + if (!isHidden()) { List cards = new ArrayList<>(); cards.addAll(cardList); if (cardList.size() == 0) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 8330458ee4..8d1bdeef6d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -518,10 +518,10 @@ public class AmenityMenuBuilder extends MenuBuilder { String imageValue = additionalInfo.get("image"); String mapillaryValue = additionalInfo.get("mapillary"); if (!Algorithms.isEmpty(imageValue)) { - params.put("image", imageValue); + params.put("osm_image", imageValue); } if (!Algorithms.isEmpty(mapillaryValue)) { - params.put("mapillary", mapillaryValue); + params.put("osm_mapillary_key", mapillaryValue); } return params; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java index c0b9de5795..5669cb1fd7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java @@ -16,6 +16,7 @@ import android.view.LayoutInflater; import android.view.View; import android.webkit.WebSettings; import android.webkit.WebView; +import android.webkit.WebViewClient; import android.widget.LinearLayout; import net.osmand.plus.OsmandApplication; @@ -89,6 +90,13 @@ public abstract class AbstractCard { }); final WebView wv = new WebView(ctx); + wv.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + return false; + } + }); + WebSettings settings = wv.getSettings(); if (hasImageUrl) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java index e960ebd774..4e3d69b652 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -98,7 +98,8 @@ public abstract class ImageCard extends AbstractCard { if (imageObject.has("ca") && !imageObject.isNull("ca")) { this.ca = imageObject.getDouble("ca"); } - if (imageObject.has("lat") && imageObject.has("lon")) { + if (imageObject.has("lat") && imageObject.has("lon") + && !imageObject.isNull("lat") && !imageObject.isNull("lon")) { double latitude = imageObject.getDouble("lat"); double longitude = imageObject.getDouble("lon"); this.location = new LatLon(latitude, longitude); @@ -113,19 +114,19 @@ public abstract class ImageCard extends AbstractCard { if (imageObject.has("key")) { this.key = imageObject.getString("key"); } - if (imageObject.has("title")) { + if (imageObject.has("title") && !imageObject.isNull("title")) { this.title = imageObject.getString("title"); } - if (imageObject.has("username")) { + if (imageObject.has("username") && !imageObject.isNull("username")) { this.userName = imageObject.getString("username"); } - if (imageObject.has("url")) { + if (imageObject.has("url") && !imageObject.isNull("url")) { this.url = imageObject.getString("url"); } - if (imageObject.has("imageUrl")) { + if (imageObject.has("imageUrl") && !imageObject.isNull("imageUrl")) { this.imageUrl = imageObject.getString("imageUrl"); } - if (imageObject.has("imageHiresUrl")) { + if (imageObject.has("imageHiresUrl") && !imageObject.isNull("imageHiresUrl")) { this.imageHiresUrl = imageObject.getString("imageHiresUrl"); } if (imageObject.has("externalLink") && !imageObject.isNull("externalLink")) { @@ -498,6 +499,9 @@ public abstract class ImageCard extends AbstractCard { downloading = false; downloaded = true; ImageCard.this.bitmap = bitmap; + if (bitmap != null && Algorithms.isEmpty(getImageHiresUrl())) { + ImageCard.this.imageHiresUrl = getUrl(); + } update(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java index 27d8525c04..313305cf67 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java @@ -13,21 +13,13 @@ public class UrlImageCard extends ImageCard { public UrlImageCard(MapActivity mapActivity, JSONObject imageObject) { super(mapActivity, imageObject); - final String url; - final boolean hasImageUrl; - if (Algorithms.isEmpty(getImageHiresUrl())) { - url = getUrl(); - hasImageUrl = false; - } else { - url = getImageHiresUrl(); - hasImageUrl = true; - } - - if (!Algorithms.isEmpty(url)) { + if (!Algorithms.isEmpty(getSuitableUrl())) { OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(View v) { - openUrl(getMapActivity(), getMyApplication(), getTitle(), url, isExternalLink(), hasImageUrl); + openUrl(getMapActivity(), getMyApplication(), getTitle(), getSuitableUrl(), + isExternalLink() || Algorithms.isEmpty(getImageHiresUrl()), + !Algorithms.isEmpty(getImageHiresUrl())); } }; if (!Algorithms.isEmpty(buttonText)) { @@ -37,4 +29,14 @@ public class UrlImageCard extends ImageCard { } } } + + private String getSuitableUrl() { + final String url; + if (Algorithms.isEmpty(getImageHiresUrl())) { + url = getUrl(); + } else { + url = getImageHiresUrl(); + } + return url; + } }