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.acuant.plugin.AcuantMobileSDK.java

@Override
public void onCancelCapture(Bitmap croppedImage, HashMap<String, Object> imageMetrics, Bitmap originalImage) {
    JSONObject obj = new JSONObject();
    try {/*from  w w w .  j a v a2 s  . c om*/
        obj.put("id", "didCancelToCaptureData");
        if (croppedImage != null) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            croppedImage.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
            byte[] byteArray = byteArrayOutputStream.toByteArray();
            String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
            obj.put("croppedImageData", encoded);
        }
        if (originalImage != null) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            originalImage.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
            byte[] byteArray = byteArrayOutputStream.toByteArray();
            String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
            obj.put("originalImageData", encoded);
        }
        if (imageMetrics != null && imageMetrics.get("HAS_GLARE") != null) {
            boolean hasGlare = Boolean.parseBoolean(imageMetrics.get("HAS_GLARE").toString());
            obj.put("HAS_GLARE", hasGlare);
        }
        if (imageMetrics != null && imageMetrics.get("GLARE_GRADE") != null) {
            float glareGrade = Float.parseFloat(imageMetrics.get("GLARE_GRADE").toString());
            obj.put("GLARE_GRADE", glareGrade);
        }

        if (imageMetrics != null && imageMetrics.get("IS_SHARP") != null) {
            boolean isSHarp = Boolean.parseBoolean(imageMetrics.get("IS_SHARP").toString());
            obj.put("IS_SHARP", isSHarp);
        }
        if (imageMetrics != null && imageMetrics.get("SHARPNESS_GRADE") != null) {
            float sharpnessGrade = Float.parseFloat(imageMetrics.get("SHARPNESS_GRADE").toString());
            obj.put("SHARPNESS_GRADE", sharpnessGrade);
        }
        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, obj);
        pluginResult.setKeepCallback(true);
        callbackId.sendPluginResult(pluginResult);
    } catch (JSONException e) {
        e.printStackTrace();
    }

}

From source file:com.acuant.plugin.AcuantMobileSDK.java

