Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinFarmer committed Jan 6, 2025
2 parents 6b78186 + 3b5198f commit 0dfa3c0
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`.

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -172,6 +184,20 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P
}
}

call.argument<String>("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<Int>("ImageLimit")?.let {
scannerSession.imageAttributes.imageLimit = it
}
Expand All @@ -184,6 +210,10 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P
scannerSession.imageAttributes.imageMovingSensitivity = it
}

call.argument<Boolean>("PerformOnDeviceOCR")?.let {
scannerSession.imageAttributes.performOnDeviceOCR = it
}

call.argument<Boolean>("StoreImagesToCameraRoll")?.let {
scannerSession.imageAttributes.storeImagesToGallery = it
}
Expand Down Expand Up @@ -322,7 +352,7 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P
private fun klippaScannerDidFinishScanningWithResult(result: KlippaScannerResult) {
val images: MutableList<Map<String, String>> = mutableListOf()

for (image in result.images) {
for (image in result.results) {
val imageDict = mapOf("Filepath" to image.location)
images.add(imageDict)
}
Expand Down
32 changes: 29 additions & 3 deletions ios/Classes/SwiftKlippaScannerSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion ios/sdk_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.5
2.0.6
24 changes: 24 additions & 0 deletions lib/klippa_scanner_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class CameraMode {
String? image;
}

enum OutputFormat {
jpeg,
pdfSingle,
pdfMerged
}

class CameraConfig {
/// Global options.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -271,6 +283,10 @@ class KlippaScannerSdk {
static const MethodChannel _channel =
const MethodChannel('klippa_scanner_sdk');

static Future<void> purge() async {
return await _channel.invokeMethod('purge');
}

static Future<Map> startSession(
final CameraConfig config, String license) async {
Map<String, dynamic> parameters = {};
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 0dfa3c0

Please sign in to comment.