paint.setColor(getResources().getColor(R.color.result_points));
if (points.length == 2) {
paint.setStrokeWidth(4.0f);
- canvas.drawLine(points[0].getX(), points[0].getY(), points[1].getX(),
- points[1].getY(), paint);
+ drawLine(canvas, paint, points[0], points[1]);
+ } else if (points.length == 4 &&
+ (rawResult.getBarcodeFormat().equals(BarcodeFormat.UPC_A)) ||
+ (rawResult.getBarcodeFormat().equals(BarcodeFormat.EAN_13))) {
+ // Hacky special case -- draw two lines, for the barcode and metadata
+ drawLine(canvas, paint, points[0], points[1]);
+ drawLine(canvas, paint, points[2], points[3]);
} else {
paint.setStrokeWidth(10.0f);
for (ResultPoint point : points) {
}
}
+ private static void drawLine(Canvas canvas, Paint paint, ResultPoint a, ResultPoint b) {
+ canvas.drawLine(a.getX(), a.getY(), b.getX(), b.getY(), paint);
+ }
+
// Put up our own UI for how to handle the decoded contents.
private void handleDecodeInternally(Result rawResult, Bitmap barcode) {
statusView.setVisibility(View.GONE);
private final String text;
private final byte[] rawBytes;
- private final ResultPoint[] resultPoints;
+ private ResultPoint[] resultPoints;
private final BarcodeFormat format;
private Hashtable resultMetadata;
private final long timestamp;
}
}
+ public void addResultPoints(ResultPoint[] newPoints) {
+ if (resultPoints == null) {
+ resultPoints = newPoints;
+ } else if (newPoints != null && newPoints.length > 0) {
+ ResultPoint[] allPoints = new ResultPoint[resultPoints.length + newPoints.length];
+ System.arraycopy(resultPoints, 0, allPoints, 0, resultPoints.length);
+ System.arraycopy(newPoints, 0, allPoints, resultPoints.length, newPoints.length);
+ resultPoints = allPoints;
+ }
+ }
+
public long getTimestamp() {
return timestamp;
}
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.ResultMetadataType;
+import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitArray;
final class UPCEANExtensionSupport {
private final int[] decodeMiddleCounters = new int[4];
private final StringBuffer decodeRowStringBuffer = new StringBuffer();
- Result decodeRow(BitArray row, int rowOffset) throws NotFoundException {
+ Result decodeRow(int rowNumber, BitArray row, int rowOffset) throws NotFoundException {
int[] extensionStartRange = UPCEANReader.findGuardPattern(row, rowOffset, false, EXTENSION_START_PATTERN);
StringBuffer result = decodeRowStringBuffer;
result.setLength(0);
- decodeMiddle(row, extensionStartRange, result);
+ int end = decodeMiddle(row, extensionStartRange, result);
String resultString = result.toString();
Hashtable extensionData = parseExtensionString(resultString);
- Result extensionResult = new Result(resultString, null, null, BarcodeFormat.UPC_EAN_EXTENSION);
+ Result extensionResult =
+ new Result(resultString,
+ null,
+ new ResultPoint[] {
+ new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, (float) rowNumber),
+ new ResultPoint((float) end, (float) rowNumber),
+ },
+ BarcodeFormat.UPC_EAN_EXTENSION);
if (extensionData != null) {
extensionResult.putAllMetadata(extensionData);
}
if (bestMatch >= 10) {
lgPatternFound |= 1 << (4 - x);
}
- // Read off separator
- while (rowOffset < end && !row.get(rowOffset)) {
- rowOffset++;
- }
- while (rowOffset < end && row.get(rowOffset)) {
- rowOffset++;
+ if (x != 4) {
+ // Read off separator if not last
+ while (rowOffset < end && !row.get(rowOffset)) {
+ rowOffset++;
+ }
+ while (rowOffset < end && row.get(rowOffset)) {
+ rowOffset++;
+ }
}
}
format);
try {
- Result extensionResult = extensionReader.decodeRow(row, endRange[1]);
+ Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
decodeResult.putAllMetadata(extensionResult.getResultMetadata());
+ decodeResult.addResultPoints(extensionResult.getResultPoints());
} catch (ReaderException re) {
// continue
}