From b6f75159e1611026bd0873fbcf81bcb791923b05 Mon Sep 17 00:00:00 2001 From: Robin Farmer Date: Mon, 6 Jan 2025 13:38:38 +0100 Subject: [PATCH] bump sdk versions and add purge method. --- CHANGELOG.md | 7 ++++ README.md | 19 +++++++++ android/build.gradle | 2 +- .../KlippaScannerSdkPlugin.kt | 40 ++++++++++++++++--- ios/Classes/SwiftKlippaScannerSdkPlugin.swift | 32 +++++++++++++-- ios/sdk_version | 2 +- lib/klippa_scanner_sdk.dart | 24 +++++++++++ pubspec.yaml | 2 +- 8 files changed, 117 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a87a40f..eb91112 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.0.5 + +* Bumped Android to 4.0.8 +* Bumped iOS to 2.0.6 +* Added method `purge()`. +* Added setup options `PerformOnDeviceOCR` and `OutputFormat`. + ## 1.0.4 * Bumped Android to 4.0.6 diff --git a/README.md b/README.md index a1e61e2..13be09d 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,12 @@ config.userShouldAcceptResultToContinue = false; // What the default color conversion will be (grayscale, original, enhanced). config.defaultColor = DefaultColor.original; +/// Whether to perform on-device OCR after scanning completes. +config.performOnDeviceOCR = false; + +/// What the output format will be (jpeg, pdfMerged, pdfSingle). (Default jpeg) +config.outputFormat = OutputFormat.jpeg; + // Enable Single Document Mode config.cameraModeSingle = new CameraMode(); // Localize the name of Single Document Mode @@ -438,6 +444,19 @@ config.cameraModeMulti?.image = "{name of image in Assets.xcassets}"; config.cameraModeSingle?.image = "{name of image in Assets.xcassets}"; ``` +## How to clear the storage. + +```dart +import 'package:klippa_scanner_sdk/klippa_scanner_sdk.dart'; + +try { + await KlippaScannerSdk.purge(); +} on PlatformException catch (e) { + print('Failed to purge storage: ' + e.toString()); +} +``` + + ## Important iOS notes Older iOS versions do not ship the Swift libraries. To make sure the SDK works on older iOS versions, you can configure the build to embed the Swift libraries using the build setting `EMBEDDED_CONTENT_CONTAINS_SWIFT = YES`. diff --git a/android/build.gradle b/android/build.gradle index 33e9de5..c08fae7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -77,7 +77,7 @@ android { } dependencies { - def fallbackKlippaScannerVersion = "4.0.6" + def fallbackKlippaScannerVersion = "4.0.8" def klippaScannerVersion = project.hasProperty('klippaScannerVersion') ? project.klippaScannerVersion : fallbackKlippaScannerVersion 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 05d4299..c92bfbd 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 @@ -13,10 +13,12 @@ import com.klippa.scanner.model.KlippaError import com.klippa.scanner.model.KlippaImageColor import com.klippa.scanner.model.KlippaMultipleDocumentMode import com.klippa.scanner.model.KlippaObjectDetectionModel +import com.klippa.scanner.model.KlippaOutputFormat import com.klippa.scanner.model.KlippaScannerResult import com.klippa.scanner.model.KlippaSegmentedDocumentMode import com.klippa.scanner.model.KlippaSingleDocumentMode import com.klippa.scanner.model.KlippaSize +import com.klippa.scanner.storage.KlippaStorage import io.flutter.embedding.engine.plugins.FlutterPlugin import io.flutter.embedding.engine.plugins.activity.ActivityAware import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding @@ -72,13 +74,23 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P } override fun onMethodCall(call: MethodCall, result: Result) { - if (call.method == "startSession") { - startSession(call, result) - } else { - result.notImplemented() + when (call.method) { + "startSession" -> startSession(call, result) + "purge" -> purge(result) + else -> result.notImplemented() } } + private fun purge(result: Result) { + val activity = activityPluginBinding?.activity ?: kotlin.run { + result.error(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist", null) + return + } + + KlippaStorage.purge(activity) + result.success(null) + } + private fun startSession(call: MethodCall, result: Result) { val activity = activityPluginBinding?.activity ?: kotlin.run { result.error(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist", null) @@ -172,6 +184,20 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P } } + call.argument("OutputFormat")?.let { + when (it) { + "jpeg" -> { + scannerSession.imageAttributes.outputFormat = KlippaOutputFormat.JPEG + } + "pdfSingle" -> { + scannerSession.imageAttributes.outputFormat = KlippaOutputFormat.PDF_SINGLE + } + "pdfMerged" -> { + scannerSession.imageAttributes.outputFormat = KlippaOutputFormat.PDF_MERGED + } + } + } + call.argument("ImageLimit")?.let { scannerSession.imageAttributes.imageLimit = it } @@ -184,6 +210,10 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P scannerSession.imageAttributes.imageMovingSensitivity = it } + call.argument("PerformOnDeviceOCR")?.let { + scannerSession.imageAttributes.performOnDeviceOCR = it + } + call.argument("StoreImagesToCameraRoll")?.let { scannerSession.imageAttributes.storeImagesToGallery = it } @@ -322,7 +352,7 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P private fun klippaScannerDidFinishScanningWithResult(result: KlippaScannerResult) { val images: MutableList> = mutableListOf() - for (image in result.images) { + for (image in result.results) { val imageDict = mapOf("Filepath" to image.location) images.add(imageDict) } diff --git a/ios/Classes/SwiftKlippaScannerSdkPlugin.swift b/ios/Classes/SwiftKlippaScannerSdkPlugin.swift index e233892..bc9352a 100644 --- a/ios/Classes/SwiftKlippaScannerSdkPlugin.swift +++ b/ios/Classes/SwiftKlippaScannerSdkPlugin.swift @@ -16,13 +16,21 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, KlippaScanner } public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - if call.method == "startSession" { + switch call.method { + case "startSession": startSession(call, result: result) - } else { + case "purge": + purge(result: result) + default: result(FlutterMethodNotImplemented) } } + private func purge(result: @escaping FlutterResult) { + KlippaScannerStorage.purge() + result(nil) + } + private func startSession(_ call: FlutterMethodCall, result: @escaping FlutterResult) { guard let args = call.arguments else { result(FlutterError.init(code: E_UNKNOWN_ERROR, message: "Unknown error", details: nil)) @@ -271,6 +279,24 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, KlippaScanner builder.klippaMenu.shouldGoToReviewScreenOnFinishPressed = shouldGoToReviewScreenOnFinishPressed } + + if let outputFormat = builderArgs?["OutputFormat"] as? String { + switch outputFormat { + case "jpeg": + builder.klippaImageAttributes.outputFormat = .jpeg + case "pdfSingle": + builder.klippaImageAttributes.outputFormat = .pdfSingle + case "pdfMerged": + builder.klippaImageAttributes.outputFormat = .pdfMerged + default: + builder.klippaImageAttributes.outputFormat = .jpeg + } + } + + if let performOnDeviceOCR = builderArgs?["PerformOnDeviceOCR"] as? Bool { + builder.klippaImageAttributes.performOnDeviceOCR = performOnDeviceOCR + } + if let brightnessLowerThreshold = builderArgs?["BrightnessLowerThreshold"] as? Double { builder.klippaImageAttributes.brightnessLowerThreshold = brightnessLowerThreshold } @@ -382,7 +408,7 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, KlippaScanner public func klippaScannerDidFinishScanningWithResult(result: KlippaScannerResult) { var images: [[String: String]] = [] - for image in result.images { + for image in result.results { let imageDict = ["Filepath" : image.path] images.append(imageDict) } diff --git a/ios/sdk_version b/ios/sdk_version index e010258..157e54f 100644 --- a/ios/sdk_version +++ b/ios/sdk_version @@ -1 +1 @@ -2.0.5 +2.0.6 diff --git a/lib/klippa_scanner_sdk.dart b/lib/klippa_scanner_sdk.dart index 8036749..408e8a2 100644 --- a/lib/klippa_scanner_sdk.dart +++ b/lib/klippa_scanner_sdk.dart @@ -58,6 +58,12 @@ class CameraMode { String? image; } +enum OutputFormat { + jpeg, + pdfSingle, + pdfMerged +} + class CameraConfig { /// Global options. @@ -142,6 +148,12 @@ class CameraConfig { /// Whether the camera automatically saves the images to the camera roll (iOS) / gallery (Android). Default true. bool? storeImagesToCameraRol; + /// Whether to perform on-device OCR after scanning completes. + bool? performOnDeviceOCR; + + /// What the output format will be (jpeg, pdfMerged, pdfSingle). (Default jpeg) + OutputFormat? outputFormat; + /// The camera mode for scanning one part documents. CameraMode? cameraModeSingle; @@ -271,6 +283,10 @@ class KlippaScannerSdk { static const MethodChannel _channel = const MethodChannel('klippa_scanner_sdk'); + static Future purge() async { + return await _channel.invokeMethod('purge'); + } + static Future startSession( final CameraConfig config, String license) async { Map parameters = {}; @@ -347,6 +363,14 @@ class KlippaScannerSdk { parameters["StoreImagesToCameraRoll"] = config.storeImagesToCameraRol; } + if (config.performOnDeviceOCR != null) { + parameters["PerformOnDeviceOCR"] = config.performOnDeviceOCR; + } + + if (config.outputFormat != null) { + parameters["OutputFormat"] = config.outputFormat; + } + if (config.cameraModeSingle != null) { parameters["CameraModeSingle"] = { 'name': config.cameraModeSingle?.name, diff --git a/pubspec.yaml b/pubspec.yaml index 8eedd46..92c1e28 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: klippa_scanner_sdk description: Allows you to do document scanning with the Klippa Scanner SDK from Flutter apps. -version: 1.0.4 +version: 1.0.5 homepage: https://github.com/klippa-app/flutter-klippa-scanner-sdk environment: