Example usage for org.apache.cordova PluginResult PluginResult

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

Introduction

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

Prototype

public PluginResult(Status status) 

Source Link

Usage

From source file:com.polyvi.xface.extension.calendar.XCalendarExt.java

License:Open Source License

/**
 * ??js/*from  w ww . ja v  a2 s  . com*/
 *
 * @param hour
 *            ?
 * @param minute
 *            
 */
private void setTime(int hour, int minute) {
    JSONObject time = new JSONObject();
    try {
        time.put("hour", hour);
        time.put("minute", minute);
        mCallbackContext.success(time);
    } catch (JSONException e) {
        PluginResult result = new PluginResult(PluginResult.Status.ERROR);
        mCallbackContext.sendPluginResult(result);
    }
}

From source file:com.polyvi.xface.extension.calendar.XCalendarExt.java

License:Open Source License

/**
 * ??js//from   w  w w  .  jav a 2 s .  c  om
 *
 * @param year
 *            
 * @param month
 *            
 * @param day
 *            
 */
private void setDate(int year, int month, int day) {
    JSONObject date = new JSONObject();
    try {
        date.put("year", year);
        date.put("month", (month + 1));// 0js1
        date.put("day", day);
        mCallbackContext.success(date);
    } catch (JSONException e) {
        PluginResult result = new PluginResult(PluginResult.Status.ERROR);
        mCallbackContext.sendPluginResult(result);
    }
}

From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java

License:Open Source License

/**
 * ??//from   ww w . ja  va 2s. c  om
 *
 * @param app
 *            app?app??????UI?
 * @param addr
 *            ?
 * @param body
 *            ?
 * @return ?
 */
private void sendSMS(String addr, String body) {

    String regularExpression = "[+*#\\d]+";
    if (!addr.matches(regularExpression)) {
        throw new IllegalArgumentException("address must be digit,*,# or +");
    }

    IntentFilter smsSendIntentFilter = new IntentFilter(SMS_SENT);
    genSendSMSBroadreceiver();
    // ??
    mContext.registerReceiver(mSendSMSBroadcastReceiver, smsSendIntentFilter);

    SmsManager manager = SmsManager.getDefault();
    ArrayList<String> textList = manager.divideMessage(body);
    ArrayList<PendingIntent> smsSendPendingIntentList = genSMSPendingIntentList(textList);
    manager.sendMultipartTextMessage(addr, null, textList, smsSendPendingIntentList, null);
    PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
    result.setKeepCallback(true);
    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;/*from w w  w. ja  v  a2s .c o 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.polyvi.xface.extension.zbar.XZBarExt.java

License:Open Source License

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    mLock = false;/*from   w w w. j  a va2 s.  com*/
    if (requestCode == ZBAR_REQUEST_CODE && mCallbackCtx != null && this.webView.getContext() != null) {
        if (resultCode == Activity.RESULT_OK && intent != null) {
            //???
            String code = intent.getStringExtra("Code");
            mCallbackCtx.success(code);
            PluginResult result = new PluginResult(PluginResult.Status.OK);
            mCallbackCtx.sendPluginResult(result);
        } else {
            mCallbackCtx.error("Error");
        }
    }
}

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//w ww .j  a v  a  2  s . c  om
        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.rjfun.cordova.admob.GenericAdPlugin.java

