org.apache.cordova.PluginResult - java examples

Here are the examples of the java api org.apache.cordova.PluginResult taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : NativeToJsMessageQueue.java
Copyright MIT License
Author : xyqfer
/**
 * Add a JavaScript statement to the list.
 */
public void addPluginResult(PluginResult result, String callbackId) {
    if (callbackId == null) {
        Log.e(LOG_TAG, "Got plugin result with no callbackId", new Throwable());
        return;
    }
    // Don't send anything if there is no result and there is no need to
    // clear the callbacks.
    boolean noResult = result.getStatus() == PluginResult.Status.NO_RESULT.ordinal();
    boolean keepCallback = result.getKeepCallback();
    if (noResult && keepCallback) {
        return;
    }
    JsMessage message = new JsMessage(result, callbackId);
    if (FORCE_ENCODE_USING_EVAL) {
        StringBuilder sb = new StringBuilder(message.calculateEncodedLength() + 50);
        message.encodeAsJsMessage(sb);
        message = new JsMessage(sb.toString());
    }
    enqueueMessage(message);
}

19 View Complete Implementation : InAppBrowser.java
Copyright MIT License
Author : demianborba
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param obj a JSONObject contain event payload information
 * @param status the status code to return to the JavaScript environment
 */
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
    if (callbackContext != null) {
        PluginResult result = new PluginResult(status, obj);
        result.setKeepCallback(keepCallback);
        callbackContext.sendPluginResult(result);
        if (!keepCallback) {
            callbackContext = null;
        }
    }
}

19 View Complete Implementation : NetworkManager.java
Copyright MIT License
Author : xyqfer
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param connection the network info to set as navigator.connection
 */
private void sendUpdate(String type) {
    if (connectionCallbackContext != null) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, type);
        result.setKeepCallback(true);
        connectionCallbackContext.sendPluginResult(result);
    }
    webView.postMessage("networkconnection", type);
}

19 View Complete Implementation : NativeToJsMessageQueue.java
Copyright MIT License
Author : xyqfer
/**
 * Add a JavaScript statement to the list.
 */
public void addPluginResult(PluginResult result, String callbackId) {
    if (callbackId == null) {
        Log.e(LOG_TAG, "Got plugin result with no callbackId", new Throwable());
        return;
    }
    // Don't send anything if there is no result and there is no need to
    // clear the callbacks.
    boolean noResult = result.getStatus() == PluginResult.Status.NO_RESULT.ordinal();
    boolean keepCallback = result.getKeepCallback();
    if (noResult && keepCallback) {
        return;
    }
    JsMessage message = new JsMessage(result, callbackId);
    if (FORCE_ENCODE_USING_EVAL) {
        StringBuilder sb = new StringBuilder(message.calculateEncodedLength() + 50);
        message.encodeAsJsMessage(sb);
        message = new JsMessage(sb.toString());
    }
    enqueueMessage(message);
}

19 View Complete Implementation : NetworkManager.java
Copyright MIT License
Author : xyqfer
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param connection the network info to set as navigator.connection
 */
private void sendUpdate(String type) {
    if (connectionCallbackContext != null) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, type);
        result.setKeepCallback(true);
        connectionCallbackContext.sendPluginResult(result);
    }
    webView.postMessage("networkconnection", type);
}

19 View Complete Implementation : InAppBrowser.java
Copyright MIT License
Author : xyqfer
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param obj a JSONObject contain event payload information
 * @param status the status code to return to the JavaScript environment
 */
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
    if (callbackContext != null) {
        PluginResult result = new PluginResult(status, obj);
        result.setKeepCallback(keepCallback);
        callbackContext.sendPluginResult(result);
        if (!keepCallback) {
            callbackContext = null;
        }
    }
}

19 View Complete Implementation : NativeToJsMessageQueue.java
Copyright MIT License
Author : demianborba
/**
 * Add a JavaScript statement to the list.
 */
