Android Open Source - JSBridge J S Bridge A P I Base






From Project

Back to project page JSBridge.

License

The source code is released under:

MIT License

If you think the Android project JSBridge listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.siva4u.jsbridge;
/*from ww w.  j  a v  a 2 s.  co m*/
import org.json.JSONObject;

import android.content.Context;
import android.webkit.WebView;

public class JSBridgeAPIBase {
  
    protected Context webViewContext;
    protected WebView webView;
    
    protected String callCallback(String inJsonStr, String outJsonStr) {
      return callCallback(JSBridge.getJSONObject(inJsonStr), outJsonStr);
    }
    protected String callCallback(String inJsonStr, JSONObject outJsonObj) {
      return callCallback(JSBridge.getJSONObject(inJsonStr), JSBridge.getString(outJsonObj));
    }
    protected String callCallback(JSONObject inJsonObj, final String outJsonStr) {
      final String callbackID = JSBridge.getString(inJsonObj, "callbackID");
      if(callbackID != null) {
        String str = JSBridge.getString(inJsonObj, "removeAfterExecute");
        if(str == null) str = "true";
        final String removeAfterExecute = str;
      webView.post(new Runnable() {
          @Override
          public void run() {
          webView.loadUrl("javascript: JSBridge._invokeJSCallback('"+callbackID+"',"+removeAfterExecute+",'"+outJsonStr+"');");
          }
      });
      return "";
      }
    return outJsonStr;
    }
    
    public JSBridgeAPIBase(Context c, WebView view) {
      webViewContext = c;
      webView = view;
    }    
}




Java Source Code List

com.siva4u.jsbridge.JSBridgeAPIBase.java
com.siva4u.jsbridge.JSBridgeCallback.java
com.siva4u.jsbridge.JSBridgeHandler.java
com.siva4u.jsbridge.JSBridgeInteface.java
com.siva4u.jsbridge.JSBridge.java
com.siva4u.jsbridge.example.TestAPIOne.java
com.siva4u.main.MainActivity.java