import com.google.zxing.ReaderException;\r
import com.google.zxing.Result;\r
import com.google.zxing.ResultPoint;\r
+import com.google.zxing.DecodeHintType;\r
import com.google.zxing.common.BitArray;\r
import com.google.zxing.common.GenericResultPoint;\r
\r
private static final int W = 3; // Pixel width of a wide line\r
private static final int N = 1; // Pixed width of a narrow line\r
\r
+ private static final int[] DEFAULT_ALLOWED_LENGTHS = { 6, 10, 14 };\r
+\r
// Stores the actual narrow line width of the image being decoded.\r
private int narrowLineWidth = -1;\r
\r
\r
String resultString = result.toString();\r
\r
+ int[] allowedLengths = (int[]) hints.get(DecodeHintType.ALLOWED_LENGTHS);\r
+ if (allowedLengths == null) {\r
+ allowedLengths = DEFAULT_ALLOWED_LENGTHS;\r
+ }\r
+\r
// To avoid false positives with 2D barcodes (and other patterns), make\r
// an assumption that the decoded string must be 6, 10 or 14 digits.\r
int length = resultString.length();\r
- if (length != 6 && length != 10 && length != 14) {\r
+ boolean lengthOK = false;\r
+ for (int i = 0; i < allowedLengths.length; i++) {\r
+ if (length == allowedLengths[i]) {\r
+ lengthOK = true;\r
+ break;\r
+ }\r
+\r
+ }\r
+ if (!lengthOK) {\r
throw ReaderException.getInstance();\r
}\r
\r