public void addPluginResult(PluginResult result, String callbackId) {
    if (callbackId == null) {
        Log.e(LOG_TAG, "Got plugin result with no callbackId", new Throwable());
        return;
    }
    // Don't send anything if there is no result and there is no need to
    // clear the callbacks.
    boolean noResult = result.getStatus() == PluginResult.Status.NO_RESULT.ordinal();
    boolean keepCallback = result.getKeepCallback();
    if (noResult && keepCallback) {
        return;
    }
    JsMessage message = new JsMessage(result, callbackId);
    if (FORCE_ENCODE_USING_EVAL) {
        StringBuilder sb = new StringBuilder(message.calculateEncodedLength() + 50);
        message.encodeAsJsMessage(sb);
        message = new JsMessage(sb.toString());
    }
    enqueueMessage(message);
}

19 View Complete Implementation : InAppBrowser.java
Copyright MIT License
Author : xyqfer
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param obj a JSONObject contain event payload information
 * @param status the status code to return to the JavaScript environment
 */
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
    if (callbackContext != null) {
        PluginResult result = new PluginResult(status, obj);
        result.setKeepCallback(keepCallback);
        callbackContext.sendPluginResult(result);
        if (!keepCallback) {
            callbackContext = null;
        }
    }
}

19 View Complete Implementation : CordovaWebView.java
Copyright MIT License
Author : demianborba
/**
 * Send a plugin result back to JavaScript.
 * (This is a convenience method)
 *
 * @param result
 * @param callbackId
 */
public void sendPluginResult(PluginResult result, String callbackId) {
    this.jsMessageQueue.addPluginResult(result, callbackId);
}

19 View Complete Implementation : NetworkManager.java
Copyright MIT License
Author : xyqfer
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param connection the network info to set as navigator.connection
 */
private void sendUpdate(String type) {
    if (connectionCallbackContext != null) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, type);
        result.setKeepCallback(true);
        connectionCallbackContext.sendPluginResult(result);
    }
    webView.postMessage("networkconnection", type);
}

19 View Complete Implementation : InAppBrowser.java
Copyright MIT License
Author : xyqfer
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param obj a JSONObject contain event payload information
 * @param status the status code to return to the JavaScript environment
 */
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
    if (callbackContext != null) {
        PluginResult result = new PluginResult(status, obj);
        result.setKeepCallback(keepCallback);
        callbackContext.sendPluginResult(result);
        if (!keepCallback) {
            callbackContext = null;
        }
    }
}

19 View Complete Implementation : InAppBrowser.java
Copyright MIT License
Author : xyqfer
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param obj a JSONObject contain event payload information
 * @param status the status code to return to the JavaScript environment
 */
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
    if (callbackContext != null) {
        PluginResult result = new PluginResult(status, obj);
        result.setKeepCallback(keepCallback);
        callbackContext.sendPluginResult(result);
        if (!keepCallback) {
            callbackContext = null;
        }
    }
}

19 View Complete Implementation : InAppBrowser.java
Copyright MIT License
Author : demianborba
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param obj a JSONObject contain event payload information
 * @param status the status code to return to the JavaScript environment
 */
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
    if (callbackContext != null) {
        PluginResult result = new PluginResult(status, obj);
        result.setKeepCallback(keepCallback);
        callbackContext.sendPluginResult(result);
        if (!keepCallback) {
            callbackContext = null;
        }
    }
}

19 View Complete Implementation : InAppBrowser.java
Copyright MIT License
Author : demianborba
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param obj a JSONObject contain event payload information
 * @param status the status code to return to the JavaScript environment
 */
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
    if (callbackContext != null) {
        PluginResult result = new PluginResult(status, obj);
        result.setKeepCallback(keepCallback);
        callbackContext.sendPluginResult(result);
        if (!keepCallback) {
            callbackContext = null;
        }
    }
}

19 View Complete Implementation : NetworkManager.java
Copyright MIT License
Author : xyqfer
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param connection the network info to set as navigator.connection
 */
private void sendUpdate(String type) {
    if (connectionCallbackContext != null) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, type);
        result.setKeepCallback(true);
        connectionCallbackContext.sendPluginResult(result);
    }
    webView.postMessage("networkconnection", type);
}

18 View Complete Implementation : CallbackProgressDialog.java
Copyright MIT License
Author : xyqfer
private void sendCallback() {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
}

