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.polyvi.xface.extension.messaging.XMessagingExt.java

License:Open Source License

/**
 * ???/*  w  w  w  .  ja v a 2 s . c o m*/
 *
 * @param status
 *            ???
 * */
private void resolveSMSSendResult(SMS_RESULT_STATUS status) {
    PluginResult.Status callbackStatus = PluginResult.Status.OK;
    if (status != SMS_RESULT_STATUS.SEND_SUCCESS) {
        callbackStatus = PluginResult.Status.ERROR;
    }
    PluginResult result = new PluginResult(callbackStatus, status.ordinal());
    result.setKeepCallback(false);
    mCallbackContext.sendPluginResult(result);
}

From source file:com.polyvi.xface.extension.zbar.XZBarExt.java

License:Open Source License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (COMMAND_START.equals(action) && !mLock && apiLevel >= 8) {
        mCallbackCtx = callbackContext;//w w  w.  ja  v a 2  s.  co m
        mLock = true;
        Intent intent = new Intent();
        intent.setClass(cordova.getActivity(), XCameraActivity.class);
        cordova.startActivityForResult(this, intent, 1);
        PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
        result.setKeepCallback(true);
        callbackContext.sendPluginResult(result);
        return true;
    }
    return false;
}

From source file:com.projectoxford.cordova.speechrecognition.OxfordSpeechRecognition.java

License:Open Source License

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

    Log.d("OxfordSpeechRecognition", "excute");

    // Dispatcher
    if (ACTION_INIT.equals(action)) {
        Log.d("OxfordSpeechRecognition", "initialize");
        // init/*from   w  w w.ja v a 2 s  .  c o  m*/
        initializeRecoClient(args);
    } else if (ACTION_SPEECH_RECOGNIZE_START.equals(action)) {
        Log.d("OxfordSpeechRecognition", "start - 1");
        speechRecognizerCallbackContext = callbackContext;
        // Speech recognition from the microphone.  The microphone is turned on and data from the microphone
        // is sent to the Speech Recognition Service.  A built in Silence Detector
        // is applied to the microphone data before it is sent to the recognition service.
        m_micClient.startMicAndRecognition();
        Log.d("OxfordSpeechRecognition", "start - 2");

        PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT);
        pr.setKeepCallback(true);
        callbackContext.sendPluginResult(pr);
    } else if (ACTION_SPEECH_RECOGNIZE_STOP.equals(action)) {
        stop(false);
    } else if (ACTION_SPEECH_RECOGNIZE_ABORT.equals(action)) {
        stop(true);
    } else {
        // Invalid action
        String res = "Unknown action: " + action;
        return false;
    }
    return true;
}

From source file:com.projectoxford.cordova.speechrecognition.OxfordSpeechRecognition.java

License:Open Source License

public void onPartialResponseReceived(final String response) {
    Log.d("OxfordSpeechRecognition", "partial");

    JSONObject event = new JSONObject();
    try {//from ww w.  j a v a 2 s .  c o m
        event.put("partial", response);
    } catch (JSONException e) {
        // this will never happen
    }
    PluginResult pr = new PluginResult(PluginResult.Status.OK, event);
    pr.setKeepCallback(true);
    speechRecognizerCallbackContext.sendPluginResult(pr);
}

From source file:com.projectoxford.cordova.speechrecognition.OxfordSpeechRecognition.java

License:Open Source License

public void onFinalResponseReceived(final RecognitionResult response) {
    Log.d("OxfordSpeechRecognition", "final");
    boolean isFinalDicationMessage = m_recoMode == SpeechRecognitionMode.LongDictation
            && (response.RecognitionStatus == RecognitionStatus.EndOfDictation
                    || response.RecognitionStatus == RecognitionStatus.DictationEndSilenceTimeout);
    if ((m_recoMode == SpeechRecognitionMode.ShortPhrase) || isFinalDicationMessage) {
        // we got the final result, so it we can end the mic reco.  No need to do this
        // for dataReco, since we already called endAudio() on it as soon as we were done
        // sending all the data.
        m_micClient.endMicAndRecognition();
    }//from  w  ww . j av a2s  .  c o m

    if ((m_recoMode == SpeechRecognitionMode.ShortPhrase) || isFinalDicationMessage) {
        //speechRecognizerCallbackContext.sendPluginResult(pr); 
    }

    JSONObject event = new JSONObject();
    String result = "";
    if (!isFinalDicationMessage && response.Results.length > 0) {
        //for (int i = 0; i < response.Results.length; i++) {
        //response.Results[i].DisplayText;
        //}
        result = response.Results[0].DisplayText;
    }
    try {
        event.put("result", result);
    } catch (JSONException e) {
        // this will never happen
    }
    PluginResult pr = new PluginResult(PluginResult.Status.OK, event);
    pr.setKeepCallback(true);
    speechRecognizerCallbackContext.sendPluginResult(pr);
}

From source file:com.redant.cordova.beacons.Beacons.java

License:Apache License

private void createRangingCallbacks() {

    iBeaconManager.setRangeNotifier(new RangeNotifier() {
        @Override// w w w .j  a  va  2  s  .c om
        public void didRangeBeaconsInRegion(final Collection<IBeacon> iBeacons, final Region region) {

            threadPoolExecutor.execute(new Runnable() {
                public void run() {

                    try {
                        if (iBeacons.size() > 0) {

                            IBeacon beacon = null;

                            for (IBeacon _beacon : iBeacons) {
                                if (beacon == null) {
                                    beacon = _beacon;
                                } else if (_beacon.getRssi() > beacon.getRssi()) {
                                    beacon = _beacon;
                                }
                            }

                            if (beacon.getRssi() != 0 && beacon.getRssi() > sensitivity) {

                                JSONObject beaconProperties = new JSONObject();
                                beaconProperties.put("major", beacon.getMajor());
                                beaconProperties.put("minor", beacon.getMinor());
                                beaconProperties.put("rssi", beacon.getRssi());

                                PluginResult result = new PluginResult(PluginResult.Status.OK,
                                        beaconProperties);
                                result.setKeepCallback(true);
                                callbackId.sendPluginResult(result);
                            }
                        }

                    } catch (Exception e) {
                        Log.e(TAG, "'rangingBeaconsDidFailForRegion' exception " + e.getCause());
                        beaconServiceNotifier.rangingBeaconsDidFailForRegion(region, e);
                    }
                }
            });
        }

    });

}

From source file:com.redapesolutions.syncnow.SyncNowPlugin.java

private synchronized PluginResult setPluginResult(String message) {
    PluginResult result = new PluginResult(PluginResult.Status.OK, message);
    result.setKeepCallback(true);
    return result;
}

From source file:com.ripperdesignandmultimedia.phoneblockplugin.PhoneBlockerPlugin.java

License:Open Source License

/**
 * Create a new plugin result and send it back to JavaScript
 * // w w w.j ava2  s.co  m
 * @param phone state sent back to the designated success callback
 */
private void updatePhoneState(String phoneState, boolean keepCallback) {
    if (this.phoneBlockerCallbackId != null) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, phoneState);
        result.setKeepCallback(keepCallback);
        this.success(result, this.phoneBlockerCallbackId);
    }
}

From source file:com.ripperdesignandmultimedia.phoneblockplugin.PhoneBlockerPlugin.java

License:Open Source License

@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
    PluginResult.Status status = PluginResult.Status.INVALID_ACTION;
    String result = "Unsupported Operation: " + action;
    // either start or stop the listener...
    if (action.equals("startMonitoringPhoneState")) {
        if (this.phoneBlockerCallbackId != null) {
            return new PluginResult(PluginResult.Status.ERROR, "Phone listener already running.");
        }/*from w  w w  .  ja  v a  2s . co  m*/
        this.phoneBlockerCallbackId = callbackId;
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        return pluginResult;
    } else if (action.equals("stopMonitoringPhoneState")) {
        removePhoneBlocker();
        this.updatePhoneState("", false); // release status callback
        this.phoneBlockerCallbackId = null;
        return new PluginResult(PluginResult.Status.NO_RESULT);
    } else if (action.equals("stopPhoneCall")) {
        onReceive();
    }

    return new PluginResult(status, result); // no valid action called
}

