Search in sources :

Example 16 with WebResourceError

use of android.webkit.WebResourceError in project LiYuJapanese by 54wall.

the class WebViewActivity method initWebView.

private void initWebView() {
    webView.setWebChromeClient(new MyWebChromeClient(this));
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            progressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            webView.loadUrl(url);
            progressBar.setVisibility(View.GONE);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
        }
    });
    webView.clearCache(true);
    webView.clearHistory();
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getPointerCount() > 1) {
                // Multi touch detected
                return true;
            }
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    {
                        // save the x
                        m_downX = event.getX();
                    }
                    break;
                case MotionEvent.ACTION_MOVE:
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_UP:
                    {
                        // set x so that it doesn't move
                        event.setLocation(m_downX, event.getY());
                    }
                    break;
            }
            return false;
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) WebResourceRequest(android.webkit.WebResourceRequest) WebResourceError(android.webkit.WebResourceError) WebView(android.webkit.WebView) TextView(android.widget.TextView) View(android.view.View) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient) MotionEvent(android.view.MotionEvent)

Example 17 with WebResourceError

use of android.webkit.WebResourceError in project MvvmNews by huanglinqing123.

the class NewsDetailActivity method initWebView.

@SuppressLint("SetJavaScriptEnabled")
private void initWebView() {
    webview.getSettings().setBlockNetworkImage(true);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setDomStorageEnabled(true);
    webview.getSettings().setAllowFileAccess(true);
    webview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    webview.getSettings().setDatabaseEnabled(true);
    webview.getSettings().setAppCacheEnabled(true);
    webview.getSettings().setAllowFileAccess(true);
    webview.getSettings().setAppCacheMaxSize(5 * 1024 * 1024);
    webview.getSettings().setPluginState(WebSettings.PluginState.ON);
    webview.loadUrl(getIntent().getStringExtra("newsurl"));
    webview.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

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

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            webview.setVisibility(View.GONE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            webview.getSettings().setBlockNetworkImage(false);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) WebResourceRequest(android.webkit.WebResourceRequest) WebResourceError(android.webkit.WebResourceError) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient) SuppressLint(android.annotation.SuppressLint)

Example 18 with WebResourceError

use of android.webkit.WebResourceError in project AppCenter-SDK-Android by Microsoft.

the class MSALoginActivity method signOut.

@SuppressWarnings("unused")
public void signOut(View view) {
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            if (url.startsWith(REDIRECT_URL)) {
                clearCookies();
                Uri uri = Uri.parse(url);
                sSharedPreferences.edit().remove(MSA_REFRESH_TOKEN_SCOPE_KEY).apply();
                sSharedPreferences.edit().remove(MSA_REFRESH_TOKEN_KEY).apply();
                sSharedPreferences.edit().remove(MSA_AUTH_TYPE_KEY).apply();
                sSharedPreferences.edit().remove(MSA_TOKEN_KEY).apply();
                String error = uri.getQueryParameter("error");
                if (error != null) {
                    failSignOut(0, error);
                } else {
                    signIn(null);
                }
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            clearCookies();
            failSignOut(errorCode, description);
        }

        @Override
        @TargetApi(Build.VERSION_CODES.M)
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            clearCookies();
            failSignOut(error.getErrorCode(), error.getDescription());
        }
    });
    mWebView.loadUrl(SIGN_OUT_URL + REDIRECT_URI_PARAM + CLIENT_ID_PARAM);
}
Also used : WebResourceRequest(android.webkit.WebResourceRequest) WebResourceError(android.webkit.WebResourceError) WebView(android.webkit.WebView) Uri(android.net.Uri) TargetApi(android.annotation.TargetApi) SuppressLint(android.annotation.SuppressLint) WebViewClient(android.webkit.WebViewClient)

Example 19 with WebResourceError

use of android.webkit.WebResourceError in project AppCenter-SDK-Android by Microsoft.

the class MSALoginActivity method signIn.

@SuppressWarnings("unused")
public void signIn(View view) {
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            checkSignInCompletion(url);
        }

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

        @Override
        @TargetApi(Build.VERSION_CODES.M)
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            failSignIn(error.getErrorCode(), error.getDescription());
        }
    });
    boolean compactTicket = mAuthType == AuthenticationProvider.Type.MSA_COMPACT;
    String responseType = compactTicket ? "token" : "code";
    String[] scopes = compactTicket ? SCOPES_COMPACT : SCOPES_DELEGATE;
    mWebView.loadUrl(AUTHORIZE_URL + REDIRECT_URI_PARAM + CLIENT_ID_PARAM + "&response_type=" + responseType + "&scope=" + TextUtils.join("+", scopes));
}
Also used : WebResourceRequest(android.webkit.WebResourceRequest) WebResourceError(android.webkit.WebResourceError) WebView(android.webkit.WebView) TargetApi(android.annotation.TargetApi) SuppressLint(android.annotation.SuppressLint) WebViewClient(android.webkit.WebViewClient)

Example 20 with WebResourceError

use of android.webkit.WebResourceError in project android-sdk by testpress.

the class WebViewUtils method initWebView.

@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" })
public void initWebView(String htmlContent, final Activity activity) {
    initWebView(webView);
    webView.addJavascriptInterface(new ImageHandler(activity), "ImageHandler");
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            WebViewUtils.this.onPageStarted();
            hasError = false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (!hasError) {
                String javascript = getJavascript(activity);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    webView.evaluateJavascript(javascript, null);
                } else {
                    webView.loadUrl(javascript, null);
                }
                onLoadFinished();
            }
        }

        @SuppressWarnings("deprecation")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return WebViewUtils.this.shouldOverrideUrlLoading(activity, url);
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            if (InternetConnectivityChecker.isConnected(activity)) {
                return;
            }
            onNetworkError();
            hasError = true;
        }
    });
    loadHtml(htmlContent);
}
Also used : Bitmap(android.graphics.Bitmap) WebResourceRequest(android.webkit.WebResourceRequest) WebResourceError(android.webkit.WebResourceError) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient) SuppressLint(android.annotation.SuppressLint)

Aggregations

WebResourceError (android.webkit.WebResourceError)36 WebResourceRequest (android.webkit.WebResourceRequest)36 WebView (android.webkit.WebView)36 WebViewClient (android.webkit.WebViewClient)35 Bitmap (android.graphics.Bitmap)22 SuppressLint (android.annotation.SuppressLint)16 WebChromeClient (android.webkit.WebChromeClient)12 WebSettings (android.webkit.WebSettings)12 WebResourceResponse (android.webkit.WebResourceResponse)10 SslError (android.net.http.SslError)9 SslErrorHandler (android.webkit.SslErrorHandler)9 TargetApi (android.annotation.TargetApi)8 View (android.view.View)8 Intent (android.content.Intent)7 Uri (android.net.Uri)7 TextView (android.widget.TextView)6 Nullable (androidx.annotation.Nullable)4 ConsoleMessage (android.webkit.ConsoleMessage)3 Context (android.content.Context)2 ColorStateList (android.content.res.ColorStateList)2