diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java index b24534c55d..412dbafd02 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java @@ -136,6 +136,7 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { contentWebView = (WebView) mainView.findViewById(R.id.content_web_view); WebSettings webSettings = contentWebView.getSettings(); webSettings.setJavaScriptEnabled(true); + contentWebView.setWebViewClient(new WikipediaWebViewClient(getActivity(), darkMode)); return mainView; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaWebViewClient.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaWebViewClient.java new file mode 100644 index 0000000000..a4c336ec70 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaWebViewClient.java @@ -0,0 +1,55 @@ +package net.osmand.plus.mapcontextmenu; + +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.support.v4.app.FragmentActivity; +import android.support.v7.app.AlertDialog; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import net.osmand.plus.R; + + +public class WikipediaWebViewClient extends WebViewClient { + + private static final String PAGE_PREFIX_HTTP = "http://"; + private static final String PAGE_PREFIX_HTTPS = "https://"; + + private Context context; + private boolean nightMode; + + public WikipediaWebViewClient(FragmentActivity context, boolean nightMode) { + this.context = context; + this.nightMode = nightMode; + } + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) { + warnAboutExternalLoad(url, context, nightMode); + } else { + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + context.startActivity(i); + } + return true; + } + + private static void warnAboutExternalLoad(final String url, final Context context, final boolean nightMode) { + if (context == null) { + return; + } + new AlertDialog.Builder(context) + .setTitle(url) + .setMessage(R.string.online_webpage_warning) + .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + WikipediaDialogFragment.showFullArticle(context, Uri.parse(url), nightMode); + } + }) + .setNegativeButton(R.string.shared_string_cancel, null) + .show(); + } +}