diff --git a/README.md b/README.md index 4888add..c732141 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,4 @@ Add a repository: Gradle dependency string: - com.hardbacknutter.tinyzxingwrapper:TinyZXingWrapper:1.0.1:release@aar + com.hardbacknutter.tinyzxingwrapper:TinyZXingWrapper:1.1.0:release@aar diff --git a/TinyZXingWrapper/build.gradle b/TinyZXingWrapper/build.gradle index cd774f3..a725dea 100644 --- a/TinyZXingWrapper/build.gradle +++ b/TinyZXingWrapper/build.gradle @@ -26,7 +26,7 @@ kotlin { ext { // build version for the library - tinyZXingWrapperVersion = "1.0.1" + tinyZXingWrapperVersion = "1.1.0" } android { diff --git a/TinyZXingWrapper/src/main/java/com/hardbacknutter/tinyzxingwrapper/ScanOptions.java b/TinyZXingWrapper/src/main/java/com/hardbacknutter/tinyzxingwrapper/ScanOptions.java index 49e5274..daa70b6 100644 --- a/TinyZXingWrapper/src/main/java/com/hardbacknutter/tinyzxingwrapper/ScanOptions.java +++ b/TinyZXingWrapper/src/main/java/com/hardbacknutter/tinyzxingwrapper/ScanOptions.java @@ -68,18 +68,25 @@ public ScanOptions setUseCameraWithLensFacing(final int lensFacing) { /** * Set the desired barcode formats to try and decode. + *

+ * IMPORTANT: + * The value is stored as an {@link ArrayList} with the {@code String} values + * of the {@link BarcodeFormat} enum names ! * * @param list of {@link BarcodeFormat}s to try decoding * * @return this * * @see DecodeHintType#POSSIBLE_FORMATS + * @see BarcodeScanner.Builder#addHints(Bundle) */ @NonNull public ScanOptions setBarcodeFormats(@NonNull final List list) { if (!list.isEmpty()) { intent.putStringArrayListExtra(DecodeHintType.POSSIBLE_FORMATS.name(), list.stream() + // Note we store the NAME of the enum + // so we do not have to parcel the enum values .map(Enum::name) .collect(Collectors.toCollection(ArrayList::new))); } diff --git a/TinyZXingWrapper/src/main/java/com/hardbacknutter/tinyzxingwrapper/scanner/BarcodeScanner.java b/TinyZXingWrapper/src/main/java/com/hardbacknutter/tinyzxingwrapper/scanner/BarcodeScanner.java index b36ef37..e3ec0da 100644 --- a/TinyZXingWrapper/src/main/java/com/hardbacknutter/tinyzxingwrapper/scanner/BarcodeScanner.java +++ b/TinyZXingWrapper/src/main/java/com/hardbacknutter/tinyzxingwrapper/scanner/BarcodeScanner.java @@ -41,6 +41,7 @@ import java.util.stream.Collectors; import com.hardbacknutter.tinyzxingwrapper.ScanContract; +import com.hardbacknutter.tinyzxingwrapper.ScanOptions; /** * The main scanner code. @@ -372,16 +373,15 @@ public Builder setDecoderFactory(@NonNull final DecoderFactory decoderFactory) { *

* Only used if {@link #setDecoderFactory(DecoderFactory)} is NOT called. * - * @param barcodeFormats names of {@link BarcodeFormat}s to scan for + * @param barcodeFormats the {@link BarcodeFormat}s to scan for * * @return this */ @NonNull public Builder setBarcodeFormats(@NonNull final List barcodeFormats) { - hints.put(DecodeHintType.POSSIBLE_FORMATS, - barcodeFormats.stream() - .map(Enum::name) - .collect(Collectors.toCollection(ArrayList::new))); + // Used directly, so we just store the enums. + // For intent use, see #addHints + hints.put(DecodeHintType.POSSIBLE_FORMATS, new ArrayList<>(barcodeFormats)); return this; } @@ -449,7 +449,12 @@ public Builder addHint(@NonNull final DecodeHintType hintType, * Add a collection of hints. * If the data type does not match the hint type, the hint is quietly ignored. *

- * {@link DecodeHintType#NEED_RESULT_POINT_CALLBACK} is NOT supported + * IMPORTANT: + * {@link DecodeHintType#POSSIBLE_FORMATS} is expected to have as value + * an {@link ArrayList} with the {@code String} values of the {@link BarcodeFormat} + * enum names ! + *

+ * Note that {@link DecodeHintType#NEED_RESULT_POINT_CALLBACK} is NOT supported * as it's used internally. *

* Only used if {@link #setDecoderFactory(DecoderFactory)} is NOT called. @@ -457,6 +462,8 @@ public Builder addHint(@NonNull final DecodeHintType hintType, * @param args a Bundle with hints; may contain other options which will be ignored. * * @return this + * + * @see ScanOptions#setBarcodeFormats(List) */ @NonNull public Builder addHints(@Nullable final Bundle args) { @@ -467,9 +474,34 @@ public Builder addHints(@Nullable final Bundle args) { .forEach(hintType -> { final String hintName = hintType.name(); if (args.containsKey(hintName)) { + // A switch 'hint': if present, store it with a boolean 'True' + // (this is faster than 6 string equality test) + // PURE_BARCODE + // TRY_HARDER + // ASSUME_CODE_39_CHECK_DIGIT + // ASSUME_GS1 + // RETURN_CODABAR_START_END + // ALSO_INVERTED if (hintType.getValueType().equals(Void.class)) { this.hints.put(hintType, Boolean.TRUE); + + } else if ("POSSIBLE_FORMATS".equals(hintName)) { + // the value is ArrayList of strings with the enum names. + // Convert them back to the actual enums. + final ArrayList list = args.getStringArrayList( + hintName); + if (list != null) { + final List formats = + list.stream() + .map(BarcodeFormat::valueOf) + .collect(Collectors.toList()); + this.hints.put(hintType, formats); + } } else { + // OTHER + // CHARACTER_SET + // ALLOWED_LENGTHS + // ALLOWED_EAN_EXTENSIONS final Object hintData = args.get(hintName); if (hintType.getValueType().isInstance(hintData)) { this.hints.put(hintType, hintData);