18 View Complete Implementation : CallbackContext.java
Copyright MIT License
Author : zhangyd-c
public void sendPluginResult(PluginResult pluginResult) {
    synchronized (this) {
        if (finished) {
            LOG.w(LOG_TAG, "Attempted to send a second callback for ID: " + callbackId + "\nResult was: " + pluginResult.getMessage());
            return;
        } else {
            finished = !pluginResult.getKeepCallback();
        }
    }
    webView.sendPluginResult(pluginResult, callbackId);
}

18 View Complete Implementation : CallbackProgressDialog.java
Copyright MIT License
Author : xyqfer
private void sendCallback() {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
}

18 View Complete Implementation : CallbackProgressDialog.java
Copyright MIT License
Author : xyqfer
private void sendCallback() {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
}

18 View Complete Implementation : HotCodePushPlugin.java
Copyright MIT License
Author : zhangyd-c
/**
 * Dispatch stored events for the default callback.
 */
private void dispatchDefaultCallbackStoredResults() {
    if (defaultCallbackStoredResults.size() == 0 || jsDefaultCallback == null) {
        return;
    }
    for (PluginResult result : defaultCallbackStoredResults) {
        sendMessageToDefaultCallback(result);
    }
    defaultCallbackStoredResults.clear();
}

18 View Complete Implementation : AmazonPurchasingObserver.java
Copyright MIT License
Author : tikurahul
@Override
public void onGetUserIdResponse(final GetUserIdResponse userIdResponse) {
    if (userIdResponse == null) {
        // should never happen
        throw new AmazonInAppException("'null' userId response.");
    }
    final String requestId = userIdResponse.getRequestId();
    final String callbackId = requestCallbacks.remove(requestId);
    try {
        final JSONObject jobj = new JSONObject();
        final GetUserIdRequestStatus userIdRequestStatus = userIdResponse.getUserIdRequestStatus();
        jobj.put("requestId", userIdResponse.getRequestId());
        jobj.put("userIdRequestStatus", userIdRequestStatus);
        if (userIdRequestStatus == GetUserIdRequestStatus.SUCCESSFUL) {
            jobj.put("userId", userIdResponse.getUserId());
        }
        final PluginResult pluginInResult = new PluginResult(Status.OK, jobj);
        pluginInResult.setKeepCallback(false);
        plugin.webView.sendPluginResult(pluginInResult, callbackId);
    } catch (final JSONException e) {
        Log.d("MINE", e.getMessage());
        final PluginResult pluginInResult = new PluginResult(Status.JSON_EXCEPTION);
        pluginInResult.setKeepCallback(false);
        plugin.webView.sendPluginResult(pluginInResult, callbackId);
    }
}

18 View Complete Implementation : HotCodePushPlugin.java
Copyright MIT License
Author : zhangyd-c
/**
 * Dispatch stored events for the default callback.
 */
private void dispatchDefaultCallbackStoredResults() {
    if (defaultCallbackStoredResults.size() == 0 || jsDefaultCallback == null) {
        return;
    }
    for (PluginResult result : defaultCallbackStoredResults) {
        sendMessageToDefaultCallback(result);
    }
    defaultCallbackStoredResults.clear();
}

18 View Complete Implementation : CallbackProgressDialog.java
Copyright MIT License
Author : xyqfer
private void sendCallback() {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
}

18 View Complete Implementation : CallbackContext.java
Copyright MIT License
Author : zhangyd-c
public void sendPluginResult(PluginResult pluginResult) {
    synchronized (this) {
        if (finished) {
            LOG.w(LOG_TAG, "Attempted to send a second callback for ID: " + callbackId + "\nResult was: " + pluginResult.getMessage());
            return;
        } else {
            finished = !pluginResult.getKeepCallback();
        }
    }
    webView.sendPluginResult(pluginResult, callbackId);
}

18 View Complete Implementation : HotCodePushPlugin.java
Copyright MIT License
Author : zhangyd-c
/**
 * Dispatch stored events for the default callback.
 */
private void dispatchDefaultCallbackStoredResults() {
    if (defaultCallbackStoredResults.size() == 0 || jsDefaultCallback == null) {
        return;
    }
    for (PluginResult result : defaultCallbackStoredResults) {
        sendMessageToDefaultCallback(result);
    }
    defaultCallbackStoredResults.clear();
}

