Example usage for android.net.http SslError toString

List of usage examples for android.net.http SslError toString

Introduction

In this page you can find the example usage for android.net.http SslError toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of this object.

Usage

From source file:com.appnexus.opensdk.MRAIDImplementation.java

WebViewClient getWebViewClient() {

    return new WebViewClient() {

        @Override//  w w  w  . ja  va2s .  c  o  m
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!url.startsWith("mraid:") && !url.startsWith("javascript:")) {
                Intent intent;
                if (owner.owner.getOpensNativeBrowser()) {
                    intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                } else {
                    intent = new Intent(owner.getContext(), BrowserActivity.class);
                    intent.putExtra("url", url);
                }
                try {
                    owner.getContext().startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    Clog.w(Clog.mraidLogTag, Clog.getString(R.string.opening_url_failed, url));
                }
                return true;
            } else if (url.startsWith("mraid://")) {
                MRAIDImplementation.this.dispatch_mraid_call(url);

                return true;
            }

            // See if any native activities can handle the Url
            try {
                owner.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                // If it's an IAV, prevent it from closing
                if (owner.owner instanceof InterstitialAdView) {
                    ((InterstitialAdView) (owner.owner)).interacted();
                }
                return true;
            } catch (ActivityNotFoundException e) {
                return false;
            }
        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            Clog.e(Clog.httpRespLogTag,
                    Clog.getString(R.string.webclient_error, error.getPrimaryError(), error.toString()));
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingURL) {
            Clog.e(Clog.httpRespLogTag, Clog.getString(R.string.webclient_error, errorCode, description));
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // Fire the ready event only once
            if (!readyFired) {
                view.loadUrl(String.format("javascript:window.mraid.util.setPlacementType('%s')",
                        owner.owner.isBanner() ? "inline" : "interstitial"));
                view.loadUrl("javascript:window.mraid.util.setIsViewable(true)");
                view.loadUrl("javascript:window.mraid.util.stateChangeEvent('default')");
                view.loadUrl("javascript:window.mraid.util.readyEvent();");

                // Store width and height for close()
                default_width = owner.getLayoutParams().width;
                default_height = owner.getLayoutParams().height;

                readyFired = true;
            }
        }
    };
}

From source file:com.pdftron.pdf.controls.ReflowPagerAdapter.java

public void initialize() {
    // set loading file depending on night mode
    if (sIsNightMode) {
        mLoadingFile = NIGHT_MODE_LOADING_FILE;
    } else {//from ww w .  j  a  v  a2s  .co m
        mLoadingFile = NORMAL_MODE_LOADING_FILE;
    }

    if (mWebViewRepository != null) {
        mWebViewRepository.reset();
    }

    ReflowWebView[] webViews = mWebViewRepository.getWebViews();
    for (final ReflowWebView webView : webViews) {
        webView.clearCache(true); // reset reading css file
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWillNotCacheDrawing(false);
        if (sIsNightMode) {
            webView.setBackgroundColor(Color.BLACK);
        } else {
            webView.setBackgroundColor(Color.WHITE);
        }
        webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        webView.loadUrl("about:blank");
        webView.setListener(this);

        webView.setWebChromeClient(new WebChromeClient()); // enable the use of methods like alert in javascript
        webView.setWebViewClient(new WebViewClient() {
            // now all links the user clicks load in your WebView
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
                Log.e(TAG, description + " url: " + failingUrl);
            }

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                super.onReceivedSslError(view, handler, error);
                Log.e(TAG, error.toString());
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.startsWith("file:///") && url.endsWith(".html")) {
                    int slashPos = url.lastIndexOf('/');
                    try {
                        int objNum = Integer.parseInt(url.substring(slashPos + 1, url.length() - 5));
                        int pageNum = 0;
                        for (int i = 1; i <= mPageCount; i++) {
                            try {
                                Page page = mDoc.getPage(i);
                                if (page.getSDFObj().getObjNum() == objNum) {
                                    pageNum = i;
                                    break;
                                }
                            } catch (Exception e) {
                            }
                        }
                        if (pageNum != 0) {
                            mViewPager.setCurrentItem(pageNum - 1);
                        }
                    } catch (NumberFormatException e) {
                        return true;
                    }
                } else {
                    if (url.startsWith("mailto:")
                            || android.util.Patterns.EMAIL_ADDRESS.matcher(url).matches()) {
                        if (url.startsWith("mailto:")) {
                            url = url.substring(7);
                        }
                        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", url, null));
                        mContext.startActivity(Intent.createChooser(intent,
                                mContext.getResources().getString(R.string.tools_misc_sendemail)));
                    } else {
                        // ACTION_VIEW needs the address to have http or https
                        if (!url.startsWith("https://") && !url.startsWith("http://")) {
                            url = "http://" + url;
                        }
                        if (DEBUG)
                            Log.d(TAG, url);
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                        mContext.startActivity(Intent.createChooser(intent,
                                mContext.getResources().getString(R.string.tools_misc_openwith)));
                    }
                }
                return true;
            }
        });
    }
}