Example usage for android.webkit WebResourceError getErrorCode

List of usage examples for android.webkit WebResourceError getErrorCode

Introduction

In this page you can find the example usage for android.webkit WebResourceError getErrorCode.

Prototype

public abstract int getErrorCode();

Source Link

Document

Gets the error code of the error.

Usage

From source file:com.microsoft.azure.engagement.fragment.FeaturesFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Nullable//from  www .  j a v a  2s .co m
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View view = inflater.inflate(R.layout.fragment_features, container, false);
    progressBar = view.findViewById(R.id.progressBar);
    errorContainer = view.findViewById(R.id.errorContainer);
    retryButton = view.findViewById(R.id.retryButton);
    retryButton.setOnClickListener(this);
    webView = (WebView) view.findViewById(R.id.webView);
    webView.setWebViewClient(new WebViewClient() {
        @TargetApi(android.os.Build.VERSION_CODES.M)
        @Override
        public void onReceivedError(WebView view, WebResourceRequest req, WebResourceError err) {
            onReceivedError(view, err.getErrorCode(), err.getDescription().toString(), req.getUrl().toString());
        }

        @SuppressWarnings("deprecation")
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            webViewError = true;
        }

        @Override
        public void onReceivedHttpError(WebView view, WebResourceRequest request,
                WebResourceResponse errorResponse) {
            super.onReceivedHttpError(view, request, errorResponse);
            webViewError = true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
            webView.setVisibility(webViewError ? View.GONE : View.VISIBLE);
            errorContainer.setVisibility(webViewError ? View.VISIBLE : View.GONE);
        }
    });
    webView.getSettings().setJavaScriptEnabled(true);

    displayLoadingView();
    webView.loadUrl(getString(R.string.drawer_features_url));

    AzmeTracker.startActivity(getActivity(), "features");
    return view;
}

From source file:com.taobao.luaview.view.LVWebView.java

@TargetApi(Build.VERSION_CODES.M)
private void setupDefaultWebViewClient() {
    if (mWebView != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            mWebView.setWebViewClient(new WebViewClient() {
                @Override//from   ww  w .  j  a  v  a2  s.c  o  m
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    return false; // ????
                }

                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    super.onPageStarted(view, url, favicon);
                    mIsLoading = true;
                    if (LuaUtil.isTable(mLuaUserdata.getCallback())) {
                        LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onPageStarted"));
                    }
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                    mIsLoading = false;
                    if (LuaUtil.isTable(mLuaUserdata.getCallback())) {
                        LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onPageFinished"));
                    }

                    if (LVWebView.this.isRefreshing()) {
                        LVWebView.this.setRefreshing(false);
                    }
                }

                @Override
                public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                    super.onReceivedError(view, request, error);
                    mIsLoading = false;
                    if (LuaUtil.isTable(mLuaUserdata.getCallback())) {
                        LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onReceivedError"),
                                valueOf(error.getErrorCode()), valueOf(String.valueOf(error.getDescription())),
                                valueOf(String.valueOf(request.getUrl())));
                    }

                    if (LVWebView.this.isRefreshing()) {
                        LVWebView.this.setRefreshing(false);
                    }
                }
            });
        } else {
            mWebView.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    return false; // ????
                }

                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    super.onPageStarted(view, url, favicon);
                    mIsLoading = true;
                    if (LuaUtil.isTable(mLuaUserdata.getCallback())) {
                        LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onPageStarted"));
                    }
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                    mIsLoading = false;
                    if (LuaUtil.isTable(mLuaUserdata.getCallback())) {
                        LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onPageFinished"));
                    }

                    if (LVWebView.this.isRefreshing()) {
                        LVWebView.this.setRefreshing(false);
                    }
                }

                @Override
                public void onReceivedError(WebView view, int errorCode, String description,
                        String failingUrl) {
                    super.onReceivedError(view, errorCode, description, failingUrl);
                    mIsLoading = false;
                    if (LuaUtil.isTable(mLuaUserdata.getCallback())) {
                        LuaUtil.callFunction(LuaUtil.getFunction(mLuaUserdata.getCallback(), "onReceivedError"),
                                errorCode, description, failingUrl);
                    }

                    if (LVWebView.this.isRefreshing()) {
                        LVWebView.this.setRefreshing(false);
                    }
                }
            });
        }
    }
}