17 View Complete Implementation : LocalNotification.java
Copyright MIT License
Author : zhangyd-c
/**
 * Ask if user has enabled permission for local notifications.
 *
 * @param command The callback context used when calling back into
 *                JavaScript.
 */
private void check(CallbackContext command) {
    boolean allowed = getNotMgr().hasPermission();
    PluginResult result = new PluginResult(PluginResult.Status.OK, allowed);
    command.sendPluginResult(result);
}

17 View Complete Implementation : LocalNotification.java
Copyright MIT License
Author : zhangyd-c
/**
 * Ask if user has enabled permission for local notifications.
 *
 * @param command The callback context used when calling back into
 *                JavaScript.
 */
private void check(CallbackContext command) {
    boolean allowed = getNotMgr().hasPermission();
    PluginResult result = new PluginResult(PluginResult.Status.OK, allowed);
    command.sendPluginResult(result);
}

17 View Complete Implementation : CallbackContext.java
Copyright MIT License
Author : xyqfer
public void sendPluginResult(PluginResult pluginResult) {
    synchronized (this) {
        if (finished) {
            Log.w(LOG_TAG, "Attempted to send a second callback for ID: " + callbackId + "\nResult was: " + pluginResult.getMessage());
            return;
        } else {
            finished = !pluginResult.getKeepCallback();
        }
    }
    webView.sendPluginResult(pluginResult, callbackId);
}

17 View Complete Implementation : CallbackContext.java
Copyright MIT License
Author : demianborba
public void sendPluginResult(PluginResult pluginResult) {
    synchronized (this) {
        if (finished) {
            Log.w(LOG_TAG, "Attempted to send a second callback for ID: " + callbackId + "\nResult was: " + pluginResult.getMessage());
            return;
        } else {
            finished = !pluginResult.getKeepCallback();
        }
    }
    webView.sendPluginResult(pluginResult, callbackId);
}

17 View Complete Implementation : PluginManager.java
Copyright MIT License
Author : demianborba
private void execHelper(final String service, final String action, final String callbackId, final String rawArgs) {
    CordovaPlugin plugin = getPlugin(service);
    if (plugin == null) {
        Log.d(TAG, "exec() call to unknown plugin: " + service);
        PluginResult cr = new PluginResult(PluginResult.Status.CLreplaced_NOT_FOUND_EXCEPTION);
        app.sendPluginResult(cr, callbackId);
        return;
    }
    try {
        CallbackContext callbackContext = new CallbackContext(callbackId, app);
        long pluginStartTime = System.currentTimeMillis();
        boolean wasValidAction = plugin.execute(action, rawArgs, callbackContext);
        long duration = System.currentTimeMillis() - pluginStartTime;
        if (duration > SLOW_EXEC_WARNING_THRESHOLD) {
            Log.w(TAG, "THREAD WARNING: exec() call to " + service + "." + action + " blocked the main thread for " + duration + "ms. Plugin should use CordovaInterface.getThreadPool().");
        }
        if (!wasValidAction) {
            PluginResult cr = new PluginResult(PluginResult.Status.INVALID_ACTION);
            app.sendPluginResult(cr, callbackId);
        }
    } catch (JSONException e) {
        PluginResult cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
        app.sendPluginResult(cr, callbackId);
    }
}

17 View Complete Implementation : LocalNotification.java
Copyright MIT License
Author : zhangyd-c
/**
 * Ask if user has enabled permission for local notifications.
 *
 * @param command The callback context used when calling back into
 *                JavaScript.
 */
private void check(CallbackContext command) {
    boolean allowed = getNotMgr().hasPermission();
    PluginResult result = new PluginResult(PluginResult.Status.OK, allowed);
    command.sendPluginResult(result);
}

17 View Complete Implementation : NetworkManager.java
Copyright MIT License
Author : xyqfer
/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false otherwise.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("getConnectionInfo")) {
        this.connectionCallbackContext = callbackContext;
        NetworkInfo info = sockMan.getActiveNetworkInfo();
        String connectionType = "";
        try {
            connectionType = this.getConnectionInfo(info).get("type").toString();
        } catch (JSONException e) {
        }
        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    }
    return false;
}

