Example usage for org.apache.cordova PluginResult setKeepCallback

List of usage examples for org.apache.cordova PluginResult setKeepCallback

Introduction

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

Prototype

public void setKeepCallback(boolean b) 

Source Link

Usage

From source file:io.ingame.squarecamera.CameraLauncher.java

License:Apache License

private void setOutputUri(Intent intent, Uri uri) {
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);

    JSONObject response;//from   w ww  .  j  a v  a 2s . com
    try {
        response = new JSONObject();
        response.put("uri", uri.toString());
        response.put("pending", true);
    } catch (JSONException e) {
        Log.e(LOG_TAG, "On pending result creation" + e);
        return;
    }

    PluginResult r = new PluginResult(PluginResult.Status.OK, response);
    r.setKeepCallback(true);
    callbackContext.sendPluginResult(r);
}

From source file:io.ionic.links.IonicDeeplink.java

License:Open Source License

private void sendToJs(JSONObject event, CallbackContext callback) {
    final PluginResult result = new PluginResult(PluginResult.Status.OK, event);
    result.setKeepCallback(true);
    callback.sendPluginResult(result);//from  w  w  w.  j a v a 2 s.c o m
}

From source file:io.jxcore.node.jxcore.java

License:Open Source License

public static void CreateResult(Object value, String callback_id, boolean async, boolean is_error) {
    PluginResult result;

    if (value == null) {
        result = new PluginResult(is_error ? Status.ERROR : Status.OK, 0);
    } else if (is_error) {
        result = new PluginResult(Status.ERROR, (String) value);
    } else if (value.getClass().equals(Integer.class)) {
        result = new PluginResult(Status.OK, (Integer) value);
    } else if (value.getClass().equals(Boolean.class)) {
        result = new PluginResult(Status.OK, (Boolean) value);
    } else if (value.getClass().equals(Double.class)) {
        result = new PluginResult(Status.OK, (Float) value);
    } else if (value.getClass().equals(String.class)) {
        result = new PluginResult(Status.OK, (String) value);
    } else if (value.getClass().equals(byte[].class)) {
        result = new PluginResult(Status.OK, ((byte[]) value));
    } else if (value.getClass().equals(String[].class)) {
        String[] arr = (String[]) value;
        try {/*ww w .j  a v a  2  s .  co  m*/
            result = new PluginResult(Status.OK, new JSONArray(arr[0]));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return;
        }
    } else {
        result = new PluginResult(Status.OK, value.toString());
    }

    if (async) {
        result.setKeepCallback(true);
        if (addon.callbacks.containsKey(callback_id)) {
            activity.runOnUiThread(new CoreRunnable(callback_id, result) {
                @Override
                public void run() {
                    CallbackContext ctx = addon.callbacks.get(callback_id_);
                    ctx.sendPluginResult(result_);
                }
            });
        }
    } else {
        CallbackContext ctx = addon.callbacks.remove(callback_id);
        ctx.sendPluginResult(result);
    }
}

From source file:io.jxcore.node.jxcore.java

License:Open Source License

@Override
public boolean execute(final String action, final JSONArray data, final CallbackContext callbackContext) {

    PluginResult result = null;
    try {/*  w  w  w . j a va 2  s. c  o  m*/
        if (action.equals("isReady")) {
            result = new PluginResult(Status.OK, jxcoreInitialized);
        } else if (action.equals("Evaluate")) {
            final String json = data.get(0).toString() + ", '" + callbackContext.getCallbackId() + "')";
            callbacks.put(callbackContext.getCallbackId(), callbackContext);

            result = new PluginResult(Status.NO_RESULT);
            result.setKeepCallback(true);

            coreThread.handler.post(new CoreRunnable(callbackContext.getCallbackId(), json) {
                @Override
                public void run() {
                    long res = evalEngine(str_param_);
                    if (res >= 0) {
                        String str_err = getString(res);

                        CreateResult(str_err, callback_id_, true, true);
                    }
                }
            });

        } else {
            result = new PluginResult(Status.OK);
        }
    } catch (Exception ex) {
        result = new PluginResult(Status.ERROR, ex.toString());
    }

    if (result != null)
        callbackContext.sendPluginResult(result);

    return true;
}

From source file:io.strider.camera.CameraLauncher.java

License:Apache License

