Search in sources :

Example 1 with CallBackFunction

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

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

the class JsbridgeWebFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    mBridgeWebView = new BridgeWebView(getActivity());
    mAgentWeb = AgentWeb.with(this).setAgentWebParent((ViewGroup) view, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)).useDefaultIndicator(-1, 2).setAgentWebWebSettings(getSettings()).setWebViewClient(getWebViewClient()).setWebChromeClient(mWebChromeClient).setWebView(mBridgeWebView).setSecurityType(AgentWeb.SecurityType.STRICT_CHECK).createAgentWeb().ready().go(getUrl());
    initView(view);
    mBridgeWebView.registerHandler("submitFromWeb", new BridgeHandler() {

        @Override
        public void handler(String data, CallBackFunction function) {
            function.onCallBack("submitFromWeb exe, response data δΈ­ζ–‡ from Java");
        }
    });
    User user = new User();
    Location location = new Location();
    location.address = "SDU";
    user.location = location;
    user.name = "Agentweb --> Jsbridge";
    mBridgeWebView.callHandler("functionInJs", new Gson().toJson(user), new CallBackFunction() {

        @Override
        public void onCallBack(String data) {
            Log.i(TAG, "data:" + data);
        }
    });
    mBridgeWebView.send("hello");
}
Also used : BridgeWebView(com.github.lzyzsd.jsbridge.BridgeWebView) BridgeHandler(com.github.lzyzsd.jsbridge.BridgeHandler) Gson(com.google.gson.Gson) CallBackFunction(com.github.lzyzsd.jsbridge.CallBackFunction) LinearLayout(android.widget.LinearLayout)

Aggregations

BridgeHandler (com.github.lzyzsd.jsbridge.BridgeHandler)2 CallBackFunction (com.github.lzyzsd.jsbridge.CallBackFunction)2 SuppressLint (android.annotation.SuppressLint)1 LinearLayout (android.widget.LinearLayout)1 BridgeWebView (com.github.lzyzsd.jsbridge.BridgeWebView)1 BridgeWebViewClient (com.github.lzyzsd.jsbridge.BridgeWebViewClient)1 DefaultHandler (com.github.lzyzsd.jsbridge.DefaultHandler)1 Gson (com.google.gson.Gson)1