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.microsoft.azure.engagement.cordova.AZME.java

License:Open Source License

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {

    if (action.equals("enableURL")) {
        EngagementShared.instance().logD("enableURL=" + lastRedirect);
        PluginResult result = new PluginResult(PluginResult.Status.OK, lastRedirect);
        result.setKeepCallback(true);
        callbackContext.sendPluginResult(result);
        onOpenUrlHandlerContext = callbackContext;
        return true;
    } else if (action.equals("enableDataPush")) {

        EngagementShared.instance().logD("enableDataPush");
        PluginResult result = new PluginResult(PluginResult.Status.OK);
        result.setKeepCallback(true);/*  ww  w . jav a  2  s .  com*/
        callbackContext.sendPluginResult(result);
        dataPushHandlerContext = callbackContext;
        EngagementShared.instance().enableDataPush();
        return true;
    } else if (action.equals("getStatus")) {

        final CallbackContext cb = callbackContext;

        EngagementShared.instance().getStatus(new EngagementDelegate() {
            @Override
            public void onGetStatusResult(JSONObject _result) {
                cb.success(_result);
            }
        });
        return true;
    } else if (action.equals("startActivity")) {

        try {
            String activityName = args.getString(0);
            String extraInfos = args.getString(1);
            EngagementShared.instance().startActivity(activityName, extraInfos);
            callbackContext.success();
        } catch (JSONException e) {
            callbackContext.error("invalid args for startActivity");
        }
        return true;
    } else if (action.equals("endActivity")) {
        EngagementShared.instance().endActivity();
        callbackContext.success();
        return true;
    } else if (action.equals("sendEvent")) {

        try {
            String eventName = args.getString(0);
            String extraInfos = args.getString(1);
            EngagementShared.instance().sendEvent(eventName, extraInfos);
            callbackContext.success();
        } catch (JSONException e) {
            callbackContext.error("invalid args for sendEvent");
        }
        return true;
    } else if (action.equals("startJob")) {

        try {
            String jobName = args.getString(0);
            String extraInfos = args.getString(1);
            EngagementShared.instance().startJob(jobName, extraInfos);
            callbackContext.success();

        } catch (JSONException e) {
            callbackContext.error("invalid args for startJob");
        }
        return true;
    } else if (action.equals("endJob")) {

        try {
            String jobName = args.getString(0);
            EngagementShared.instance().endJob(jobName);
            callbackContext.success();
        } catch (JSONException e) {
            callbackContext.error("invalid args for endJob");
        }
        return true;
    } else if (action.equals("sendSessionEvent")) {

        try {
            String eventName = args.getString(0);
            String extraInfos = args.getString(1);
            EngagementShared.instance().sendSessionEvent(eventName, extraInfos);
            callbackContext.success();

        } catch (JSONException e) {
            callbackContext.error("invalid args for sendSessionEvent");
        }
        return true;
    } else if (action.equals("sendSessionError")) {

        try {
            String error = args.getString(0);
            String extraInfos = args.getString(1);
            EngagementShared.instance().sendSessionError(error, extraInfos);
            callbackContext.success();

        } catch (JSONException e) {
            callbackContext.error("invalid args for sendSessionError");
        }
        return true;
    } else if (action.equals("sendError")) {

        try {
            String error = args.getString(0);
            String extraInfos = args.getString(1);
            EngagementShared.instance().sendError(error, extraInfos);
            callbackContext.success();

        } catch (JSONException e) {
            callbackContext.error("invalid args for sendError");
        }
        return true;
    } else if (action.equals("sendJobEvent")) {

        try {
            String eventName = args.getString(0);
            String jobName = args.getString(1);
            String extraInfos = args.getString(2);
            EngagementShared.instance().sendJobEvent(eventName, jobName, extraInfos);
            callbackContext.success();

        } catch (JSONException e) {
            callbackContext.error("invalid args for sendJobEvent");
        }
        return true;
    } else if (action.equals("sendJobError")) {

        try {
            String error = args.getString(0);
            String jobName = args.getString(1);
            String extraInfos = args.getString(2);
            EngagementShared.instance().sendJobError(error, jobName, extraInfos);
            callbackContext.success();

        } catch (JSONException e) {
            callbackContext.error("invalid args for sendJobError");
        }
        return true;
    } else if (action.equals("sendAppInfo")) {

        try {
            String extraInfos = args.getString(0);
            EngagementShared.instance().sendAppInfo(extraInfos);
            callbackContext.success();
        } catch (JSONException e) {
            callbackContext.error("invalid args for sendAppInfo");
        }
        return true;

    } else if (action.equals("requestPermissions")) {

        JSONArray permissions = new JSONArray();
        if (realtimeLocation || fineRealtimeLocation)
            permissions.put("ACCESS_FINE_LOCATION");
        else if (lazyAreaLocation)
            permissions.put("ACCESS_COARSE_LOCATION");

        JSONObject ret = EngagementShared.instance().requestPermissions(permissions);
        if (!ret.has("error"))
            callbackContext.success(ret);
        else {
            String errString = null;
            try {
                errString = ret.getString("error");
            } catch (JSONException e) {
                Log.e(EngagementShared.LOG_TAG, "missing error tag");
            }
            callbackContext.error(errString);
        }

        return true;
    } else if (action.equals("setEnabled")) {

        try {
            boolean enabled = args.getBoolean(0);
            EngagementShared.instance().setEnabled(enabled);
            callbackContext.success(enabled ? 1 : 0);
        } catch (JSONException e) {
            callbackContext.error("invalid args for setEnabled");
        }
        return true;

    } else if (action.equals("isEnabled")) {
        callbackContext.success(EngagementShared.instance().isEnabled() ? 1 : 0);
        return true;

    }

    String str = "Unrecognized Command : " + action;
    EngagementShared.instance().logE(str);
    callbackContext.error(str);
    return false;
}

