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:com.acuant.plugin.AcuantMobileSDK.java

@Override
public void tagReadFailed(final String tag_read_error_message) {
    cordova.getThreadPool().execute(new Runnable() {
        @Override/* www  . ja v a 2 s.  co m*/
        public void run() {
            try {
                JSONObject obj = new JSONObject();
                obj.put("id", "tagReadFailed");
                obj.put("errorType", ErrorType.AcuantErrorUnknown);
                obj.put("errorMessage", tag_read_error_message);
                PluginResult result = new PluginResult(PluginResult.Status.ERROR, obj);
                result.setKeepCallback(true);
                callbackId.sendPluginResult(result);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:com.adobe.phonegap.contentsync.Sync.java

License:Apache License

private void updateProgress(CallbackContext callbackContext, ProgressEvent progress) {
    try {//  ww w  . j a  v a 2  s  . c  o  m
        if (progress.getLoaded() != progress.getTotal() || progress.getStatus() == STATUS_COMPLETE) {
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progress.toJSONObject());
            pluginResult.setKeepCallback(true);
            callbackContext.sendPluginResult(pluginResult);
        }
    } catch (JSONException e) {
        // never happens
    }
}

From source file:com.adobe.phonegap.csdk.AssetBrowser.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 context from which we were invoked.
 *//*w  w  w.jav a2  s.c  o m*/
@SuppressLint("NewApi")
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    this.callbackContext = callbackContext;

    Log.d(LOG_TAG, "+++++++++++");

    if (action.equals("downloadFiles")) {
        // setup data source types
        JSONArray dataSourceTypes = args.getJSONArray(0);
        int typeLength = dataSourceTypes.length();
        int[] sources = new int[typeLength];
        for (int i = 0; i < typeLength; i++) {
            sources[i] = dataSourceTypes.getInt(i);
        }

        Log.d(LOG_TAG, ">>>>>>>>>>>>>>>>>>");

        // setup output file name
        downloadLocation = args.getString(1);

        Intent i = new Intent(cordova.getActivity(), AssetBrowserActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        i.putExtra("dataSources", sources);
        cordova.startActivityForResult(this, i, 0);

        PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
        r.setKeepCallback(true);
        callbackContext.sendPluginResult(r);
    } else if (action.equals("uploadFile")) {
        String url = args.getString(0);
        URL assetUrl = !url.startsWith("content") ? createURL(url)
                : createURL(FileHelper.getRealPath(cordova.getActivity(), Uri.parse(url)));
        String filename = assetUrl.getFile();
        String mimeType = FileHelper.getMimeType(url, cordova);
        String uploadName = args.getString(1);
        if (uploadName == null || "".equals(uploadName)) {
            uploadName = filename;
        }
        boolean overwrite = args.getBoolean(2);

        Log.d(LOG_TAG, "url: " + url);
        Log.d(LOG_TAG, "filename: " + filename);
        Log.d(LOG_TAG, "mimeType: " + mimeType);
        Log.d(LOG_TAG, "uploadName: " + uploadName);

        AdobeAssetFile.create(uploadName, AdobeAssetFolder.getRoot(), assetUrl, mimeType, uploadCallback, null);

    } else {
        return false;
    }
    return true;
}

From source file:com.adobe.phonegap.csdk.ImageEditor.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 context from which we were invoked.
*///from www.j a v  a  2s  .  co  m
@SuppressLint("NewApi")
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    this.callbackContext = callbackContext;

    if (action.equals("edit")) {
        String imageStr = args.getString(0);
        if (imageStr == null || "".equals(imageStr)) {
            this.callbackContext.error("Image Path must be specified");
        }
        Uri imageUri = Uri.parse(imageStr);

        AdobeImageIntent.Builder builder = new AdobeImageIntent.Builder(
                this.cordova.getActivity().getApplicationContext()).setData(imageUri);

        // setup options
        setOutputType(builder, args.getInt(1));
        setToolsArray(builder, args.getJSONArray(2));
        builder.withOutputQuality(args.getInt(3));
        builder.withNoExitConfirmation(args.getBoolean(4));
        builder.withOutputSize(MegaPixels.valueOf("Mp" + args.getString(5)));
        builder.saveWithNoChanges(args.getBoolean(6));
        builder.withVibrationEnabled(args.getBoolean(7));

        int color = args.getInt(8);
        if (color != 0) {
            builder.withAccentColor(color);
        }

        int previewSize = args.getInt(9);
        if (previewSize > 0) {
            builder.withPreviewSize(previewSize);
        }

        String outputFile = args.getString(10);
        if (!"".equals(outputFile)) {
            File fp = new File(outputFile);
            builder.withOutput(fp);
        }

        Intent imageEditorIntent = builder.build();

        this.cordova.startActivityForResult((CordovaPlugin) this, imageEditorIntent, 1);

        PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
        r.setKeepCallback(true);
        callbackContext.sendPluginResult(r);
    } else {
        return false;
    }
    return true;
}

From source file:com.android.plugins.GyroscopeListener.java

License:Open Source License

/**
 * Executes the request.//w  w w .  j av a  2s  .  com
 *
 * @param action        The action to execute.
 * @param args          The exec() arguments.
 * @param callbackId    The callback id used when calling back into JavaScript.
 * @return              Whether the action was valid.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("start")) {
        this.callbackContext = callbackContext;
        if (this.status != GyroscopeListener.RUNNING) {
            // If not running, then this is an async call, so don't worry about waiting
            // We drop the callback onto our stack, call start, and let start and the sensor callback fire off the callback down the road
            this.start();
        }
    } else if (action.equals("stop")) {
        if (this.status == GyroscopeListener.RUNNING) {
            this.stop();
        }
    } else {
        // Unsupported action
        return false;
    }

    PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, "");
    result.setKeepCallback(true);
    callbackContext.sendPluginResult(result);
    return true;
}

From source file:com.android.plugins.GyroscopeListener.java

License:Open Source License

private void fail(int code, String message) {
    // Error object
    JSONObject errorObj = new JSONObject();
    try {//from   w  w w .  ja  v  a2 s .co  m
        errorObj.put("code", code);
        errorObj.put("message", message);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    PluginResult err = new PluginResult(PluginResult.Status.ERROR, errorObj);
    err.setKeepCallback(true);
    callbackContext.sendPluginResult(err);
}

From source file:com.android.plugins.GyroscopeListener.java

License:Open Source License

private void win() {
    // Success return object
    PluginResult result = new PluginResult(PluginResult.Status.OK, this.getOrientationJSON());
    result.setKeepCallback(true);
    callbackContext.sendPluginResult(result);
}

From source file:com.android.plugins.MagnetometerListener.java

License:Open Source License

/**
 * Executes the request.//ww w  . jav  a  2s  .com
 *
 * @param action        The action to execute.
 * @param args          The exec() arguments.
 * @param callbackId    The callback id used when calling back into JavaScript.
 * @return              Whether the action was valid.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("start")) {
        this.callbackContext = callbackContext;
        if (this.status != MagnetometerListener.RUNNING) {
            // If not running, then this is an async call, so don't worry about waiting
            // We drop the callback onto our stack, call start, and let start and the sensor callback fire off the callback down the road
            this.start();
        }
    } else if (action.equals("stop")) {
        if (this.status == MagnetometerListener.RUNNING) {
            this.stop();
        }
    } else {
        // Unsupported action
        return false;
    }

    PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, "");
    result.setKeepCallback(true);
    callbackContext.sendPluginResult(result);
    return true;
}

From source file:com.blackberry.community.SimpleXpBeaconPlugin.java

License:Apache License

private void monitorSuccessResponse(CallbackContext callbackContext) throws JSONException {

    // {"desc":"...","status":"OK"}

    JSONObject response = new JSONObject();
    response.put(JSON_KEY_DESCRIPTION, JSON_VALUE_REQUESTED_MONITORING);
    response.put(JSON_KEY_STATUS, JSON_VALUE_OK);
    response.put(JSON_KEY_EVENT, JSON_VALUE_STARTED);

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

From source file:com.bsafe.sensors.motion.BSMotionSensorsPlugin.java

License:Apache License

/**
 * Executes the request./*from  w w w  .j  av a  2 s  . c o  m*/
 *
 * @param action        The action to execute.
 * @param args          The exec() arguments.
 * @param callbackId    The callback id used when calling back into JavaScript.
 * @return              Whether the action was valid.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("start")) {
        this.callbackContext = callbackContext;
        if (this.status != BSMotionSensorsPlugin.RUNNING) {
            // If not running, then this is an async call, so don't worry about waiting
            // We drop the callback onto our stack, call start, and let start and the sensor callback fire off the callback down the road
            this.start();
        }
    } else if (action.equals("stop")) {
        if (this.status == BSMotionSensorsPlugin.RUNNING) {
            this.stop();
        }
    } else {
        // Unsupported action
        return false;
    }

    PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, "");
    result.setKeepCallback(true);
    callbackContext.sendPluginResult(result);
    return true;
}