|
|
@@ -5,7 +5,9 @@ import android.annotation.SuppressLint;
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.graphics.Bitmap;
|
|
|
import android.net.Uri;
|
|
|
+import android.net.http.SslError;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
@@ -15,8 +17,10 @@ import android.view.View;
|
|
|
import android.webkit.ConsoleMessage;
|
|
|
import android.webkit.JsPromptResult;
|
|
|
import android.webkit.JsResult;
|
|
|
+import android.webkit.SslErrorHandler;
|
|
|
import android.webkit.ValueCallback;
|
|
|
import android.webkit.WebChromeClient;
|
|
|
+import android.webkit.WebResourceError;
|
|
|
import android.webkit.WebResourceRequest;
|
|
|
import android.webkit.WebResourceResponse;
|
|
|
import android.webkit.WebSettings;
|
|
|
@@ -158,6 +162,24 @@ public class RAWebView extends RelativeLayout {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void clearCache() {
|
|
|
+ if (mWebView != null) {
|
|
|
+ mWebView.clearCache(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void loadHtmlString(String html) {
|
|
|
+ if (html != null) {
|
|
|
+ mWebView.loadData(html, "text/html", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void reload() {
|
|
|
+ if (mWebView != null) {
|
|
|
+ mWebView.reload();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void evaluateJavascript(String script, ValueCallback<String> resultCallback) {
|
|
|
if (mWebView != null) {
|
|
|
mWebView.evaluateJavascript(script, resultCallback);
|
|
|
@@ -191,7 +213,7 @@ public class RAWebView extends RelativeLayout {
|
|
|
|
|
|
Uri uri = request.getUrl();
|
|
|
String url = uri.getPath();
|
|
|
- if (url.startsWith("/file://")) {
|
|
|
+ if (url != null && url.startsWith("/file://")) {
|
|
|
|
|
|
String path = url.replace("/file://","");
|
|
|
File file = new File(path);
|
|
|
@@ -208,6 +230,66 @@ public class RAWebView extends RelativeLayout {
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
+ super.onPageStarted(view, url, favicon);
|
|
|
+
|
|
|
+ Log.d(TAG, "onPageStarted: ");
|
|
|
+ if (mLoadCallback != null) {
|
|
|
+ mLoadCallback.onPageStarted(view, url, favicon);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPageFinished(WebView view, String url) {
|
|
|
+ super.onPageFinished(view, url);
|
|
|
+ Log.d(TAG, "onPageFinished: ");
|
|
|
+ if (mLoadCallback != null) {
|
|
|
+ mLoadCallback.onPageFinished(view, url);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReceivedError(WebView view, int errorCode,String description, String failingUrl) {
|
|
|
+// super.onReceivedError(view, errorCode, description, failingUrl);
|
|
|
+
|
|
|
+ Log.d(TAG, "onReceivedError: 0");
|
|
|
+ if (mLoadCallback != null) {
|
|
|
+ mLoadCallback.onReceivedError(view, errorCode, description, failingUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
|
|
+// super.onReceivedError(view, request, error);
|
|
|
+//
|
|
|
+// Log.d(TAG, "onReceivedError: 1");
|
|
|
+// if (mLoadCallback != null) {
|
|
|
+// mLoadCallback.onReceivedError(view, request, error);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
|
|
|
+ super.onReceivedHttpError(view, request, errorResponse);
|
|
|
+
|
|
|
+ Log.d(TAG, "onReceivedHttpError: ");
|
|
|
+ if (mLoadCallback != null) {
|
|
|
+ mLoadCallback.onReceivedHttpError(view, request, errorResponse);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
|
|
|
+ super.onReceivedSslError(view, handler, error);
|
|
|
+
|
|
|
+ Log.d(TAG, "onReceivedSslError: ");
|
|
|
+ if (mLoadCallback != null) {
|
|
|
+ mLoadCallback.onReceivedSslError(view, handler, error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
@@ -291,4 +373,21 @@ public class RAWebView extends RelativeLayout {
|
|
|
public void setFileChooserCallback(WebViewFileChooserCallback callback) {
|
|
|
this.mFileChooserCallback = callback;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Load Callback
|
|
|
+ * */
|
|
|
+ public interface WebViewLoadCallback {
|
|
|
+ void onPageStarted(WebView view, String url, Bitmap favicon);
|
|
|
+ void onPageFinished(WebView view, String url);
|
|
|
+ void onReceivedError(WebView view, int errorCode,String description, String failingUrl);
|
|
|
+// void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error);
|
|
|
+ void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse);
|
|
|
+ void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error);
|
|
|
+ }
|
|
|
+
|
|
|
+ private WebViewLoadCallback mLoadCallback;
|
|
|
+ public void setLoadCallback(WebViewLoadCallback callback) {
|
|
|
+ this.mLoadCallback = callback;
|
|
|
+ }
|
|
|
}
|