Merge pull request #4221 from osmandapp/mapillary_no_image_view
Add no internet view to mapillary
This commit is contained in:
commit
64870b1638
5 changed files with 166 additions and 44 deletions
48
OsmAnd/res/layout/mapillary_no_internet.xml
Normal file
48
OsmAnd/res/layout/mapillary_no_internet.xml
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="?attr/bg_color"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/wifiOff"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:src="@drawable/ic_action_wifi_off"/>
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="30dp"
|
||||||
|
android:background="@null"
|
||||||
|
android:text="@string/no_inet_connection"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="24dp"
|
||||||
|
android:background="@null"
|
||||||
|
android:text="@string/mappilary_no_internet_desc"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"/>
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/retry_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:text="@string/retry"
|
||||||
|
android:textColor="?attr/color_dialog_buttons"
|
||||||
|
android:textSize="@dimen/default_sub_text_size"
|
||||||
|
osmand:textAllCapsCompat="true"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -3,45 +3,56 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<ImageView
|
<FrameLayout
|
||||||
android:id="@+id/imageView"
|
android:id="@+id/staticImageViewLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:scaleType="centerCrop"/>
|
|
||||||
|
|
||||||
<ProgressBar
|
<ImageView
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/imageView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:paddingTop="16dp"
|
|
||||||
android:paddingBottom="16dp"
|
|
||||||
android:background="@android:color/transparent">
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/leftArrowButton"
|
|
||||||
android:layout_width="44dp"
|
|
||||||
android:layout_height="44dp"
|
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
|
||||||
android:src="@drawable/ic_arrow_back"/>
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"/>
|
android:scaleType="centerCrop"/>
|
||||||
|
|
||||||
<ImageButton
|
<ProgressBar
|
||||||
android:id="@+id/rightArrowButton"
|
android:id="@+id/progressBar"
|
||||||
android:layout_width="44dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="44dp"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:layout_gravity="center"/>
|
||||||
android:src="@drawable/ic_arrow_forward"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
android:background="@android:color/transparent">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/leftArrowButton"
|
||||||
|
android:layout_width="44dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:src="@drawable/ic_arrow_back"/>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/rightArrowButton"
|
||||||
|
android:layout_width="44dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:src="@drawable/ic_arrow_forward"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<include layout="@layout/mapillary_no_internet"
|
||||||
|
android:id="@+id/mapillaryNoInternetLayout"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
18
OsmAnd/res/layout/mapillary_web_view.xml
Normal file
18
OsmAnd/res/layout/mapillary_web_view.xml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<WebView
|
||||||
|
android:id="@+id/webView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</WebView>
|
||||||
|
|
||||||
|
<include layout="@layout/mapillary_no_internet"
|
||||||
|
android:id="@+id/mapillaryNoInternetLayout"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
|
@ -2656,4 +2656,6 @@
|
||||||
<string name="quick_action_btn_tutorial_title">Change button position</string>
|
<string name="quick_action_btn_tutorial_title">Change button position</string>
|
||||||
<string name="quick_action_btn_tutorial_descr">Long tap and drag the button to change its position on the screen</string>
|
<string name="quick_action_btn_tutorial_descr">Long tap and drag the button to change its position on the screen</string>
|
||||||
<string name="shared_string_action_name">Action name</string>
|
<string name="shared_string_action_name">Action name</string>
|
||||||
|
<string name="mappilary_no_internet_desc">You need internet to view photos from Mapillary</string>
|
||||||
|
<string name="retry">Retry</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -15,7 +15,10 @@ import android.view.ViewGroup;
|
||||||
import android.webkit.ConsoleMessage;
|
import android.webkit.ConsoleMessage;
|
||||||
import android.webkit.JavascriptInterface;
|
import android.webkit.JavascriptInterface;
|
||||||
import android.webkit.WebChromeClient;
|
import android.webkit.WebChromeClient;
|
||||||
|
import android.webkit.WebResourceError;
|
||||||
|
import android.webkit.WebResourceRequest;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import android.webkit.WebViewClient;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
@ -33,6 +36,7 @@ import net.osmand.data.QuadRect;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
import net.osmand.map.TileSourceManager;
|
import net.osmand.map.TileSourceManager;
|
||||||
|
import net.osmand.plus.IconsCache;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||||
|
@ -78,15 +82,18 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
|
||||||
private double ca = Double.NaN;
|
private double ca = Double.NaN;
|
||||||
|
|
||||||
private View staticImageView;
|
private View staticImageView;
|
||||||
|
private View noInternetView;
|
||||||
private List<Pair<QuadPointDouble, GeometryTile>> tiles = new ArrayList<>();
|
private List<Pair<QuadPointDouble, GeometryTile>> tiles = new ArrayList<>();
|
||||||
private double fetchedTileLat = Double.NaN;
|
private double fetchedTileLat = Double.NaN;
|
||||||
private double fetchedTileLon = Double.NaN;
|
private double fetchedTileLon = Double.NaN;
|
||||||
private List<MapillaryImage> sequenceImages = new ArrayList<>();
|
private List<MapillaryImage> sequenceImages = new ArrayList<>();
|
||||||
private AtomicInteger downloadRequestNumber = new AtomicInteger();
|
private AtomicInteger downloadRequestNumber = new AtomicInteger();
|
||||||
|
private IconsCache ic;
|
||||||
|
|
||||||
public MapillaryImageDialog(@NonNull MapActivity mapActivity, @NonNull Bundle bundle) {
|
public MapillaryImageDialog(@NonNull MapActivity mapActivity, @NonNull Bundle bundle) {
|
||||||
super(mapActivity, CardDialogType.MAPILLARY);
|
super(mapActivity, CardDialogType.MAPILLARY);
|
||||||
restoreFields(bundle);
|
restoreFields(bundle);
|
||||||
|
this.ic = mapActivity.getMyApplication().getIconsCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapillaryImageDialog(MapActivity mapActivity, String key, String sKey, String imageUrl,
|
public MapillaryImageDialog(MapActivity mapActivity, String key, String sKey, String imageUrl,
|
||||||
|
@ -100,6 +107,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
|
||||||
this.viewerUrl = viewerUrl;
|
this.viewerUrl = viewerUrl;
|
||||||
this.latLon = latLon;
|
this.latLon = latLon;
|
||||||
this.ca = ca;
|
this.ca = ca;
|
||||||
|
this.ic = mapActivity.getMyApplication().getIconsCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
|
@ -208,17 +216,27 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
|
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
|
||||||
private WebView getWebView() {
|
private View getWebView() {
|
||||||
final WebView webView = new WebView(getMapActivity());
|
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));
|
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.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
|
||||||
webView.setScrollContainer(false);
|
view.setScrollContainer(false);
|
||||||
webView.getSettings().setJavaScriptEnabled(true);
|
webView.getSettings().setJavaScriptEnabled(true);
|
||||||
webView.addJavascriptInterface(new MapillaryWebAppInterface(), "Android");
|
webView.addJavascriptInterface(new MapillaryWebAppInterface(), "Android");
|
||||||
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
||||||
isPortrait() ? ViewGroup.LayoutParams.MATCH_PARENT : AndroidUtils.dpToPx(getMapActivity(), 360f),
|
isPortrait() ? ViewGroup.LayoutParams.MATCH_PARENT : AndroidUtils.dpToPx(getMapActivity(), 360f),
|
||||||
isPortrait() ? AndroidUtils.dpToPx(getMapActivity(), 270f) : ViewGroup.LayoutParams.MATCH_PARENT);
|
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() {
|
webView.setWebChromeClient(new WebChromeClient() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
|
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
|
||||||
|
@ -229,8 +247,15 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
|
||||||
return false;
|
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);
|
webView.loadUrl(viewerUrl);
|
||||||
return webView;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MapillaryWebAppInterface {
|
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)) {
|
if (!Algorithms.isEmpty(imageUrl)) {
|
||||||
MenuBuilder.execute(new DownloadImageTask(staticImageView, downloadRequestNumber.incrementAndGet(), downloadRequestNumber));
|
MenuBuilder.execute(new DownloadImageTask(staticImageView, downloadRequestNumber.incrementAndGet(), downloadRequestNumber));
|
||||||
fetchSequence();
|
fetchSequence();
|
||||||
}
|
}
|
||||||
updateArrowButtons();
|
updateArrowButtons();
|
||||||
return staticImageView;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchSequence() {
|
private void fetchSequence() {
|
||||||
|
@ -493,6 +528,8 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
|
noInternetView.setVisibility(View.GONE);
|
||||||
|
staticImageView.setVisibility(View.VISIBLE);
|
||||||
if (progressBar != null) {
|
if (progressBar != null) {
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
@ -518,8 +555,14 @@ public class MapillaryImageDialog extends ContextMenuCardDialog {
|
||||||
if (progressBar != null) {
|
if (progressBar != null) {
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if (bitmap != null && imageView != null) {
|
if (imageView != null) {
|
||||||
imageView.setImageDrawable(new BitmapDrawable(getMapActivity().getResources(), bitmap));
|
if (bitmap != null) {
|
||||||
|
imageView.setImageDrawable(new BitmapDrawable(getMapActivity().getResources(), bitmap));
|
||||||
|
} else {
|
||||||
|
imageView.setImageDrawable(null);
|
||||||
|
staticImageView.setVisibility(View.GONE);
|
||||||
|
noInternetView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue