Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to use "quickCapture" to circumvent the "Retry"/"Ok" screen #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -287,7 +302,7 @@ class DocumentScannerActivity : AppCompatActivity() {
*/
private fun openCamera() {
document = null
cameraUtil.openCamera(documents.size)
cameraUtil.openCamera(documents.size, useQuickCapture)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down