diff --git a/documentscanner-demo/src/main/java/com/websitebeaver/documentscanner/demo/MainActivity.kt b/documentscanner-demo/src/main/java/com/websitebeaver/documentscanner/demo/MainActivity.kt index a973e59..100d403 100644 --- a/documentscanner-demo/src/main/java/com/websitebeaver/documentscanner/demo/MainActivity.kt +++ b/documentscanner-demo/src/main/java/com/websitebeaver/documentscanner/demo/MainActivity.kt @@ -23,7 +23,8 @@ class MainActivity : AppCompatActivity() { */ private val documentScanner = DocumentScanner( this, - { croppedImageResults -> + useQuickCapture = true, + successHandler = { croppedImageResults -> // display the first cropped image croppedImageView.setImageBitmap( ImageUtil().readBitmapFromFileUriString( @@ -32,11 +33,11 @@ class MainActivity : AppCompatActivity() { ) ) }, - { + errorHandler = { // an error happened errorMessage -> Log.v("documentscannerlogs", errorMessage) }, - { + cancelHandler = { // user canceled document scan Log.v("documentscannerlogs", "User canceled document scan") } diff --git a/documentscanner/src/main/java/com/websitebeaver/documentscanner/DocumentScanner.kt b/documentscanner/src/main/java/com/websitebeaver/documentscanner/DocumentScanner.kt index 4fe5ff9..ee20c9a 100644 --- a/documentscanner/src/main/java/com/websitebeaver/documentscanner/DocumentScanner.kt +++ b/documentscanner/src/main/java/com/websitebeaver/documentscanner/DocumentScanner.kt @@ -33,6 +33,7 @@ class DocumentScanner( private val cancelHandler: (() -> Unit)? = null, private var responseType: String? = null, private var letUserAdjustCrop: Boolean? = null, + private var useQuickCapture: Boolean? = null, private var maxNumDocuments: Int? = null, private var croppedImageQuality: Int? = null ) { @@ -54,6 +55,10 @@ class DocumentScanner( DocumentScannerExtra.EXTRA_LET_USER_ADJUST_CROP, letUserAdjustCrop ) + documentScanIntent.putExtra( + DocumentScannerExtra.EXTRA_USE_QUICK_CAPTURE, + useQuickCapture + ) documentScanIntent.putExtra( DocumentScannerExtra.EXTRA_MAX_NUM_DOCUMENTS, maxNumDocuments diff --git a/documentscanner/src/main/java/com/websitebeaver/documentscanner/DocumentScannerActivity.kt b/documentscanner/src/main/java/com/websitebeaver/documentscanner/DocumentScannerActivity.kt index 48d9a95..2cf663c 100644 --- a/documentscanner/src/main/java/com/websitebeaver/documentscanner/DocumentScannerActivity.kt +++ b/documentscanner/src/main/java/com/websitebeaver/documentscanner/DocumentScannerActivity.kt @@ -43,6 +43,12 @@ class DocumentScannerActivity : AppCompatActivity() { */ private var letUserAdjustCrop = DefaultSetting.LET_USER_ADJUST_CROP + /** + * @property useQuickCapture whether to use "quickCapture" to bypass default "Retry"/"Ok" + * behaviour + */ + private var useQuickCapture = DefaultSetting.USE_QUICK_CAPTURE + /** * @property croppedImageQuality the 0 - 100 quality of the cropped image */ @@ -210,6 +216,15 @@ class DocumentScannerActivity : AppCompatActivity() { } } + intent.extras?.get(DocumentScannerExtra.EXTRA_USE_QUICK_CAPTURE)?.let { + if (!arrayOf("true", "false").contains(it.toString())) { + throw Exception( + "${DocumentScannerExtra.EXTRA_USE_QUICK_CAPTURE} must true or false" + ) + } + useQuickCapture = it as Boolean + } + // validate croppedImageQuality option, and update value if user sets it intent.extras?.get(DocumentScannerExtra.EXTRA_CROPPED_IMAGE_QUALITY)?.let { if (it !is Int || it < 0 || it > 100) { @@ -287,7 +302,7 @@ class DocumentScannerActivity : AppCompatActivity() { */ private fun openCamera() { document = null - cameraUtil.openCamera(documents.size) + cameraUtil.openCamera(documents.size, useQuickCapture) } /** diff --git a/documentscanner/src/main/java/com/websitebeaver/documentscanner/constants/DefaultSetting.kt b/documentscanner/src/main/java/com/websitebeaver/documentscanner/constants/DefaultSetting.kt index e22938f..8a57750 100644 --- a/documentscanner/src/main/java/com/websitebeaver/documentscanner/constants/DefaultSetting.kt +++ b/documentscanner/src/main/java/com/websitebeaver/documentscanner/constants/DefaultSetting.kt @@ -7,6 +7,7 @@ class DefaultSetting { companion object { const val CROPPED_IMAGE_QUALITY = 100 const val LET_USER_ADJUST_CROP = true + const val USE_QUICK_CAPTURE = false const val MAX_NUM_DOCUMENTS = 24 const val RESPONSE_TYPE = ResponseType.IMAGE_FILE_PATH } diff --git a/documentscanner/src/main/java/com/websitebeaver/documentscanner/constants/DocumentScannerExtra.kt b/documentscanner/src/main/java/com/websitebeaver/documentscanner/constants/DocumentScannerExtra.kt index 442d455..327bfdd 100644 --- a/documentscanner/src/main/java/com/websitebeaver/documentscanner/constants/DocumentScannerExtra.kt +++ b/documentscanner/src/main/java/com/websitebeaver/documentscanner/constants/DocumentScannerExtra.kt @@ -7,6 +7,7 @@ class DocumentScannerExtra { companion object { const val EXTRA_CROPPED_IMAGE_QUALITY = "croppedImageQuality" const val EXTRA_LET_USER_ADJUST_CROP = "letUserAdjustCrop" + const val EXTRA_USE_QUICK_CAPTURE = "useQuickCapture" const val EXTRA_MAX_NUM_DOCUMENTS = "maxNumDocuments" } } \ No newline at end of file diff --git a/documentscanner/src/main/java/com/websitebeaver/documentscanner/utils/CameraUtil.kt b/documentscanner/src/main/java/com/websitebeaver/documentscanner/utils/CameraUtil.kt index e4f4c20..8046d4f 100644 --- a/documentscanner/src/main/java/com/websitebeaver/documentscanner/utils/CameraUtil.kt +++ b/documentscanner/src/main/java/com/websitebeaver/documentscanner/utils/CameraUtil.kt @@ -54,9 +54,12 @@ class CameraUtil( * @param pageNumber the current document page number */ @Throws(IOException::class) - fun openCamera(pageNumber: Int) { + fun openCamera(pageNumber: Int, useQuickCapture: Boolean = false) { // create intent to launch camera val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) + if (useQuickCapture) { + takePictureIntent.putExtra("android.intent.extra.quickCapture", true) + } // create new file for photo val photoFile: File = FileUtil().createImageFile(activity, pageNumber)