From source file:com.microsoft.azure.engagement.cordova.AZME.java

License:Open Source License

public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    String invokeString = intent.getDataString();
    if (invokeString != null && !invokeString.equals("")) {
        EngagementShared.instance().logD("onNewIntent, handleOpenURL " + invokeString);
        if (onOpenUrlHandlerContext != null) {
            PluginResult result = new PluginResult(PluginResult.Status.OK, invokeString);
            result.setKeepCallback(true);
            onOpenUrlHandlerContext.sendPluginResult(result);
        } else/*from ww w.  j a v  a 2 s  . c  o  m*/
            EngagementShared.instance().logD("Cannot trigger onOpenUrl if enableURL not previously called");

    }
}

From source file:com.microsoft.c3p.cordova.C3PCordovaPlugin.java

License:Open Source License

private static void returnResult(JavaScriptValue result, CallbackContext callbackContext,
        boolean keepCallback) {
    PluginResult pluginResult;
    switch (result.getType()) {
    case Null:/*ww w  .ja v  a  2  s .  co m*/
    case String:
        pluginResult = new PluginResult(PluginResult.Status.OK, result.getString());
        break;
    case Number:
        // TODO: Fix Cordova to avoid this loss of precision?
        pluginResult = new PluginResult(PluginResult.Status.OK, (float) result.getDouble());
        break;
    case Boolean:
        pluginResult = new PluginResult(PluginResult.Status.OK, result.getBoolean());
        break;
    case Object:
        pluginResult = new PluginResult(PluginResult.Status.OK, (JSONObject) JSValue.toObject(result));
        break;
    case Array:
        pluginResult = new PluginResult(PluginResult.Status.OK, (JSONArray) JSValue.toObject(result));
        break;
    default:
        throw new RuntimeException("Result object was not of any expected type.");
    }

    if (keepCallback) {
        pluginResult.setKeepCallback(true);
    }

    callbackContext.sendPluginResult(pluginResult);
}

From source file:com.mirasense.scanditsdk.plugin.Marshal.java

License:Apache License

public static PluginResult createOkResult(JSONArray args) {
    PluginResult result = new PluginResult(PluginResult.Status.OK, args);
    result.setKeepCallback(true);
    return result;
}

From source file:com.mirasense.scanditsdk.plugin.Marshal.java