17 View Complete Implementation : NetworkManager.java
Copyright MIT License
Author : xyqfer
/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false otherwise.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("getConnectionInfo")) {
        this.connectionCallbackContext = callbackContext;
        NetworkInfo info = sockMan.getActiveNetworkInfo();
        String connectionType = "";
        try {
            connectionType = this.getConnectionInfo(info).get("type").toString();
        } catch (JSONException e) {
        }
        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    }
    return false;
}

17 View Complete Implementation : AmazonPurchasingObserver.java
Copyright MIT License
Author : tikurahul
@Override
public void onPurchaseUpdatesResponse(final PurchaseUpdatesResponse purchaseUpdatesResponse) {
    if (purchaseUpdatesResponse == null) {
        // should never happen
        throw new AmazonInAppException("'null' purchase updates response.");
    }
    final String requestId = purchaseUpdatesResponse.getRequestId();
    final String callbackId = requestCallbacks.remove(requestId);
    try {
        final AmazonPurchaseUpdatesResponse amazonPurchaseUpdatesResponse = new AmazonPurchaseUpdatesResponse(purchaseUpdatesResponse);
        final PluginResult pluginResult = new PluginResult(Status.OK, amazonPurchaseUpdatesResponse.toJSON());
        pluginResult.setKeepCallback(false);
        plugin.webView.sendPluginResult(pluginResult, callbackId);
    } catch (final JSONException e) {
        final PluginResult pluginInResult = new PluginResult(Status.JSON_EXCEPTION);
        pluginInResult.setKeepCallback(false);
        plugin.webView.sendPluginResult(pluginInResult, callbackId);
    }
}

17 View Complete Implementation : NetworkManager.java
Copyright MIT License
Author : xyqfer
/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false otherwise.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("getConnectionInfo")) {
        this.connectionCallbackContext = callbackContext;
        NetworkInfo info = sockMan.getActiveNetworkInfo();
        String connectionType = "";
        try {
            connectionType = this.getConnectionInfo(info).get("type").toString();
        } catch (JSONException e) {
        }
        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    }
    return false;
}

17 View Complete Implementation : PluginManager.java
Copyright MIT License
Author : tikurahul
private void execHelper(final String service, final String action, final String callbackId, final String rawArgs) {
    CordovaPlugin plugin = getPlugin(service);
    if (plugin == null) {
        Log.d(TAG, "exec() call to unknown plugin: " + service);
        PluginResult cr = new PluginResult(PluginResult.Status.CLreplaced_NOT_FOUND_EXCEPTION);
        app.sendPluginResult(cr, callbackId);
        return;
    }
    try {
        CallbackContext callbackContext = new CallbackContext(callbackId, app);
        long pluginStartTime = System.currentTimeMillis();
        boolean wasValidAction = plugin.execute(action, rawArgs, callbackContext);
        long duration = System.currentTimeMillis() - pluginStartTime;
        if (duration > SLOW_EXEC_WARNING_THRESHOLD) {
            Log.w(TAG, "THREAD WARNING: exec() call to " + service + "." + action + " blocked the main thread for " + duration + "ms. Plugin should use CordovaInterface.getThreadPool().");
        }
        if (!wasValidAction) {
            PluginResult cr = new PluginResult(PluginResult.Status.INVALID_ACTION);
            app.sendPluginResult(cr, callbackId);
        }
    } catch (JSONException e) {
        PluginResult cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
        app.sendPluginResult(cr, callbackId);
    }
}

17 View Complete Implementation : CallbackContext.java
Copyright MIT License
Author : xyqfer
public void sendPluginResult(PluginResult pluginResult) {
    synchronized (this) {
        if (finished) {
            Log.w(LOG_TAG, "Attempted to send a second callback for ID: " + callbackId + "\nResult was: " + pluginResult.getMessage());
            return;
        } else {
            finished = !pluginResult.getKeepCallback();
        }
    }
    webView.sendPluginResult(pluginResult, callbackId);
}

