Search in sources :

Example 6 with WebChromeClient

use of android.webkit.WebChromeClient in project superCleanMaster by joyoyao.

the class DeciveInfoFragment method initWebview.

private void initWebview() {
    // TODO Auto-generated method stub
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    // 设置可以访问文件
    webSettings.setAllowFileAccess(true);
    // 设置可以支持缩放
    webSettings.setSupportZoom(true);
    // 设置默认缩放方式尺寸是far
    webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
    // 设置出现缩放工具
    webSettings.setBuiltInZoomControls(false);
    webSettings.setDefaultFontSize(20);
    // 访问assets目录下的文件
    mWebView.loadUrl("http://girl-atlas.com");
    // 设置WebViewClient
    mWebView.setWebViewClient(new WebViewClient() {

        // url拦截
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // 使用自己的WebView组件来响应Url加载事件,而不是使用默认浏览器器加载页面
            view.loadUrl(url);
            // 相应完成返回true
            return true;
        // return super.shouldOverrideUrlLoading(view, url);
        }

        // 页面开始加载
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            mProgressBar.setVisibility(View.VISIBLE);
            super.onPageStarted(view, url, favicon);
        }

        // 页面加载完成
        @Override
        public void onPageFinished(WebView view, String url) {
            mProgressBar.setVisibility(View.GONE);
            super.onPageFinished(view, url);
        }

        // WebView加载的所有资源url
        @Override
        public void onLoadResource(WebView view, String url) {
            super.onLoadResource(view, url);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    });
    // 设置WebChromeClient
    mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
        public // 处理javascript中的alert
        boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
            return super.onJsAlert(view, url, message, result);
        }

        ;

        @Override
        public // 处理javascript中的confirm
        boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
            return super.onJsConfirm(view, url, message, result);
        }

        ;

        @Override
        public // 处理javascript中的prompt
        boolean onJsPrompt(WebView view, String url, String message, String defaultValue, final JsPromptResult result) {
            return super.onJsPrompt(view, url, message, defaultValue, result);
        }

        ;

        // 设置网页加载的进度条
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            mProgressBar.setProgress(newProgress);
            super.onProgressChanged(view, newProgress);
        }

        // 设置程序的Title
        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
        }
    });
    mWebView.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
                    // 表示按返回键
                    // 后退
                    mWebView.goBack();
                    // 已处理
                    return true;
                }
            }
            return false;
        }
    });
}
Also used : InjectView(butterknife.InjectView) View(android.view.View) WebView(android.webkit.WebView) JsResult(android.webkit.JsResult) KeyEvent(android.view.KeyEvent) Bitmap(android.graphics.Bitmap) WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) JsPromptResult(android.webkit.JsPromptResult) WebViewClient(android.webkit.WebViewClient)

Example 7 with WebChromeClient

use of android.webkit.WebChromeClient in project platform_frameworks_base by android.

the class LooperAcceleration method makeView.

private View makeView() {
    LinearLayout layout = new LinearLayout(this);
    layout.addView(new IsAcceleratedView(this), LayoutParams.MATCH_PARENT, 60);
    if (INCLUDE_WEBVIEW) {
        WebView wv = new WebView(this);
        wv.setWebViewClient(new WebViewClient());
        wv.setWebChromeClient(new WebChromeClient());
        wv.loadUrl("http://www.webkit.org/blog-files/3d-transforms/poster-circle.html");
        layout.addView(wv, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    }
    return layout;
}
Also used : WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) LinearLayout(android.widget.LinearLayout) WebViewClient(android.webkit.WebViewClient)

Example 8 with WebChromeClient

use of android.webkit.WebChromeClient in project weex-example by KalicyZhou.

the class WXWebView method initWebView.

