Added more metadata to the integrator

git-svn-id: https://zxing.googlecode.com/svn/trunk@2068 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2011-12-06 20:13:27 +00:00
parent 48da80e6d6
commit f2fe9dbd67
3 changed files with 45 additions and 4 deletions

View file

@ -292,7 +292,14 @@ public final class IntentIntegrator {
String contents = intent.getStringExtra("SCAN_RESULT"); String contents = intent.getStringExtra("SCAN_RESULT");
String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT"); String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES"); byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
return new IntentResult(contents, formatName, rawBytes); int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");
return new IntentResult(contents,
formatName,
rawBytes,
orientation,
errorCorrectionLevel);
} }
return new IntentResult(); return new IntentResult();
} }

View file

@ -26,15 +26,23 @@ public final class IntentResult {
private final String contents; private final String contents;
private final String formatName; private final String formatName;
private final byte[] rawBytes; private final byte[] rawBytes;
private final Integer orientation;
private final String errorCorrectionLevel;
IntentResult() { IntentResult() {
this(null, null, null); this(null, null, null, null, null);
} }
IntentResult(String contents, String formatName, byte[] rawBytes) { IntentResult(String contents,
String formatName,
byte[] rawBytes,
Integer orientation,
String errorCorrectionLevel) {
this.contents = contents; this.contents = contents;
this.formatName = formatName; this.formatName = formatName;
this.rawBytes = rawBytes; this.rawBytes = rawBytes;
this.orientation = orientation;
this.errorCorrectionLevel = errorCorrectionLevel;
} }
/** /**
@ -58,4 +66,30 @@ public final class IntentResult {
return rawBytes; return rawBytes;
} }
/**
* @return rotation of the image, in degrees, which resulted in a successful scan. May be null.
*/
public Integer getOrientation() {
return orientation;
}
/**
* @return name of the error correction level used in the barcode, if applicable
*/
public String getErrorCorrectionLevel() {
return errorCorrectionLevel;
}
@Override
public String toString() {
StringBuilder dialogText = new StringBuilder(100);
dialogText.append("Format: ").append(formatName).append('\n');
dialogText.append("Contents: ").append(contents).append('\n');
int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
dialogText.append("Raw bytes: (").append(rawBytesLength).append(" bytes)\n");
dialogText.append("Orientation: ").append(orientation).append('\n');
dialogText.append("EC level: ").append(errorCorrectionLevel).append('\n');
return dialogText.toString();
}
} }

View file

@ -105,7 +105,7 @@ public final class ZXingTestActivity extends Activity {
if (result != null) { if (result != null) {
String contents = result.getContents(); String contents = result.getContents();
if (contents != null) { if (contents != null) {
showDialog(R.string.result_succeeded, "Format: " + result.getFormatName() + "\nContents: " + contents); showDialog(R.string.result_succeeded, result.toString());
} else { } else {
showDialog(R.string.result_failed, getString(R.string.result_failed_why)); showDialog(R.string.result_failed, getString(R.string.result_failed_why));
} }