17 View Complete Implementation : CallbackContext.java
Copyright MIT License
Author : tikurahul
public void sendPluginResult(PluginResult pluginResult) {
    synchronized (this) {
        if (finished) {
            Log.w(LOG_TAG, "Attempted to send a second callback for ID: " + callbackId + "\nResult was: " + pluginResult.getMessage());
            return;
        } else {
            finished = !pluginResult.getKeepCallback();
        }
    }
    webView.sendPluginResult(pluginResult, callbackId);
}

17 View Complete Implementation : NetworkManager.java
Copyright MIT License
Author : xyqfer
/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false otherwise.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("getConnectionInfo")) {
        this.connectionCallbackContext = callbackContext;
        NetworkInfo info = sockMan.getActiveNetworkInfo();
        String connectionType = "";
        try {
            connectionType = this.getConnectionInfo(info).get("type").toString();
        } catch (JSONException e) {
        }
        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    }
    return false;
}

17 View Complete Implementation : AmazonPurchasingObserver.java
Copyright MIT License
Author : tikurahul
@Override
public void onPurchaseUpdatesResponse(final PurchaseUpdatesResponse purchaseUpdatesResponse) {
    if (purchaseUpdatesResponse == null) {
        // should never happen
        throw new AmazonInAppException("'null' purchase updates response.");
    }
    final String requestId = purchaseUpdatesResponse.getRequestId();
    final String callbackId = requestCallbacks.remove(requestId);
    try {
        final AmazonPurchaseUpdatesResponse amazonPurchaseUpdatesResponse = new AmazonPurchaseUpdatesResponse(purchaseUpdatesResponse);
        final PluginResult pluginResult = new PluginResult(Status.OK, amazonPurchaseUpdatesResponse.toJSON());
        pluginResult.setKeepCallback(false);
        plugin.webView.sendPluginResult(pluginResult, callbackId);
    } catch (final JSONException e) {
        final PluginResult pluginInResult = new PluginResult(Status.JSON_EXCEPTION);
        pluginInResult.setKeepCallback(false);
        plugin.webView.sendPluginResult(pluginInResult, callbackId);
    }
}

16 View Complete Implementation : InAppChromeClient.java
Copyright MIT License
Author : zhangyd-c
/**
 * Tell the client to display a prompt dialog to the user.
 * If the client returns true, WebView will replacedume that the client will
 * handle the prompt dialog and call the appropriate JsPromptResult method.
 *
 * The prompt bridge provided for the InAppBrowser is capable of executing any
 * oustanding callback belonging to the InAppBrowser plugin. Care has been
 * taken that other callbacks cannot be triggered, and that no other code
 * execution is possible.
 *
 * To trigger the bridge, the prompt default value should be of the form:
 *
 * gap-iab://<callbackId>
 *
 * where <callbackId> is the string id of the callback to trigger (something
 * like "InAppBrowser0123456789")
 *
 * If present, the prompt message is expected to be a JSON-encoded value to
 * preplaced to the callback. A JSON_EXCEPTION is returned if the JSON is invalid.
 *
 * @param view
 * @param url
 * @param message
 * @param defaultValue
 * @param result
 */
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
    // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute.
    if (defaultValue != null && defaultValue.startsWith("gap")) {
        if (defaultValue.startsWith("gap-iab://")) {
            PluginResult scriptResult;
            String scriptCallbackId = defaultValue.substring(10);
            if (scriptCallbackId.startsWith("InAppBrowser")) {
                if (message == null || message.length() == 0) {
                    scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray());
                } else {
                    try {
                        scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message));
                    } catch (JSONException e) {
                        scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
                    }
                }
                this.webView.sendPluginResult(scriptResult, scriptCallbackId);
                result.confirm("");
                return true;
            }
        } else {
            // Anything else with a gap: prefix should get this message
            LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue);
            result.cancel();
            return true;
        }
    }
    return false;
}