private void initWebView(WebView wv) {
    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAppCacheEnabled(true);
    settings.setUseWideViewPort(true);
    settings.setDomStorageEnabled(true);
    settings.setSupportZoom(false);
    settings.setBuiltInZoomControls(false);
    wv.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            WXLogUtils.v("tag", "onPageOverride " + url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            WXLogUtils.v("tag", "onPageStarted " + url);
            if (mOnPageListener != null) {
                mOnPageListener.onPageStart(url);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            WXLogUtils.v("tag", "onPageFinished " + url);
            if (mOnPageListener != null) {
                mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
            }
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            if (mOnErrorListener != null) {
                //mOnErrorListener.onError("error", "page error code:" + error.getErrorCode() + ", desc:" + error.getDescription() + ", url:" + request.getUrl());
                mOnErrorListener.onError("error", "page error");
            }
        }

        @Override
        public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
            super.onReceivedHttpError(view, request, errorResponse);
            if (mOnErrorListener != null) {
                mOnErrorListener.onError("error", "http error");
            }
        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            super.onReceivedSslError(view, handler, error);
            if (mOnErrorListener != null) {
                mOnErrorListener.onError("error", "ssl error");
            }
        }
    });
    wv.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            showWebView(newProgress == 100);
            showProgressBar(newProgress != 100);
            WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            if (mOnPageListener != null) {
                mOnPageListener.onReceivedTitle(view.getTitle());
            }
        }
    });
}
Also used : SslErrorHandler(android.webkit.SslErrorHandler) WebResourceRequest(android.webkit.WebResourceRequest) SslError(android.net.http.SslError) Bitmap(android.graphics.Bitmap) WebResourceResponse(android.webkit.WebResourceResponse) WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebResourceError(android.webkit.WebResourceError) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 9 with WebChromeClient

use of android.webkit.WebChromeClient in project weex-example by KalicyZhou.

the class WXWebViewTest method testLoadUrl.

@Test
public void testLoadUrl() throws Exception {
    String url = "http://www.taobao.com";
    view.loadUrl(url);
    WebViewClient client = shadow.getWebViewClient();
    client.onPageStarted(webView, url, null);
    client.onPageFinished(webView, url);
    WebChromeClient chromeClient = shadow.getWebChromeClient();
    chromeClient.onProgressChanged(webView, 10);
    chromeClient.onProgressChanged(webView, 100);
    chromeClient.onReceivedTitle(webView, "test");
}
Also used : WebChromeClient(android.webkit.WebChromeClient) WebViewClient(android.webkit.WebViewClient) Test(org.junit.Test)

Example 10 with WebChromeClient

use of android.webkit.WebChromeClient in project android_frameworks_base by ResurrectionRemix.

the class LooperAcceleration method makeView.

private View makeView() {
    LinearLayout layout = new LinearLayout(this);
    layout.addView(new IsAcceleratedView(this), LayoutParams.MATCH_PARENT, 60);
    if (INCLUDE_WEBVIEW) {
        WebView wv = new WebView(this);
        wv.setWebViewClient(new WebViewClient());
        wv.setWebChromeClient(new WebChromeClient());
        wv.loadUrl("http://www.webkit.org/blog-files/3d-transforms/poster-circle.html");
        layout.addView(wv, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    }
    return layout;
}
Also used : WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) LinearLayout(android.widget.LinearLayout) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebChromeClient (android.webkit.WebChromeClient)39 WebView (android.webkit.WebView)32 WebViewClient (android.webkit.WebViewClient)29 WebSettings (android.webkit.WebSettings)13 View (android.view.View)12 Bitmap (android.graphics.Bitmap)9 SuppressLint (android.annotation.SuppressLint)6 JsResult (android.webkit.JsResult)6 WebResourceRequest (android.webkit.WebResourceRequest)6 Intent (android.content.Intent)5 LinearLayout (android.widget.LinearLayout)5 Uri (android.net.Uri)4 KeyEvent (android.view.KeyEvent)4 JsPromptResult (android.webkit.JsPromptResult)4 WebResourceError (android.webkit.WebResourceError)4 WebResourceResponse (android.webkit.WebResourceResponse)3 InjectView (butterknife.InjectView)3 IOException (java.io.IOException)3 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2