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.moodstocks.phonegap.plugin.MoodstocksPlugin.java

License:Open Source License

@Override
public void onSyncComplete() {
    Log.d(TAG, "[SYNC] Complete!");

    JSONObject obj = new JSONObject();

    try {/*  www.ja va2 s .  c om*/
        obj.put(MESSAGE, "Sync completed.");
        obj.put(STATUS, 3);
        obj.put(PROGRESS, 100);
    } catch (JSONException e) {
        e.printStackTrace();
    }

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

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

License:Open Source License

@Override
public void onSyncFailed(MoodstocksError e) {
    e.log();//  w ww.  j  av  a 2  s .co  m

    JSONObject obj = new JSONObject();

    try {
        obj.put(MESSAGE, "Sync failed with error code " + e.getErrorCode());
        obj.put(STATUS, 0);
        obj.put(PROGRESS, 0);
    } catch (JSONException e1) {
        e1.printStackTrace();
    }

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

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

License:Open Source License

@Override
public void onSyncProgress(int total, int current) {
    Log.d(TAG, "[SYNC] " + current + "/" + total);

    JSONObject obj = new JSONObject();

    try {/*from   www .j av  a  2s .  c o m*/
        obj.put(MESSAGE, "Sync is progressing.");
        obj.put(STATUS, 2);
        obj.put(PROGRESS, 100 * (current / total));
    } catch (JSONException e) {
        e.printStackTrace();
    }

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

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

License:Open Source License

@Override
public void onBackPressed() {
    if (backPressActivated) {
        session.pause();//from w w  w .jav a 2 s  . c  om

        JSONObject obj = new JSONObject();
        try {
            obj.put(FORMAT, null);
            obj.put(VALUE, null);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        PluginResult r = new PluginResult(PluginResult.Status.OK, obj);
        r.setKeepCallback(false);

        MoodstocksPlugin.getScanCallback().sendPluginResult(r);

        // Remove the web view from web container when quitting
        webContainer.removeView(MoodstocksPlugin.getOverlay());
        super.onBackPressed();
    }
}

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

License:Open Source License

@Override
public void onScanComplete(Result result) {
    if (result != null) {
        session.pause();/*from ww  w . ja  v a2 s.co m*/
        // result found, send to overlay
        JSONObject obj = new JSONObject();
        try {
            obj.put(FORMAT, result.getType());
            obj.put(VALUE, result.getValue());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        PluginResult r = new PluginResult(PluginResult.Status.OK, obj);
        r.setKeepCallback(true);

        MoodstocksPlugin.getScanCallback().sendPluginResult(r);
    }
}

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

License:Open Source License

public static void scanSuccess(Result result) {
    PluginResult scanResult = new PluginResult(PluginResult.Status.OK, result.getValue());
    scanResult.setKeepCallback(true);
    scanCallbackContext.sendPluginResult(scanResult);
}

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

License:Open Source License

public static void recognisePhotoSuccess(Result result) {
    PluginResult scanResult = new PluginResult(PluginResult.Status.OK, result.getValue());
    scanResult.setKeepCallback(false);
    recognisePhotoCallbackContext.sendPluginResult(scanResult);
}

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

License:Open Source License

public static void recognisePhotoFail() {
    PluginResult scanResult = new PluginResult(PluginResult.Status.ERROR, "No Image Found");
    scanResult.setKeepCallback(false);
    recognisePhotoCallbackContext.sendPluginResult(scanResult);
}

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

License:Open Source License

public static void scanNoResult() {
    PluginResult scanResult = new PluginResult(PluginResult.Status.ERROR, "No Image Found");
    scanResult.setKeepCallback(true);
    scanCallbackContext.sendPluginResult(scanResult);
}

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

License:Open Source License

public static void syncFinished(int count) {
    PluginResult syncResult = new PluginResult(PluginResult.Status.OK, count);
    syncResult.setKeepCallback(false); // final sync callback -- doesn't need keeping
    syncCallbackContext.sendPluginResult(syncResult);
}