16 View Complete Implementation : InAppChromeClient.java
Copyright MIT License
Author : zhangyd-c
/**
 * Tell the client to display a prompt dialog to the user.
 * If the client returns true, WebView will replacedume that the client will
 * handle the prompt dialog and call the appropriate JsPromptResult method.
 *
 * The prompt bridge provided for the InAppBrowser is capable of executing any
 * oustanding callback belonging to the InAppBrowser plugin. Care has been
 * taken that other callbacks cannot be triggered, and that no other code
 * execution is possible.
 *
 * To trigger the bridge, the prompt default value should be of the form:
 *
 * gap-iab://<callbackId>
 *
 * where <callbackId> is the string id of the callback to trigger (something
 * like "InAppBrowser0123456789")
 *
 * If present, the prompt message is expected to be a JSON-encoded value to
 * preplaced to the callback. A JSON_EXCEPTION is returned if the JSON is invalid.
 *
 * @param view
 * @param url
 * @param message
 * @param defaultValue
 * @param result
 */
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
    // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute.
    if (defaultValue != null && defaultValue.startsWith("gap")) {
        if (defaultValue.startsWith("gap-iab://")) {
            PluginResult scriptResult;
            String scriptCallbackId = defaultValue.substring(10);
            if (scriptCallbackId.startsWith("InAppBrowser")) {
                if (message == null || message.length() == 0) {
                    scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray());
                } else {
                    try {
                        scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message));
                    } catch (JSONException e) {
                        scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
                    }
                }
                this.webView.sendPluginResult(scriptResult, scriptCallbackId);
                result.confirm("");
                return true;
            }
        } else {
            // Anything else with a gap: prefix should get this message
            LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue);
            result.cancel();
            return true;
        }
    }
    return false;
}

16 View Complete Implementation : HotCodePushPlugin.java
Copyright MIT License
Author : zhangyd-c
/**
 * Send message to default plugin callback.
 * Default callback - is a callback that we receive on initialization (device ready).
 * Through it we are broadcasting different events.
 * <p/>
 * If callback is not set yet - message will be stored until it is initialized.
 *
 * @param message message to send to web side
 * @return true if message was sent; false - otherwise
 */
private boolean sendMessageToDefaultCallback(final PluginResult message) {
    if (jsDefaultCallback == null) {
        defaultCallbackStoredResults.add(message);
        return false;
    }
    message.setKeepCallback(true);
    jsDefaultCallback.sendPluginResult(message);
    return true;
}

16 View Complete Implementation : InAppChromeClient.java
Copyright MIT License
Author : zhangyd-c
/**
 * Tell the client to display a prompt dialog to the user.
 * If the client returns true, WebView will replacedume that the client will
 * handle the prompt dialog and call the appropriate JsPromptResult method.
 *
 * The prompt bridge provided for the InAppBrowser is capable of executing any
 * oustanding callback belonging to the InAppBrowser plugin. Care has been
 * taken that other callbacks cannot be triggered, and that no other code
 * execution is possible.
 *
 * To trigger the bridge, the prompt default value should be of the form:
 *
 * gap-iab://<callbackId>
 *
 * where <callbackId> is the string id of the callback to trigger (something
 * like "InAppBrowser0123456789")
 *
 * If present, the prompt message is expected to be a JSON-encoded value to
 * preplaced to the callback. A JSON_EXCEPTION is returned if the JSON is invalid.
 *
 * @param view
 * @param url
 * @param message
 * @param defaultValue
 * @param result
 */
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
    // See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute.
    if (defaultValue != null && defaultValue.startsWith("gap")) {
        if (defaultValue.startsWith("gap-iab://")) {
            PluginResult scriptResult;
            String scriptCallbackId = defaultValue.substring(10);
            if (scriptCallbackId.startsWith("InAppBrowser")) {
                if (message == null || message.length() == 0) {
                    scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray());
                } else {
                    try {
                        scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message));
                    } catch (JSONException e) {
                        scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
                    }
                }
                this.webView.sendPluginResult(scriptResult, scriptCallbackId);
                result.confirm("");
                return true;
            }
        } else {
            // Anything else with a gap: prefix should get this message
            LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue);
            result.cancel();
            return true;
        }
    }
    return false;
}

16 View Complete Implementation : HotCodePushPlugin.java
Copyright MIT License
Author : zhangyd-c
/**
 * Send to JS side event with message, that plugin is installing replacedets on the external storage and not yet ready for work.
 * That happens only on the first launch.
 *
 * @param eventName event name, that is send to JS side
 * @param callback  JS callback
 */
