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:BarcodeReaderPlugin.java

@Override
public void onBarcodeEvent(final BarcodeReadEvent event) {
    if (event != null) {
        Log.v(TAG, "onBarcodeEvent: barcodeData=" + event.getBarcodeData());

        if (barcodeListenerCallbackContext != null) {
            PluginResult result = new PluginResult(PluginResult.Status.OK, event.getBarcodeData());
            result.setKeepCallback(true);
            barcodeListenerCallbackContext.sendPluginResult(result);
        }//from   ww  w  .ja v a2s . c  o  m
    } else {
        Log.w(TAG, "onBarcodeEvent: (no data)");
    }
}

From source file:BarcodeReaderPlugin.java

@Override
public void onFailureEvent(BarcodeFailureEvent event) {
    if (event != null) {
        Log.v(TAG, "onFailureEvent: timestamp=" + event.getTimestamp());

        if (barcodeListenerCallbackContext != null) {
            PluginResult result = new PluginResult(PluginResult.Status.ERROR, event.getTimestamp());
            result.setKeepCallback(true);
            barcodeListenerCallbackContext.sendPluginResult(result);
        }//from w  w  w  .  ja va2s  . c  o m
    } else {
        Log.w(TAG, "onFailureEvent: (no data)");
    }
}

From source file:BarcodeReaderPlugin.java

private void SendNoResult(CallbackContext callbackContext, boolean keepCallback) {
    // Return "no result" result - neither success nor failure callbacks will be called
    PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
    pluginResult.setKeepCallback(keepCallback);
    callbackContext.sendPluginResult(pluginResult);
}

From source file:ai.api.ApiAiPlugin.java

License:Apache License

@Override
public void onAudioLevel(final float level) {

    float normLevel = level;

    if (level > maxLevel) {
        maxLevel = maxLevel + (level - maxLevel) / 2;
        normLevel = maxLevel;/*from  ww w.java  2s  . c  o m*/
    }

    if (level < minLevel) {
        minLevel = minLevel - (minLevel - level) / 2;
        normLevel = minLevel;
    }

    normLevel = (normLevel - minLevel) / (maxLevel - minLevel);

    if (levelMeterCallback != null) {
        final PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, (float) normLevel);
        pluginResult.setKeepCallback(true);
        levelMeterCallback.sendPluginResult(pluginResult);
    }
}

From source file:ai.api.ApiAiPlugin.java

License:Apache License

@Override
public void onListeningStarted() {
    if (listeningStartCallback != null) {
        final PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
        pluginResult.setKeepCallback(true);
        listeningStartCallback.sendPluginResult(pluginResult);
    }// w  w  w.j av a 2s  . com
}

From source file:ai.api.ApiAiPlugin.java

License:Apache License

@Override
public void onListeningFinished() {
    if (listeningFinishCallback != null) {
        final PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
        pluginResult.setKeepCallback(true);
        listeningFinishCallback.sendPluginResult(pluginResult);
    }//from   w w  w .  ja  v  a 2 s .co  m
}

From source file:ai.api.ApiAiPlugin.java

License:Apache License

@Override
public void onListeningCanceled() {
    if (listeningCanceledCallback != null) {
        final PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
        pluginResult.setKeepCallback(true);
        listeningCanceledCallback.sendPluginResult(pluginResult);
    }/*  ww  w.j  a va  2  s.  com*/
}

From source file:ai.api.ApiAiPlugin.java

License:Apache License

public void onPartialResults(final List<String> results) {
    if (partialResultsCallback != null) {
        final PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, gson.toJson(results));
        pluginResult.setKeepCallback(true);
        partialResultsCallback.sendPluginResult(pluginResult);
    }/*  ww w  . j a va 2 s  .  c om*/
}

From source file:ai.api.ApiAiPlugin.java

License:Apache License

public void onRecognitionResults(final List<String> recognitionResults) {
    if (recognitionResultsCallback != null && recognitionResults != null) {
        final PluginResult pluginResult = new PluginResult(PluginResult.Status.OK,
                gson.toJson(recognitionResults));
        pluginResult.setKeepCallback(true);
        recognitionResultsCallback.sendPluginResult(pluginResult);
    }/*from  ww w.  j ava2  s.c  o m*/
}

From source file:at.modalog.cordova.plugin.cache.Cache.java

License:MIT License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    /*try/*from w  w w. j a  v  a 2  s.c  o m*/
    {
    */
    if (action.equals("clear")) {
        Log.v(LOG_TAG, "Cordova Android Cache.clear() called.");
        this.callbackContext = callbackContext;

        final Cache self = this;
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                try {
                    // clear the cache
                    self.webView.clearCache(true);

                    // 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 clearing webview cache.";
                    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;
    /*
    }
    catch (JSONException e)
    {
    // TODO: signal JSON problem to JS
    //callbackContext.error("Problem with JSON");
    return false;
    }
    */
}