public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
    PluginResult result = null;//w ww.  j  a v  a 2 s .  c  om
    if ("getAdSettings".equals(action)) {
        this.getAdSettings(callbackContext);
        return true;
    } else {
        JSONObject isOk;
        if ("setOptions".equals(action)) {
            isOk = inputs.optJSONObject(0);
            this.setOptions(isOk);
            result = new PluginResult(Status.OK);
        } else {
            String adId;
            boolean autoShow;
            boolean isOk1;
            if ("createBanner".equals(action)) {
                isOk = inputs.optJSONObject(0);
                if (isOk.length() > 1) {
                    this.setOptions(isOk);
                }

                adId = isOk.optString("adId");
                autoShow = !isOk.has("autoShow") || isOk.optBoolean("autoShow");
                isOk1 = this.createBanner(adId, autoShow);
                result = new PluginResult(isOk1 ? Status.OK : Status.ERROR);
            } else if ("removeBanner".equals(action)) {
                this.removeBanner();
                result = new PluginResult(Status.OK);
            } else if ("hideBanner".equals(action)) {
                this.hideBanner();
                result = new PluginResult(Status.OK);
            } else if ("showBanner".equals(action)) {
                int isOk2 = inputs.optInt(0);
                this.showBanner(isOk2, 0, 0);
                result = new PluginResult(Status.OK);
            } else if ("showBannerAtXY".equals(action)) {
                isOk = inputs.optJSONObject(0);
                int adId1 = isOk.optInt("x");
                int autoShow1 = isOk.optInt("y");
                this.showBanner(10, adId1, autoShow1);
                result = new PluginResult(Status.OK);
            } else if ("prepareInterstitial".equals(action)) {
                isOk = inputs.optJSONObject(0);
                if (isOk.length() > 1) {
                    this.setOptions(isOk);
                }

                adId = isOk.optString("adId");
                autoShow = !isOk.has("autoShow") || isOk.optBoolean("autoShow");
                isOk1 = this.prepareInterstitial(adId, autoShow);
                result = new PluginResult(isOk1 ? Status.OK : Status.ERROR);
            } else if ("showInterstitial".equals(action)) {
                this.showInterstitial();
                result = new PluginResult(Status.OK);
            } else if ("isInterstitialReady".equals(action)) {
                result = new PluginResult(Status.OK, this.interstitialReady);
            } else if ("prepareRewardVideoAd".equals(action)) {
                isOk = inputs.optJSONObject(0);
                if (isOk.length() > 1) {
                    this.setOptions(isOk);
                }

                adId = isOk.optString("adId");
                autoShow = !isOk.has("autoShow") || isOk.optBoolean("autoShow");
                isOk1 = this.prepareRewardVideoAd(adId, autoShow);
                result = new PluginResult(isOk1 ? Status.OK : Status.ERROR);
            } else if ("showRewardVideoAd".equals(action)) {
                boolean isOk3 = this.showRewardVideoAd();
                result = new PluginResult(isOk3 ? Status.OK : Status.ERROR);
            } else {
                Log.w("GenericAdPlugin", String.format("Invalid action passed: %s", new Object[] { action }));
                result = new PluginResult(Status.INVALID_ACTION);
            }
        }

        this.sendPluginResult(result, callbackContext);
        return true;
    }
}

From source file:com.rjfun.cordova.qq.QQPlugin.java

@Override
public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
    PluginResult result = null;/*from  w  w w  .  jav a 2 s  .com*/

    if (ACTION_SET_OPTIONS.equals(action)) {
        JSONObject options = inputs.optJSONObject(0);
        this.setOptions(options);
        result = new PluginResult(Status.OK);

    } else if (ACTION_SHARE.equals(action)) {
        JSONObject options = inputs.optJSONObject(0);
        if (options.length() > 1) {
            this.setOptions(options);
        }
        boolean isOk = this.share(options);

        // we send callback in qq callback
        currentCallbackContext = callbackContext;
        return true;

    } else {
        Log.w(LOGTAG, String.format("Invalid action passed: %s", action));
        result = new PluginResult(Status.INVALID_ACTION);
    }

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

    return true;
}

From source file:com.scala.cordova.plugin.expnginx.ExpNginx.java

License:MIT License

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

    final Activity activity = cordova.getActivity();
    final Nginx nginx = Nginx.create();
    if (action.equals("start")) {
        Log.v(LOG_TAG, "Cordova Android ExpNginx.start() called.");
        this.callbackContext = callbackContext;
        final ExpNginx self = this;
        activity.runOnUiThread(new Runnable() {
            public void run() {
                try {
                    nginx.start();/*from w w  w  .j ava  2 s .c o m*/
                    // send success result to cordova
                    PluginResult result = new PluginResult(PluginResult.Status.OK);
                    result.setKeepCallback(false);
                    self.callbackContext.sendPluginResult(result);
                } catch (Exception e) {
                    String msg = "Error while starting ExpNginx.";
                    Log.e(LOG_TAG, msg);

                    // return error answer to cordova
                    PluginResult result = new PluginResult(PluginResult.Status.ERROR, msg);
                    result.setKeepCallback(false);
                    self.callbackContext.sendPluginResult(result);
                }
            }

        });
        return true;
    }

    if (action.equals("stop")) {
        Log.v(LOG_TAG, "Cordova Android ExpNginx.stop() called.");
        this.callbackContext = callbackContext;
        final ExpNginx self = this;

        activity.runOnUiThread(new Runnable() {

            public void run() {
                try {
                    // stop nginx server
                    Integer delay = (Integer) args.get(0);
                    nginx.stop(delay);

                    // send success result to cordova
                    PluginResult result = new PluginResult(PluginResult.Status.OK);
                    result.setKeepCallback(false);
                    self.callbackContext.sendPluginResult(result);
                } catch (Exception e) {
                    String msg = "Error while stoping ExpNginx.";
                    Log.e(LOG_TAG, msg);

                    // return error answer to cordova
                    PluginResult result = new PluginResult(PluginResult.Status.ERROR, msg);
                    result.setKeepCallback(false);
                    self.callbackContext.sendPluginResult(result);
                }
            }

        });
        return true;
    }

    return false;

}

From source file:com.sebible.cordova.videosnapshot.VideoSnapshot.java

License:Apache License

private void fail(String message) {
    this.callbackContext.error(message);
    PluginResult r = new PluginResult(PluginResult.Status.ERROR);
    callbackContext.sendPluginResult(r);
}