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: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  www . j  a va  2  s.  com*/
    } 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   ww  w .jav  a  2 s . co  m
    } else {
        Log.w(TAG, "onFailureEvent: (no data)");
    }
}

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   w  w w  .  j a  va2s .  c  om
    }

    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

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);
    }//w  w w .  ja v  a2 s. co m
}

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  w w w  .  j a v  a2 s.  com*/
}

From source file:au.com.micropacific.cordova.CipherlabRS30Plugin.java

License:Open Source License

public void receieveScan(String data, int format) {

    final JSONObject result = new JSONObject();
    try {/*w  w w .j  a  v  a  2  s.co  m*/
        result.put("text", data);
        result.put("formatID", format);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    PluginResult progressResult = new PluginResult(PluginResult.Status.OK, result);
    progressResult.setKeepCallback(true);

    if (receiveScanCallback == null) {
        Log.v("CipherlabRS30Plugin", "receiveScanCallback is null.");
    } else {
        receiveScanCallback.sendPluginResult(progressResult);
    }
}

From source file:br.com.denguezerocidadao.Capture.java

License:Apache License

/**
 * Called when the video view exits.// ww w  .  j  a v  a2s .  c  om
 *
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 * @throws JSONException
 */
public void onActivityResult(int requestCode, int resultCode, final Intent intent) {

    // Result received okay
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == CAPTURE_VIDEO) {

            final Capture that = this;
            Runnable captureVideo = new Runnable() {

                @Override
                public void run() {

                    Uri data = null;

                    if (intent != null) {
                        // Get the uri of the video clip
                        data = intent.getData();
                    }

                    if (data == null) {
                        File movie = new File(getTempDirectoryPath(), "Capture.avi");
                        data = Uri.fromFile(movie);
                    }

                    // create a file object from the uri
                    if (data == null) {
                        that.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null"));
                    } else {
                        results.put(createMediaFile(data));

                        if (results.length() >= limit) {
                            // Send Uri back to JavaScript for viewing video
                            that.callbackContext
                                    .sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
                        } else {
                            // still need to capture more video clips
                            captureVideo(duration, quality);
                        }
                    }
                }
            };
            this.cordova.getThreadPool().execute(captureVideo);
        }
    }
    // If canceled
    else if (resultCode == Activity.RESULT_CANCELED) {
        // If we have partial results send them back to the user
        if (results.length() > 0) {
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
        }
        // user canceled the action
        else {
            this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Canceled."));
        }
    }
    // If something else
    else {
        // If we have partial results send them back to the user
        if (results.length() > 0) {
            this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
        }
        // something bad happened
        else {
            this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Did not complete!"));
        }
    }
}

From source file:br.com.hotforms.StatusBarManager.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false otherwise.
 *///w w  w.  ja  v  a 2  s.  c  o  m
@Override
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext)
        throws JSONException {
    Log.v(TAG, "Executing action: " + action);
    final Activity activity = this.cordova.getActivity();
    final Window window = activity.getWindow();

    if ("_ready".equals(action)) {
        boolean statusBarVisible = (window.getAttributes().flags
                & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible));
    } else if ("show".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
        });
        return true;
    } else if ("hide".equals(action)) {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

                if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                    window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
                }
            }
        });
        return true;
    } else if ("setTranslucent".equals(action)) {
        if (currentapiVersion >= android.os.Build.VERSION_CODES.KITKAT) {
            this.cordova.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                    if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                        window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                        window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
                    }

                    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                }
            });
            return true;
        } else {
            return false;
        }
    } else if ("setTransparent".equals(action)) {
        if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            this.cordova.getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

                    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
                }
            });
            return true;
        } else {
            return false;
        }
    } else if ("setColor".equals(action)) {
        if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            this.setColor(args.getInt(0), args.getInt(1), args.getInt(2));
            return true;
        } else {
            return false;
        }
    }

    return false;
}

From source file:ch.rts.cordova.is.tablet.IsTablet.java

License:Apache License

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

    Log.d(LOG_TAG, "Plugin execute called - " + this.toString());
    Context context = this.cordova.getActivity().getApplicationContext();
    boolean result = isTabletDevice(context);
    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
    return true;/*w  w  w  .ja v  a  2s .com*/
}

From source file:cn.edu.gdmec.t00385.lightsensor.LightSensorListener.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 *
 * @param action                The action to execute.
 * @param args                 JSONArry of arguments for the plugin.
 * @param callbackS=Context     The callback id used when calling back into JavaScript.
 * @return                     True if the action was valid.
 * @throws JSONException // w w  w.  java2  s.  co m
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("start")) {
        this.start();
    } else if (action.equals("stop")) {
        this.stop();
    } else if (action.equals("getStatus")) {
        int i = this.getStatus();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i));
    } else if (action.equals("getLumen")) {
        // If not running, then this is an async call, so don't worry about waiting
        if (this.status != LightSensorListener.RUNNING) {
            int r = this.start();
            if (r == LightSensorListener.ERROR_FAILED_TO_START) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION,
                        LightSensorListener.ERROR_FAILED_TO_START));
                return true;
            }
            // Set a timeout callback on the main thread.
            Handler handler = new Handler(Looper.getMainLooper());
            handler.postDelayed(new Runnable() {
                public void run() {
                    LightSensorListener.this.timeout();
                }
            }, 2000);
        }
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, getCompassHeading()));
    } else if (action.equals("setTimeout")) {
        this.setTimeout(args.getLong(0));
    } else if (action.equals("getTimeout")) {
        long l = this.getTimeout();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, l));
    } else {
        // Unsupported action
        return false;
    }
    return true;
}