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.commontime.plugin.LocationManager.java

License:Apache License

private void registerDelegateCallbackId(JSONObject arguments, final CallbackContext callbackContext) {

    _handleCallSafely(callbackContext, new ILocationManagerCommand() {

        @Override/*w  w w  .  j av  a  2s .co  m*/
        public PluginResult run() {
            debugLog("Registering delegate callback ID: " + callbackContext.getCallbackId());
            //delegateCallbackId = callbackContext.getCallbackId();

            createMonitorCallbacks(callbackContext);
            createRangingCallbacks(callbackContext);
            createManagerCallbacks(callbackContext);

            PluginResult result = new PluginResult(PluginResult.Status.OK);
            result.setKeepCallback(true);
            return result;
        }
    });

}

From source file:com.commontime.plugin.LocationManager.java

License:Apache License

private void isMonitoringAvailableForClass(final JSONObject arguments, final CallbackContext callbackContext) {
    _handleCallSafely(callbackContext, new ILocationManagerCommand() {

        @Override//from  ww  w  . j a v  a  2  s.c o  m
        public PluginResult run() {

            boolean isValid = true;
            try {
                parseRegion(arguments);
            } catch (Exception e) {
                //will fail is the region is circular or some expected structure is missing 
                isValid = false;
            }

            PluginResult result = new PluginResult(PluginResult.Status.OK, isValid);
            result.setKeepCallback(true);
            return result;

        }
    });
}

From source file:com.commontime.plugin.LocationManager.java

License:Apache License

private void isAdvertisingAvailable(CallbackContext callbackContext) {

    _handleCallSafely(callbackContext, new ILocationManagerCommand() {
        @Override/*from w ww  . jav  a2 s.c  o m*/
        public PluginResult run() {

            //not supported at Android yet (see Android L)
            PluginResult result = new PluginResult(PluginResult.Status.OK, false);
            result.setKeepCallback(true);
            return result;

        }
    });

}

From source file:com.commontime.plugin.LocationManager.java

License:Apache License

private void isAdvertising(CallbackContext callbackContext) {

    _handleCallSafely(callbackContext, new ILocationManagerCommand() {
        @Override/*from  w w w .  j  a  va2 s.  c om*/
        public PluginResult run() {

            //not supported on Android
            PluginResult result = new PluginResult(PluginResult.Status.OK, false);
            result.setKeepCallback(true);
            return result;

        }
    });

}

From source file:com.commontime.plugin.LocationManager.java

License:Apache License

private void startAdvertising(JSONObject arguments, CallbackContext callbackContext) {

    _handleCallSafely(callbackContext, new ILocationManagerCommand() {
        @Override/*from   www .  j  a  va 2  s.  c o  m*/
        public PluginResult run() {

            //not supported on Android
            PluginResult result = new PluginResult(PluginResult.Status.ERROR,
                    "iBeacon Advertising is not supported on Android");
            result.setKeepCallback(true);
            return result;
        }
    });

}

From source file:com.commontime.plugin.LocationManager.java

License:Apache License

private void stopAdvertising(CallbackContext callbackContext) {

    _handleCallSafely(callbackContext, new ILocationManagerCommand() {
        @Override//  ww  w. ja  v a2  s.  com
        public PluginResult run() {

            //not supported on Android
            PluginResult result = new PluginResult(PluginResult.Status.ERROR,
                    "iBeacon Advertising is not supported on Android");
            result.setKeepCallback(true);
            return result;

        }
    });
}

From source file:com.connectsdk.cordova.ConnectSDKCordova.java

License:Apache License

public void sendEvent(CallbackContext callbackContext, String event, Object... objs) {
    if (callbackContext != null) {
        PluginResult result;

        JSONArray arr = new JSONArray();
        arr.put(event);//from ww w  .  j a va  2  s .  c  om

        for (Object obj : objs) {
            arr.put(obj);
        }

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

From source file:com.connectsdk.cordova.ConnectSDKCordova.java

License:Apache License

public void sendErrorEvent(CallbackContext callbackContext, ServiceCommandError error) {
    if (callbackContext != null) {
        JSONObject errorObj = new JSONObject();

        try {/*from  www .  j a  v a 2s.co m*/
            errorObj.put("message", error.getMessage());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        PluginResult result = new PluginResult(PluginResult.Status.ERROR, errorObj);
        result.setKeepCallback(true);
        callbackContext.sendPluginResult(result);
    }
}

From source file:com.connectsdk.cordova.JSCommand.java

License:Apache License

void sendSuccessEvent(Object... objs) {
    if (callbackContext == null)
        return;//from   w w  w .j  a  va2s  .  c o m

    JSONArray arr = new JSONArray();
    arr.put("success");

    for (Object o : objs) {
        arr.put(o);
    }

    if (subscription) {
        PluginResult pendingResult = new PluginResult(PluginResult.Status.OK, arr);
        pendingResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pendingResult);
    } else {
        callbackContext.success(arr);
        checkDone();
    }
}

From source file:com.cooee.cordova.plugins.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.
 *//*www.  j  av a2  s.  com*/
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.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.takePicture(destType, encodingType);
            } else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
                this.getImage(srcType, destType, encodingType);
            }
        } 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;
}