/**
 * 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                 A PluginResult object with a status and message.
 *///w  w  w  .  j av  a 2  s  .co  m
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    this.callbackContext = callbackContext;

    if (action.equals("takePicture")) {
        int srcType = CAMERA;
        int destType = FILE_URI;
        this.saveToPhotoAlbum = false;
        this.targetHeight = 0;
        this.targetWidth = 0;
        this.encodingType = JPEG;
        this.mediaType = PICTURE;
        this.mQuality = 80;

        this.mQuality = args.getInt(0);
        destType = args.getInt(1);
        srcType = args.getInt(2);
        this.targetWidth = args.getInt(3);
        this.targetHeight = args.getInt(4);
        this.encodingType = args.getInt(5);
        this.mediaType = args.getInt(6);
        //this.allowEdit = args.getBoolean(7); // This field is unused.
        this.correctOrientation = args.getBoolean(8);
        this.saveToPhotoAlbum = args.getBoolean(9);

        // If the user specifies a 0 or smaller width/height
        // make it -1 so later comparisons succeed
        if (this.targetWidth < 1) {
            this.targetWidth = -1;
        }
        if (this.targetHeight < 1) {
            this.targetHeight = -1;
        }

        try {
            if (srcType == CAMERA) {
                this.cleanCache();
                this.takePicture(destType, encodingType);
            }
            //            else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
            //               this.getImage(srcType, destType);
            //            }
        } catch (IllegalArgumentException e) {
            callbackContext.error("Illegal Argument Exception");
            PluginResult r = new PluginResult(PluginResult.Status.ERROR);
            callbackContext.sendPluginResult(r);
            return true;
        }

        PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
        r.setKeepCallback(true);
        callbackContext.sendPluginResult(r);

        return true;

    } else if (action.equals("cleanup")) {
        try {
            this.cleanCache();
        } catch (IllegalArgumentException e) {
            callbackContext.error("Illegal Argument Exception");
            PluginResult r = new PluginResult(PluginResult.Status.ERROR);
            callbackContext.sendPluginResult(r);
            return true;
        }

        PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
        r.setKeepCallback(true);
        callbackContext.sendPluginResult(r);

        return true;
    }

    return false;
}

From source file:io.winch.phonegap.plugin.WinchPlugin.java

License:Open Source License

private void iterateAsString(final CallbackContext callbackContext, JSONArray args) {
    try {//  w  ww.  ja  v  a  2s  .  c  o m
        String namespace = args.getString(0);
        Enumerator it1 = new Enumerator() {
            public int next() {
                JSONObject obj = new JSONObject();
                try {
                    obj.put(KEY, key);
                    obj.put(DATA, new String(data));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                PluginResult r = new PluginResult(PluginResult.Status.OK, obj);
                r.setKeepCallback(true);
                callbackContext.sendPluginResult(r);
                return Enumerator.Code.NONE;
            }
        };
        mWinch.getNamespace(namespace).enumerate(it1);
    } catch (JSONException e1) {
        e1.printStackTrace();
    } catch (WinchError e) {
        e.log();
        PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage());
        callbackContext.sendPluginResult(r);
    }

    PluginResult r = new PluginResult(PluginResult.Status.OK, false);
    r.setKeepCallback(false);
    callbackContext.sendPluginResult(r);
}

From source file:io.winch.phonegap.plugin.WinchPlugin.java

License:Open Source License

private void iterateAsBase64(final CallbackContext callbackContext, JSONArray args) {
    try {//from  w  w w  .  j  a v  a2  s .  c o  m
        String namespace = args.getString(0);
        Enumerator it1 = new Enumerator() {
            public int next() {
                JSONObject obj = new JSONObject();
                try {
                    obj.put(KEY, key);
                    String base64 = Base64.encodeToString(data, Base64.NO_WRAP);
                    obj.put(DATA, base64);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                PluginResult r = new PluginResult(PluginResult.Status.OK, obj);
                r.setKeepCallback(true);
                callbackContext.sendPluginResult(r);
                return Enumerator.Code.NONE;
            }
        };
        mWinch.getNamespace(namespace).enumerate(it1);
    } catch (JSONException e1) {
        e1.printStackTrace();
    } catch (WinchError e) {
        e.log();
        PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage());
        callbackContext.sendPluginResult(r);
    }

    PluginResult r = new PluginResult(PluginResult.Status.OK, false);
    r.setKeepCallback(false);
    callbackContext.sendPluginResult(r);
}

From source file:io.winch.phonegap.plugin.WinchPlugin.java

License:Open Source License

private PluginResult buildProgressResult(int status, float progress, boolean keepCallback) {
    JSONObject obj = new JSONObject();
    try {/*w w w.  jav  a2s.co  m*/
        obj.put(STATUS, status);
        obj.put(PROGRESS, progress);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    PluginResult r = new PluginResult(PluginResult.Status.OK, obj);
    r.setKeepCallback(keepCallback);

    return r;
}

From source file:io.winch.phonegap.plugin.WinchPlugin.java

License:Open Source License

private PluginResult buildErrorResult(int errorCode, String errorMessage) {
    JSONObject obj = new JSONObject();
    try {//from  w w w. j  a  v a  2  s .  c o m
        obj.put(CODE, errorCode);
        obj.put(MESSAGE, errorMessage);
    } catch (JSONException e1) {
        e1.printStackTrace();
    }

    PluginResult r = new PluginResult(PluginResult.Status.ERROR, obj);
    r.setKeepCallback(false);

    return r;
}

From source file:it.alfonsovinti.cordova.plugins.bixolonprint.BixolonPrint.java

License:Open Source License

private void sendMsrTrackData(JSONObject obj, boolean keepCallback) {
    if (msrReaderCallbackContext != null) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
        result.setKeepCallback(keepCallback);
        this.msrReaderCallbackContext.sendPluginResult(result);
    }//from w  ww .ja  va 2s.  c  om
}