From a6b99f1e41bbabd030fdeca8b72694e13606842d Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 8 May 2017 22:01:00 +0300 Subject: [PATCH] Fix webgl. Added photo_id to Mapillary start intent. --- .../layout-land/context_menu_card_dialog.xml | 7 +-- .../res/layout/context_menu_card_dialog.xml | 7 +-- OsmAnd/res/values/strings.xml | 1 + .../builders/cards/NoImagesCard.java | 2 +- .../builders/cards/UrlImageCard.java | 14 +----- .../cards/dialogs/ContextMenuCardDialog.java | 11 +++++ .../ContextMenuCardDialogFragment.java | 18 +++++++ .../mapillary/MapillaryContributeCard.java | 2 +- .../plus/mapillary/MapillaryImageCard.java | 2 +- .../plus/mapillary/MapillaryImageDialog.java | 48 ++++++++++++++++--- .../plus/mapillary/MapillaryPlugin.java | 7 ++- 11 files changed, 89 insertions(+), 30 deletions(-) diff --git a/OsmAnd/res/layout-land/context_menu_card_dialog.xml b/OsmAnd/res/layout-land/context_menu_card_dialog.xml index 3b83e5ad54..69302a430e 100644 --- a/OsmAnd/res/layout-land/context_menu_card_dialog.xml +++ b/OsmAnd/res/layout-land/context_menu_card_dialog.xml @@ -19,6 +19,7 @@ android:minHeight="@dimen/dashboard_map_toolbar" android:background="@color/osmand_orange" android:gravity="center_vertical" + android:clickable="true" android:orientation="horizontal"> diff --git a/OsmAnd/res/layout/context_menu_card_dialog.xml b/OsmAnd/res/layout/context_menu_card_dialog.xml index 069918a32f..fd6bf7988a 100644 --- a/OsmAnd/res/layout/context_menu_card_dialog.xml +++ b/OsmAnd/res/layout/context_menu_card_dialog.xml @@ -13,6 +13,7 @@ android:minHeight="@dimen/dashboard_map_toolbar" android:background="@color/osmand_orange" android:gravity="center_vertical" + android:clickable="true" android:orientation="horizontal"> diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 23e42a93c5..b48077e8a6 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Open Mapillary Install Improve coverage with Mapillary You can take your own photos or series of photos and add it to this map location.\n\nTo do this you need install Mapillary app from Google Play. diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java index 8b2f4adb2d..7b6f02fb70 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java @@ -23,7 +23,7 @@ public class NoImagesCard extends AbstractCard { view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - MapillaryPlugin.openMapillary(getMapActivity()); + MapillaryPlugin.openMapillary(getMapActivity(), null); } }); } 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 f6bdb8f735..cee2010716 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java @@ -22,22 +22,10 @@ public class UrlImageCard extends ImageCard { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(getImageUrl())); + intent.setData(Uri.parse(getUrl())); v.getContext().startActivity(intent); } }; } } - - @Override - public void update() { - super.update(); - if (view != null) { - ImageView image = (ImageView) view.findViewById(R.id.image); - image.setVisibility(View.GONE); - TextView urlText = (TextView) view.findViewById(R.id.url); - urlText.setText(getImageUrl()); - urlText.setVisibility(View.VISIBLE); - } - } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialog.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialog.java index de80efbe7c..29fc6b6395 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialog.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialog.java @@ -2,6 +2,8 @@ package net.osmand.plus.mapcontextmenu.builders.cards.dialogs; import android.os.Bundle; import android.support.annotation.NonNull; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import net.osmand.plus.OsmandSettings; @@ -10,6 +12,8 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapillary.MapillaryImageDialog; import net.osmand.plus.views.OsmandMapTileView; +import java.util.List; + public abstract class ContextMenuCardDialog { private MapActivity mapActivity; @@ -56,6 +60,13 @@ public abstract class ContextMenuCardDialog { return description; } + protected boolean haveMenuItems() { + return false; + } + + protected void createMenuItems(Menu menu) { + } + public void saveMenu(Bundle bundle) { bundle.putString(KEY_CARD_DIALOG_TYPE, type.name()); if (title != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialogFragment.java index 4eefb528bf..e9a674bc75 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialogFragment.java @@ -4,6 +4,8 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; +import android.support.v7.widget.AppCompatImageView; +import android.support.v7.widget.PopupMenu; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -13,6 +15,7 @@ import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.util.Algorithms; public class ContextMenuCardDialogFragment extends Fragment { @@ -51,6 +54,21 @@ public class ContextMenuCardDialogFragment extends Fragment { if (!Algorithms.isEmpty(dialog.getDescription())) { ((TextView) view.findViewById(R.id.description)).setText(dialog.getDescription()); } + AppCompatImageView moreButton = (AppCompatImageView) view.findViewById(R.id.more_button); + if (dialog.haveMenuItems()) { + moreButton.setVisibility(View.VISIBLE); + moreButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final PopupMenu optionsMenu = new PopupMenu(getContext(), v); + DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); + dialog.createMenuItems(optionsMenu.getMenu()); + optionsMenu.show(); + } + }); + } else { + moreButton.setVisibility(View.GONE); + } return view; } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryContributeCard.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryContributeCard.java index 1e50716ce9..7803ab52de 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryContributeCard.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryContributeCard.java @@ -25,7 +25,7 @@ public class MapillaryContributeCard extends ImageCard { view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - MapillaryPlugin.openMapillary(getMapActivity()); + MapillaryPlugin.openMapillary(getMapActivity(), null); } }); } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java index 8ab7a38037..4235a8f93d 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java @@ -17,7 +17,7 @@ public class MapillaryImageCard extends ImageCard { @Override public void onClick(View v) { getMapActivity().getContextMenu().hideMenues(); - MapillaryImageDialog.show(getMapActivity(), getImageHiresUrl(), getUrl(), getLocation(), + MapillaryImageDialog.show(getMapActivity(), getKey(), getImageHiresUrl(), getUrl(), getLocation(), getCa(), getMyApplication().getString(R.string.mapillary), null); } }; diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java index 3710b2aa56..170abbdd3c 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java @@ -8,6 +8,8 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.view.Gravity; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.webkit.ConsoleMessage; @@ -21,6 +23,7 @@ import android.widget.ProgressBar; import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidUtils; import net.osmand.data.LatLon; +import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import net.osmand.plus.mapcontextmenu.builders.cards.dialogs.ContextMenuCardDialog; @@ -30,6 +33,7 @@ import net.osmand.util.Algorithms; public class MapillaryImageDialog extends ContextMenuCardDialog { + private static final String KEY_MAPILLARY_DIALOG_IMAGE_KEY = "key_mapillary_dialog_image_key"; private static final String KEY_MAPILLARY_DIALOG_IMAGE_URL = "key_mapillary_dialog_image_url"; private static final String KEY_MAPILLARY_DIALOG_VIEWER_URL = "key_mapillary_dialog_viewer_url"; private static final String KEY_MAPILLARY_DIALOG_LATLON = "key_mapillary_dialog_latlon"; @@ -42,6 +46,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { private static final String WEBGL_ERROR_MESSAGE = "Error creating WebGL context"; + private String key; private String imageUrl; private String viewerUrl; private LatLon latLon; @@ -52,17 +57,22 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { restoreFields(bundle); } - public MapillaryImageDialog(MapActivity mapActivity, String imageUrl, String viewerUrl, LatLon latLon, double ca, + public MapillaryImageDialog(MapActivity mapActivity, String key, String imageUrl, String viewerUrl, LatLon latLon, double ca, String title, String description) { super(mapActivity, CardDialogType.MAPILLARY); this.title = title; this.description = description; + this.key = key; this.imageUrl = imageUrl; this.viewerUrl = viewerUrl; this.latLon = latLon; this.ca = ca; } + public String getKey() { + return key; + } + public String getViewerUrl() { return viewerUrl; } @@ -77,6 +87,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { public void saveMenu(Bundle bundle) { super.saveMenu(bundle); + bundle.putSerializable(KEY_MAPILLARY_DIALOG_IMAGE_KEY, key); bundle.putSerializable(KEY_MAPILLARY_DIALOG_IMAGE_URL, imageUrl); bundle.putSerializable(KEY_MAPILLARY_DIALOG_VIEWER_URL, viewerUrl); bundle.putSerializable(KEY_MAPILLARY_DIALOG_LATLON, latLon); @@ -86,6 +97,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { @Override protected void restoreFields(Bundle bundle) { super.restoreFields(bundle); + this.key = bundle.getString(KEY_MAPILLARY_DIALOG_IMAGE_KEY); this.imageUrl = bundle.getString(KEY_MAPILLARY_DIALOG_IMAGE_URL); this.viewerUrl = bundle.getString(KEY_MAPILLARY_DIALOG_VIEWER_URL); Object latLonObj = bundle.getSerializable(KEY_MAPILLARY_DIALOG_LATLON); @@ -136,11 +148,31 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { } } + @Override + protected boolean haveMenuItems() { + return true; + } + + @Override + protected void createMenuItems(Menu menu) { + MenuItem item = menu.add(R.string.open_mapillary) + .setIcon(getMapActivity().getMyApplication().getIconsCache().getThemedIcon( + R.drawable.ic_action_mapillary)); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + MapillaryPlugin.openMapillary(getMapActivity(), key); + return true; + } + }); + } + + @SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"}) private WebView getWebView() { final WebView webView = new WebView(getMapActivity()); webView.setBackgroundColor(Color.argb(1, 0, 0, 0)); - webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); + //webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); webView.setScrollContainer(false); webView.getSettings().setJavaScriptEnabled(true); webView.addJavascriptInterface(new MapillaryWebAppInterface(), "Android"); @@ -153,7 +185,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { public boolean onConsoleMessage(ConsoleMessage consoleMessage) { if (!Algorithms.isEmpty(consoleMessage.message()) && consoleMessage.message().contains(WEBGL_ERROR_MESSAGE)) { MapillaryPlugin.setWebGlSupported(false); - show(getMapActivity(), imageUrl, viewerUrl, getLatLon(), getCa(), getTitle(), getDescription()); + show(getMapActivity(), key, imageUrl, viewerUrl, getLatLon(), getCa(), getTitle(), getDescription()); } return false; } @@ -172,6 +204,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { MapillaryImageDialog.this.latLon = latLon; MapillaryImageDialog.this.ca = ca; if (!Algorithms.isEmpty(key)) { + MapillaryImageDialog.this.key = key; MapillaryImageDialog.this.imageUrl = MAPILLARY_HIRES_IMAGE_URL_TEMPLATE + key; MapillaryImageDialog.this.viewerUrl = MAPILLARY_VIEWER_URL_TEMPLATE + key; } @@ -182,6 +215,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { private View getStaticImageView() { LinearLayout ll = new LinearLayout(getMapActivity()); + ll.setClickable(true); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( isPortrait() ? ViewGroup.LayoutParams.MATCH_PARENT : AndroidUtils.dpToPx(getMapActivity(), 360f), isPortrait() ? AndroidUtils.dpToPx(getMapActivity(), 270f) : ViewGroup.LayoutParams.MATCH_PARENT); @@ -205,9 +239,11 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { } - public static MapillaryImageDialog show(MapActivity mapActivity, String imageUrl, String viewerUrl, LatLon latLon, double ca, - String title, String description) { - MapillaryImageDialog dialog = new MapillaryImageDialog(mapActivity, imageUrl, viewerUrl, latLon, ca, title, description); + public static MapillaryImageDialog show(MapActivity mapActivity, String key, String imageUrl, + String viewerUrl, LatLon latLon, double ca, + String title, String description) { + MapillaryImageDialog dialog = new MapillaryImageDialog(mapActivity, key, imageUrl, viewerUrl, + latLon, ca, title, description); ContextMenuCardDialogFragment.showInstance(dialog); return dialog; } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java index 2ce6ce85e1..cb9a7a9b24 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java @@ -184,7 +184,7 @@ public class MapillaryPlugin extends OsmandPlugin { mapillaryControl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - openMapillary(map); + openMapillary(map, null); } }); @@ -205,12 +205,15 @@ public class MapillaryPlugin extends OsmandPlugin { } } - public static boolean openMapillary(FragmentActivity activity) { + public static boolean openMapillary(FragmentActivity activity, String imageKey) { boolean success = false; OsmandApplication app = (OsmandApplication) activity.getApplication(); if (isPackageInstalled(MAPILLARY_PACKAGE_ID, app)) { Intent launchIntent = app.getPackageManager().getLaunchIntentForPackage(MAPILLARY_PACKAGE_ID); if (launchIntent != null) { + if (imageKey != null) { + launchIntent.putExtra("photo_id", imageKey); + } app.startActivity(launchIntent); success = true; }