Add no internet view
This commit is contained in:
parent
2624ecaef0
commit
ccee8b3e36
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,6 +3,11 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/staticImageViewLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -44,4 +49,10 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<include layout="@layout/mapillary_no_internet"
|
||||
android:id="@+id/mapillaryNoInternetLayout"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</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_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="mappilary_no_internet_desc">You need internet to view photos from Mapillary</string>
|
||||
<string name="retry">Retry</string>
|
||||
</resources>
|
||||
|
|
|
@ -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<Pair<QuadPointDouble, GeometryTile>> tiles = new ArrayList<>();
|
||||
private double fetchedTileLat = Double.NaN;
|
||||
private double fetchedTileLon = Double.NaN;
|
||||
private List<MapillaryImage> 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);
|
||||
return webView;
|
||||
}
|
||||
});
|
||||
webView.loadUrl(viewerUrl);
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue