diff --git a/OsmAnd/res/layout/mapillary_no_internet.xml b/OsmAnd/res/layout/mapillary_no_internet.xml
new file mode 100644
index 0000000000..5758539b9c
--- /dev/null
+++ b/OsmAnd/res/layout/mapillary_no_internet.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/mapillary_static_image_view.xml b/OsmAnd/res/layout/mapillary_static_image_view.xml
index b6ab505797..54207ea752 100644
--- a/OsmAnd/res/layout/mapillary_static_image_view.xml
+++ b/OsmAnd/res/layout/mapillary_static_image_view.xml
@@ -3,45 +3,56 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
-
+ android:layout_height="match_parent">
-
-
-
-
-
-
-
+ android:scaleType="centerCrop"/>
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/mapillary_web_view.xml b/OsmAnd/res/layout/mapillary_web_view.xml
new file mode 100644
index 0000000000..3afc91e2af
--- /dev/null
+++ b/OsmAnd/res/layout/mapillary_web_view.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index f44c21c30f..386b4aef71 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -2656,4 +2656,6 @@
Change button position
Long tap and drag the button to change its position on the screen
Action name
+ You need internet to view photos from Mapillary
+ Retry
diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java
index 4f0658283d..a00f63f036 100644
--- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java
+++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java
@@ -15,7 +15,10 @@ import android.view.ViewGroup;
import android.webkit.ConsoleMessage;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
+import android.webkit.WebResourceError;
+import android.webkit.WebResourceRequest;
import android.webkit.WebView;
+import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -33,6 +36,7 @@ import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager;
+import net.osmand.plus.IconsCache;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
@@ -78,15 +82,18 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
private double ca = Double.NaN;
private View staticImageView;
+ private View noInternetView;
private List> tiles = new ArrayList<>();
private double fetchedTileLat = Double.NaN;
private double fetchedTileLon = Double.NaN;
private List sequenceImages = new ArrayList<>();
private AtomicInteger downloadRequestNumber = new AtomicInteger();
+ private IconsCache ic;
public MapillaryImageDialog(@NonNull MapActivity mapActivity, @NonNull Bundle bundle) {
super(mapActivity, CardDialogType.MAPILLARY);
restoreFields(bundle);
+ this.ic = mapActivity.getMyApplication().getIconsCache();
}
public MapillaryImageDialog(MapActivity mapActivity, String key, String sKey, String imageUrl,
@@ -100,6 +107,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
this.viewerUrl = viewerUrl;
this.latLon = latLon;
this.ca = ca;
+ this.ic = mapActivity.getMyApplication().getIconsCache();
}
public String getKey() {
@@ -208,17 +216,27 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
- private WebView getWebView() {
- final WebView webView = new WebView(getMapActivity());
+ private View getWebView() {
+ View view = getMapActivity().getLayoutInflater().inflate(R.layout.mapillary_web_view, null);
+ final WebView webView = view.findViewById(R.id.webView);
webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
+ final View noInternetView = view.findViewById(R.id.mapillaryNoInternetLayout);
+ ((ImageView) noInternetView.findViewById(R.id.wifiOff)).setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_wifi_off));
//webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
- webView.setScrollContainer(false);
+ view.setScrollContainer(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new MapillaryWebAppInterface(), "Android");
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
isPortrait() ? ViewGroup.LayoutParams.MATCH_PARENT : AndroidUtils.dpToPx(getMapActivity(), 360f),
isPortrait() ? AndroidUtils.dpToPx(getMapActivity(), 270f) : ViewGroup.LayoutParams.MATCH_PARENT);
- webView.setLayoutParams(lp);
+ view.setLayoutParams(lp);
+ webView.setWebViewClient(new WebViewClient() {
+ @Override
+ public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
+ webView.loadUrl("about:blank");
+ noInternetView.setVisibility(View.VISIBLE);
+ }
+ });
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
@@ -229,8 +247,15 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
return false;
}
});
+ noInternetView.findViewById(R.id.retry_button).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ noInternetView.setVisibility(View.GONE);
+ webView.loadUrl(viewerUrl);
+ }
+ });
webView.loadUrl(viewerUrl);
- return webView;
+ return view;
}
private class MapillaryWebAppInterface {
@@ -273,14 +298,24 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
}
});
- staticImageView = view;
+ staticImageView = view.findViewById(R.id.staticImageViewLayout);
+
+ noInternetView = view.findViewById(R.id.mapillaryNoInternetLayout);
+ ((ImageView) noInternetView.findViewById(R.id.wifiOff)).setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_wifi_off));
+ noInternetView.findViewById(R.id.retry_button).setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ MenuBuilder.execute(new DownloadImageTask(staticImageView, downloadRequestNumber.incrementAndGet(), downloadRequestNumber));
+ fetchSequence();
+ }
+ });
if (!Algorithms.isEmpty(imageUrl)) {
MenuBuilder.execute(new DownloadImageTask(staticImageView, downloadRequestNumber.incrementAndGet(), downloadRequestNumber));
fetchSequence();
}
updateArrowButtons();
- return staticImageView;
+ return view;
}
private void fetchSequence() {
@@ -493,6 +528,8 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
@Override
protected void onPreExecute() {
+ noInternetView.setVisibility(View.GONE);
+ staticImageView.setVisibility(View.VISIBLE);
if (progressBar != null) {
progressBar.setVisibility(View.VISIBLE);
}
@@ -518,8 +555,14 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
- if (bitmap != null && imageView != null) {
- imageView.setImageDrawable(new BitmapDrawable(getMapActivity().getResources(), bitmap));
+ if (imageView != null) {
+ if (bitmap != null) {
+ imageView.setImageDrawable(new BitmapDrawable(getMapActivity().getResources(), bitmap));
+ } else {
+ imageView.setImageDrawable(null);
+ staticImageView.setVisibility(View.GONE);
+ noInternetView.setVisibility(View.VISIBLE);
+ }
}
}
}