Skip to content

Commit

Permalink
Merge pull request #816 from navaronbracke/reorganise_classes
Browse files Browse the repository at this point in the history
fix: use rawValue on Android as well for formats
  • Loading branch information
navaronbracke authored Oct 23, 2023
2 parents eb4e241 + 5eb93f8 commit 68330a7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class MobileScannerHandler(
"stop" -> stop(result)
"analyzeImage" -> analyzeImage(call, result)
"setScale" -> setScale(call, result)
"resetScale" -> resetScale(call, result)
"resetScale" -> resetScale(result)
"updateScanWindow" -> updateScanWindow(call)
else -> result.notImplemented()
}
Expand All @@ -144,8 +144,8 @@ class MobileScannerHandler(
var barcodeScannerOptions: BarcodeScannerOptions? = null
if (formats != null) {
val formatsList: MutableList<Int> = mutableListOf()
for (index in formats) {
formatsList.add(BarcodeFormats.values()[index].intValue)
for (formatValue in formats) {
formatsList.add(BarcodeFormats.fromRawValue(formatValue).intValue)
}
barcodeScannerOptions = if (formatsList.size == 1) {
BarcodeScannerOptions.Builder().setBarcodeFormats(formatsList.first())
Expand Down Expand Up @@ -250,7 +250,7 @@ class MobileScannerHandler(
}
}

private fun resetScale(call: MethodCall, result: MethodChannel.Result) {
private fun resetScale(result: MethodChannel.Result) {
try {
mobileScanner!!.resetScale()
result.success(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,41 @@ package dev.steenbakker.mobile_scanner.objects

enum class BarcodeFormats(val intValue: Int) {
UNKNOWN(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_UNKNOWN),
ALL_FORMATS(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_ALL_FORMATS), CODE_128(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_CODE_128), CODE_39(
com.google.mlkit.vision.barcode.common.Barcode.FORMAT_CODE_39
),
CODE_93(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_CODE_93), CODABAR(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_CODABAR), DATA_MATRIX(
com.google.mlkit.vision.barcode.common.Barcode.FORMAT_DATA_MATRIX
),
EAN_13(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_EAN_13), EAN_8(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_EAN_8), ITF(
com.google.mlkit.vision.barcode.common.Barcode.FORMAT_ITF
),
QR_CODE(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_QR_CODE), UPC_A(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_UPC_A), UPC_E(
com.google.mlkit.vision.barcode.common.Barcode.FORMAT_UPC_E
),
PDF417(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_PDF417), AZTEC(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_AZTEC);
ALL_FORMATS(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_ALL_FORMATS),
CODE_128(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_CODE_128),
CODE_39(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_CODE_39),
CODE_93(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_CODE_93),
CODABAR(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_CODABAR),
DATA_MATRIX(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_DATA_MATRIX),
EAN_13(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_EAN_13),
EAN_8(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_EAN_8),
ITF(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_ITF),
QR_CODE(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_QR_CODE),
UPC_A(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_UPC_A),
UPC_E(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_UPC_E),
PDF417(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_PDF417),
AZTEC(com.google.mlkit.vision.barcode.common.Barcode.FORMAT_AZTEC);

companion object {
fun fromRawValue(rawValue: Int): BarcodeFormats {
return when(rawValue) {
-1 -> UNKNOWN
0 -> ALL_FORMATS
1 -> CODE_128
2 -> CODE_39
4 -> CODE_93
8 -> CODABAR
16 -> DATA_MATRIX
32 -> EAN_13
64 -> EAN_8
128 -> ITF
256 -> QR_CODE
512 -> UPC_A
1024 -> UPC_E
2048 -> PDF417
4096 -> AZTEC
else -> UNKNOWN
}
}
}
}
2 changes: 1 addition & 1 deletion lib/mobile_scanner_web_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class MobileScannerWebPlugin {
'rawBytes': code.rawBytes,
'format': code.format.rawValue,
'displayValue': code.displayValue,
'type': code.type.index,
'type': code.type.rawValue,
if (corners != null && corners.isNotEmpty)
'corners': corners
.map(
Expand Down
26 changes: 13 additions & 13 deletions lib/src/mobile_scanner_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ class MobileScannerController {
final Map<String, dynamic> arguments = {};

cameraFacingState.value = cameraFacingOverride ?? facing;
arguments['facing'] = cameraFacingState.value.index;
arguments['facing'] = cameraFacingState.value.rawValue;
arguments['torch'] = torchEnabled;
arguments['speed'] = detectionSpeed.index;
arguments['speed'] = detectionSpeed.rawValue;
arguments['timeout'] = detectionTimeoutMs;
arguments['returnImage'] = returnImage;

/* if (scanWindow != null) {
arguments['scanWindow'] = [
Expand All @@ -147,19 +148,18 @@ class MobileScannerController {
} */

if (formats != null) {
if (kIsWeb || Platform.isIOS || Platform.isMacOS) {
if (kIsWeb || Platform.isIOS || Platform.isMacOS || Platform.isAndroid) {
arguments['formats'] = formats!.map((e) => e.rawValue).toList();
} else if (Platform.isAndroid) {
arguments['formats'] = formats!.map((e) => e.index).toList();
if (cameraResolution != null) {
arguments['cameraResolution'] = <int>[
cameraResolution!.width.toInt(),
cameraResolution!.height.toInt(),
];
}
}
}
arguments['returnImage'] = returnImage;

if (cameraResolution != null) {
arguments['cameraResolution'] = <int>[
cameraResolution!.width.toInt(),
cameraResolution!.height.toInt(),
];
}

return arguments;
}

Expand Down Expand Up @@ -329,7 +329,7 @@ class MobileScannerController {
torchState.value =
torchState.value == TorchState.off ? TorchState.on : TorchState.off;

await _methodChannel.invokeMethod('torch', torchState.value.index);
await _methodChannel.invokeMethod('torch', torchState.value.rawValue);
}

/// Changes the state of the camera (front or back).
Expand Down

0 comments on commit 68330a7

Please sign in to comment.