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:au.com.micropacific.cordova.CipherlabRS30Plugin.java

License:Open Source License

public void receieveScan(String data, int format) {

    final JSONObject result = new JSONObject();
    try {/*from www .  j  a v a  2s .com*/
        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:co.lingeng.cordova.wechat_pay.WechatPay.java

License:Apache License

public static void successCallback(String result) {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result);
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
}

From source file:co.lingeng.cordova.wechat_pay.WechatPay.java

License:Apache License

public static void failedCallback(String result) {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, result);
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
}

From source file:co.mwater.foregroundcameraplugin.ForegroundCameraLauncher.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 * /* ww w . j  a va  2 s  .  co  m*/
 * @param action
 *            The action to execute.
 * @param args
 *            JSONArry of arguments for the plugin.
 * @param callbackId
 *            The callback id used when calling back into JavaScript.
 * @return A PluginResult object with a status and message.
 */
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";
    this.callbackContext = callbackContext;

    try {
        if (action.equals("takePicture")) {
            this.mQuality = args.getInt(0);
            this.destinationType = args.getInt(1);
            this.targetWidth = args.getInt(3);
            this.targetHeight = args.getInt(4);

            this.takePicture();

            PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
            r.setKeepCallback(true);
            callbackContext.sendPluginResult(r);
            return true;
        }
        return false;
    } catch (JSONException e) {
        e.printStackTrace();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
        return true;
    }
}

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

