Search in sources :

Example 6 with WebResourceError

use of android.webkit.WebResourceError in project WeexErosFramework by bmfe.

the class BMWebView 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() {

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

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

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

        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            if (BMWebView.this.mOnErrorListener != null) {
                BMWebView.this.mOnErrorListener.onError("error", "page error");
            }
        }

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

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

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

        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            if (BMWebView.this.mOnPageListener != null) {
                BMWebView.this.mOnPageListener.onReceivedTitle(view.getTitle());
            }
        }
    });
}
Also used : SslErrorHandler(android.webkit.SslErrorHandler) Bitmap(android.graphics.Bitmap) WebResourceRequest(android.webkit.WebResourceRequest) WebResourceResponse(android.webkit.WebResourceResponse) WebSettings(android.webkit.WebSettings) SslError(android.net.http.SslError) WebChromeClient(android.webkit.WebChromeClient) WebResourceError(android.webkit.WebResourceError) IWebView(com.taobao.weex.ui.view.IWebView) WebView(android.webkit.WebView) WXWebView(com.taobao.weex.ui.view.WXWebView) WebViewClient(android.webkit.WebViewClient)

Example 7 with WebResourceError

use of android.webkit.WebResourceError in project WeexErosFramework by bmfe.

the class BMWXWebView method initWebView.

private void initWebView(WebView wv) {
    WebSettings settings = wv.getSettings();
    settings.setAppCacheEnabled(true);
    settings.setUseWideViewPort(true);
    settings.setDomStorageEnabled(true);
    settings.setSupportZoom(false);
    settings.setBuiltInZoomControls(false);
    addWebJavascriptInterface(wv);
    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());
            }
        }

        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            mContentHeight = Integer.parseInt(message);
            mContentHeight = mContentHeight / (WXViewUtils.defaultPixelScaleFactor(getView().getContext()) * 2);
            Map<String, String> params = new HashMap<>();
            params.put("contentHeight", mContentHeight + "");
            if (mWXWeb != null) {
                mWXWeb.fireEvent("bmPageFinish", params);
            }
            result.confirm();
            return true;
        }
    });
}
Also used : SslErrorHandler(android.webkit.SslErrorHandler) WebResourceRequest(android.webkit.WebResourceRequest) SslError(android.net.http.SslError) SuppressLint(android.annotation.SuppressLint) JsResult(android.webkit.JsResult) Bitmap(android.graphics.Bitmap) WebResourceResponse(android.webkit.WebResourceResponse) WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebResourceError(android.webkit.WebResourceError) WebView(android.webkit.WebView) IWebView(com.taobao.weex.ui.view.IWebView) HashMap(java.util.HashMap) Map(java.util.Map) WebViewClient(android.webkit.WebViewClient)

Example 8 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 9 with WebResourceError

use of android.webkit.WebResourceError in project MyJapanese 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 10 with WebResourceError

use of android.webkit.WebResourceError in project IbookerEditorAndroid by zrunker.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ibookerEditorView = findViewById(R.id.ibookereditorview);
    ibookerEditorView.setIEEditViewBackgroundColor(Color.parseColor("#DDDDDD")).setIEEditViewIbookerEdHint("书客编辑器").setIbookerEditorImgPreviewListener(new IbookerEditorWebView.IbookerEditorImgPreviewListener() {

        @Override
        public void onIbookerEditorImgPreview(String currentPath, int position, ArrayList<String> imgAllPathList) {
            Toast.makeText(MainActivity.this, currentPath + "===" + position + "===" + imgAllPathList.toString(), Toast.LENGTH_LONG).show();
            Intent intent = new Intent(MainActivity.this, ImgVPagerActivity.class);
            intent.putExtra("currentPath", currentPath);
            intent.putExtra("position", position);
            intent.putStringArrayListExtra("imgAllPathList", imgAllPathList);
            startActivity(intent);
        }
    }).setIbookerEditorWebViewUrlLoadingListener(new IbookerEditorWebView.IbookerEditorWebViewUrlLoadingListener() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);
            return true;
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(request.getUrl().toString()));
                startActivity(intent);
            }
            return true;
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        }

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

        @Override
        public void onPageFinished(WebView view, String url) {
        }
    });
    ibookerEditorView.getIbookerEditorVpView().getEditView().getIbookerEd().setText("[链接描述](http://ips.ifeng.com/video19.ifeng.com/video09/2018/09/28/p2749834-102-998769-221938.mp4?ifsign=1&vid=2f24cc82-9236-4289-adcc-5e34ae569cc8&uid=1516537011039_hyemhv7718&from=weMedia_pc&pver=weMediaHTML5Player_v1.0.0&sver=&se=%E9%A3%9E%E7%A2%9F%E8%AF%B4&cat=8622&ptype=8622&platform=pc&sourceType=h5&dt=1538135880000&gid=SLTFYWYkO4jp&sign=16536514b3d291920ac6253872661e9c&tm=1538206173419)\n" + "                   " + "\"This come from string. You can insert inline formula:\" +\n" + "            \" \\\\(ax^2 + bx + c = 0\\\\) \" +\n" + "            \"or displayed formula: $$\\\\sum_{i=0}^n i^2 = \\\\frac{(n^2+n)(2n+1)}{6}$$\";" + "### 书客编辑器\n***\n书客编辑器从这里开始,我们的每一次开始,都那么小心翼翼,这一次如果可以的话不妨就现在开始试试。\n\n书客编辑器,简易,高效。轻轻松松记录你的每一刻。\n>书客编辑器不仅仅是为了“还好”而设计\n\n“还好”,那就意味着产品不够好;“很好”,那就意味着还需要努力;产品目标只为“最好”。\n```\nWish you every day to be beautiful.\n```\n书客编辑器期待你的加入!!!\n\n![书客编辑器](http://editor.ibooker.cc/resources/images-logos/ic_launcher_96.png)\n![书客创作](http://www.ibookerfile.cc/upload/images/acontents/1_1519218464761acontentimage.jpg)");
}
Also used : SslErrorHandler(android.webkit.SslErrorHandler) WebResourceRequest(android.webkit.WebResourceRequest) SslError(android.net.http.SslError) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Bitmap(android.graphics.Bitmap) IbookerEditorWebView(cc.ibooker.ibookereditorlib.IbookerEditorWebView) WebResourceError(android.webkit.WebResourceError) IbookerEditorWebView(cc.ibooker.ibookereditorlib.IbookerEditorWebView) WebView(android.webkit.WebView)

Aggregations

WebResourceError (android.webkit.WebResourceError)27 WebResourceRequest (android.webkit.WebResourceRequest)27 WebView (android.webkit.WebView)27 WebViewClient (android.webkit.WebViewClient)26 Bitmap (android.graphics.Bitmap)18 SuppressLint (android.annotation.SuppressLint)11 WebSettings (android.webkit.WebSettings)10 WebChromeClient (android.webkit.WebChromeClient)9 SslError (android.net.http.SslError)8 SslErrorHandler (android.webkit.SslErrorHandler)8 WebResourceResponse (android.webkit.WebResourceResponse)7 View (android.view.View)6 Intent (android.content.Intent)5 Uri (android.net.Uri)5 TargetApi (android.annotation.TargetApi)4 TextView (android.widget.TextView)3 Nullable (android.support.annotation.Nullable)2 MotionEvent (android.view.MotionEvent)2 JavascriptInterface (android.webkit.JavascriptInterface)2 JsPromptResult (android.webkit.JsPromptResult)2