diff --git a/README.md b/README.md index 8c1da9c..0cd5939 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,8 @@ config.imageMovingMessage = "Too much movement"; config.model.fileName = "model"; config.model.modelLabels = "labelmap"; -// If you would like to enable automatic capturing of images. +// If you want to adjust the timer options. +config.timer.allowed = true config.timer.enabled = true; config.timer.duration = 1.0; @@ -195,6 +196,12 @@ config.success.message = "Success!"; // The amount of seconds the preview should be visible for, should be a float. config.previewDuration = 1.0; +// To limit the amount of images that can be taken. +config.imageLimit = 10; + +// The message to display when the limit has been reached. +config.imageLimitReachedMessage = "You have reached the image limit"; + ``` ## Android only @@ -209,12 +216,6 @@ config.storagePath = "/sdcard/scanner"; // The filename to use for the output images, supports replacement tokens %dateTime% and %randomUUID%. config.outputFileName = "KlippaScannerExample-%dateTime%-%randomUUID%"; -// To limit the amount of images that can be taken. -config.imageLimit = 10; - -// The message to display when the limit has been reached. -config.imageLimitReachedMessage = "You have reached the image limit"; - // The threshold sensitive the motion detection is. (lower value is higher sensitivity, default 50). config.imageMovingSensitivityAndroid = 50; ``` diff --git a/android/build.gradle b/android/build.gradle index de5206d..d64b826 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,7 +2,7 @@ group 'com.klippa.scanner.klippa_scanner_sdk' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.5.20' + ext.kotlin_version = '1.6.10' repositories { google() jcenter() @@ -55,6 +55,6 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - def klippaScannerVersion = project.hasProperty('klippaScannerVersion') ? project.klippaScannerVersion : "2.0.3" + def klippaScannerVersion = project.hasProperty('klippaScannerVersion') ? project.klippaScannerVersion : "2.0.6" implementation "com.klippa:scanner:$klippaScannerVersion" } diff --git a/android/src/main/kotlin/com/klippa/scanner/klippa_scanner_sdk/KlippaScannerSdkPlugin.kt b/android/src/main/kotlin/com/klippa/scanner/klippa_scanner_sdk/KlippaScannerSdkPlugin.kt index 9aeec4d..d583990 100644 --- a/android/src/main/kotlin/com/klippa/scanner/klippa_scanner_sdk/KlippaScannerSdkPlugin.kt +++ b/android/src/main/kotlin/com/klippa/scanner/klippa_scanner_sdk/KlippaScannerSdkPlugin.kt @@ -126,6 +126,10 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P KlippaScanner.model.modelLabels = call.argument("Model.modelLabels")!! } + if (call.hasArgument("Timer.allowed")) { + KlippaScanner.menu.allowTimer = call.argument("Timer.allowed")!! + } + if (call.hasArgument("Timer.enabled")) { KlippaScanner.menu.isTimerEnabled = call.argument("Timer.enabled")!! } @@ -159,8 +163,8 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P KlippaScanner.shutterButton.allowShutterButton = call.argument("ShutterButton.allowshutterButton")!! } - if (call.hasArgument("ShutterButton.hideShutterbutton")) { - KlippaScanner.shutterButton.hideShutterButton = call.argument("ShutterButton.hideShutterbutton")!! + if (call.hasArgument("ShutterButton.hideShutterButton")) { + KlippaScanner.shutterButton.hideShutterButton = call.argument("ShutterButton.hideShutterButton")!! } if (call.hasArgument("StoragePath")) { @@ -215,8 +219,27 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P val receivedData = data ?: return false val extras = receivedData.extras ?: return false - val images: ArrayList = extras.getParcelableArrayList(KlippaScanner.IMAGES) as ArrayList - Toast.makeText(context, "Result was " + images.size + " images", Toast.LENGTH_LONG).show() + val receivedImages: ArrayList = extras.getParcelableArrayList(KlippaScanner.IMAGES) as ArrayList + + val images: MutableList> = mutableListOf() + + for (image in receivedImages) { + val imageDict = mapOf("Filepath" to image.filePath) + images.add(imageDict) + } + + val multipleDocuments: Boolean = extras.getBoolean(KlippaScanner.CREATE_MULTIPLE_RECEIPTS) + val cropEnabled: Boolean = extras.getBoolean(KlippaScanner.CROP) + val timerEnabled: Boolean = extras.getBoolean(KlippaScanner.TIMER_ENABLED) + + val resultDict = mapOf( + "Images" to images, + "MultipleDocuments" to multipleDocuments, + "Crop" to cropEnabled, + "TimerEnabled" to timerEnabled) + + resultHandler?.success(resultDict) + resultHandler = null return true } else if (requestCode == this.SESSION_REQUEST_CODE && resultCode == Activity.RESULT_CANCELED) { var error: String? = null @@ -224,10 +247,9 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P error = data.getStringExtra(KlippaScanner.ERROR) } if (error != null) { - Toast.makeText(context, "Scanner was canceled with error: $error", Toast.LENGTH_LONG).show() - println(error) + resultHandler?.error(E_CANCELED, "Scanner was canceled with error: $error", null) } else { - Toast.makeText(context, "Scanner was canceled", Toast.LENGTH_LONG).show() + resultHandler?.error(E_CANCELED, "Scanner was canceled", null) } return false } diff --git a/example/android/build.gradle b/example/android/build.gradle index 641dac1..09a1d9c 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.5.20' + ext.kotlin_version = '1.6.10' repositories { google() jcenter() @@ -25,7 +25,7 @@ allprojects { maven { url "https://jitpack.io/" } } project.ext { - klippaScannerVersion = "2.0.3" + klippaScannerVersion = "2.0.6" } } diff --git a/ios/.sdk_version b/ios/.sdk_version index f905682..e8423da 100644 --- a/ios/.sdk_version +++ b/ios/.sdk_version @@ -1 +1 @@ -0.4.7 +0.4.10 diff --git a/ios/Classes/SwiftKlippaScannerSdkPlugin.swift b/ios/Classes/SwiftKlippaScannerSdkPlugin.swift index 9b1ce95..b0a205a 100644 --- a/ios/Classes/SwiftKlippaScannerSdkPlugin.swift +++ b/ios/Classes/SwiftKlippaScannerSdkPlugin.swift @@ -73,6 +73,10 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, ImageScannerC KlippaScanner.setup.previewDuration = previewDuration as? Double ?? 0 } + if let isTimerAllowed = builderArgs?["Timer.allowed"] { + KlippaScanner.setup.allowTimer = isTimerAllowed as? Bool ?? false + } + if let isTimerEnabled = builderArgs?["Timer.enabled"] { KlippaScanner.setup.isTimerEnabled = isTimerEnabled as? Bool ?? false } @@ -95,7 +99,7 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, ImageScannerC } if let allowShutterButton = builderArgs?["ShutterButton.allowShutterButton"] { - if let hideShutterButton = builderArgs?["ShutterButton.hideShutterbutton"] { + if let hideShutterButton = builderArgs?["ShutterButton.hideShutterButton"] { KlippaScanner.setup.set(allowShutterButton: allowShutterButton as? Bool ?? true, hideShutterButton: hideShutterButton as? Bool ?? false) } } @@ -107,6 +111,10 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, ImageScannerC if let imageTooDarkMessage = builderArgs?["ImageTooDarkMessage"] { KlippaScanner.setup.imageTooDarkMessage = imageTooDarkMessage as? String ?? "" } + + if let imageLimitReachedMessage = builderArgs?["ImageLimitReachedMessage"] { + KlippaScanner.setup.imageLimitReachedMessage = imageLimitReachedMessage as? String ?? "" + } if let primaryColor = builderArgs?["PrimaryColor"] { let color = primaryColor as? String ?? "" @@ -164,6 +172,10 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, ImageScannerC KlippaScanner.setup.storeImagesToCameraRoll = storeImagesToCameraRoll as? Bool ?? true } + if let imageLimit = builderArgs?["ImageLimit"] { + KlippaScanner.setup.imageLimit = imageLimit as? Int ?? 0 + } + let rootViewController = UIApplication.shared.windows.last!.rootViewController! let modelFile = builderArgs?["Model.fileName"] as? String ?? "" @@ -205,7 +217,9 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, ImageScannerC let resultDict = [ "Images" : images, - "MultipleDocuments" : result.multipleDocumentsModeEnabled + "MultipleDocuments" : result.multipleDocumentsModeEnabled, + "Crop": result.cropEnabled, + "TimerEnabled" : result.timerEnabled ] as [String : Any] resultHandler!(resultDict) diff --git a/ios/klippa_scanner_sdk.podspec b/ios/klippa_scanner_sdk.podspec index 247be67..1ca6ace 100644 --- a/ios/klippa_scanner_sdk.podspec +++ b/ios/klippa_scanner_sdk.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'klippa_scanner_sdk' - s.version = '0.0.1' + s.version = '0.0.2' s.summary = 'Allows you to do document scanning with the Klippa Scanner SDK from Flutter apps.' s.description = <<-DESC Allows you to do document scanning with the Klippa Scanner SDK from Flutter apps. diff --git a/lib/klippa_scanner_sdk.dart b/lib/klippa_scanner_sdk.dart index 6ac5299..5b88545 100644 --- a/lib/klippa_scanner_sdk.dart +++ b/lib/klippa_scanner_sdk.dart @@ -1,4 +1,3 @@ - import 'dart:async'; import 'dart:ui'; @@ -11,10 +10,12 @@ class ModelOptions { /// The name of the label file when using custom object detection. String modelLabels; - } class TimerOptions { + /// Whether the timerButton is shown or hidden. + bool allowed; + /// Whether automatically capturing of images is enabled. Only available when using a custom object detection model. bool enabled; @@ -34,26 +35,22 @@ class Dimensions { class SuccessOptions { /// After capture, show a checkmark preview with this success message, instead of a preview of the image. - String message; + String message; /// The amount of seconds the success message should be visible for, should be a float. - num previewDuration; + num previewDuration; } -enum DefaultColor { - original, grayscale -} +enum DefaultColor { original, grayscale } class ShutterButton { /// Whether to allow or disallow the shutter button to work (can only be disabled if a model is supplied) - bool allowshutterButton; + bool allowshutterButton; /// Whether the shutter button should be hidden (only works if allowShutterButton is false) - bool hideShutterbutton; + bool hideShutterButton; } - - class CameraConfig { /// Global options. @@ -84,6 +81,12 @@ class CameraConfig { /// The amount of seconds the preview should be visible for, should be a float. num previewDuration; + /// To limit the amount of images that can be taken. + num imageLimit; + + /// The message to display when the limit has reached + String imageLimitReachedMessage; + /// If you would like to use a custom model for object detection. Model + labels file should be packaged in your bundle. ModelOptions model = new ModelOptions(); @@ -107,12 +110,6 @@ class CameraConfig { /// What the default color conversion will be (grayscale, original) DefaultColor defaultColor; - /// To limit the amount of images that can be taken. - num imageLimit; - - /// The message to display when the limit has reached - String imageLimitReachedMessage; - /// The filename to be given to the image results. String outputFileName; @@ -178,9 +175,10 @@ class KIVHexColor { class KlippaScannerSdk { static const MethodChannel _channel = - const MethodChannel('klippa_scanner_sdk'); + const MethodChannel('klippa_scanner_sdk'); - static Future startSession(final CameraConfig config, String license) async { + static Future startSession( + final CameraConfig config, String license) async { Map parameters = {}; parameters['License'] = license; @@ -232,6 +230,9 @@ class KlippaScannerSdk { } if (config.timer != null) { + if (config.timer.allowed != null) { + parameters["Timer.allowed"] = config.timer.allowed; + } if (config.timer.enabled != null) { parameters["Timer.enabled"] = config.timer.enabled; } @@ -259,13 +260,22 @@ class KlippaScannerSdk { } if (config.shutterButton != null) { - if(config.shutterButton.allowshutterButton != null) { - parameters["ShutterButton.allowShutterButton"] = config.shutterButton.allowshutterButton; + if (config.shutterButton.allowshutterButton != null) { + parameters["ShutterButton.allowShutterButton"] = + config.shutterButton.allowshutterButton; } - if (config.shutterButton.hideShutterbutton != null) { - parameters["ShutterButton.hideShutterbutton"] = config.shutterButton.hideShutterbutton; + if (config.shutterButton.hideShutterButton != null) { + parameters["ShutterButton.hideShutterButton"] = + config.shutterButton.hideShutterButton; } + } + if (config.imageLimit != null) { + parameters["ImageLimit"] = config.imageLimit; + } + + if (config.imageLimitReachedMessage != null) { + parameters["ImageLimitReachedMessage"] = config.imageLimitReachedMessage; } /// Android only @@ -278,20 +288,13 @@ class KlippaScannerSdk { parameters["DefaultColor"] = describeEnum(config.defaultColor); } - if (config.imageLimit != null) { - parameters["ImageLimit"] = config.imageLimit; - } - - if (config.imageLimitReachedMessage != null) { - parameters["ImageLimitReachedMessage"] = config.imageLimitReachedMessage; - } - if (config.outputFileName != null) { parameters["OutputFilename"] = config.outputFileName; } if (config.imageMovingSensitivityAndroid != null) { - parameters["ImageMovingSensitivityAndroid"] = config.imageMovingSensitivityAndroid; + parameters["ImageMovingSensitivityAndroid"] = + config.imageMovingSensitivityAndroid; } /// iOS only @@ -305,15 +308,18 @@ class KlippaScannerSdk { } if (config.primaryColor != null) { - parameters["PrimaryColor"] = KIVHexColor.flutterColorToHex(config.primaryColor, true); + parameters["PrimaryColor"] = + KIVHexColor.flutterColorToHex(config.primaryColor, true); } if (config.accentColor != null) { - parameters["AccentColor"] = KIVHexColor.flutterColorToHex(config.accentColor, true); + parameters["AccentColor"] = + KIVHexColor.flutterColorToHex(config.accentColor, true); } if (config.overlayColor != null) { - parameters["OverlayColor"] = KIVHexColor.flutterColorToHex(config.overlayColor, true); + parameters["OverlayColor"] = + KIVHexColor.flutterColorToHex(config.overlayColor, true); } if (config.overlayColorAlpha != null) { @@ -321,23 +327,28 @@ class KlippaScannerSdk { } if (config.warningBackgroundColor != null) { - parameters["WarningBackgroundColor"] = KIVHexColor.flutterColorToHex(config.warningBackgroundColor, true); + parameters["WarningBackgroundColor"] = + KIVHexColor.flutterColorToHex(config.warningBackgroundColor, true); } if (config.warningTextColor != null) { - parameters["WarningTextColor"] = KIVHexColor.flutterColorToHex(config.warningTextColor, true); + parameters["WarningTextColor"] = + KIVHexColor.flutterColorToHex(config.warningTextColor, true); } if (config.iconEnabledColor != null) { - parameters["IconEnabledColor"] = KIVHexColor.flutterColorToHex(config.iconEnabledColor, true); + parameters["IconEnabledColor"] = + KIVHexColor.flutterColorToHex(config.iconEnabledColor, true); } if (config.iconDisabledColor != null) { - parameters["IconDisabledColor"] = KIVHexColor.flutterColorToHex(config.iconDisabledColor, true); + parameters["IconDisabledColor"] = + KIVHexColor.flutterColorToHex(config.iconDisabledColor, true); } if (config.reviewIconColor != null) { - parameters["ReviewIconColor"] = KIVHexColor.flutterColorToHex(config.reviewIconColor, true); + parameters["ReviewIconColor"] = + KIVHexColor.flutterColorToHex(config.reviewIconColor, true); } if (config.isViewFinderEnabled != null) { @@ -345,14 +356,16 @@ class KlippaScannerSdk { } if (config.imageMovingSensitivityiOS != null) { - parameters["ImageMovingSensitivityiOS"] = config.imageMovingSensitivityiOS; + parameters["ImageMovingSensitivityiOS"] = + config.imageMovingSensitivityiOS; } if (config.storeImagesToCameraRol != null) { parameters["StoreImagesToCameraRoll"] = config.storeImagesToCameraRol; } - final Map startSessionResult = await _channel.invokeMethod('startSession', parameters); + final Map startSessionResult = + await _channel.invokeMethod('startSession', parameters); return startSessionResult; } }