package com.marshalchen.ua.common.commonUtils.moduleUtils;

import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.marshalchen.ua.common.commonUtils.logUtils.Logs;

/**
 * A webview which can open url by itself and can show some error message when receive error
 */

public class SampleWebViewClient extends WebViewClient {



    String showErrorString = "<html><body><h1>" + "Network error" + "</h1></body></html>";


    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);    //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    public void onReceivedError(WebView view, int errorCode,
                                String description, String failingUrl) {
        super.onReceivedError(view, errorCode, description, failingUrl);

        Logs.i("-MyWebViewClient->onReceivedError()--\n errorCode=" + errorCode + " \ndescription=" + description + " \nfailingUrl=" + failingUrl);

        view.loadDataWithBaseURL("", showErrorString, "text/html", "utf-8", null);

    }

    public String getShowErrorString() {
        return showErrorString;
    }

    public void setShowErrorString(String showErrorString) {
        this.showErrorString = showErrorString;
    }

}

@@ -53,16 +53,98 @@
 Utils;%0A%0A
+import android.webkit.WebResourceError;%0Aimport android.webkit.WebResourceRequest;%0A
 import a
@@ -854,32 +854,33 @@
 mplates.%0A    %7D%0A%0A
+%0A
     @Override%0A  
@@ -927,315 +927,112 @@
 ew, 
-int errorCode,%0A                                String description, String failingUrl) %7B%0A        super.onReceivedError(view, errorCode, description, failingUrl);%0A%0A        Logs.i(%22-MyWebViewClient-%3EonReceivedError()--%5Cn errorCode=%22 + errorCode + %22 %5Cndescription=%22 + description + %22 %5CnfailingUrl=%22 + failingUrl
+WebResourceRequest request, WebResourceError error) %7B%0A        super.onReceivedError(view, request, error
 );%0A%0A
@@ -1114,17 +1114,16 @@
  null);%0A
-%0A
     %7D%0A%0A 

Update SampleWebViewClient for the new API of OnReceivedError