use of android.webkit.WebSettings in project habpanelviewer by vbier.
the class ClientWebView method initialize.
synchronized void initialize(final IConnectionListener cl) {
setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
if (consoleMessage.message().contains("SSE error, closing EventSource")) {
cl.disconnected();
}
return super.onConsoleMessage(consoleMessage);
}
});
setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (isHabPanelUrl(url)) {
evaluateJavascript("angular.element(document.body).scope().$root.kioskMode", s -> {
mKioskMode = Boolean.parseBoolean(s);
Log.d(TAG, "HABPanel page loaded. kioskMode=" + mKioskMode);
});
}
}
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, final SslError error) {
Log.d(TAG, "onReceivedSslError: " + error.getUrl());
SslCertificate cert = error.getCertificate();
if (ConnectionUtil.isTrusted(error.getCertificate())) {
Log.d(TAG, "certificate is trusted: " + error.getUrl());
handler.proceed();
return;
}
String h;
try {
URL url = new URL(error.getUrl());
h = url.getHost();
} catch (MalformedURLException e) {
h = getContext().getString(R.string.unknownHost);
}
final String host = h;
String r = getContext().getString(R.string.notValid);
switch(error.getPrimaryError()) {
case SslError.SSL_DATE_INVALID:
r = getContext().getString(R.string.invalidDate);
break;
case SslError.SSL_EXPIRED:
r = getContext().getString(R.string.expired);
break;
case SslError.SSL_IDMISMATCH:
r = getContext().getString(R.string.hostnameMismatch);
break;
case SslError.SSL_NOTYETVALID:
r = getContext().getString(R.string.notYetValid);
break;
case SslError.SSL_UNTRUSTED:
r = getContext().getString(R.string.untrusted);
break;
}
final String reason = r;
String c = getContext().getString(R.string.issuedBy) + cert.getIssuedBy().getDName() + "<br/>";
c += getContext().getString(R.string.issuedTo) + cert.getIssuedTo().getDName() + "<br/>";
c += getContext().getString(R.string.validFrom) + SimpleDateFormat.getDateInstance().format(cert.getValidNotBeforeDate()) + "<br/>";
c += getContext().getString(R.string.validUntil) + SimpleDateFormat.getDateInstance().format(cert.getValidNotAfterDate()) + "<br/>";
final String certInfo = c;
new AlertDialog.Builder(ClientWebView.this.getContext()).setTitle(getContext().getString(R.string.certInvalid)).setMessage(getContext().getString(R.string.sslCert) + "https://" + host + " " + reason + ".\n\n" + certInfo.replaceAll("<br/>", "\n") + "\n" + getContext().getString(R.string.storeSecurityException)).setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
try {
ConnectionUtil.addCertificate(error.getCertificate());
} catch (Exception e) {
e.printStackTrace();
}
handler.proceed();
}).setNegativeButton(android.R.string.no, (dialog, whichButton) -> loadData("<html><body><h1>" + getContext().getString(R.string.certInvalid) + "</h1><h2>" + getContext().getString(R.string.sslCert) + "https://" + host + " " + reason + ".</h2>" + certInfo + "</body></html>", "text/html", "UTF-8")).show();
}
@Override
public void onReceivedHttpAuthRequest(WebView view, final HttpAuthHandler handler, final String host, final String realm) {
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()).setCancelable(false).setTitle(R.string.login_required).setMessage(getContext().getString(R.string.host_realm, host, realm)).setView(R.layout.dialog_login).setPositiveButton(R.string.okay, (dialog12, id) -> {
EditText userT = ((AlertDialog) dialog12).findViewById(R.id.username);
EditText passT = ((AlertDialog) dialog12).findViewById(R.id.password);
handler.proceed(userT.getText().toString(), passT.getText().toString());
}).setNegativeButton(R.string.cancel, (dialog1, which) -> handler.cancel());
final AlertDialog alert = dialog.create();
alert.show();
}
});
setOnTouchListener((v, event) -> (event.getAction() == MotionEvent.ACTION_MOVE && mDraggingPrevented));
CookieManager.getInstance().setAcceptCookie(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
}
WebSettings webSettings = getSettings();
webSettings.setDomStorageEnabled(true);
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
getContext().registerReceiver(mNetworkReceiver, intentFilter);
}
use of android.webkit.WebSettings in project habpanelviewer by vbier.
the class ClientWebView method updateFromPreferences.
void updateFromPreferences(SharedPreferences prefs) {
Boolean isDesktop = prefs.getBoolean("pref_desktop_mode", false);
Boolean isJavascript = prefs.getBoolean("pref_javascript", false);
mDraggingPrevented = prefs.getBoolean("pref_prevent_dragging", false);
WebSettings webSettings = getSettings();
webSettings.setUseWideViewPort(isDesktop);
webSettings.setLoadWithOverviewMode(isDesktop);
webSettings.setJavaScriptEnabled(isJavascript);
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm == null ? null : cm.getActiveNetworkInfo();
boolean loadStartUrl = false;
boolean reloadUrl = false;
if (mStartPage == null || !mStartPage.equalsIgnoreCase(prefs.getString("pref_start_url", ""))) {
mStartPage = prefs.getString("pref_start_url", "");
loadStartUrl = true;
}
if (mServerURL == null || !mServerURL.equalsIgnoreCase(prefs.getString("pref_server_url", "!$%"))) {
mServerURL = prefs.getString("pref_server_url", "");
loadStartUrl = mStartPage == null || mStartPage.isEmpty();
}
if (mAllowMixedContent != prefs.getBoolean("pref_allow_mixed_content", false)) {
mAllowMixedContent = prefs.getBoolean("pref_allow_mixed_content", false);
reloadUrl = true;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webSettings.setMixedContentMode(mAllowMixedContent ? WebSettings.MIXED_CONTENT_ALWAYS_ALLOW : WebSettings.MIXED_CONTENT_NEVER_ALLOW);
}
if (activeNetwork != null && activeNetwork.isConnectedOrConnecting()) {
if (loadStartUrl) {
loadStartUrl();
} else if (reloadUrl) {
reload();
}
} else {
loadData("<html><body><h1>" + getContext().getString(R.string.waitingNetwork) + "</h1><h2>" + getContext().getString(R.string.notConnected) + "</h2></body></html>", "text/html", "UTF-8");
}
}
use of android.webkit.WebSettings in project AmazMod by edotassi.
the class StravaAuthActivity method onCreate.
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
WebSettings webSettings = this.mWebView.getSettings();
String string = webSettings.getUserAgentString();
Log.d((String) "Strava-AuthActivity", (String) ("UserAgent before : " + string), (Object[]) new Object[0]);
if (string.contains(" wv")) {
webSettings.setUserAgentString(string.replace(" wv", ""));
} else {
webSettings.setUserAgentString(string.replace("Version/", "xxx/"));
}
Log.d((String) "Strava-AuthActivity", (String) ("UserAgent after : " + string), (Object[]) new Object[0]);
this.mWebView.setWebViewClient((WebViewClient) new a(this));
}
use of android.webkit.WebSettings in project connect-android-sdk by telenordigital.
the class WebViewHelper method setupWebView.
// 1. HtmlToAndroidInstructionsInterface has no public fields.
// 2. We need JS for the web page.
@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" })
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setupWebView(final WebView webView, ConnectWebViewClient client, final String pageToLoad) {
webView.setWebViewClient(client);
webView.setVerticalScrollBarEnabled(true);
webView.setHorizontalScrollBarEnabled(false);
final WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setSaveFormData(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
}
webView.addJavascriptInterface(new HtmlToAndroidInstructionsInterface(client), "AndroidInterface");
webView.setFocusable(true);
webView.setFocusableInTouchMode(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
acceptAllCookies(webView);
webView.loadUrl(pageToLoad);
webView.postDelayed(new RepeatingDelayedPageReloader(webView, pageToLoad), WEB_VIEW_TIMEOUT);
}
use of android.webkit.WebSettings in project Stringlate by LonamiWebs.
the class BrowserActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_online_help);
webview = findViewById(R.id.webview);
WebSettings webSettings = webview.getSettings();
webSettings.setAllowFileAccess(false);
webSettings.setUserAgentString("Mozilla/5.0 (Linux; U; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
Intent intent = getIntent();
if (isShowingStringlateHelp = intent.getBooleanExtra(EXTRA_DO_SHOW_STRINGLATE_HELP, false)) {
webSettings.setAllowFileAccess(true);
String locale = Locale.getDefault().getLanguage();
if (!helpAvailableForLocale(locale))
locale = ONLINE_HELP_DEFAULT_LOCALE;
webview.loadUrl(String.format("file:///android_res/raw/%s.html", locale));
}
if (!TextUtils.isEmpty(intent.getStringExtra(EXTRA_LOAD_URL))) {
webview.loadUrl(intent.getStringExtra(EXTRA_LOAD_URL));
}
}
Aggregations