package com.biopassid.facesdkreactnative import android.content.Context import android.graphics.Color import android.util.Log import android.util.Size import br.com.biopassid.facesdk.config.FaceConfig import br.com.biopassid.facesdk.config.enums.FaceCameraLensDirection import br.com.biopassid.facesdk.config.enums.FaceImageFormat import br.com.biopassid.facesdk.config.enums.FaceMaskFormat import br.com.biopassid.facesdk.config.enums.FaceResolutionPreset import br.com.biopassid.facesdk.model.FaceAttributes import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap private const val TAG = "FaceSdkReactNativeModule/Utils" object Utils { fun mapToFaceConfig(context: Context?, faceConfig: ReadableMap): FaceConfig { val mapConfig = faceConfig.toHashMap() val resolutionPreset: FaceResolutionPreset = when (mapConfig["resolutionPreset"] as String) { "LOW" -> FaceResolutionPreset.LOW "MEDIUM" -> FaceResolutionPreset.MEDIUM "HIGH" -> FaceResolutionPreset.HIGH "VERYHIGH" -> FaceResolutionPreset.VERYHIGH "ULTRAHIGH" -> FaceResolutionPreset.ULTRAHIGH else -> FaceResolutionPreset.MAX } val lensDirection: FaceCameraLensDirection = when (mapConfig["lensDirection"] as String) { "BACK" -> FaceCameraLensDirection.BACK else -> FaceCameraLensDirection.FRONT } val imageFormat: FaceImageFormat = when (mapConfig["imageFormat"] as String) { "PNG" -> FaceImageFormat.PNG else -> FaceImageFormat.JPEG } val licenseKey = mapConfig["licenseKey"] as String val flashEnabled = mapConfig["flashEnabled"] as Boolean val fontFamily = mapConfig["fontFamily"] as String // Gets liveness options properties val mapLiveness = mapConfig["liveness"] as Map<*, *> val livenessEnabled = mapLiveness["enabled"] as Boolean val livenessDebug = mapLiveness["debug"] as Boolean val livenessTimeToCapture = mapLiveness["timeToCapture"] as Double val livenessMaxFaceDetectionTime = mapLiveness["maxFaceDetectionTime"] as Double val livenessMinFaceProp = mapLiveness["minFaceProp"] as Double val livenessMaxFaceProp = mapLiveness["maxFaceProp"] as Double val livenessMinFaceWidth = mapLiveness["minFaceWidth"] as Double val livenessMinFaceHeight = mapLiveness["minFaceHeight"] as Double val livenessIed = mapLiveness["ied"] as Double val livenessBboxPad = mapLiveness["bboxPad"] as Double val livenessFaceDetectionThresh = mapLiveness["faceDetectionThresh"] as Double val livenessRollThresh = mapLiveness["rollThresh"] as Double val livenessPitchThresh = mapLiveness["pitchThresh"] as Double val livenessYawThresh = mapLiveness["yawThresh"] as Double val livenessClosedEyesThresh = mapLiveness["closedEyesThresh"] as Double val livenessSmilingThresh = mapLiveness["smilingThresh"] as Double val livenessTooDarkThresh = mapLiveness["tooDarkThresh"] as Double val livenessTooLightThresh = mapLiveness["tooLightThresh"] as Double val livenessCentralizationThresh = mapLiveness["faceCentralizationThresh"] as Double // Gets continuous capture options properties val mapContinuousCapture = mapConfig["continuousCapture"] as Map<*, *> val continuousCaptureEnabled = mapContinuousCapture["enabled"] as Boolean val continuousCaptureTimeToCapture = mapContinuousCapture["timeToCapture"] as Double val continuousCaptureMaxNumberFrames = mapContinuousCapture["maxNumberFrames"] as Double // Gets face detection options properties val mapFaceDetection = mapConfig["faceDetection"] as Map<*, *> val faceDetectionEnabled = mapFaceDetection["enabled"] as Boolean val faceDetectionAutoCapture = mapFaceDetection["autoCapture"] as Boolean val faceDetectionMultipleFacesEnabled = mapFaceDetection["multipleFacesEnabled"] as Boolean val faceDetectionTimeToCapture = mapFaceDetection["timeToCapture"] as Double val faceDetectionMaxFaceDetectionTime = mapFaceDetection["maxFaceDetectionTime"] as Double val faceDetectionScoreThreshold = mapFaceDetection["scoreThreshold"] as Double // Gets mask options properties val mapMask = mapConfig["mask"] as Map<*, *> val maskEnabled = mapMask["enabled"] as Boolean val maskType: FaceMaskFormat = when (mapMask["type"] as String) { "SQUARE" -> FaceMaskFormat.SQUARE "ELLIPSE" -> FaceMaskFormat.ELLIPSE else -> FaceMaskFormat.FACE } val maskBackgroundColor = mapMask["backgroundColor"] as String val maskFrameColor = mapMask["frameColor"] as String val maskFrameEnabledColor = mapMask["frameEnabledColor"] as String val maskFrameErrorColor = mapMask["frameErrorColor"] as String // Gets title text properties val mapTitleText = mapConfig["titleText"] as Map<*, *> val titleTextEnabled = mapTitleText["enabled"] as Boolean val titleTextContent = mapTitleText["content"] as String val titleTextColor = mapTitleText["textColor"] as String val titleTextSize = mapTitleText["textSize"] as Double // Gets help text properties val mapHelpText = mapConfig["helpText"] as Map<*, *> val helpTextEnabled = mapHelpText["enabled"] as Boolean val helpTextContent = mapHelpText["content"] as String val helpTextColor = mapHelpText["textColor"] as String val helpTextSize = mapHelpText["textSize"] as Double // Gets loading text properties val mapLoadingText = mapConfig["loadingText"] as Map<*, *> val loadingTextEnabled = mapLoadingText["enabled"] as Boolean val loadingTextContent = mapLoadingText["content"] as String val loadingTextColor = mapLoadingText["textColor"] as String val loadingTextSize = mapLoadingText["textSize"] as Double // Gets feedback text properties val mapFeedbackText = mapConfig["feedbackText"] as Map<*, *> val feedbackTextEnabled = mapFeedbackText["enabled"] as Boolean val feedbackTextColor = mapFeedbackText["textColor"] as String val feedbackTextSize = mapFeedbackText["textSize"] as Double val mapFeedbackTextMessages = mapFeedbackText["messages"] as Map<*, *> val feedbackTextNoDetectionMessage = mapFeedbackTextMessages["noDetection"] as String val feedbackTextMultipleFacesMessage = mapFeedbackTextMessages["multipleFaces"] as String val feedbackTextFaceCenteredMessage = mapFeedbackTextMessages["faceCentered"] as String val feedbackTextTooCloseMessage = mapFeedbackTextMessages["tooClose"] as String val feedbackTextTooFarMessage = mapFeedbackTextMessages["tooFar"] as String val feedbackTextTooLeftMessage = mapFeedbackTextMessages["tooLeft"] as String val feedbackTextTooRightMessage = mapFeedbackTextMessages["tooRight"] as String val feedbackTextTooUpMessage = mapFeedbackTextMessages["tooUp"] as String val feedbackTextTooDownMessage = mapFeedbackTextMessages["tooDown"] as String val feedbackTextInvalidIEDMessage = mapFeedbackTextMessages["invalidIED"] as String val feedbackTextFaceAngleMisalignedMessage = mapFeedbackTextMessages["faceAngleMisaligned"] as String val feedbackTextClosedEyesMessage = mapFeedbackTextMessages["closedEyes"] as String val feedbackTextSmilingMessage = mapFeedbackTextMessages["smiling"] as String val feedbackTexTooDarkMessage = mapFeedbackTextMessages["tooDark"] as String val feedbackTextTooLightMessage = mapFeedbackTextMessages["tooLight"] as String // Gets back button properties val mapBackButton = mapConfig["backButton"] as Map<*, *> val backButtonEnabled = mapBackButton["enabled"] as Boolean val backButtonBackgroundColor = mapBackButton["backgroundColor"] as String val backButtonPadding = mapBackButton["buttonPadding"] as Double val mapBackButtonSize = mapBackButton["buttonSize"] as Map<*, *> val backButtonSize = Size( (mapBackButtonSize["width"] as Double).toInt(), (mapBackButtonSize["height"] as Double).toInt() ) val mapBackButtonIcon = mapBackButton["iconOptions"] as Map<*, *> val backButtonIconEnabled = mapBackButtonIcon["enabled"] as Boolean val backButtonIconFile = mapBackButtonIcon["iconFile"] as String val backButtonIconColor = mapBackButtonIcon["iconColor"] as String val mapBackButtonIconSize = mapBackButtonIcon["iconSize"] as Map<*, *> val backButtonIconSize = Size( (mapBackButtonIconSize["width"] as Double).toInt(), (mapBackButtonIconSize["height"] as Double).toInt() ) val mapBackButtonLabel = mapBackButton["labelOptions"] as Map<*, *> val backButtonLabelEnabled = mapBackButtonLabel["enabled"] as Boolean val backButtonLabelContent = mapBackButtonLabel["content"] as String val backButtonLabelTextColor = mapBackButtonLabel["textColor"] as String val backButtonLabelTextSize = mapBackButtonLabel["textSize"] as Double // Gets flash button properties val mapFlashButton = mapConfig["flashButton"] as Map<*, *> val flashButtonEnabled = mapFlashButton["enabled"] as Boolean val flashButtonBackgroundColor = mapFlashButton["backgroundColor"] as String val flashButtonPadding = mapFlashButton["buttonPadding"] as Double val mapFlashButtonSize = mapFlashButton["buttonSize"] as Map<*, *> val flashButtonSize = Size( (mapFlashButtonSize["width"] as Double).toInt(), (mapFlashButtonSize["height"] as Double).toInt() ) // Gets flash on properties val mapFlashOnIconOptions = mapFlashButton["flashOnIconOptions"] as Map<*, *> val flashOnButtonIconEnabled = mapFlashOnIconOptions["enabled"] as Boolean val flashOnButtonIconFile = mapFlashOnIconOptions["iconFile"] as String val flashOnButtonIconColor = mapFlashOnIconOptions["iconColor"] as String val mapFlashOnButtonIconSize = mapFlashOnIconOptions["iconSize"] as Map<*, *> val flashOnButtonIconSize = Size( (mapFlashOnButtonIconSize["width"] as Double).toInt(), (mapFlashOnButtonIconSize["height"] as Double).toInt() ) val mapFlashOnLabelOptions = mapFlashButton["flashOnLabelOptions"] as Map<*, *> val flashOnButtonLabelEnabled = mapFlashOnLabelOptions["enabled"] as Boolean val flashOnButtonLabelContent = mapFlashOnLabelOptions["content"] as String val flashOnButtonLabelTextColor = mapFlashOnLabelOptions["textColor"] as String val flashOnButtonLabelTextSize = mapFlashOnLabelOptions["textSize"] as Double // Gets flash off properties val mapFlashOffIconOptions = mapFlashButton["flashOffIconOptions"] as Map<*, *> val flashOffButtonIconEnabled = mapFlashOffIconOptions["enabled"] as Boolean val flashOffButtonIconFile = mapFlashOffIconOptions["iconFile"] as String val flashOffButtonIconColor = mapFlashOffIconOptions["iconColor"] as String val mapFlashOffButtonIconSize = mapFlashOffIconOptions["iconSize"] as Map<*, *> val flashOffButtonIconSize = Size( (mapFlashOffButtonIconSize["width"] as Double).toInt(), (mapFlashOffButtonIconSize["height"] as Double).toInt() ) val mapFlashOffLabelOptions = mapFlashButton["flashOffLabelOptions"] as Map<*, *> val flashOffButtonLabelEnabled = mapFlashOffLabelOptions["enabled"] as Boolean val flashOffButtonLabelContent = mapFlashOffLabelOptions["content"] as String val flashOffButtonLabelTextColor = mapFlashOffLabelOptions["textColor"] as String val flashOffButtonLabelTextSize = mapFlashOffLabelOptions["textSize"] as Double // Gets switch camera button properties val mapSwitchCameraButton = mapConfig["switchCameraButton"] as Map<*, *> val switchCameraButtonEnabled = mapSwitchCameraButton["enabled"] as Boolean val switchCameraButtonBackgroundColor = mapSwitchCameraButton["backgroundColor"] as String val switchCameraButtonPadding = mapSwitchCameraButton["buttonPadding"] as Double val mapSwitchCameraButtonSize = mapSwitchCameraButton["buttonSize"] as Map<*, *> val switchCameraButtonSize = Size( (mapSwitchCameraButtonSize["width"] as Double).toInt(), (mapSwitchCameraButtonSize["height"] as Double).toInt() ) val mapSwitchCameraButtonIcon = mapSwitchCameraButton["iconOptions"] as Map<*, *> val switchCameraButtonIconEnabled = mapSwitchCameraButtonIcon["enabled"] as Boolean val switchCameraButtonIconFile = mapSwitchCameraButtonIcon["iconFile"] as String val switchCameraButtonIconColor = mapSwitchCameraButtonIcon["iconColor"] as String val mapSwitchCameraButtonIconSize = mapSwitchCameraButtonIcon["iconSize"] as Map<*, *> val switchCameraButtonIconSize = Size( (mapSwitchCameraButtonIconSize["width"] as Double).toInt(), (mapSwitchCameraButtonIconSize["height"] as Double).toInt() ) val mapSwitchCameraButtonLabel = mapSwitchCameraButton["labelOptions"] as Map<*, *> val switchCameraButtonLabelEnabled = mapSwitchCameraButtonLabel["enabled"] as Boolean val switchCameraButtonLabelContent = mapSwitchCameraButtonLabel["content"] as String val switchCameraButtonLabelTextColor = mapSwitchCameraButtonLabel["textColor"] as String val switchCameraButtonLabelTextSize = mapSwitchCameraButtonLabel["textSize"] as Double // Gets capture button properties val mapCaptureButton = mapConfig["captureButton"] as Map<*, *> val captureButtonEnabled = mapCaptureButton["enabled"] as Boolean val captureButtonBackgroundColor = mapCaptureButton["backgroundColor"] as String val captureButtonPadding = mapCaptureButton["buttonPadding"] as Double val mapCaptureButtonSize = mapCaptureButton["buttonSize"] as Map<*, *> val captureButtonSize = Size( (mapCaptureButtonSize["width"] as Double).toInt(), (mapCaptureButtonSize["height"] as Double).toInt() ) val mapCaptureButtonIcon = mapCaptureButton["iconOptions"] as Map<*, *> val captureButtonIconEnabled = mapCaptureButtonIcon["enabled"] as Boolean val captureButtonIconFile = mapCaptureButtonIcon["iconFile"] as String val captureButtonIconColor = mapCaptureButtonIcon["iconColor"] as String val mapCaptureButtonIconSize = mapCaptureButtonIcon["iconSize"] as Map<*, *> val captureButtonIconSize = Size( (mapCaptureButtonIconSize["width"] as Double).toInt(), (mapCaptureButtonIconSize["height"] as Double).toInt() ) val mapCaptureButtonLabel = mapCaptureButton["labelOptions"] as Map<*, *> val captureButtonLabelEnabled = mapCaptureButtonLabel["enabled"] as Boolean val captureButtonLabelContent = mapCaptureButtonLabel["content"] as String val captureButtonLabelTextColor = mapCaptureButtonLabel["textColor"] as String val captureButtonLabelTextSize = mapCaptureButtonLabel["textSize"] as Double // Gets font family resource val fontFamilyRes = getResourceId(context, "font", fontFamily) // Gets back button image resource val backButtonIconRes = getResourceId(context, "drawable", backButtonIconFile) // Gets flash on button image resource val flashOnButtonIconRes = getResourceId(context, "drawable", flashOnButtonIconFile) // Gets flash off button image resource val flashOffButtonIconRes = getResourceId(context, "drawable", flashOffButtonIconFile) // Gets switch camera button image resource val switchCameraButtonIconRes = getResourceId(context, "drawable", switchCameraButtonIconFile) // Gets capture button image resource val captureButtonIconRes = getResourceId(context, "drawable", captureButtonIconFile) val config = FaceConfig() config.licenseKey = licenseKey config.resolutionPreset = resolutionPreset config.lensDirection = lensDirection config.imageFormat = imageFormat config.flashEnabled = flashEnabled config.fontFamily = fontFamilyRes ?: br.com.biopassid.facesdk.R.font.facesdk_opensans_bold // Sets liveness options properties config.liveness.enabled = livenessEnabled config.liveness.debug = livenessDebug config.liveness.timeToCapture = livenessTimeToCapture.toLong() config.liveness.maxFaceDetectionTime = livenessMaxFaceDetectionTime.toLong() config.liveness.minFaceProp = livenessMinFaceProp.toFloat() config.liveness.maxFaceProp = livenessMaxFaceProp.toFloat() config.liveness.minFaceWidth = livenessMinFaceWidth.toInt() config.liveness.minFaceHeight = livenessMinFaceHeight.toInt() config.liveness.ied = livenessIed.toInt() config.liveness.bboxPad = livenessBboxPad.toInt() config.liveness.faceDetectionThresh = livenessFaceDetectionThresh.toFloat() config.liveness.rollThresh = livenessRollThresh.toFloat() config.liveness.pitchThresh = livenessPitchThresh.toFloat() config.liveness.yawThresh = livenessYawThresh.toFloat() config.liveness.closedEyesThresh = livenessClosedEyesThresh.toFloat() config.liveness.smilingThresh = livenessSmilingThresh.toFloat() config.liveness.tooDarkThresh = livenessTooDarkThresh.toInt() config.liveness.tooLightThresh = livenessTooLightThresh.toInt() config.liveness.faceCentralizationThresh = livenessCentralizationThresh.toFloat() // Sets continuous capture options properties config.continuousCapture.enabled = continuousCaptureEnabled config.continuousCapture.timeToCapture = continuousCaptureTimeToCapture.toLong() config.continuousCapture.maxNumberFrames = continuousCaptureMaxNumberFrames.toInt() // Sets face detection options properties config.faceDetection.enabled = faceDetectionEnabled config.faceDetection.autoCapture = faceDetectionAutoCapture config.faceDetection.multipleFacesEnabled = faceDetectionMultipleFacesEnabled config.faceDetection.timeToCapture = faceDetectionTimeToCapture.toLong() config.faceDetection.maxFaceDetectionTime = faceDetectionMaxFaceDetectionTime.toLong() config.faceDetection.scoreThreshold = faceDetectionScoreThreshold.toFloat() // Sets mask options properties config.mask.enabled = maskEnabled config.mask.type = maskType config.mask.backgroundColor = hexStringToColor(maskBackgroundColor) ?: config.mask.backgroundColor config.mask.frameColor = hexStringToColor(maskFrameColor) ?: config.mask.frameColor config.mask.frameEnabledColor = hexStringToColor(maskFrameEnabledColor) ?: config.mask.frameEnabledColor config.mask.frameErrorColor = hexStringToColor(maskFrameErrorColor) ?: config.mask.frameErrorColor // Sets title text properties config.titleText.enabled = titleTextEnabled config.titleText.content = titleTextContent config.titleText.textColor = hexStringToColor(titleTextColor) ?: config.titleText.textColor config.titleText.textSize = titleTextSize.toInt() // Sets help text properties config.helpText.enabled = helpTextEnabled config.helpText.content = helpTextContent config.helpText.textColor = hexStringToColor(helpTextColor) ?: config.helpText.textColor config.helpText.textSize = helpTextSize.toInt() // Sets loading text properties config.loadingText.enabled = loadingTextEnabled config.loadingText.content = loadingTextContent config.loadingText.textColor = hexStringToColor(loadingTextColor) ?: config.loadingText.textColor config.loadingText.textSize = loadingTextSize.toInt() // Sets feedback text properties config.feedbackText.enabled = feedbackTextEnabled config.feedbackText.textColor = hexStringToColor(feedbackTextColor) ?: config.feedbackText.textColor config.feedbackText.textSize = feedbackTextSize.toInt() config.feedbackText.messages.noDetection = feedbackTextNoDetectionMessage config.feedbackText.messages.multipleFaces = feedbackTextMultipleFacesMessage config.feedbackText.messages.faceCentered = feedbackTextFaceCenteredMessage config.feedbackText.messages.tooClose = feedbackTextTooCloseMessage config.feedbackText.messages.tooFar = feedbackTextTooFarMessage config.feedbackText.messages.tooLeft = feedbackTextTooLeftMessage config.feedbackText.messages.tooRight = feedbackTextTooRightMessage config.feedbackText.messages.tooUp = feedbackTextTooUpMessage config.feedbackText.messages.tooDown = feedbackTextTooDownMessage config.feedbackText.messages.invalidIED = feedbackTextInvalidIEDMessage config.feedbackText.messages.faceAngleMisaligned = feedbackTextFaceAngleMisalignedMessage config.feedbackText.messages.closedEyes = feedbackTextClosedEyesMessage config.feedbackText.messages.smiling = feedbackTextSmilingMessage config.feedbackText.messages.tooDark = feedbackTexTooDarkMessage config.feedbackText.messages.tooLight = feedbackTextTooLightMessage // Sets back button properties config.backButton.enabled = backButtonEnabled config.backButton.backgroundColor = hexStringToColor(backButtonBackgroundColor) ?: config.backButton.backgroundColor config.backButton.buttonPadding = backButtonPadding.toInt() config.backButton.buttonSize = backButtonSize config.backButton.iconOptions.enabled = backButtonIconEnabled config.backButton.iconOptions.iconFile = backButtonIconRes ?: br.com.biopassid.facesdk.R.drawable.facesdk_ic_close config.backButton.iconOptions.iconColor = hexStringToColor(backButtonIconColor) ?: config.backButton.iconOptions.iconColor config.backButton.iconOptions.iconSize = backButtonIconSize config.backButton.labelOptions.enabled = backButtonLabelEnabled config.backButton.labelOptions.content = backButtonLabelContent config.backButton.labelOptions.textColor = hexStringToColor(backButtonLabelTextColor) ?: config.backButton.labelOptions.textColor config.backButton.labelOptions.textSize = backButtonLabelTextSize.toInt() // Sets flash button properties config.flashButton.enabled = flashButtonEnabled config.flashButton.backgroundColor = hexStringToColor(flashButtonBackgroundColor) ?: config.flashButton.backgroundColor config.flashButton.buttonPadding = flashButtonPadding.toInt() config.flashButton.buttonSize = flashButtonSize // Sets flash on properties config.flashButton.flashOnIconOptions.enabled = flashOnButtonIconEnabled config.flashButton.flashOnIconOptions.iconFile = flashOnButtonIconRes ?: br.com.biopassid.facesdk.R.drawable.facesdk_ic_flash_on config.flashButton.flashOnIconOptions.iconColor = hexStringToColor(flashOnButtonIconColor) ?: config.flashButton.flashOnIconOptions.iconColor config.flashButton.flashOnIconOptions.iconSize = flashOnButtonIconSize config.flashButton.flashOnLabelOptions.enabled = flashOnButtonLabelEnabled config.flashButton.flashOnLabelOptions.content = flashOnButtonLabelContent config.flashButton.flashOnLabelOptions.textColor = hexStringToColor(flashOnButtonLabelTextColor) ?: config.flashButton.flashOnLabelOptions.textColor config.flashButton.flashOnLabelOptions.textSize = flashOnButtonLabelTextSize.toInt() // Sets flash off properties config.flashButton.flashOffIconOptions.enabled = flashOffButtonIconEnabled config.flashButton.flashOffIconOptions.iconFile = flashOffButtonIconRes ?: br.com.biopassid.facesdk.R.drawable.facesdk_ic_flash_off config.flashButton.flashOffIconOptions.iconColor = hexStringToColor(flashOffButtonIconColor) ?: config.flashButton.flashOffIconOptions.iconColor config.flashButton.flashOffIconOptions.iconSize = flashOffButtonIconSize config.flashButton.flashOffLabelOptions.enabled = flashOffButtonLabelEnabled config.flashButton.flashOffLabelOptions.content = flashOffButtonLabelContent config.flashButton.flashOffLabelOptions.textColor = hexStringToColor(flashOffButtonLabelTextColor) ?: config.flashButton.flashOffLabelOptions.textColor config.flashButton.flashOffLabelOptions.textSize = flashOffButtonLabelTextSize.toInt() // Sets switch camera button properties config.switchCameraButton.enabled = switchCameraButtonEnabled config.switchCameraButton.backgroundColor = hexStringToColor(switchCameraButtonBackgroundColor) ?: config.switchCameraButton.backgroundColor config.switchCameraButton.buttonPadding = switchCameraButtonPadding.toInt() config.switchCameraButton.buttonSize = switchCameraButtonSize config.switchCameraButton.iconOptions.enabled = switchCameraButtonIconEnabled config.switchCameraButton.iconOptions.iconFile = switchCameraButtonIconRes ?: br.com.biopassid.facesdk.R.drawable.facesdk_ic_switch_camera config.switchCameraButton.iconOptions.iconColor = hexStringToColor(switchCameraButtonIconColor) ?: config.switchCameraButton.iconOptions.iconColor config.switchCameraButton.iconOptions.iconSize = switchCameraButtonIconSize config.switchCameraButton.labelOptions.enabled = switchCameraButtonLabelEnabled config.switchCameraButton.labelOptions.content = switchCameraButtonLabelContent config.switchCameraButton.labelOptions.textColor = hexStringToColor(switchCameraButtonLabelTextColor) ?: config.switchCameraButton.labelOptions.textColor config.switchCameraButton.labelOptions.textSize = switchCameraButtonLabelTextSize.toInt() // Sets capture button properties config.captureButton.enabled = captureButtonEnabled config.captureButton.backgroundColor = hexStringToColor(captureButtonBackgroundColor) ?: config.captureButton.backgroundColor config.captureButton.buttonPadding = captureButtonPadding.toInt() config.captureButton.buttonSize = captureButtonSize config.captureButton.iconOptions.enabled = captureButtonIconEnabled config.captureButton.iconOptions.iconFile = captureButtonIconRes ?: br.com.biopassid.facesdk.R.drawable.facesdk_ic_capture config.captureButton.iconOptions.iconColor = hexStringToColor(captureButtonIconColor) ?: config.captureButton.iconOptions.iconColor config.captureButton.iconOptions.iconSize = captureButtonIconSize config.captureButton.labelOptions.enabled = captureButtonLabelEnabled config.captureButton.labelOptions.content = captureButtonLabelContent config.captureButton.labelOptions.textColor = hexStringToColor(captureButtonLabelTextColor) ?: config.captureButton.labelOptions.textColor config.captureButton.labelOptions.textSize = captureButtonLabelTextSize.toInt() return config } fun onFaceCaptureToNativeMap( image: String, faceAttributes: FaceAttributes? ): WritableNativeMap { val onFaceCaptureMap = hashMapOf( "image" to image, "faceAttributes" to faceAttributesToMap(faceAttributes) ) return Arguments.makeNativeMap(onFaceCaptureMap) } fun onFaceDetectedToNativeMap(faceAttributes: FaceAttributes): WritableNativeMap { val onFaceDetectedMap = hashMapOf("faceAttributes" to faceAttributesToMap(faceAttributes)) return Arguments.makeNativeMap(onFaceDetectedMap) } private fun faceAttributesToMap(faceAttributes: FaceAttributes?): Map? { faceAttributes ?: return null return hashMapOf( "faceProp" to faceAttributes.faceProp, "faceWidth" to faceAttributes.faceWidth, "faceHeight" to faceAttributes.faceHeight, "ied" to faceAttributes.ied, "bbox" to hashMapOf( "left" to faceAttributes.bbox.left, "top" to faceAttributes.bbox.top, "right" to faceAttributes.bbox.right, "bottom" to faceAttributes.bbox.bottom, ), "rollAngle" to faceAttributes.rollAngle, "pitchAngle" to faceAttributes.pitchAngle, "yawAngle" to faceAttributes.yawAngle, "averageLightIntensity" to faceAttributes.averageLightIntensity, "leftEyeOpenProbability" to faceAttributes.leftEyeOpenProbability, "rightEyeOpenProbability" to faceAttributes.rightEyeOpenProbability, "smilingProbability" to faceAttributes.smilingProbability ) } private fun hexStringToColor(hexString: String): Int? { return try { Color.parseColor(hexString) } catch (e: Exception) { Log.e(TAG, "Error when trying parse color.") null } } private fun getResourceId( context: Context?, resourceName: String, variableName: String ): Int? { try { val resId = context?.resources?.getIdentifier( variableName, resourceName, context.packageName ) if (resId != null && resId != 0) { return resId } Log.e(TAG, "Could not get resource id.") return null } catch (e: Exception) { Log.e(TAG, "Could not get resource id.") return null } } }