License:Apache License

public static PluginResult createFailResult(String message) {
    PluginResult result = new PluginResult(PluginResult.Status.ERROR, message);
    result.setKeepCallback(true);
    return result;
}

From source file:com.mirasense.scanditsdk.plugin.ScanditSDK.java

License:Apache License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    mCallbackContext = callbackContext;//ww  w  .  ja  v  a2s  .c o  m
    PluginResult result = null;

    if (action.equals(SCAN)) {
        scan(args);
        result = new PluginResult(Status.NO_RESULT);
        result.setKeepCallback(true);
        return true;
    } else {
        result = new PluginResult(Status.INVALID_ACTION);
        callbackContext.error("Invalid Action");
        return false;
    }
}

From source file:com.mirasense.scanditsdk.plugin.ScanditSDK.java

License:Apache License

@Override
public void onResultByRelay(Bundle bundle) {
    String barcode = bundle.getString("barcode");
    String symbology = bundle.getString("symbology");
    JSONArray args = new JSONArray();
    args.put(barcode);//  www  .  ja v  a2  s . c om
    args.put(symbology);
    PluginResult result = new PluginResult(Status.OK, args);
    result.setKeepCallback(true);
    mCallbackContext.sendPluginResult(result);
}

From source file:com.mobiquitynetworks.cordova.mnnotifications.NotificationsManager.java

@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
    if (action.equals(EVENT_START_MONITORING)) {

        Log.v(TAG, "EVENT_START_MONITORING");
        this.startMonitoring(data, callbackContext);

        return true;
    } else if (action.equals(EVENT_REGISTER_CALLBACK)) {
        Log.v(TAG, "EVENT_REGISTER_CALLBACK");
        String event = data.getString(0);
        Log.v(TAG, event);//from   w w  w  .j a v  a2  s.  c o  m

        IntentProxy.setBtListener(this);
        IntentProxy.setgeoListener(this);

        PluginResult result = new PluginResult(PluginResult.Status.OK, "Set callback for " + event);
        result.setKeepCallback(true);
        this.contexts.put(event, callbackContext);
        callbackContext.sendPluginResult(result);
        return true;
    }

    return false;
}

From source file:com.mobiquitynetworks.cordova.mnnotifications.NotificationsManager.java

