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, List<PluginResult> multipartMessages) 

Source Link

Usage

From source file:com.plugin.am.LocalNotification.java

License:Apache License

/**
 * Checks if a notification with an ID was triggered.
 *
 * @param id//from w w w .j  av a2s .com
 *          The notification ID to be check.
 * @param callbackContext
 */
public static void isTriggered(String id, CallbackContext command) {
    SharedPreferences settings = getSharedPreferences();
    Map<String, ?> alarms = settings.getAll();
    boolean isScheduled = alarms.containsKey(id);
    boolean isTriggered = isScheduled;

    if (isScheduled) {
        JSONObject arguments = (JSONObject) alarms.get(id);
        Options options = new Options(context).parse(arguments);
        Date fireDate = new Date(options.getDate());

        isTriggered = new Date().after(fireDate);
    }

    PluginResult result = new PluginResult(PluginResult.Status.OK, isTriggered);

    command.sendPluginResult(result);
}

From source file:com.plugin.gcm.GameThrivePush.java

License:Apache License

private static void callbackSuccess(CallbackContext callbackContext, JSONObject jsonObject) {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, jsonObject);
    pluginResult.setKeepCallback(true);//from   w w w .  ja va2s .c om
    callbackContext.sendPluginResult(pluginResult);
}

From source file:com.plugin.gcm.GameThrivePush.java

License:Apache License

private static void callbackError(CallbackContext callbackContext, String str) {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, str);
    pluginResult.setKeepCallback(true);/*from w  w  w  . j  ava  2  s .  c  o  m*/
    callbackContext.sendPluginResult(pluginResult);
}

From source file:com.plugin.gcm.OneSignalPush.java

License:Open Source License

private static void callbackError(CallbackContext callbackContext, JSONObject jsonObject) {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, jsonObject);
    pluginResult.setKeepCallback(true);/* www . j a  v  a  2 s. co  m*/
    callbackContext.sendPluginResult(pluginResult);
}

From source file:com.polyvi.xface.ams.XAppInstallListener.java

License:Open Source License

@Override
public void onProgressUpdated(AMS_OPERATION_TYPE type, InstallStatus progressState) {
    JSONObject jsonObj = new JSONObject();
    try {/*from ww  w.  j a  va2 s . com*/
        jsonObj.put(TAG_INSTALL_PROGRESS, progressState.ordinal());
        jsonObj.put(TAG_OPERATION_TYPE, type.ordinal());
        jsonObj.put(TAG_CALLBACK, "progress");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    PluginResult result = new PluginResult(PluginResult.Status.OK, jsonObj);
    // js???js
    result.setKeepCallback(true);
    mCallbackCtx.sendPluginResult(result);
}

From source file:com.polyvi.xface.extension.advancedfiletransfer.FileDownloader.java

License:Open Source License

@Override
public void onProgressUpdated(int completeSize, long totalSize) {
    mDownloadInfo.setCompleteSize(completeSize);
    JSONObject jsonObj = new JSONObject();
    try {/*from w w  w.j  a  v a2s  .c  o  m*/
        File file = new File(mLocalFilePath);
        FileUtils filePlugin = (FileUtils) mWebView.pluginManager.getPlugin("File");
        if (filePlugin != null) {
            jsonObj = filePlugin.getEntryForFile(file);
            jsonObj.put("loaded", completeSize);
            jsonObj.put("total", totalSize);
            jsonObj.put("status", "unfinished");
        }
    } catch (JSONException e) {
        XLog.e(CLASS_NAME, e.getMessage());
    }
    PluginResult result = new PluginResult(PluginResult.Status.OK, jsonObj);
    result.setKeepCallback(true);
    mCallbackCtx.sendPluginResult(result);
}

From source file:com.polyvi.xface.extension.advancedfiletransfer.FileUploader.java

License:Open Source License

@Override
public void onError(int errorCode) {
    setState(INIT);//  w w  w  . j a v  a2 s  . c  o m
    JSONObject error = new JSONObject();
    Status status = Status.ERROR;
    try {
        error.put("code", errorCode);
        error.put("source", mFilePath);
        error.put("target", mServer);
    } catch (JSONException e) {
        status = Status.JSON_EXCEPTION;
        XLog.e(CLASS_NAME, e.getMessage());
    }
    PluginResult result = new PluginResult(status, error);
    mCallbackCtx.sendPluginResult(result);
}

From source file:com.polyvi.xface.extension.advancedfiletransfer.FileUploader.java

License:Open Source License

@Override
public void onProgressUpdated(int completeSize, long totalSize) {
    JSONObject jsonObj = new JSONObject();
    try {/*from   w  w  w . j  a v  a 2s .co m*/
        jsonObj.put("loaded", completeSize);
        jsonObj.put("total", totalSize);
    } catch (JSONException e) {
        XLog.e(CLASS_NAME, e.getMessage());
    }
    PluginResult result = new PluginResult(PluginResult.Status.OK, jsonObj);
    result.setKeepCallback(true);
    mCallbackCtx.sendPluginResult(result);
}

From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java

License:Open Source License

/**
 * ?mac???/*from  w w w . ja  va 2s . c o  m*/
 *
 * @param args
 *            ?mac?json
 * @return PluginResult
 */
private PluginResult isBoundBluetooth(JSONArray args) {
    String addressDevice = null;
    try {
        addressDevice = args.getString(0);
    } catch (JSONException e) {
        e.printStackTrace();
        return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
    }
    BluetoothDevice device = mBtadapter.getRemoteDevice(addressDevice);
    boolean isBound = false;

    if (device != null && device.getBondState() == BluetoothDevice.BOND_BONDED)
        isBound = true;
    else
        isBound = false;
    return new PluginResult(PluginResult.Status.OK, isBound);
}

From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java

License:Open Source License

/**
 * ???/*from  w  w w .  ja va 2s  .c  o  m*/
 *
 * @return PluginResult
 */
private PluginResult stopDiscovering() {
    boolean stopped = true;
    if (mBtadapter.isDiscovering()) {
        stopped = mBtadapter.cancelDiscovery();
        mIsDiscovering = false;
    }
    return new PluginResult(PluginResult.Status.OK, stopped);
}