Skip to content

Commit

Permalink
New Properties added for getPictures method: noOfPages and imageQuality
Browse files Browse the repository at this point in the history
  • Loading branch information
nilotpalkapri committed Jan 23, 2024
1 parent 3568874 commit 67386a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CunningDocumentScannerPlugin : FlutterPlugin, MethodCallHandler, ActivityA
private var binding: ActivityPluginBinding? = null
private var pendingResult: Result? = null
private lateinit var activity: Activity
private val START_DOCUMENT_ACTIVITY: Int = 0x362738


/// The MethodChannel that will the communication between Flutter and native Android
///
Expand All @@ -35,13 +37,11 @@ class CunningDocumentScannerPlugin : FlutterPlugin, MethodCallHandler, ActivityA

override fun onMethodCall(call: MethodCall, result: Result) {
if (call.method == "getPictures") {
val crop = call.argument<Boolean>("crop");
if (crop != null) {
this.pendingResult = result
startScan(crop)
} else {
result.error("INVALID_ARGUMENT", "The value 'crop' is not a boolean", null)
}
val crop = call.argument<Boolean>("crop") ?: true;
val noOfPages = call.argument<Int>("noOfPages") ?: 50;
val imageQuality = call.argument<Int>("imageQuality") ?: 100;
this.pendingResult = result
startScan(crop, noOfPages, imageQuality)
} else {
result.notImplemented()
}
Expand Down Expand Up @@ -109,15 +109,19 @@ class CunningDocumentScannerPlugin : FlutterPlugin, MethodCallHandler, ActivityA
/**
* create intent to launch document scanner and set custom options
*/
private fun createDocumentScanIntent(crop: Boolean): Intent {
private fun createDocumentScanIntent(crop: Boolean, noOfPages: Int, imageQuality: Int): Intent {
val documentScanIntent = Intent(activity, DocumentScannerActivity::class.java)
documentScanIntent.putExtra(
DocumentScannerExtra.EXTRA_LET_USER_ADJUST_CROP,
crop
)
documentScanIntent.putExtra(
DocumentScannerExtra.EXTRA_MAX_NUM_DOCUMENTS,
if(crop) 100 else 1
noOfPages
)
documentScanIntent.putExtra(
DocumentScannerExtra.EXTRA_CROPPED_IMAGE_QUALITY,
if(imageQuality>100) 100 else if(imageQuality<0) 0 else imageQuality
)

return documentScanIntent
Expand All @@ -127,8 +131,8 @@ class CunningDocumentScannerPlugin : FlutterPlugin, MethodCallHandler, ActivityA
/**
* add document scanner result handler and launch the document scanner
*/
private fun startScan(crop: Boolean) {
val intent = createDocumentScanIntent(crop)
private fun startScan(crop: Boolean, noOfPages: Int, imageQuality: Int) {
val intent = createDocumentScanIntent(crop, noOfPages, imageQuality)
try {
ActivityCompat.startActivityForResult(
this.activity,
Expand Down Expand Up @@ -156,8 +160,4 @@ class CunningDocumentScannerPlugin : FlutterPlugin, MethodCallHandler, ActivityA
private fun removeActivityResultListener() {
this.delegate?.let { this.binding?.removeActivityResultListener(it) }
}

companion object {
private const val START_DOCUMENT_ACTIVITY: Int = 0x362738
}
}
4 changes: 2 additions & 2 deletions lib/cunning_document_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CunningDocumentScanner {
MethodChannel('cunning_document_scanner');

/// Call this to start get Picture workflow.
static Future<List<String>?> getPictures(bool crop) async {
static Future<List<String>?> getPictures(bool crop, [int noOfPages = 100, int imageQuality = 100]) async {
Map<Permission, PermissionStatus> statuses = await [
Permission.camera,
].request();
Expand All @@ -18,7 +18,7 @@ class CunningDocumentScanner {
}

final List<dynamic>? pictures =
await _channel.invokeMethod('getPictures', {'crop': crop});
await _channel.invokeMethod('getPictures', {'crop': crop, 'noOfPages': noOfPages, 'imageQuality': imageQuality});
return pictures?.map((e) => e as String).toList();
}
}

0 comments on commit 67386a1

Please sign in to comment.