Skip to content

Commit

Permalink
added v11.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sMaltsevAcuant committed Feb 10, 2023
1 parent a48477b commit fcdfc54
Show file tree
Hide file tree
Showing 32 changed files with 1,152 additions and 432 deletions.
232 changes: 187 additions & 45 deletions README.md

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions acuantcamera/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'

android {
compileSdkVersion 32
compileSdkVersion 33

defaultConfig {
minSdkVersion 21
targetSdkVersion 32
targetSdkVersion 33
}

buildTypes {
Expand All @@ -33,11 +33,11 @@ android {
}
dependencies {
// Kotlin lang
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'

// App compat and UI things
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

Expand All @@ -49,9 +49,9 @@ dependencies {
implementation "androidx.camera:camera-view:$camerax_version"

//acuant specific stuff
implementation 'androidx.exifinterface:exifinterface:1.3.3'
implementation 'androidx.exifinterface:exifinterface:1.3.5'
implementation 'com.google.mlkit:barcode-scanning:17.0.2'
implementation 'com.rmtheis:tess-two:9.1.0'
implementation 'com.acuant:acuantcommon:11.5.4'
implementation 'com.acuant:acuantimagepreparation:11.5.4'
implementation 'com.acuant:acuantcommon:11.6.0'
implementation 'com.acuant:acuantimagepreparation:11.6.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,20 @@ abstract class AcuantBaseCameraFragment: Fragment() {
val exif = Exif.createFromFileString(savedUri)
val rotation = exif.rotation

val file = File(savedUri)

if (captureType != null) {
addExif(File(savedUri), captureType, rotation)
addExif(file, captureType, rotation)
} else {
addExif(File(savedUri), "NOT SPECIFIED (implementer used deprecated constructor that lacks this data)", rotation)
addExif(file, "NOT SPECIFIED (implementer used deprecated constructor that lacks this data)", rotation)
}

fullyDone = true
listener.onSaved(savedUri)

val bytes = file.readBytes()
file.delete()

listener.onSaved(bytes)
}

override fun onError(exception: ImageCaptureException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.acuant.acuantcamera.camera

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -24,14 +25,17 @@ class AcuantCameraActivity: AppCompatActivity(), ICameraActivityFinish {
super.onCreate(savedInstanceState)
binding = ActivityCameraBinding.inflate(layoutInflater)

val unserializedOptions = intent.getSerializableExtra(ACUANT_EXTRA_CAMERA_OPTIONS)

val options: AcuantCameraOptions = if (unserializedOptions == null) {
AcuantCameraOptions.DocumentCameraOptionsBuilder().build()
var options = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent?.getSerializableExtra(ACUANT_EXTRA_CAMERA_OPTIONS, AcuantCameraOptions::class.java)
} else {
unserializedOptions as AcuantCameraOptions
@Suppress("DEPRECATION")
intent?.getSerializableExtra(ACUANT_EXTRA_CAMERA_OPTIONS) as AcuantCameraOptions?
}

if (options == null)
options = AcuantCameraOptions.DocumentCameraOptionsBuilder().build()

if (options.preventScreenshots) {
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
}
Expand Down Expand Up @@ -59,10 +63,11 @@ class AcuantCameraActivity: AppCompatActivity(), ICameraActivityFinish {
}
}

//Camera Responses
override fun onCameraDone(imageUrl: String, barCodeString: String?) {
override fun onCameraDone(imageBytes: ByteArray, barCodeString: String?) {
val intent = Intent()
intent.putExtra(ACUANT_EXTRA_IMAGE_URL, imageUrl)
//We can not do this as the maximum transaction size is way too small.
// intent.putExtra(ACUANT_EXTRA_IMAGE_BYTES, imageBytes)
AcuantCameraActivity.imageBytes = imageBytes
intent.putExtra(ACUANT_EXTRA_PDF417_BARCODE, barCodeString)
this@AcuantCameraActivity.setResult(RESULT_OK, intent)
this@AcuantCameraActivity.finish()
Expand Down Expand Up @@ -109,4 +114,23 @@ class AcuantCameraActivity: AppCompatActivity(), ICameraActivityFinish {
super.onResume()
hideTopMenu()
}

companion object {
private var imageBytes: ByteArray? = null

@JvmStatic
@Synchronized
fun getLatestCapturedBytes(clearBytesAfterRead: Boolean): ByteArray? {
val bytes = imageBytes?.clone()
if (clearBytesAfterRead) {
if (imageBytes != null) {
for (i in imageBytes!!.indices) {
imageBytes!![i] = (0).toByte()
}
imageBytes = null
}
}
return bytes
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ internal constructor(
}

@Deprecated("No longer reliant on GMS, option is ignored", ReplaceWith(""))
@Suppress("unused")
fun setUseGms(value: Boolean) : DocumentCameraOptionsBuilder {
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import kotlin.math.pow
import kotlin.math.roundToInt
import kotlin.math.sqrt

enum class DocumentCameraState { Align, MoveCloser, MoveBack, HoldSteady, CountingDown, Capturing }
enum class DocumentCameraState { Align, NotInFrame, MoveCloser, MoveBack, HoldSteady, CountingDown, Capturing }

class AcuantDocCameraFragment: AcuantBaseCameraFragment() {

Expand Down Expand Up @@ -78,7 +78,7 @@ class AcuantDocCameraFragment: AcuantBaseCameraFragment() {

if (!firstThreeTimings.contains((-1).toLong())) {
hasFinishedTest = true
if (firstThreeTimings.minOrNull() ?: (TOO_SLOW_FOR_AUTO_THRESHOLD + 10) > TOO_SLOW_FOR_AUTO_THRESHOLD) {
if ((firstThreeTimings.minOrNull() ?: (TOO_SLOW_FOR_AUTO_THRESHOLD + 10)) > TOO_SLOW_FOR_AUTO_THRESHOLD) {
setTapToCapture()
}
}
Expand All @@ -96,8 +96,8 @@ class AcuantDocCameraFragment: AcuantBaseCameraFragment() {
detectedPoints = PointsUtils.fixPoints(PointsUtils.scalePoints(detectedPoints, camContainer, analyzerSize, previewSize, rectangleView))
realDpi = PointsUtils.scaleDpi(analyzerDPI, analyzerSize, imageCapture?.resolutionInfo?.resolution)
if (previewSize != null) {
val mult = 0.02f
val view = Rect((previewSize.left * (1 + mult)).toInt(), (previewSize.top * (1 + mult)).toInt(), (previewSize.right * (1 - mult)).toInt(), (previewSize.bottom * (1 - mult)).toInt())
val insetFromEdges = 0.02f
val view = Rect((previewSize.left * (1 + insetFromEdges)).toInt(), (previewSize.top * (1 + insetFromEdges)).toInt(), (previewSize.right * (1 - insetFromEdges)).toInt(), (previewSize.bottom * (1 - insetFromEdges)).toInt())
var isContained = true
detectedPoints.forEach {
if (!view.contains(it.y, it.x)) {
Expand All @@ -107,7 +107,7 @@ class AcuantDocCameraFragment: AcuantBaseCameraFragment() {
if (isContained) {
docState
} else {
DocumentState.NoDocument
DocumentState.OutOfBounds
}
} else {
docState
Expand All @@ -122,6 +122,11 @@ class AcuantDocCameraFragment: AcuantBaseCameraFragment() {
setTextFromState(DocumentCameraState.Align)
resetWorkflow()
}
DocumentState.OutOfBounds -> {
rectangleView?.setViewFromState(DocumentCameraState.NotInFrame)
setTextFromState(DocumentCameraState.NotInFrame)
resetWorkflow()
}
DocumentState.TooClose -> {
rectangleView?.setViewFromState(DocumentCameraState.MoveBack)
setTextFromState(DocumentCameraState.MoveBack)
Expand Down Expand Up @@ -160,8 +165,8 @@ class AcuantDocCameraFragment: AcuantBaseCameraFragment() {
else -> {
val middle = PointsUtils.findMiddleForCamera(points, fragmentCameraBinding?.root?.width, fragmentCameraBinding?.root?.height)
captureImage(object : IAcuantSavedImage {
override fun onSaved(uri: String) {
cameraActivityListener.onCameraDone(uri, latestBarcode)
override fun onSaved(bytes: ByteArray) {
cameraActivityListener.onCameraDone(bytes, latestBarcode)
}

override fun onError(error: AcuantError) {
Expand Down Expand Up @@ -246,7 +251,16 @@ class AcuantDocCameraFragment: AcuantBaseCameraFragment() {
context?.resources?.getDimension(R.dimen.cam_info_width)?.toInt() ?: 300
textView.textSize =
context?.resources?.getDimension(R.dimen.cam_doc_font) ?: 24f
textView.text = getString(R.string.acuant_camera_not_in_frame)
textView.text = getString(R.string.acuant_camera_too_close)
textView.setTextColor(Color.WHITE)
}
DocumentCameraState.NotInFrame -> {
textView.background = defaultTextDrawable
textView.layoutParams?.width =
context?.resources?.getDimension(R.dimen.cam_info_width)?.toInt() ?: 300
textView.textSize =
context?.resources?.getDimension(R.dimen.cam_doc_font) ?: 24f
textView.text = getString(R.string.acuant_camera_out_of_bounds)
textView.setTextColor(Color.WHITE)
}
DocumentCameraState.CountingDown -> {
Expand Down Expand Up @@ -350,8 +364,8 @@ class AcuantDocCameraFragment: AcuantBaseCameraFragment() {
textView?.setBackgroundColor(greenTransparent)
textView?.text = getString(R.string.acuant_camera_capturing)
captureImage(object : IAcuantSavedImage {
override fun onSaved(uri: String) {
cameraActivityListener.onCameraDone(uri, latestBarcode)
override fun onSaved(bytes: ByteArray) {
cameraActivityListener.onCameraDone(bytes, latestBarcode)
}

override fun onError(error: AcuantError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

package com.acuant.acuantcamera.constant

@Suppress("unused")
@Deprecated("This form of returning an image has been removed", ReplaceWith("AcuantCameraActivity.getLatestCapturedBytes()"))
const val ACUANT_EXTRA_IMAGE_URL = "imageUrl"
const val ACUANT_EXTRA_PDF417_BARCODE = "barCodeString"
const val ACUANT_EXTRA_CAMERA_OPTIONS = "cameraOptions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.graphics.Point

enum class DocumentType {Id, Passport, Other}

enum class DocumentState { NoDocument, TooFar, TooClose, GoodDocument }
enum class DocumentState { NoDocument, TooFar, TooClose, GoodDocument, OutOfBounds }

class DocumentFrameResult (val points: Array<Point>?,
val currentDistRatio: Float?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ import java.lang.Exception
class MrzCameraInitializer : IAcuantPackage {

override fun initialize(credential: Credential, context: Context, callback: IAcuantPackageCallback) {
if(credential.secureAuthorizations != null) {
try {
initializeOcr(context)
} catch (e: Exception) {
e.printStackTrace()
callback.onInitializeFailed(
listOf(AcuantError(ErrorCodes.ERROR_FailedToLoadOcrFiles,
ErrorDescriptions.ERROR_DESC_FailedToLoadOcrFiles, e.toString())))
return
}
callback.onInitializeSuccess()
} else {
callback.onInitializeFailed(listOf(AcuantError(ErrorCodes.ERROR_InvalidCredentials, ErrorDescriptions.ERROR_DESC_InvalidCredentials)))
try {
initializeOcr(context)
} catch (e: Exception) {
e.printStackTrace()
callback.onInitializeFailed(
listOf(AcuantError(ErrorCodes.ERROR_FailedToLoadOcrFiles,
ErrorDescriptions.ERROR_DESC_FailedToLoadOcrFiles, e.toString())))
return
}
callback.onInitializeSuccess()
}

@Throws(IOException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.acuant.acuantcamera.interfaces
import com.acuant.acuantcommon.background.AcuantListener

interface IAcuantSavedImage: AcuantListener {
fun onSaved(uri: String)
fun onSaved(bytes: ByteArray)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.acuant.acuantcamera.interfaces
import com.acuant.acuantcamera.helper.MrzResult
import com.acuant.acuantcommon.background.AcuantListener

interface ICameraActivityFinish : AcuantListener{
fun onCameraDone(imageUrl: String, barCodeString: String?)
interface ICameraActivityFinish : AcuantListener {
fun onCameraDone(imageBytes: ByteArray, barCodeString: String?)
fun onCameraDone(mrzResult: MrzResult)
fun onCameraDone(barCodeString: String)
fun onCancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ abstract class BaseRectangleView(context: Context, attr: AttributeSet?) : View(c
textureViewWidth = width
}

fun setAndDrawPoints(points:Array<Point>?){
if(this.points != null) {
fun setAndDrawPoints(points:Array<Point>?) {
if (this.points != null) {
oldPoints = this.points
}
this.points = points
Expand All @@ -128,7 +128,7 @@ abstract class BaseRectangleView(context: Context, attr: AttributeSet?) : View(c

private fun calcPath() {
path = Path()
if(points != null && points!!.size == 4) {
if (points != null && points!!.size == 4) {

path.moveTo(points!![3].y.toFloat(), points!![3].x.toFloat())
path.lineTo(points!![0].y.toFloat(), points!![0].x.toFloat())
Expand All @@ -139,10 +139,11 @@ abstract class BaseRectangleView(context: Context, attr: AttributeSet?) : View(c
}

internal fun setDrawBox(drawBox : Boolean) {
if(allowBox)
if (allowBox) {
this.drawBox = drawBox
else
} else {
this.drawBox = false
}
}

override fun onDraw(canvas: Canvas) {
Expand Down Expand Up @@ -181,7 +182,7 @@ abstract class BaseRectangleView(context: Context, attr: AttributeSet?) : View(c
frame!!.top.toFloat(), frame!!.right.toFloat(), frame!!.top.toFloat(), frame!!.left.toFloat())

} else {
if(oldPoints == null || oldPoints!!.size != 4) {
if (oldPoints == null || oldPoints!!.size != 4) {
drawBracketsFromCords(canvas, points!![0].x.toFloat(), points!![0].y.toFloat(), points!![1].x.toFloat(), points!![1].y.toFloat(),
points!![2].x.toFloat(), points!![2].y.toFloat(), points!![3].x.toFloat(), points!![3].y.toFloat())
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@ import com.acuant.acuantcamera.camera.document.DocumentCameraState
class DocRectangleView(context: Context, attr: AttributeSet?) : BaseRectangleView(context, attr) {
fun setViewFromState(state: DocumentCameraState) {
when(state) {
DocumentCameraState.MoveCloser -> {
DocumentCameraState.MoveCloser,
DocumentCameraState.MoveBack,
DocumentCameraState.NotInFrame -> {
setDrawBox(false)
paint.color = paintColorCloser
paintBracket.color = paintColorBracketCloser
animateTarget = false
}
DocumentCameraState.MoveBack -> {
setDrawBox(false)
paint.color = paintColorCloser
paintBracket.color = paintColorBracketCloser
animateTarget = false
}
DocumentCameraState.CountingDown -> {
setDrawBox(true)
paint.color = paintColorHold
paintBracket.color = paintColorBracketHold
animateTarget = true
}
DocumentCameraState.HoldSteady -> {
DocumentCameraState.CountingDown,
DocumentCameraState.HoldSteady-> {
setDrawBox(true)
paint.color = paintColorHold
paintBracket.color = paintColorBracketHold
Expand Down
7 changes: 4 additions & 3 deletions acuantcamera/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
<string name="acuant_camera_align">ALIGN</string>
<string name="acuant_camera_align_and_tap">ALIGN AND TAP</string>
<string name="acuant_camera_move_closer">MOVE CLOSER</string>
<string name="acuant_camera_not_in_frame">TOO CLOSE!</string>
<string name="acuant_camera_too_close">TOO CLOSE</string>
<string name="acuant_camera_out_of_bounds">NOT IN FRAME</string>
<string name="acuant_camera_hold_steady">HOLD STEADY</string>
<string name="acuant_camera_capturing">CAPTURING</string>

Expand All @@ -35,10 +36,10 @@
<string name="acuant_glare_mrz">Try Repositioning</string>
<string name="acuant_read_mrz">Read Successful</string>
<string name="camera_load_error">Camera Load Error</string>
<string name="ok">ok</string>
<string name="ok">OK</string>
<string name="no_camera_permission">This application cannot run because it does not have the camera permission. The application will now exit.</string>
<string name="cam_perm_request_text">The camera is required to capture documents. If the permission has been declined you will need to manually go to the app settings to enable it.</string>
<string name="error_starting_cam">An error occurred while starting the camera, possibly in use by another application.</string>
<string name="acuant_camera_capturing_barcode">Capturing...</string>
<string name="acuant_camera_capturing_barcode">Capturing</string>
<string name="acuant_camera_align_barcode">Capture Barcode</string>
</resources>
Loading

0 comments on commit fcdfc54

Please sign in to comment.