Search in sources :

Example 1 with DefaultHandler

use of com.github.lzyzsd.jsbridge.DefaultHandler 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)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 BridgeHandler (com.github.lzyzsd.jsbridge.BridgeHandler)1 BridgeWebViewClient (com.github.lzyzsd.jsbridge.BridgeWebViewClient)1 CallBackFunction (com.github.lzyzsd.jsbridge.CallBackFunction)1 DefaultHandler (com.github.lzyzsd.jsbridge.DefaultHandler)1