@Override
public void didFailWithError(int code, String message) {
    JSONObject obj = new JSONObject();
    try {//from ww w.  jav  a2 s  . c  o m
        obj.put("id", "didFailWithError");
        obj.put("data", false);
        obj.put("errorType", code);
        obj.put("errorMessage", message);
        PluginResult result = new PluginResult(PluginResult.Status.ERROR, obj);
        result.setKeepCallback(true);
        callbackId.sendPluginResult(result);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.acuant.plugin.AcuantMobileSDK.java

private void sendCardData(final PluginResult.Status statusCallback, final JSONObject objCallback,
        Handler handler) {/*w  w  w  . j  a  va 2 s .c o  m*/
    handler.post(new Runnable() {
        @Override
        public void run() {
            PluginResult resultCallback = new PluginResult(statusCallback, objCallback);
            resultCallback.setKeepCallback(true);
            callbackId.sendPluginResult(resultCallback);
        }
    });
}

From source file:com.acuant.plugin.AcuantMobileSDK.java

@Override
public void validateLicenseKeyCompleted(LicenseDetails details) {
    JSONObject obj = new JSONObject();
    try {//from w w w  .  j  a va 2  s.  c om
        if (details != null && details.isLicenseKeyActivated()) {
            sdkValidated = true;
            obj.put("id", "mobileSDKWasValidated");
            obj.put("data", true);
            obj.put("message", details.getWebResponseDescription());
            obj.put("isAssureIDAllowed", details.isAssureIDAllowed());
            obj.put("isFacialAllowed", details.isFacialAllowed());
            PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } else {
            sdkValidated = false;
            obj.put("id", "didFailWithError");
            obj.put("data", false);
            obj.put("errorType", ErrorType.AcuantErrorInvalidLicenseKey);
            obj.put("errorMessage", details.getResponseMessageAuthorization());
            PluginResult result = new PluginResult(PluginResult.Status.ERROR, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.acuant.plugin.AcuantMobileSDK.java

@Override
public void onCardImageCaptured() {
    cordova.getThreadPool().execute(new Runnable() {
        @Override// w ww .  j  av  a  2s .  c o  m
        public void run() {
            try {
                JSONObject obj = new JSONObject();
                obj.put("id", "onCardImageCaptured");
                PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
                result.setKeepCallback(true);
                callbackId.sendPluginResult(result);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:com.acuant.plugin.AcuantMobileSDK.java

@Override
public void onCardCroppingStart(Activity activity) {
    cordova.getThreadPool().execute(new Runnable() {
        @Override//w  w  w.j  a  va2  s .  c o m
        public void run() {
            try {
                JSONObject obj = new JSONObject();
                obj.put("id", "didCardCroppingStart");
                PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
                result.setKeepCallback(true);
                callbackId.sendPluginResult(result);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:com.acuant.plugin.AcuantMobileSDK.java

@Override
public void onCardCroppingFinish(final Bitmap bitmap, int detectedType,
        final HashMap<String, Object> imageMetrics) {

    if (bitmap != null) {
        cordova.getThreadPool().execute(new Runnable() {
            @Override/*ww w . jav a  2  s.  c  o  m*/
            public void run() {
                try {
                    JSONObject obj = new JSONObject();
                    obj.put("id", "didCaptureCropImage");
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
                    byte[] byteArray = byteArrayOutputStream.toByteArray();
                    String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
                    obj.put("data", encoded);

                    if (imageMetrics != null && imageMetrics.get("HAS_GLARE") != null) {
                        boolean hasGlare = Boolean.parseBoolean(imageMetrics.get("HAS_GLARE").toString());
                        obj.put("HAS_GLARE", hasGlare);
                    }
                    if (imageMetrics != null && imageMetrics.get("GLARE_GRADE") != null) {
                        float glareGrade = Float.parseFloat(imageMetrics.get("GLARE_GRADE").toString());
                        obj.put("GLARE_GRADE", glareGrade);
                    }

                    if (imageMetrics != null && imageMetrics.get("IS_SHARP") != null) {
                        boolean isSHarp = Boolean.parseBoolean(imageMetrics.get("IS_SHARP").toString());
                        obj.put("IS_SHARP", isSHarp);
                    }
                    if (imageMetrics != null && imageMetrics.get("SHARPNESS_GRADE") != null) {
                        float sharpnessGrade = Float.parseFloat(imageMetrics.get("SHARPNESS_GRADE").toString());
                        obj.put("SHARPNESS_GRADE", sharpnessGrade);
                    }
                    PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
                    result.setKeepCallback(true);
                    callbackId.sendPluginResult(result);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    } else {
        cordova.getThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    JSONObject obj = new JSONObject();
                    obj.put("id", "didFailWithError");
                    obj.put("errorType", 8);
                    obj.put("errorMessage", "Unable to detect the card. Please try again.");
                    PluginResult result = new PluginResult(PluginResult.Status.ERROR, obj);
                    result.setKeepCallback(true);
                    callbackId.sendPluginResult(result);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

}

From source file:com.acuant.plugin.AcuantMobileSDK.java

@Override
public void onCardCroppingFinish(final Bitmap bitmap, final boolean scanBackSide, int detectedType,
        final HashMap<String, Object> imageMetrics) {
    if (bitmap != null) {
        cordova.getThreadPool().execute(new Runnable() {
            @Override/*from w w w .  ja v  a2s.c  o  m*/
            public void run() {
                try {
                    JSONObject obj = new JSONObject();
                    if ((cardRegion == 0 || cardRegion == 1) && isBarcodeSide) {
                        obj.put("id", "cropBarcode");
                    } else {
                        obj.put("id", "didCaptureCropImage");
                    }
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
                    byte[] byteArray = byteArrayOutputStream.toByteArray();
                    String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
                    obj.put("data", encoded);
                    obj.put("scanBackSide", scanBackSide);
                    if (imageMetrics != null && imageMetrics.get("HAS_GLARE") != null) {
                        boolean hasGlare = Boolean.parseBoolean(imageMetrics.get("HAS_GLARE").toString());
                        obj.put("HAS_GLARE", hasGlare);
                    }
                    if (imageMetrics != null && imageMetrics.get("GLARE_GRADE") != null) {
                        float glareGrade = Float.parseFloat(imageMetrics.get("GLARE_GRADE").toString());
                        obj.put("GLARE_GRADE", glareGrade);
                    }

                    if (imageMetrics != null && imageMetrics.get("IS_SHARP") != null) {
                        boolean isSHarp = Boolean.parseBoolean(imageMetrics.get("IS_SHARP").toString());
                        obj.put("IS_SHARP", isSHarp);
                    }
                    if (imageMetrics != null && imageMetrics.get("SHARPNESS_GRADE") != null) {
                        float sharpnessGrade = Float.parseFloat(imageMetrics.get("SHARPNESS_GRADE").toString());
                        obj.put("SHARPNESS_GRADE", sharpnessGrade);
                    }
                    PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
                    result.setKeepCallback(true);
                    callbackId.sendPluginResult(result);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    } else {
        cordova.getThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    JSONObject obj = new JSONObject();
                    obj.put("id", "didFailWithError");
                    obj.put("errorType", 8);
                    obj.put("errorMessage", "Unable to detect the card. Please try again.");
                    PluginResult result = new PluginResult(PluginResult.Status.ERROR, obj);
                    result.setKeepCallback(true);
                    callbackId.sendPluginResult(result);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });

    }

}

From source file:com.acuant.plugin.AcuantMobileSDK.java

@Override
public void onOriginalCapture(final Bitmap bitmap) {
    if (bitmap != null) {

        cordova.getThreadPool().execute(new Runnable() {
            @Override/*from w w w  .jav  a2  s.  c o m*/
            public void run() {
                try {
                    JSONObject obj = new JSONObject();
                    obj.put("id", "didCaptureOriginalImage");
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
                    byte[] byteArray = byteArrayOutputStream.toByteArray();
                    String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
                    obj.put("data", encoded);
                    PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
                    result.setKeepCallback(true);
                    callbackId.sendPluginResult(result);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });

    } else {

        cordova.getThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    JSONObject obj = new JSONObject();
                    obj.put("id", "didFailWithError");
                    obj.put("errorType", 8);
                    obj.put("errorMessage", "Unable to detect the card. Please try again.");
                    obj.put("ErrorInMethod", "onOriginalCapture");
                    PluginResult result = new PluginResult(PluginResult.Status.ERROR, obj);
                    result.setKeepCallback(true);
                    callbackId.sendPluginResult(result);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });

    }

}

From source file:com.acuant.plugin.AcuantMobileSDK.java

@Override
public void onPDF417Finish(String result) {
    JSONObject obj = new JSONObject();
    try {// w  w w .  j  a  va2s  .c o  m
        obj.put("id", "didCaptureData");
        obj.put("data", result);
        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, obj);
        pluginResult.setKeepCallback(true);
        callbackId.sendPluginResult(pluginResult);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}