Example usage for org.apache.cordova CordovaBridge CordovaBridge

List of usage examples for org.apache.cordova CordovaBridge CordovaBridge

Introduction

In this page you can find the example usage for org.apache.cordova CordovaBridge CordovaBridge.

Prototype

public CordovaBridge(PluginManager pluginManager, NativeToJsMessageQueue jsMessageQueue) 

Source Link

Usage

From source file:com.zsxsoft.cordova.x5.X5WebViewEngine.java

License:Apache License

@Override
public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client,
        CordovaResourceApi resourceApi, PluginManager pluginManager,
        NativeToJsMessageQueue nativeToJsMessageQueue) {
    if (this.cordova != null) {
        throw new IllegalStateException();
    }/*  ww w  .  j  a va  2  s  .  com*/
    // Needed when prefs are not passed by the constructor
    if (preferences == null) {
        preferences = parentWebView.getPreferences();
    }
    this.parentWebView = parentWebView;
    this.cordova = cordova;
    this.client = client;
    this.resourceApi = resourceApi;
    this.pluginManager = pluginManager;
    this.nativeToJsMessageQueue = nativeToJsMessageQueue;
    webView.init(this, cordova);

    initWebViewSettings();

    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(
            new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
                @Override
                public void setNetworkAvailable(boolean value) {
                    webView.setNetworkAvailable(value);
                }

                @Override
                public void runOnUiThread(Runnable r) {
                    X5WebViewEngine.this.cordova.getActivity().runOnUiThread(r);
                }
            }));
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2)
        nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova));
    bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
    exposeJsInterface(webView, bridge);
}

From source file:org.crosswalk.engine.XWalkWebViewEngine.java

License:Apache License

@Override
public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client,
        CordovaResourceApi resourceApi, PluginManager pluginManager,
        NativeToJsMessageQueue nativeToJsMessageQueue) {
    if (this.cordova != null) {
        throw new IllegalStateException();
    }// w w w . j  a v  a  2 s . c om
    this.parentWebView = parentWebView;
    this.cordova = cordova;
    this.client = client;
    this.resourceApi = resourceApi;
    this.pluginManager = pluginManager;
    this.nativeToJsMessageQueue = nativeToJsMessageQueue;

    webView.init(this);

    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(
            new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
                @Override
                public void setNetworkAvailable(boolean value) {
                    webView.setNetworkAvailable(value);
                }

                @Override
                public void runOnUiThread(Runnable r) {
                    XWalkWebViewEngine.this.cordova.getActivity().runOnUiThread(r);
                }
            }));
    bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
}

From source file:org.jeremyup.cordova.x5engine.X5WebViewEngine.java

License:Apache License

@Override
public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client,
        CordovaResourceApi resourceApi, PluginManager pluginManager,
        NativeToJsMessageQueue nativeToJsMessageQueue) {
    if (this.cordova != null) {
        throw new IllegalStateException();
    }//from   w  w  w .jav  a  2  s.  c o m
    // Needed when prefs are not passed by the constructor
    if (preferences == null) {
        preferences = parentWebView.getPreferences();
    }
    this.parentWebView = parentWebView;
    this.cordova = cordova;
    this.client = client;
    this.resourceApi = resourceApi;
    this.pluginManager = pluginManager;
    this.nativeToJsMessageQueue = nativeToJsMessageQueue;
    webView.init(this, cordova);

    initWebViewSettings();

    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(
            new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
                @Override
                public void setNetworkAvailable(boolean value) {
                    webView.setNetworkAvailable(value);
                }

                @Override
                public void runOnUiThread(Runnable r) {
                    X5WebViewEngine.this.cordova.getActivity().runOnUiThread(r);
                }
            }));
    /* Pay attention:
     * Error maybe occur here!!!
     * If your cordova-android version below 6+,this method about EvalBridgeMode() may be not existed.
     * Please comment out below the lines 126-127.
    */
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2)
        nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova));
    bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
    exposeJsInterface(webView, bridge);
}