Search in sources :

Example 1 with BridgeWebViewClient

use of com.github.lzyzsd.jsbridge.BridgeWebViewClient in project LearnApp by YouCii.

the class WebFragment method onStart.

@Override
@SuppressLint("SetJavaScriptEnabled")
public void onStart() {
    super.onStart();
    numAdd.setOnClickListener(this);
    numDec.setOnClickListener(this);
    webSettings(webView);
    webView.setDefaultHandler(new DefaultHandler());
    webView.setWebViewClient(new BridgeWebViewClient(webView));
    webView.loadUrl("file:///android_asset/android.html");
    webView.addJavascriptInterface(new jsInterface(), "Android");
    webView.registerHandler("decNativeNum", new BridgeHandler() {

        @Override
        public void handler(String data, CallBackFunction function) {
            if (data.contains("啊啊")) {
                nativeNum.setText((Integer.parseInt(nativeNum.getText().toString()) - 1) + "");
            } else {
                ToastUtils.showShortToast(data);
            }
            function.onCallBack(data);
        }
    });
}
Also used : BridgeWebViewClient(com.github.lzyzsd.jsbridge.BridgeWebViewClient) BridgeHandler(com.github.lzyzsd.jsbridge.BridgeHandler) CallBackFunction(com.github.lzyzsd.jsbridge.CallBackFunction) DefaultHandler(com.github.lzyzsd.jsbridge.DefaultHandler) SuppressLint(android.annotation.SuppressLint)

Example 2 with BridgeWebViewClient

use of com.github.lzyzsd.jsbridge.BridgeWebViewClient in project AgentWeb by Justson.

the class JsbridgeWebFragment method getWebViewClient.

private WebViewClient getWebViewClient() {
    return new WebViewClient() {

        BridgeWebViewClient mBridgeWebViewClient = new BridgeWebViewClient(mBridgeWebView);

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

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            if (mBridgeWebViewClient.shouldOverrideUrlLoading(view, request.getUrl().toString())) {
                return true;
            } else {
                return super.shouldOverrideUrlLoading(view, request);
            }
        }

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

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mBridgeWebViewClient.onPageFinished(view, url);
        }
    };
}
Also used : Bitmap(android.graphics.Bitmap) WebResourceRequest(android.webkit.WebResourceRequest) BridgeWebViewClient(com.github.lzyzsd.jsbridge.BridgeWebViewClient) BridgeWebView(com.github.lzyzsd.jsbridge.BridgeWebView) WebView(android.webkit.WebView) BridgeWebViewClient(com.github.lzyzsd.jsbridge.BridgeWebViewClient) WebViewClient(com.just.agentweb.WebViewClient)

Aggregations

BridgeWebViewClient (com.github.lzyzsd.jsbridge.BridgeWebViewClient)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 WebResourceRequest (android.webkit.WebResourceRequest)1 WebView (android.webkit.WebView)1 BridgeHandler (com.github.lzyzsd.jsbridge.BridgeHandler)1 BridgeWebView (com.github.lzyzsd.jsbridge.BridgeWebView)1 CallBackFunction (com.github.lzyzsd.jsbridge.CallBackFunction)1 DefaultHandler (com.github.lzyzsd.jsbridge.DefaultHandler)1 WebViewClient (com.just.agentweb.WebViewClient)1