use of com.google.zxing.BarcodeFormat in project zxing by zxing.
the class UPCEANReader method decodeRow.
/**
* <p>Like {@link #decodeRow(int, BitArray, Map)}, but
* allows caller to inform method about where the UPC/EAN start pattern is
* found. This allows this to be computed once and reused across many implementations.</p>
*
* @param rowNumber row index into the image
* @param row encoding of the row of the barcode image
* @param startGuardRange start/end column where the opening start pattern was found
* @param hints optional hints that influence decoding
* @return {@link Result} encapsulating the result of decoding a barcode in the row
* @throws NotFoundException if no potential barcode is found
* @throws ChecksumException if a potential barcode is found but does not pass its checksum
* @throws FormatException if a potential barcode is found but format is invalid
*/
public Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, Map<DecodeHintType, ?> hints) throws NotFoundException, ChecksumException, FormatException {
ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
if (resultPointCallback != null) {
resultPointCallback.foundPossibleResultPoint(new ResultPoint((startGuardRange[0] + startGuardRange[1]) / 2.0f, rowNumber));
}
StringBuilder result = decodeRowStringBuffer;
result.setLength(0);
int endStart = decodeMiddle(row, startGuardRange, result);
if (resultPointCallback != null) {
resultPointCallback.foundPossibleResultPoint(new ResultPoint(endStart, rowNumber));
}
int[] endRange = decodeEnd(row, endStart);
if (resultPointCallback != null) {
resultPointCallback.foundPossibleResultPoint(new ResultPoint((endRange[0] + endRange[1]) / 2.0f, rowNumber));
}
// Make sure there is a quiet zone at least as big as the end pattern after the barcode. The
// spec might want more whitespace, but in practice this is the maximum we can count on.
int end = endRange[1];
int quietEnd = end + (end - endRange[0]);
if (quietEnd >= row.getSize() || !row.isRange(end, quietEnd, false)) {
throw NotFoundException.getNotFoundInstance();
}
String resultString = result.toString();
// UPC/EAN should never be less than 8 chars anyway
if (resultString.length() < 8) {
throw FormatException.getFormatInstance();
}
if (!checkChecksum(resultString)) {
throw ChecksumException.getChecksumInstance();
}
float left = (startGuardRange[1] + startGuardRange[0]) / 2.0f;
float right = (endRange[1] + endRange[0]) / 2.0f;
BarcodeFormat format = getBarcodeFormat();
Result decodeResult = new Result(resultString, // no natural byte representation for these barcodes
null, new ResultPoint[] { new ResultPoint(left, rowNumber), new ResultPoint(right, rowNumber) }, format);
int extensionLength = 0;
try {
Result extensionResult = extensionReader.decodeRow(rowNumber, row, endRange[1]);
decodeResult.putMetadata(ResultMetadataType.UPC_EAN_EXTENSION, extensionResult.getText());
decodeResult.putAllMetadata(extensionResult.getResultMetadata());
decodeResult.addResultPoints(extensionResult.getResultPoints());
extensionLength = extensionResult.getText().length();
} catch (ReaderException re) {
// continue
}
int[] allowedExtensions = hints == null ? null : (int[]) hints.get(DecodeHintType.ALLOWED_EAN_EXTENSIONS);
if (allowedExtensions != null) {
boolean valid = false;
for (int length : allowedExtensions) {
if (extensionLength == length) {
valid = true;
break;
}
}
if (!valid) {
throw NotFoundException.getNotFoundInstance();
}
}
if (format == BarcodeFormat.EAN_13 || format == BarcodeFormat.UPC_A) {
String countryID = eanManSupport.lookupCountryIdentifier(resultString);
if (countryID != null) {
decodeResult.putMetadata(ResultMetadataType.POSSIBLE_COUNTRY, countryID);
}
}
return decodeResult;
}
use of com.google.zxing.BarcodeFormat in project zxing by zxing.
the class ExpandedProductResultParser method parse.
@Override
public ExpandedProductParsedResult parse(Result result) {
BarcodeFormat format = result.getBarcodeFormat();
if (format != BarcodeFormat.RSS_EXPANDED) {
// ExtendedProductParsedResult NOT created. Not a RSS Expanded barcode
return null;
}
String rawText = getMassagedText(result);
String productID = null;
String sscc = null;
String lotNumber = null;
String productionDate = null;
String packagingDate = null;
String bestBeforeDate = null;
String expirationDate = null;
String weight = null;
String weightType = null;
String weightIncrement = null;
String price = null;
String priceIncrement = null;
String priceCurrency = null;
Map<String, String> uncommonAIs = new HashMap<>();
int i = 0;
while (i < rawText.length()) {
String ai = findAIvalue(i, rawText);
if (ai == null) {
// ExtendedProductParsedResult NOT created. Not match with RSS Expanded pattern
return null;
}
i += ai.length() + 2;
String value = findValue(i, rawText);
i += value.length();
switch(ai) {
case "00":
sscc = value;
break;
case "01":
productID = value;
break;
case "10":
lotNumber = value;
break;
case "11":
productionDate = value;
break;
case "13":
packagingDate = value;
break;
case "15":
bestBeforeDate = value;
break;
case "17":
expirationDate = value;
break;
case "3100":
case "3101":
case "3102":
case "3103":
case "3104":
case "3105":
case "3106":
case "3107":
case "3108":
case "3109":
weight = value;
weightType = ExpandedProductParsedResult.KILOGRAM;
weightIncrement = ai.substring(3);
break;
case "3200":
case "3201":
case "3202":
case "3203":
case "3204":
case "3205":
case "3206":
case "3207":
case "3208":
case "3209":
weight = value;
weightType = ExpandedProductParsedResult.POUND;
weightIncrement = ai.substring(3);
break;
case "3920":
case "3921":
case "3922":
case "3923":
price = value;
priceIncrement = ai.substring(3);
break;
case "3930":
case "3931":
case "3932":
case "3933":
if (value.length() < 4) {
// ExtendedProductParsedResult NOT created. Not match with RSS Expanded pattern
return null;
}
price = value.substring(3);
priceCurrency = value.substring(0, 3);
priceIncrement = ai.substring(3);
break;
default:
// No match with common AIs
uncommonAIs.put(ai, value);
break;
}
}
return new ExpandedProductParsedResult(rawText, productID, sscc, lotNumber, productionDate, packagingDate, bestBeforeDate, expirationDate, weight, weightType, weightIncrement, price, priceIncrement, priceCurrency, uncommonAIs);
}
use of com.google.zxing.BarcodeFormat in project smartmodule by carozhu.
the class CaptureActivity method qrcodeSetting.
private void qrcodeSetting() {
decodeFormats = new Vector<BarcodeFormat>(2);
decodeFormats.clear();
decodeFormats.add(BarcodeFormat.QR_CODE);
decodeFormats.add(BarcodeFormat.DATA_MATRIX);
// TODO: 16/1/29 set select qrcode mode title
if (null != mHandler) {
mHandler.setDecodeFormats(decodeFormats);
}
int width = DisplayMetricsUtil.getScreenWidth(context);
viewfinderView.refreshDrawableState();
//cameraManager.setManualFramingRect(300, 300);
//cameraManager.setManualFramingRect((width / 2) + (width / 2)/2, (width / 2) + (width / 2)/2);
//cameraManager.setManualFramingRect((width / 2) + 30, (width / 2) + 30);//old
cameraManager.setManualFramingRect((width / 2) + 120, (width / 2) + 120);
viewfinderView.refreshDrawableState();
}
use of com.google.zxing.BarcodeFormat in project barcodescanner by dm77.
the class FormatSelectorDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (mSelectedIndices == null || mListener == null) {
dismiss();
return null;
}
String[] formats = new String[ZXingScannerView.ALL_FORMATS.size()];
boolean[] checkedIndices = new boolean[ZXingScannerView.ALL_FORMATS.size()];
int i = 0;
for (BarcodeFormat format : ZXingScannerView.ALL_FORMATS) {
formats[i] = format.toString();
if (mSelectedIndices.contains(i)) {
checkedIndices[i] = true;
} else {
checkedIndices[i] = false;
}
i++;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Set the dialog title
builder.setTitle(R.string.choose_formats).setMultiChoiceItems(formats, checkedIndices, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (isChecked) {
// If the user checked the item, add it to the selected items
mSelectedIndices.add(which);
} else if (mSelectedIndices.contains(which)) {
// Else, if the item is already in the array, remove it
mSelectedIndices.remove(mSelectedIndices.indexOf(which));
}
}
}).setPositiveButton(R.string.ok_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// or return them to the component that opened the dialog
if (mListener != null) {
mListener.onFormatsSaved(mSelectedIndices);
}
}
}).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
return builder.create();
}
use of com.google.zxing.BarcodeFormat in project zxing-android-embedded by journeyapps.
the class DecoratedBarcodeView method initializeFromIntent.
/**
* Convenience method to initialize camera id, decode formats and prompt message from an intent.
*
* @param intent the intent, as generated by IntentIntegrator
*/
public void initializeFromIntent(Intent intent) {
// Scan the formats the intent requested, and return the result to the calling activity.
Set<BarcodeFormat> decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
Map<DecodeHintType, Object> decodeHints = DecodeHintManager.parseDecodeHints(intent);
CameraSettings settings = new CameraSettings();
if (intent.hasExtra(Intents.Scan.CAMERA_ID)) {
int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1);
if (cameraId >= 0) {
settings.setRequestedCameraId(cameraId);
}
}
String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
if (customPromptMessage != null) {
setStatusText(customPromptMessage);
}
// Check to see if the scan should be inverted.
boolean inverted = intent.getBooleanExtra(Intents.Scan.INVERTED_SCAN, false);
String characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);
MultiFormatReader reader = new MultiFormatReader();
reader.setHints(decodeHints);
barcodeView.setCameraSettings(settings);
barcodeView.setDecoderFactory(new DefaultDecoderFactory(decodeFormats, decodeHints, characterSet, inverted));
}
Aggregations