- Open an external web browser when you click an external links in the Help.

This commit is contained in:
dgis 2021-03-01 12:20:55 +01:00
parent 10873f0973
commit 9dc51f38bf

View file

@ -16,8 +16,8 @@ package org.emulator.calculator;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Dialog; import android.app.Dialog;
import android.graphics.PorterDuff; import android.content.Intent;
import android.graphics.drawable.Drawable; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -30,6 +30,8 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDialogFragment; import androidx.appcompat.app.AppCompatDialogFragment;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import java.util.Locale;
public class InfoWebFragment extends AppCompatDialogFragment { public class InfoWebFragment extends AppCompatDialogFragment {
@Override @Override
@ -62,9 +64,7 @@ public class InfoWebFragment extends AppCompatDialogFragment {
Toolbar toolbar = view.findViewById(Utils.resId(this, "id", "my_toolbar")); Toolbar toolbar = view.findViewById(Utils.resId(this, "id", "my_toolbar"));
toolbar.setTitle(title); toolbar.setTitle(title);
Utils.colorizeDrawableWithColor(requireContext(), toolbar.getNavigationIcon(), android.R.attr.colorForeground); Utils.colorizeDrawableWithColor(requireContext(), toolbar.getNavigationIcon(), android.R.attr.colorForeground);
toolbar.setNavigationOnClickListener(v -> { toolbar.setNavigationOnClickListener(v -> dismiss());
dismiss();
});
WebView webView = view.findViewById(Utils.resId(this, "id", "webViewInfo")); WebView webView = view.findViewById(Utils.resId(this, "id", "webViewInfo"));
webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setJavaScriptEnabled(true);
@ -77,6 +77,16 @@ public class InfoWebFragment extends AppCompatDialogFragment {
// Inject a CSS style to wrap the table of content if needed // Inject a CSS style to wrap the table of content if needed
view.evaluateJavascript("javascript:(function(){var css=document.createElement(\"style\");css.type=\"text/css\";css.innerHTML=\".nav1{overflow-wrap:break-word;}\";document.head.appendChild(css);})();", null); view.evaluateJavascript("javascript:(function(){var css=document.createElement(\"style\");css.type=\"text/css\";css.innerHTML=\".nav1{overflow-wrap:break-word;}\";document.head.appendChild(css);})();", null);
} }
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url != null && url.toLowerCase(Locale.ENGLISH).matches("^https?://.*")) {
// External pages should be loaded in external web browser.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
}); });
webView.loadUrl(getString(Utils.resId(this, "string", "help_url"))); webView.loadUrl(getString(Utils.resId(this, "string", "help_url")));