private void startMonitoring(JSONArray data, CallbackContext callbackContext) {
    Log.v(TAG, "CONFIG START");

    final Context c = this.cordova.getActivity().getApplicationContext();
    Properties p = readSDKProperties(c);

    //gets configuration

    String sConfig;//from  w  ww.  java 2  s  .  c  o m
    sConfig = "\nMobiquity Networks ProximityService configuration:\n"
            + "_________________________________________________________________\n" + "app key:\t\t"
            + p.getProperty("mobiquity.apm.appkey") + "\n" + "license:\t\t"
            + p.getProperty("mobiquity.apm.secret") + "\n" + "monitoring on period:\t"
            + p.getProperty("mobiquity.apm.monitoring.on_period") + "\n" + "monitoring off period:\t"
            + p.getProperty("mobiquity.apm.monitoring.off_period") + "\n" + "use idfa:\t\t"
            + p.getProperty("mobiquity.apm.stats.use_idfa_when_possible") + "\n" + "Endpoint:\t\t"
            + p.getProperty("mobiquity.apm.network.endpoint") + "\n" + "debug:\t\t"
            + p.getProperty("mobiquity.apm.debug") + "\n"
            + "_________________________________________________________________";
    Log.v(TAG, sConfig);
    Log.v(TAG, "CONFIG STOP");

    //data: [
    // {"tags": ["development","software"],
    //  "gender":"M","birthday":"1986-11-20","username":"matt@aimatt.com","language":"English","kids":2,"maritalStatus":"married"
    // },
    // {"battery":0.2}]

    Log.v(TAG, "data: " + data.toString());

    if (data.length() > 0) {
        try {

            JSONObject user = (JSONObject) data.get(0);
            Log.v(TAG, "user: " + user.toString());

            TrackingUser.Builder userBuilder = new TrackingUser.Builder();
            userBuilder.role(TrackingUser.Role.PRODUSER);
            TrackingAudience.Builder audienceBuilder = new TrackingAudience.Builder();

            // Username
            if (user.getString("username") != null) {
                userBuilder.username(user.getString("username"));
            }

            // Gender
            String gender = user.getString("gender");

            if (gender.equals("M")) {
                audienceBuilder.gender(TrackingAudience.Gender.MALE);
            } else if (gender.equals("F")) {
                audienceBuilder.gender(TrackingAudience.Gender.FEMALE);
            }

            // Marital Status
            String maritalStatus = user.getString("maritalStatus");

            if (maritalStatus.equals("married")) {
                audienceBuilder.maritalStatus(TrackingAudience.MaritalStatus.MARRIED);
            } else if (maritalStatus.equals("single")) {
                audienceBuilder.maritalStatus(TrackingAudience.MaritalStatus.SINGLE);
            }

            // Kids
            audienceBuilder.kids(user.getInt("kids"));

            // Tags
            JSONArray tagsJson = user.getJSONArray("tags");
            if (tagsJson != null) {
                ArrayList<String> tags = new ArrayList<String>();

                int len = tagsJson.length();
                for (int i = 0; i < len; i++) {
                    tags.add(tagsJson.get(i).toString());
                }

                audienceBuilder.tags(new HashSet<String>(tags));
            }

            // Education
            String education = user.getString("education");

            if (education.equals("CLL")) {
                audienceBuilder.education(TrackingAudience.Education.COLLEGE);
            } else if (education.equals("GS")) {
                audienceBuilder.education(TrackingAudience.Education.GRAD_SCHOOL);
            } else if (education.equals("NCLL")) {
                audienceBuilder.education(TrackingAudience.Education.NON_COLLEGE);
            }

            // Ethnicity
            String ethnicity = user.getString("ethnicity");

            if (ethnicity.equals("AA")) {
                audienceBuilder.ethnicity(TrackingAudience.Ethnicity.AFRICAN_AMERICAN);
            } else if (ethnicity.equals("AS")) {
                audienceBuilder.ethnicity(TrackingAudience.Ethnicity.ASIAN);
            } else if (ethnicity.equals("CC")) {
                audienceBuilder.ethnicity(TrackingAudience.Ethnicity.CAUSASIAN);
            } else if (ethnicity.equals("HP")) {
                audienceBuilder.ethnicity(TrackingAudience.Ethnicity.HISPANIC);
            }

            // TODO: Language

            userBuilder.audience(audienceBuilder.build());
            final TrackingUser trackingUser = userBuilder.build();

            cordova.getThreadPool().execute(new Runnable() {
                public void run() {
                    ProximityManager.getInstance().setTrackingUserInformation(trackingUser);
                    ProximityManager.getInstance().startService(c);
                }
            });

            // TODO: Custom Vars
            //                HashMap<String, String> trackingCustomVars = new HashMap<String, String>();
            //                trackingCustomVars.put("custom1", "foo");
            //                trackingCustomVars.put("custom2", "bar");
            //                ProximityManager.setTrackingCustomVars(trackingCustomVars);

            String message = "startMonitoring success";
            PluginResult result = new PluginResult(PluginResult.Status.OK, message.toString());
            result.setKeepCallback(true);
            callbackContext.sendPluginResult(result);

        } catch (JSONException e) {
            Log.e(TAG, "Exception parsing JSON", e);
        }
    }

}

From source file:com.moodstocks.phonegap.plugin.MoodstocksPlugin.java

License:Open Source License

@Override
public void onSyncStart() {
    Log.d(TAG, "[SYNC] Starting...");

    JSONObject obj = new JSONObject();

    try {/*from   w  w w . ja va  2s  .c  o m*/
        obj.put(MESSAGE, "Sync starts.");
        obj.put(STATUS, 1);
        obj.put(PROGRESS, 0);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    PluginResult r = new PluginResult(PluginResult.Status.OK, obj);
    r.setKeepCallback(true);
    this.syncCallback.sendPluginResult(r);
}