From source file:com.samsung.richnotification.RichNotification.java

License:Apache License

/**
 * This function will send a new notification or will update the notification sent.
 *
 * @param data//w w  w .  j a  v  a 2 s .c o m
*            The JSONArray with parameters required for sending the notification.
 * @param callbackContext
 *            The callback id used when calling back into JavaScript.
 * @return true if the notification is sent or false if the notification is not sent.
 *
 */
private boolean sendRichNotification(JSONArray data, CallbackContext callbackContext) throws JSONException {
    RichNotificationOptions options = null;
    SrnPrimaryTemplate primaryTemplate = null;
    SrnSecondaryTemplate secondaryTemplate = null;

    // This function takes care of error callbacks
    if (!initRichNotification(callbackContext)) {
        Log.e(TAG, "Initialization failed.");
        return false;
    }

    if (Log.isLoggable(RICHNOTI, Log.DEBUG))
        Log.d(TAG, "Creating the notification.");

    // Fetch options from the data object
    options = new RichNotificationOptions(data);
    options.printLogs();

    SrnRichNotification noti = null;
    UUID uuid = null;

    try {
        uuid = UUID.fromString(options.uuid);
    } catch (IllegalArgumentException invalidUUID) {
        Log.e(TAG, "Invalid UUID supplied. Creating a new notification.");
        options.uuid = null;
    }

    if (options.uuid == null)
        noti = new SrnRichNotification(mContext);
    else
        noti = new SrnRichNotification(mContext, uuid);

    // Set notification icon
    if (!options.notificationIcon.isEmpty()) {
        Bitmap notiIconBit = RichNotificationHelper.getIconBitmap(mContext,
                "file://" + options.notificationIcon);
        SrnImageAsset notiIconAsst = new SrnImageAsset(mContext, "notiIcon", notiIconBit);
        noti.setIcon(notiIconAsst);
    }

    noti.setAlertType(options.alertType, options.popupType);

    noti.setReadout(options.readoutTitle, options.readout);
    noti.setTitle(options.notificationTitle);

    primaryTemplate = RichNotificationHelper.createPrimaryTemplate(mContext, options);
    secondaryTemplate = RichNotificationHelper.createSecondaryTemplate(mContext, options);

    noti.setPrimaryTemplate(primaryTemplate);

    if (secondaryTemplate != null)
        noti.setSecondaryTemplate(secondaryTemplate);

    // Action related
    List<SrnAction> actionList = RichNotificationHelper.createActions(mContext, callbackContext, options);
    if (actionList != null) {
        noti.addActions(actionList);
    } else {
        if (Log.isLoggable(RICHNOTI, Log.DEBUG))
            Log.d(TAG, "Actions not defined");
    }

    try {
        options.uuid = mRichNotificationManager.notify(noti).toString();

        JSONObject successMsg = new JSONObject();
        successMsg.put("returnType", RichNotificationHelper.RETURN_TYPE_NOTIFICATION_SENT);
        successMsg.put("returnValue", options.uuid);

        if (Log.isLoggable(RICHNOTI, Log.DEBUG))
            Log.d(TAG, "Notification sent. UUID: " + options.uuid);
        PluginResult sentResult = new PluginResult(PluginResult.Status.OK, successMsg);
        sentResult.setKeepCallback(true);
        callbackContext.sendPluginResult(sentResult);
        return true;
    } catch (SecurityException secEx) {
        Log.e(TAG, "Permission denied");
        callbackContext.error(RichNotificationHelper.PERMISSION_DENIED);
        return false;
    }
}