private void sendPluginNotReadyToWork(String eventName, CallbackContext callback) {
    PluginResult pluginResult = PluginResultHelper.createPluginResult(eventName, null, ChcpError.replacedETS_FOLDER_IN_NOT_YET_INSTALLED);
    callback.sendPluginResult(pluginResult);
}

16 View Complete Implementation : HotCodePushPlugin.java
Copyright MIT License
Author : zhangyd-c
/**
 * Send to JS side event with message, that plugin is installing replacedets on the external storage and not yet ready for work.
 * That happens only on the first launch.
 *
 * @param eventName event name, that is send to JS side
 * @param callback  JS callback
 */
private void sendPluginNotReadyToWork(String eventName, CallbackContext callback) {
    PluginResult pluginResult = PluginResultHelper.createPluginResult(eventName, null, ChcpError.replacedETS_FOLDER_IN_NOT_YET_INSTALLED);
    callback.sendPluginResult(pluginResult);
}

16 View Complete Implementation : NativeToJsMessageQueueTest.java
Copyright MIT License
Author : zhangyd-c
// This test is for the evalBridge, which directly calls cordova.callbackFromNative, skipping
// platform specific NativeToJs code
@Test
public void testMultipartPopAndEncodeAsJs() {
    ArrayList<PluginResult> multiparts = new ArrayList<PluginResult>();
    for (int i = 0; i < 5; i++) {
        multiparts.add(new PluginResult(PluginResult.Status.OK, i));
    }
    PluginResult multipartresult = new PluginResult(PluginResult.Status.OK, multiparts);
    NativeToJsMessageQueue queue = new NativeToJsMessageQueue();
    queue.addBridgeMode(new NativeToJsMessageQueue.NoOpBridgeMode());
    queue.setBridgeMode(0);
    queue.addPluginResult(multipartresult, "37");
    String result = queue.popAndEncodeAsJs();
    replacedertEquals(result, "cordova.callbackFromNative('37',true,1,[0,1,2,3,4],false);");
}

16 View Complete Implementation : HotCodePushPlugin.java
Copyright MIT License
Author : zhangyd-c
/**
 * Send message to default plugin callback.
 * Default callback - is a callback that we receive on initialization (device ready).
 * Through it we are broadcasting different events.
 * <p/>
 * If callback is not set yet - message will be stored until it is initialized.
 *
 * @param message message to send to web side
 * @return true if message was sent; false - otherwise
 */
private boolean sendMessageToDefaultCallback(final PluginResult message) {
    if (jsDefaultCallback == null) {
        defaultCallbackStoredResults.add(message);
        return false;
    }
    message.setKeepCallback(true);
    jsDefaultCallback.sendPluginResult(message);
    return true;
}

16 View Complete Implementation : HotCodePushPlugin.java
Copyright MIT License
Author : zhangyd-c
/**
 * Send to JS side event with message, that plugin is installing replacedets on the external storage and not yet ready for work.
 * That happens only on the first launch.
 *
 * @param eventName event name, that is send to JS side
 * @param callback  JS callback
 */
private void sendPluginNotReadyToWork(String eventName, CallbackContext callback) {
    PluginResult pluginResult = PluginResultHelper.createPluginResult(eventName, null, ChcpError.replacedETS_FOLDER_IN_NOT_YET_INSTALLED);
    callback.sendPluginResult(pluginResult);
}

16 View Complete Implementation : HotCodePushPlugin.java
Copyright MIT License
Author : zhangyd-c
/**
 * Send message to default plugin callback.
 * Default callback - is a callback that we receive on initialization (device ready).
 * Through it we are broadcasting different events.
 * <p/>
 * If callback is not set yet - message will be stored until it is initialized.
 *
 * @param message message to send to web side
 * @return true if message was sent; false - otherwise
 */
private boolean sendMessageToDefaultCallback(final PluginResult message) {
    if (jsDefaultCallback == null) {
        defaultCallbackStoredResults.add(message);
        return false;
    }
    message.setKeepCallback(true);
    jsDefaultCallback.sendPluginResult(message);
    return true;
}