@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
    Action actionMethods;/* www.  jav  a 2s. c  o  m*/
    try {
        actionMethods = Action.valueOf(action);
    } catch (Exception ex) {
        ex.printStackTrace();
        JSONObject obj = new JSONObject();
        try {
            obj.put("id", "execute");
            obj.put("error", String.valueOf(ex));
            PluginResult result = new PluginResult(PluginResult.Status.INVALID_ACTION, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return false;
    }
    JSONObject obj = new JSONObject();

    switch (actionMethods) {
    case initAcuantMobileSDK:
        methodId = "initAcuantMobileSDK";
        callbackId = callbackContext;
        if (data.getString(0) != null) {
            key = data.getString(0);
        } else {
            key = "";
        }
        if (data.getString(1) != null && !data.getString(1).trim().equalsIgnoreCase("")) {
            cloudAddressString = data.getString(1);
        } else {
            cloudAddressString = "cssnwebservices.com";
        }

        // load the controller instance
        acuantAndroidMobileSDKController = AcuantAndroidMobileSDKController.getInstance(cordova.getActivity(),
                cloudAddressString, key);
        acuantAndroidMobileSDKController.setWebServiceListener(this);
        acuantAndroidMobileSDKController.setCardCroppingListener(this);
        acuantAndroidMobileSDKController.setAcuantErrorListener(this);
        sdkController = acuantAndroidMobileSDKController;
        break;
    case initAcuantMobileSDKAndShowCardCaptureInterfaceInViewController:
        methodId = "initAcuantMobileSDKAndShowCardCaptureInterfaceInViewController";

        callbackId = callbackContext;
        if (data.getString(0) != null) {
            key = data.getString(0);
        } else {
            key = "";
        }

        if (data.getInt(1) == 1) {
            cardType = CardType.MEDICAL_INSURANCE;
        } else if (data.getInt(1) == 2) {
            cardType = CardType.DRIVERS_LICENSE;
        } else if (data.getInt(1) == 3) {
            cardType = CardType.PASSPORT;
        }

        if (cardType == CardType.DRIVERS_LICENSE) {
            cardRegion = data.getInt(2);
            isBarcodeSide = data.getBoolean(3);
        } else {
            cardRegion = 0;
            isBarcodeSide = false;
        }

        // load the controller instance
        acuantAndroidMobileSDKController = AcuantAndroidMobileSDKController.getInstanceAndShowCameraInterface(
                cordova.getActivity(), key, cordova.getActivity(), cardType, cardRegion, isBarcodeSide);
        break;
    case showManualCameraInterfaceInViewController:
        methodId = "showManualCameraInterfaceInViewController";
        callbackId = callbackContext;

        if (data.getInt(0) == 1) {
            cardType = CardType.MEDICAL_INSURANCE;
        } else if (data.getInt(0) == 2) {
            cardType = CardType.DRIVERS_LICENSE;
        } else if (data.getInt(0) == 3) {
            cardType = CardType.PASSPORT;
        }

        if (cardType == CardType.DRIVERS_LICENSE) {
            cardRegion = data.getInt(1);
            isBarcodeSide = data.getBoolean(2);
        } else {
            cardRegion = 0;
            isBarcodeSide = false;
        }
        acuantAndroidMobileSDKController.showManualCameraInterface(cordova.getActivity(), cardType, cardRegion,
                isBarcodeSide);
        break;
    case showBarcodeCameraInterfaceInViewController:
        methodId = "showBarcodeCameraInterfaceInViewController";
        callbackId = callbackContext;

        if (data.getInt(0) == 1) {
            cardType = CardType.MEDICAL_INSURANCE;
        } else if (data.getInt(0) == 2) {
            cardType = CardType.DRIVERS_LICENSE;
        } else if (data.getInt(0) == 3) {
            cardType = CardType.PASSPORT;
        }

        if (cardType == CardType.DRIVERS_LICENSE) {
            cardRegion = data.getInt(1);
        } else {
            cardRegion = 0;
        }

        acuantAndroidMobileSDKController.showCameraInterfacePDF417(cordova.getActivity(), cardType, cardRegion);
        break;
    case dismissCardCaptureInterface:
        callbackId = callbackContext;
        try {
            obj.put("id", "dismissCardCaptureInterface");
            obj.put("error", "No " + action + " Method");
            if (acuantAndroidMobileSDKController.getBarcodeCameraContext() != null) {
                acuantAndroidMobileSDKController.finishScanningBarcodeCamera();
            }
            PluginResult result = new PluginResult(PluginResult.Status.INVALID_ACTION, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case startCamera:
        methodId = "startCamera";
        callbackId = callbackContext;
        try {
            obj.put("id", methodId);
            obj.put("error", "No " + action + " Method");
            PluginResult result = new PluginResult(PluginResult.Status.INVALID_ACTION, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case stopCamera:
        methodId = "stopCamera";
        callbackId = callbackContext;
        try {
            obj.put("id", methodId);
            obj.put("error", "No " + action + " Method");
            PluginResult result = new PluginResult(PluginResult.Status.INVALID_ACTION, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case pauseScanningBarcodeCamera:
        methodId = "pauseScanningBarcodeCamera";
        callbackId = callbackContext;
        acuantAndroidMobileSDKController.pauseScanningBarcodeCamera();
        break;
    case resumeScanningBarcodeCamera:
        methodId = "resumeScanningBarcodeCamera";
        callbackId = callbackContext;
        acuantAndroidMobileSDKController.resumeScanningBarcodeCamera();
        break;
    case setLicenseKey:
        methodId = "setLicenseKey";
        callbackId = callbackContext;
        if (data.getString(0) != null && data.getString(0).trim().length() > 0) {
            key = data.getString(0);
        } else {
            obj.put("id", methodId);
            obj.put("data", false);
            obj.put("errorType", ErrorType.AcuantErrorOnActiveLicenseKey);
            obj.put("errorMessage", "The license key cannot be empty.");
            PluginResult result = new PluginResult(PluginResult.Status.ERROR, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
            break;
        }
        if (key.contains(" ")) {
            obj.put("id", methodId);
            obj.put("data", false);
            obj.put("errorType", ErrorType.AcuantErrorOnActiveLicenseKey);
            obj.put("errorMessage", "The license key cannot be empty.");
            PluginResult result = new PluginResult(PluginResult.Status.ERROR, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
            break;
        }
        acuantAndroidMobileSDKController.setLicensekey(key);
        break;
    case setCloudAddress:
        methodId = "setCloudAddress";
        callbackId = callbackContext;
        if (data.getString(0) != null) {
            cloudAddressString = data.getString(0);
        } else {
            cloudAddressString = "cssnwebservices.com";
        }
        acuantAndroidMobileSDKController.setCloudUrl(cloudAddressString);
        break;
    case setWidth:
        methodId = "setWidth";
        callbackId = callbackContext;
        int width = data.getInt(0);
        if (width == 0) {
            width = 637;
        }
        acuantAndroidMobileSDKController.setWidth(width);
        break;
    case setCanCropBarcode:
        methodId = "setCanCropBarcode";
        callbackId = callbackContext;
        canCropBarcode = data.getBoolean(0);
        acuantAndroidMobileSDKController.setCropBarcode(canCropBarcode);
        break;
    case setCanCaptureOriginalImage:
        methodId = "setCanCaptureOriginalImage";
        callbackId = callbackContext;
        canCaptureOriginalImage = data.getBoolean(0);
        acuantAndroidMobileSDKController.setCaptureOriginalCapture(canCaptureOriginalImage);
        break;
    case setCropBarcodeOnCancel:
        methodId = "setCropBarcodeOnCancel";
        callbackId = callbackContext;
        cropBarcodeOnCancel = data.getBoolean(0);
        acuantAndroidMobileSDKController.setCropBarcodeOnCancel(cropBarcodeOnCancel);
        break;
    case enableLocationAuthentication:
        methodId = "enableLocationAuthentication";
        acuantAndroidMobileSDKController.enableLocationAuthentication(cordova.getActivity());
        break;
    case setCanShowMessage:
        methodId = "setCanShowMessage";
        callbackId = callbackContext;
        canShowMessage = data.getBoolean(0);
        acuantAndroidMobileSDKController.setShowInitialMessage(canShowMessage);
        break;
    case setInitialMessage:
        methodId = "setInitialMessage";
        callbackId = callbackContext;
        String initialMessage = data.getString(0);
        int initialMessageRed = data.getInt(5);
        int initialMessageGreen = data.getInt(6);
        int initialMessageBlue = data.getInt(7);
        int initialMessageApha = data.getInt(8);
        acuantAndroidMobileSDKController.setInitialMessageDescriptor(initialMessage, initialMessageRed,
                initialMessageGreen, initialMessageBlue, initialMessageApha);
        break;
    case setCapturingMessage:
        methodId = "setCapturingMessage";
        callbackId = callbackContext;
        String capturingMessage = data.getString(0);
        int capturingMessageRed = data.getInt(5);
        int capturingMessageGreen = data.getInt(6);
        int capturingMessageBlue = data.getInt(7);
        int capturingMessageApha = data.getInt(8);
        acuantAndroidMobileSDKController.setFinalMessageDescriptor(capturingMessage, capturingMessageRed,
                capturingMessageGreen, capturingMessageBlue, capturingMessageApha);
        break;
    case processCardImage:
        methodId = "processCardImage";
        callbackId = callbackContext;
        callbackIdImageProcess = callbackContext;
        String frontImageEcodedString = data.getString(0);
        byte[] frontImageDecodedString = Base64.decode(frontImageEcodedString, Base64.DEFAULT);
        Bitmap frontImageDecodedByte = BitmapFactory.decodeByteArray(frontImageDecodedString, 0,
                frontImageDecodedString.length);
        Drawable frontImageDrawable = new BitmapDrawable(cordova.getActivity().getResources(),
                frontImageDecodedByte);

        String backImageEcodedString = data.getString(1);
        byte[] backImageDecodedString = Base64.decode(backImageEcodedString, Base64.DEFAULT);
        Bitmap backImageDecodedByte = BitmapFactory.decodeByteArray(backImageDecodedString, 0,
                backImageDecodedString.length);
        Drawable backImageDrawable = new BitmapDrawable(cordova.getActivity().getResources(),
                backImageDecodedByte);

        String stringData = data.getString(2);
        if (stringData != null && stringData.equalsIgnoreCase("null")) {
            stringData = null;
        }

        ProcessImageRequestOptions options = ProcessImageRequestOptions.getInstance();
        options.autoDetectState = data.getBoolean(3);
        options.stateID = data.getInt(4);
        options.reformatImage = data.getBoolean(5);
        options.reformatImageColor = data.getInt(6);
        options.DPI = data.getInt(7);
        options.cropImage = data.getBoolean(8);
        options.faceDetec = data.getBoolean(9);
        options.signDetec = data.getBoolean(10);
        if (cardType == CardType.DRIVERS_LICENSE) {
            options.iRegion = data.getInt(11);
        } else {
            options.iRegion = 0;
        }
        options.logTransaction = data.getBoolean(12);
        options.imageSettings = data.getInt(13);
        options.acuantCardType = cardType;
        acuantAndroidMobileSDKController.callProcessImageServices(frontImageDecodedByte, backImageDecodedByte,
                stringData, cordova.getActivity(), options);
        break;
    case cameraPrefersStatusBarHidden:
        methodId = "cameraPrefersStatusBarHidden";
        callbackId = callbackContext;
        canShowStatusBar = data.getBoolean(0);
        acuantAndroidMobileSDKController.setShowStatusBar(canShowStatusBar);
        break;
    case frameForWatermarkView:
        callbackId = callbackContext;
        xWatermark = data.getInt(0);
        yWatermark = data.getInt(1);
        widthWatermark = data.getInt(2);
        heightWatermark = data.getInt(3);
        acuantAndroidMobileSDKController.setWatermarkText(watermarkText, xWatermark, yWatermark, widthWatermark,
                heightWatermark);
        break;
    case stringForWatermarkLabel:
        callbackId = callbackContext;
        watermarkText = data.getString(0);
        acuantAndroidMobileSDKController.setWatermarkText(watermarkText, xWatermark, yWatermark, widthWatermark,
                heightWatermark);
        break;
    case frameForHelpImageView:
        callbackId = callbackContext;
        try {
            obj.put("id", "frameForHelpImageView");
            obj.put("error", "No " + action + " Method");
            PluginResult result = new PluginResult(PluginResult.Status.INVALID_ACTION, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case imageForHelpImageView:
        callbackId = callbackContext;
        String encodedImage = data.getString(0);
        if (encodedImage.contains("data:image/png;base64,")) {
            encodedImage = encodedImage.replaceFirst("data:image/png;base64,", "");
        }
        byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
        Drawable pdf417BarcodeImageDrawable = new BitmapDrawable(cordova.getActivity().getResources(),
                decodedByte);
        acuantAndroidMobileSDKController.setPdf417BarcodeImageDrawable(pdf417BarcodeImageDrawable);
        break;
    case showBackButton:
        callbackId = callbackContext;
        try {
            obj.put("id", "showBackButton");
            obj.put("error", "No " + action + " Method");
            PluginResult result = new PluginResult(PluginResult.Status.INVALID_ACTION, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case frameForBackButton:
        callbackId = callbackContext;
        try {
            obj.put("id", "frameForBackButton");
            obj.put("error", "No " + action + " Method");
            PluginResult result = new PluginResult(PluginResult.Status.INVALID_ACTION, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case imageForBackButton:
        callbackId = callbackContext;
        try {
            obj.put("id", "imageForBackButton");
            obj.put("error", "No " + action + " Method");
            PluginResult result = new PluginResult(PluginResult.Status.INVALID_ACTION, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case showiPadBrackets:
        methodId = "showiPadBrackets";
        callbackId = callbackContext;
        boolean showiPadBrackets = false;
        showiPadBrackets = data.getBoolean(0);
        acuantAndroidMobileSDKController.setCanShowBracketsOnTablet(showiPadBrackets);
        break;
    case showFlashlightButton:
        methodId = "showFlashlightButton";
        callbackId = callbackContext;
        boolean showFlashlight = false;
        showFlashlight = data.getBoolean(0);
        acuantAndroidMobileSDKController.setFlashlight(showFlashlight);
        break;
    case frameForFlashlightButton:
        methodId = "frameForFlashlightButton";
        callbackId = callbackContext;
        xFlashlight = data.getInt(0);
        yFlashlight = data.getInt(1);
        widthFlashlight = data.getInt(2);
        heightFlashlight = data.getInt(3);
        acuantAndroidMobileSDKController.setFlashlight(xFlashlight, yFlashlight, widthFlashlight,
                heightFlashlight);
        break;
    case imageForFlashlightButton:
        methodId = "imageForFlashlightButton";
        callbackId = callbackContext;
        String encodedImageOn = data.getString(0);
        if (encodedImageOn.contains("data:image/png;base64,")) {
            encodedImageOn = encodedImageOn.replaceFirst("data:image/png;base64,", "");
        }
        byte[] decodedStringOn = Base64.decode(encodedImageOn, Base64.DEFAULT);
        Bitmap decodedByteOn = BitmapFactory.decodeByteArray(decodedStringOn, 0, decodedStringOn.length);
        Drawable flashlightButtonImageDrawableOn = new BitmapDrawable(cordova.getActivity().getResources(),
                decodedByteOn);
        String encodedImageOff = data.getString(1);
        if (encodedImageOff.contains("data:image/png;base64,")) {
            encodedImageOff = encodedImageOff.replaceFirst("data:image/png;base64,", "");
        }
        byte[] decodedStringOff = Base64.decode(encodedImageOff, Base64.DEFAULT);
        Bitmap decodedByteOff = BitmapFactory.decodeByteArray(decodedStringOff, 0, decodedStringOff.length);
        Drawable flashlightButtonImageDrawableOff = new BitmapDrawable(cordova.getActivity().getResources(),
                decodedByteOff);
        acuantAndroidMobileSDKController.setFlashlightImageDrawable(flashlightButtonImageDrawableOn,
                flashlightButtonImageDrawableOff);
        break;
    case showFacialInterface:
        methodId = "showFacialInterface";
        callbackId = callbackContext;
        acuantAndroidMobileSDKController.setFacialListener(this);
        Paint subInstPaint = null;
        if (facialSubInstHexColor != null) {
            subInstPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
            Typeface currentTypeFace = subInstPaint.getTypeface();
            Typeface bold = Typeface.create(currentTypeFace, Typeface.BOLD);
            subInstPaint.setColor(Color.parseColor(facialSubInstHexColor));
            subInstPaint.setTextSize(30);
            subInstPaint.setTextAlign(Paint.Align.LEFT);
            subInstPaint.setTypeface(bold);
        }
        if (facialInstrunctionText != null) {
            Paint InstPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
            Typeface currentTypeFace = InstPaint.getTypeface();
            Typeface bold = Typeface.create(currentTypeFace, Typeface.BOLD);
            InstPaint.setColor(Color.parseColor(facialInstructionTextFontColor));
            InstPaint.setTextSize(facialInstructionTextFontSize);
            InstPaint.setTextAlign(Paint.Align.LEFT);
            InstPaint.setTypeface(bold);
            acuantAndroidMobileSDKController.setInstructionText(facialInstrunctionText, facialInstructionLeft,
                    facialInstructionTop, InstPaint);
        }
        acuantAndroidMobileSDKController.setSubInstructionText(facialSubInstructionString, facialSubInstLeft,
                facialSubInstTop, subInstPaint);
        acuantAndroidMobileSDKController.showManualFacialCameraInterface(cordova.getActivity());
        break;
    case setFacialInstructionText:
        methodId = "setFacialInstructionText";
        callbackId = callbackContext;
        String facialInstruction = data.getString(0);
        if (facialInstruction != null) {
            facialInstrunctionText = facialInstruction;
        }
        break;
    case setFacialInstructionLocation:
        methodId = "setFacialInstructionLocation";
        callbackId = callbackContext;
        facialInstructionLeft = data.getInt(0);
        facialInstructionTop = data.getInt(1);

        break;
    case setFacialInstructionTextStyle:
        methodId = "setFacialInstructionTextStyle";
        callbackId = callbackContext;
        facialInstructionTextFontColor = data.getString(0);
        facialInstructionTextFontSize = data.getInt(1);
        break;
    case setFacialRecognitionTimeout:
        methodId = "setFacialRecognitionTimeout";
        callbackId = callbackContext;
        facialTimeOut = data.getInt(0);
        acuantAndroidMobileSDKController.setFacialRecognitionTimeoutInSeconds(facialTimeOut);
        break;
    case processFacialImageValidation:
        methodId = "processFacialImageValidation";
        callbackId = callbackContext;
        callbackIdFacialProcess = callbackContext;
        cardType = CardType.FACIAL_RECOGNITION;
        String selfieImageEcodedString = data.getString(0);
        byte[] selfieImageDecodedString = Base64.decode(selfieImageEcodedString, Base64.DEFAULT);
        Bitmap selfieImageDecodedByte = BitmapFactory.decodeByteArray(selfieImageDecodedString, 0,
                selfieImageDecodedString.length);

        String faceImageEcodedString = data.getString(1);
        byte[] faceImageDecodedString = Base64.decode(faceImageEcodedString, Base64.DEFAULT);
        Bitmap faceImageDecodedByte = BitmapFactory.decodeByteArray(faceImageDecodedString, 0,
                faceImageDecodedString.length);

        ProcessImageRequestOptions facialOptions = ProcessImageRequestOptions.getInstance();
        facialOptions.logTransaction = data.getBoolean(2);

        facialOptions.acuantCardType = CardType.FACIAL_RECOGNITION;
        acuantAndroidMobileSDKController.callProcessImageServices(selfieImageDecodedByte, faceImageDecodedByte,
                null, cordova.getActivity(), facialOptions);
        break;
    case setFacialSubInstructionString:
        methodId = "setFacialSubInstructionString";
        callbackId = callbackContext;
        facialSubInstructionString = data.getString(0);
        break;
    case setFacialSubInstructionColor:
        methodId = "setFacialSubInstructionColor";
        callbackId = callbackContext;
        facialSubInstHexColor = data.getString(0);
        break;
    case setFacialSubInstructionLocation:
        methodId = "setFacialSubInstructionLocation";
        callbackId = callbackContext;
        facialSubInstLeft = data.getInt(0);
        facialSubInstTop = data.getInt(1);
        break;

    case scanEChip:
        methodId = "scanEChip";
        if (nfcAdapter == null) {
            nfcAdapter = NfcAdapter.getDefaultAdapter(cordova.getActivity());
        }

        if (nfcAdapter == null) {
            JSONObject errorObj = new JSONObject();
            errorObj.put("id", "nfcError");
            errorObj.put("errorMessage", "NFC is not available for this device");
            errorObj.put("errorType", ErrorType.AcuantErrorUnknown);
            PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, errorObj);
            pluginResult.setKeepCallback(true);
            callbackId.sendPluginResult(pluginResult);
        } else if (this.nfcAdapter != null && !this.nfcAdapter.isEnabled()) {
            JSONObject errorObj = new JSONObject();
            errorObj.put("id", "nfcError");
            errorObj.put("errorType", ErrorType.AcuantErrorUnknown);
            errorObj.put("errorMessage", "In order to use scan eChip, the NFC sensor must be turned on.");
            PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, errorObj);
            pluginResult.setKeepCallback(true);
            callbackId.sendPluginResult(pluginResult);
        } else {
            acuantAndroidMobileSDKController.listenNFC(cordova.getActivity(), nfcAdapter);
            JSONObject errorObj = new JSONObject();
            errorObj.put("id", "nfcReady");
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, errorObj);
            pluginResult.setKeepCallback(true);
            callbackId.sendPluginResult(pluginResult);
        }
        break;

    case readEChip:
        methodId = "readEChip";
        if (nfcAdapter == null) {
            JSONObject errorObj = new JSONObject();
            errorObj.put("id", "nfcError");
            errorObj.put("errorMessage", "NFC is not available for this device");
            PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, errorObj);
            pluginResult.setKeepCallback(true);
            callbackId.sendPluginResult(pluginResult);
        } else if (this.nfcAdapter != null && !this.nfcAdapter.isEnabled()) {
            JSONObject errorObj = new JSONObject();
            errorObj.put("id", "nfcError");
            errorObj.put("errorMessage", "In order to use scan eChip, the NFC sensor must be turned on.");
            PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, errorObj);
            pluginResult.setKeepCallback(true);
            callbackId.sendPluginResult(pluginResult);
        } else {
            nfcIntent.setAction("android.nfc.action.TECH_DISCOVERED");
            Intent intent = nfcIntent;
            echip_docNumber = data.getString(1);
            echip_dateOfBirth = data.getString(2);
            echip_dateOfExpiry = data.getString(3);
            acuantAndroidMobileSDKController.setAcuantTagReadingListener(this);
            acuantAndroidMobileSDKController.readNFCTag(intent, echip_docNumber, echip_dateOfBirth,
                    echip_dateOfExpiry);
        }
        break;
    case isSDKValidated:
        try {
            obj.put("id", "isSDKValidated");
            obj.put("data", sdkValidated);
            PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    default:
        callbackId = callbackContext;
        try {
            obj.put("id", "default");
            obj.put("error", "No " + action + " Method");
            PluginResult result = new PluginResult(PluginResult.Status.INVALID_ACTION, obj);
            result.setKeepCallback(true);
            callbackId.sendPluginResult(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return false;
    }
    return true;
}

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

@Override
public void onFacialRecognitionTimedOut(final Bitmap bitmap) {

    JSONObject obj = new JSONObject();
    try {//from  ww  w .j av  a2 s .  c  o  m
        obj.put("id", "onFacialRecognitionTimedOut");
        if (bitmap != null) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
            byte[] byteArray = byteArrayOutputStream.toByteArray();
            String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
            obj.put("selfieImageData", encoded);
        }
        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 onFacialRecognitionCompleted(final Bitmap bitmap) {
    JSONObject obj = new JSONObject();
    try {/*from  w  w  w. ja v a2s  .  co  m*/
        obj.put("id", "onFacialRecognitionCompleted");
        if (bitmap != null) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
            byte[] byteArray = byteArrayOutputStream.toByteArray();
            String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
            obj.put("selfieImageData", encoded);
        }
        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 onFacialRecognitionCanceled() {
    JSONObject obj = new JSONObject();
    try {/*w  w  w. ja v a2  s  .  c om*/
        obj.put("id", "onFacialRecognitionCanceled");
        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 onCancelCapture(Bitmap croppedImage, HashMap<String, Object> imageMetrics, Bitmap originalImage) {
    JSONObject obj = new JSONObject();
    try {/*from   www  . j av a  2s  . c  o m*/
        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 {//ww  w  .j av 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();
    }
}