Webview improvements (respect back button, open external links in browser)

ref https://github.com/syncthing/syncthing/issues/4264
This commit is contained in:
Felix Ableitner 2017-07-21 01:43:28 +09:00
parent c13828b734
commit a9b80fbdc4
1 changed files with 22 additions and 1 deletions

View File

@ -2,12 +2,13 @@ package com.nutomic.syncthingandroid.activities;
import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.webkit.HttpAuthHandler;
@ -90,6 +91,17 @@ public class WebGuiActivity extends SyncthingActivity
handler.proceed(mConfig.getUserName(), mConfig.getApiKey());
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Uri uri = Uri.parse(url);
if(uri.getHost().equals("127.0.0.1")) {
return false;
} else {
startActivity(new Intent(Intent.ACTION_VIEW, uri));
return true;
}
}
@Override
public void onPageFinished(WebView view, String url) {
mWebView.setVisibility(View.VISIBLE);
@ -130,6 +142,15 @@ public class WebGuiActivity extends SyncthingActivity
mWebView.loadUrl(getService().getWebGuiUrl().toString());
}
@Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
/**
* Reads the SyncthingService.HTTPS_CERT_FILE Ca Cert key and loads it in memory
*/