mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
move all Result to RXingResult
This commit is contained in:
@@ -18,11 +18,11 @@ package com.google.zxing.aztec.decoder;
|
||||
import com.google.zxing.aztec.encoder.EncoderTest;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.aztec.AztecDetectorResult;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.aztec.AztecDetectorRXingResult;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.junit.Assert;
|
||||
*/
|
||||
public final class DecoderTest extends Assert {
|
||||
|
||||
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
|
||||
private static final RXingResultPoint[] NO_POINTS = new RXingResultPoint[0];
|
||||
|
||||
@Test
|
||||
public void testHighLevelDecode() throws FormatException {
|
||||
@@ -64,7 +64,7 @@ public final class DecoderTest extends Assert {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAztecResult() throws FormatException {
|
||||
public void testAztecRXingResult() throws FormatException {
|
||||
BitMatrix matrix = BitMatrix.parse(
|
||||
"X X X X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X X X X X X X X \n" +
|
||||
@@ -90,8 +90,8 @@ public final class DecoderTest extends Assert {
|
||||
"X X X X X X X X X X X X X X \n" +
|
||||
" X X X X X X X X X X X X X \n",
|
||||
"X ", " ");
|
||||
AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, false, 30, 2);
|
||||
DecoderResult result = new Decoder().decode(r);
|
||||
AztecDetectorRXingResult r = new AztecDetectorRXingResult(matrix, NO_POINTS, false, 30, 2);
|
||||
DecoderRXingResult result = new Decoder().decode(r);
|
||||
assertEquals("88888TTTTTTTTTTTTTTTTTTTTTTTTTTTTTT", result.getText());
|
||||
assertArrayEquals(
|
||||
new byte[] {-11, 85, 85, 117, 107, 90, -42, -75, -83, 107,
|
||||
@@ -102,7 +102,7 @@ public final class DecoderTest extends Assert {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAztecResultECI() throws FormatException {
|
||||
public void testAztecRXingResultECI() throws FormatException {
|
||||
BitMatrix matrix = BitMatrix.parse(
|
||||
" X X X X X X \n" +
|
||||
" X X X X X X X X X X X X \n" +
|
||||
@@ -124,8 +124,8 @@ public final class DecoderTest extends Assert {
|
||||
" X X X X X X X X X X X \n" +
|
||||
"X X X X X X X X \n",
|
||||
"X ", " ");
|
||||
AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, false, 15, 1);
|
||||
DecoderResult result = new Decoder().decode(r);
|
||||
AztecDetectorRXingResult r = new AztecDetectorRXingResult(matrix, NO_POINTS, false, 15, 1);
|
||||
DecoderRXingResult result = new Decoder().decode(r);
|
||||
assertEquals("Français", result.getText());
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public final class DecoderTest extends Assert {
|
||||
+ "X X X X . . . X . . X X X . X X . . X . . . . X X X . \n"
|
||||
+ "X X . X . X . . . X . X . . . . X X . X . . X X . . . \n",
|
||||
"X ", ". ");
|
||||
AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, true, 16, 4);
|
||||
AztecDetectorRXingResult r = new AztecDetectorRXingResult(matrix, NO_POINTS, true, 16, 4);
|
||||
new Decoder().decode(r);
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public final class DecoderTest extends Assert {
|
||||
+ ". X X X X . . X . . X X X . X X . . X . . . . X X X . \n"
|
||||
+ "X X . . . X X . . X . X . . . . X X . X . . X . X . X \n",
|
||||
"X ", ". ");
|
||||
AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, true, 16, 4);
|
||||
AztecDetectorRXingResult r = new AztecDetectorRXingResult(matrix, NO_POINTS, true, 16, 4);
|
||||
new Decoder().decode(r);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
package com.google.zxing.aztec.detector;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.aztec.AztecDetectorResult;
|
||||
import com.google.zxing.aztec.AztecDetectorRXingResult;
|
||||
import com.google.zxing.aztec.decoder.Decoder;
|
||||
import com.google.zxing.aztec.detector.Detector.Point;
|
||||
import com.google.zxing.aztec.encoder.AztecCode;
|
||||
import com.google.zxing.aztec.encoder.Encoder;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -78,11 +78,11 @@ public final class DetectorTest extends Assert {
|
||||
copy.flip(orientationPoints.get(error2).getX(), orientationPoints.get(error2).getY());
|
||||
}
|
||||
// The detector doesn't seem to work when matrix bits are only 1x1. So magnify.
|
||||
AztecDetectorResult r = new Detector(makeLarger(copy, 3)).detect(isMirror);
|
||||
AztecDetectorRXingResult r = new Detector(makeLarger(copy, 3)).detect(isMirror);
|
||||
assertNotNull(r);
|
||||
assertEquals(r.getNbLayers(), layers);
|
||||
assertEquals(r.isCompact(), compact);
|
||||
DecoderResult res = new Decoder().decode(r);
|
||||
DecoderRXingResult res = new Decoder().decode(r);
|
||||
assertEquals(data, res.getText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ package com.google.zxing.aztec.encoder;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.aztec.AztecDetectorResult;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.aztec.AztecDetectorRXingResult;
|
||||
import com.google.zxing.aztec.AztecWriter;
|
||||
import com.google.zxing.aztec.decoder.Decoder;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -52,7 +52,7 @@ public final class EncoderTest extends Assert {
|
||||
|
||||
private static final Pattern DOTX = Pattern.compile("[^.X]");
|
||||
private static final Pattern SPACES = Pattern.compile("\\s+");
|
||||
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
|
||||
private static final RXingResultPoint[] NO_POINTS = new RXingResultPoint[0];
|
||||
|
||||
// real life tests
|
||||
|
||||
@@ -492,9 +492,9 @@ public final class EncoderTest extends Assert {
|
||||
assertEquals("Unexpected symbol format (compact)", compact, aztec.isCompact());
|
||||
assertEquals("Unexpected nr. of layers", layers, aztec.getLayers());
|
||||
BitMatrix matrix = aztec.getMatrix();
|
||||
AztecDetectorResult r =
|
||||
new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
DecoderResult res = new Decoder().decode(r);
|
||||
AztecDetectorRXingResult r =
|
||||
new AztecDetectorRXingResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
DecoderRXingResult res = new Decoder().decode(r);
|
||||
assertEquals(data, res.getText());
|
||||
// Check error correction by introducing a few minor errors
|
||||
Random random = getPseudoRandom();
|
||||
@@ -502,7 +502,7 @@ public final class EncoderTest extends Assert {
|
||||
matrix.flip(random.nextInt(matrix.getWidth()), matrix.getHeight() - 2 + random.nextInt(2));
|
||||
matrix.flip(random.nextInt(2), random.nextInt(matrix.getHeight()));
|
||||
matrix.flip(matrix.getWidth() - 2 + random.nextInt(2), random.nextInt(matrix.getHeight()));
|
||||
r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
r = new AztecDetectorRXingResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
res = new Decoder().decode(r);
|
||||
assertEquals(data, res.getText());
|
||||
}
|
||||
@@ -526,9 +526,9 @@ public final class EncoderTest extends Assert {
|
||||
assertEquals("Unexpected nr. of layers", layers, aztec.getLayers());
|
||||
BitMatrix matrix2 = aztec.getMatrix();
|
||||
assertEquals(matrix, matrix2);
|
||||
AztecDetectorResult r =
|
||||
new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
DecoderResult res = new Decoder().decode(r);
|
||||
AztecDetectorRXingResult r =
|
||||
new AztecDetectorRXingResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
DecoderRXingResult res = new Decoder().decode(r);
|
||||
assertEquals(data, res.getText());
|
||||
// Check error correction by introducing up to eccPercent/2 errors
|
||||
int ecWords = aztec.getCodeWords() * eccPercent / 100 / 2;
|
||||
@@ -543,7 +543,7 @@ public final class EncoderTest extends Assert {
|
||||
: matrix.getHeight() - 1 - random.nextInt(aztec.getLayers() * 2);
|
||||
matrix.flip(x, y);
|
||||
}
|
||||
r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
r = new AztecDetectorRXingResult(matrix, NO_POINTS, aztec.isCompact(), aztec.getCodeWords(), aztec.getLayers());
|
||||
res = new Decoder().decode(r);
|
||||
assertEquals(data, res.getText());
|
||||
}
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link AddressBookParsedResult}.
|
||||
* Tests {@link AddressBookParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class AddressBookParsedResultTestCase extends Assert {
|
||||
public final class AddressBookParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testAddressBookDocomo() {
|
||||
@@ -149,21 +149,21 @@ public final class AddressBookParsedResultTestCase extends Assert {
|
||||
String[] urls,
|
||||
String birthday,
|
||||
String note) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.ADDRESSBOOK, result.getType());
|
||||
AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
|
||||
assertEquals(title, addressResult.getTitle());
|
||||
assertArrayEquals(names, addressResult.getNames());
|
||||
assertEquals(pronunciation, addressResult.getPronunciation());
|
||||
assertArrayEquals(addresses, addressResult.getAddresses());
|
||||
assertArrayEquals(emails, addressResult.getEmails());
|
||||
assertArrayEquals(phoneNumbers, addressResult.getPhoneNumbers());
|
||||
assertArrayEquals(phoneTypes, addressResult.getPhoneTypes());
|
||||
assertEquals(org, addressResult.getOrg());
|
||||
assertArrayEquals(urls, addressResult.getURLs());
|
||||
assertEquals(birthday, addressResult.getBirthday());
|
||||
assertEquals(note, addressResult.getNote());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.ADDRESSBOOK, result.getType());
|
||||
AddressBookParsedRXingResult addressRXingResult = (AddressBookParsedRXingResult) result;
|
||||
assertEquals(title, addressRXingResult.getTitle());
|
||||
assertArrayEquals(names, addressRXingResult.getNames());
|
||||
assertEquals(pronunciation, addressRXingResult.getPronunciation());
|
||||
assertArrayEquals(addresses, addressRXingResult.getAddresses());
|
||||
assertArrayEquals(emails, addressRXingResult.getEmails());
|
||||
assertArrayEquals(phoneNumbers, addressRXingResult.getPhoneNumbers());
|
||||
assertArrayEquals(phoneTypes, addressRXingResult.getPhoneTypes());
|
||||
assertEquals(org, addressRXingResult.getOrg());
|
||||
assertArrayEquals(urls, addressRXingResult.getURLs());
|
||||
assertEquals(birthday, addressRXingResult.getBirthday());
|
||||
assertEquals(note, addressRXingResult.getNote());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -28,11 +28,11 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Tests {@link CalendarParsedResult}.
|
||||
* Tests {@link CalendarParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class CalendarParsedResultTestCase extends Assert {
|
||||
public final class CalendarParsedRXingResultTestCase extends Assert {
|
||||
|
||||
private static final double EPSILON = 1.0E-10;
|
||||
|
||||
@@ -142,11 +142,11 @@ public final class CalendarParsedResultTestCase extends Assert {
|
||||
@Test
|
||||
public void testBadGeo() {
|
||||
// Not parsed as VEVENT
|
||||
Result fakeResult = new Result("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
RXingResult fakeRXingResult = new RXingResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" +
|
||||
"GEO:-12.345\r\n" +
|
||||
"END:VEVENT\r\nEND:VCALENDAR", null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.TEXT, result.getType());
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.TEXT, result.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -223,20 +223,20 @@ public final class CalendarParsedResultTestCase extends Assert {
|
||||
String[] attendees,
|
||||
double latitude,
|
||||
double longitude) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.CALENDAR, result.getType());
|
||||
CalendarParsedResult calResult = (CalendarParsedResult) result;
|
||||
assertEquals(description, calResult.getDescription());
|
||||
assertEquals(summary, calResult.getSummary());
|
||||
assertEquals(location, calResult.getLocation());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.CALENDAR, result.getType());
|
||||
CalendarParsedRXingResult calRXingResult = (CalendarParsedRXingResult) result;
|
||||
assertEquals(description, calRXingResult.getDescription());
|
||||
assertEquals(summary, calRXingResult.getSummary());
|
||||
assertEquals(location, calRXingResult.getLocation());
|
||||
DateFormat dateFormat = makeGMTFormat();
|
||||
assertEquals(startString, dateFormat.format(calResult.getStartTimestamp()));
|
||||
assertEquals(endString, calResult.getEndTimestamp() < 0L ? null : dateFormat.format(calResult.getEndTimestamp()));
|
||||
assertEquals(organizer, calResult.getOrganizer());
|
||||
assertArrayEquals(attendees, calResult.getAttendees());
|
||||
assertEqualOrNaN(latitude, calResult.getLatitude());
|
||||
assertEqualOrNaN(longitude, calResult.getLongitude());
|
||||
assertEquals(startString, dateFormat.format(calRXingResult.getStartTimestamp()));
|
||||
assertEquals(endString, calRXingResult.getEndTimestamp() < 0L ? null : dateFormat.format(calRXingResult.getEndTimestamp()));
|
||||
assertEquals(organizer, calRXingResult.getOrganizer());
|
||||
assertArrayEquals(attendees, calRXingResult.getAttendees());
|
||||
assertEqualOrNaN(latitude, calRXingResult.getLatitude());
|
||||
assertEqualOrNaN(longitude, calRXingResult.getLongitude());
|
||||
}
|
||||
|
||||
private static void assertEqualOrNaN(double expected, double actual) {
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link EmailAddressParsedResult}.
|
||||
* Tests {@link EmailAddressParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EmailAddressParsedResultTestCase extends Assert {
|
||||
public final class EmailAddressParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testEmailAddress() {
|
||||
@@ -107,15 +107,15 @@ public final class EmailAddressParsedResultTestCase extends Assert {
|
||||
String[] bccs,
|
||||
String subject,
|
||||
String body) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.EMAIL_ADDRESS, result.getType());
|
||||
EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
|
||||
assertArrayEquals(tos, emailResult.getTos());
|
||||
assertArrayEquals(ccs, emailResult.getCCs());
|
||||
assertArrayEquals(bccs, emailResult.getBCCs());
|
||||
assertEquals(subject, emailResult.getSubject());
|
||||
assertEquals(body, emailResult.getBody());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.EMAIL_ADDRESS, result.getType());
|
||||
EmailAddressParsedRXingResult emailRXingResult = (EmailAddressParsedRXingResult) result;
|
||||
assertArrayEquals(tos, emailRXingResult.getTos());
|
||||
assertArrayEquals(ccs, emailRXingResult.getCCs());
|
||||
assertArrayEquals(bccs, emailRXingResult.getBCCs());
|
||||
assertEquals(subject, emailRXingResult.getSubject());
|
||||
assertEquals(body, emailRXingResult.getBody());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -38,15 +38,15 @@ import java.util.Map;
|
||||
* @author Antonio Manuel Benjumea Conde, Servinform, S.A.
|
||||
* @author Agustín Delgado, Servinform, S.A.
|
||||
*/
|
||||
public final class ExpandedProductParsedResultTestCase extends Assert {
|
||||
public final class ExpandedProductParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testRSSExpanded() {
|
||||
Map<String,String> uncommonAIs = new HashMap<>();
|
||||
uncommonAIs.put("123", "544654");
|
||||
Result result =
|
||||
new Result("(01)66546(13)001205(3932)4455(3102)6544(123)544654", null, null, BarcodeFormat.RSS_EXPANDED);
|
||||
ExpandedProductParsedResult o = new ExpandedProductResultParser().parse(result);
|
||||
RXingResult result =
|
||||
new RXingResult("(01)66546(13)001205(3932)4455(3102)6544(123)544654", null, null, BarcodeFormat.RSS_EXPANDED);
|
||||
ExpandedProductParsedRXingResult o = new ExpandedProductRXingResultParser().parse(result);
|
||||
assertNotNull(o);
|
||||
assertEquals("66546", o.getProductID());
|
||||
assertNull(o.getSscc());
|
||||
|
||||
@@ -19,16 +19,16 @@ package com.google.zxing.client.result;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link GeoParsedResult}.
|
||||
* Tests {@link GeoParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class GeoParsedResultTestCase extends Assert {
|
||||
public final class GeoParsedRXingResultTestCase extends Assert {
|
||||
|
||||
private static final double EPSILON = 1.0E-10;
|
||||
|
||||
@@ -47,15 +47,15 @@ public final class GeoParsedResultTestCase extends Assert {
|
||||
double altitude,
|
||||
String query,
|
||||
String uri) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.GEO, result.getType());
|
||||
GeoParsedResult geoResult = (GeoParsedResult) result;
|
||||
assertEquals(latitude, geoResult.getLatitude(), EPSILON);
|
||||
assertEquals(longitude, geoResult.getLongitude(), EPSILON);
|
||||
assertEquals(altitude, geoResult.getAltitude(), EPSILON);
|
||||
assertEquals(query, geoResult.getQuery());
|
||||
assertEquals(uri == null ? contents.toLowerCase(Locale.ENGLISH) : uri, geoResult.getGeoURI());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.GEO, result.getType());
|
||||
GeoParsedRXingResult geoRXingResult = (GeoParsedRXingResult) result;
|
||||
assertEquals(latitude, geoRXingResult.getLatitude(), EPSILON);
|
||||
assertEquals(longitude, geoRXingResult.getLongitude(), EPSILON);
|
||||
assertEquals(altitude, geoRXingResult.getAltitude(), EPSILON);
|
||||
assertEquals(query, geoRXingResult.getQuery());
|
||||
assertEquals(uri == null ? contents.toLowerCase(Locale.ENGLISH) : uri, geoRXingResult.getGeoURI());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link ISBNParsedResult}.
|
||||
* Tests {@link ISBNParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class ISBNParsedResultTestCase extends Assert {
|
||||
public final class ISBNParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testISBN() {
|
||||
@@ -34,11 +34,11 @@ public final class ISBNParsedResultTestCase extends Assert {
|
||||
}
|
||||
|
||||
private static void doTest(String contents) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.EAN_13);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.ISBN, result.getType());
|
||||
ISBNParsedResult isbnResult = (ISBNParsedResult) result;
|
||||
assertEquals(contents, isbnResult.getISBN());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.EAN_13);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.ISBN, result.getType());
|
||||
ISBNParsedRXingResult isbnRXingResult = (ISBNParsedRXingResult) result;
|
||||
assertEquals(contents, isbnRXingResult.getISBN());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -28,12 +28,12 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Tests {@link ParsedResult}.
|
||||
* Tests {@link ParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class ParsedReaderResultTestCase extends Assert {
|
||||
public final class ParsedReaderRXingResultTestCase extends Assert {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -43,208 +43,208 @@ public final class ParsedReaderResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testTextType() {
|
||||
doTestResult("", "", ParsedResultType.TEXT);
|
||||
doTestResult("foo", "foo", ParsedResultType.TEXT);
|
||||
doTestResult("Hi.", "Hi.", ParsedResultType.TEXT);
|
||||
doTestResult("This is a test", "This is a test", ParsedResultType.TEXT);
|
||||
doTestResult("This is a test\nwith newlines", "This is a test\nwith newlines",
|
||||
ParsedResultType.TEXT);
|
||||
doTestResult("This: a test with lots of @ nearly-random punctuation! No? OK then.",
|
||||
doTestRXingResult("", "", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("foo", "foo", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("Hi.", "Hi.", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("This is a test", "This is a test", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("This is a test\nwith newlines", "This is a test\nwith newlines",
|
||||
ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("This: a test with lots of @ nearly-random punctuation! No? OK then.",
|
||||
"This: a test with lots of @ nearly-random punctuation! No? OK then.",
|
||||
ParsedResultType.TEXT);
|
||||
ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBookmarkType() {
|
||||
doTestResult("MEBKM:URL:google.com;;", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:google.com;TITLE:Google;;", "Google\nhttp://google.com",
|
||||
ParsedResultType.URI);
|
||||
doTestResult("MEBKM:TITLE:Google;URL:google.com;;", "Google\nhttp://google.com",
|
||||
ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:http://google.com;;", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:HTTPS://google.com;;", "HTTPS://google.com", ParsedResultType.URI);
|
||||
doTestRXingResult("MEBKM:URL:google.com;;", "http://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("MEBKM:URL:google.com;TITLE:Google;;", "Google\nhttp://google.com",
|
||||
ParsedRXingResultType.URI);
|
||||
doTestRXingResult("MEBKM:TITLE:Google;URL:google.com;;", "Google\nhttp://google.com",
|
||||
ParsedRXingResultType.URI);
|
||||
doTestRXingResult("MEBKM:URL:http://google.com;;", "http://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("MEBKM:URL:HTTPS://google.com;;", "HTTPS://google.com", ParsedRXingResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testURLTOType() {
|
||||
doTestResult("urlto:foo:bar.com", "foo\nhttp://bar.com", ParsedResultType.URI);
|
||||
doTestResult("URLTO:foo:bar.com", "foo\nhttp://bar.com", ParsedResultType.URI);
|
||||
doTestResult("URLTO::bar.com", "http://bar.com", ParsedResultType.URI);
|
||||
doTestResult("URLTO::http://bar.com", "http://bar.com", ParsedResultType.URI);
|
||||
doTestRXingResult("urlto:foo:bar.com", "foo\nhttp://bar.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("URLTO:foo:bar.com", "foo\nhttp://bar.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("URLTO::bar.com", "http://bar.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("URLTO::http://bar.com", "http://bar.com", ParsedRXingResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmailType() {
|
||||
doTestResult("MATMSG:TO:srowen@example.org;;",
|
||||
"srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", "srowen@example.org\nStuff",
|
||||
ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
||||
"srowen@example.org\nStuff\nThis is some text", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;",
|
||||
"srowen@example.org\nStuff\nThis is some text", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
||||
"TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.TEXT);
|
||||
doTestRXingResult("MATMSG:TO:srowen@example.org;;",
|
||||
"srowen@example.org", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", "srowen@example.org\nStuff",
|
||||
ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
||||
"srowen@example.org\nStuff\nThis is some text", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;",
|
||||
"srowen@example.org\nStuff\nThis is some text", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
||||
"TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmailAddressType() {
|
||||
doTestResult("srowen@example.org", "srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("mailto:srowen@example.org", "srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("MAILTO:srowen@example.org", "srowen@example.org", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("srowen@example", "srowen@example", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("srowen", "srowen", ParsedResultType.TEXT);
|
||||
doTestResult("Let's meet @ 2", "Let's meet @ 2", ParsedResultType.TEXT);
|
||||
doTestRXingResult("srowen@example.org", "srowen@example.org", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("mailto:srowen@example.org", "srowen@example.org", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("MAILTO:srowen@example.org", "srowen@example.org", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("srowen@example", "srowen@example", ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
doTestRXingResult("srowen", "srowen", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("Let's meet @ 2", "Let's meet @ 2", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddressBookType() {
|
||||
doTestResult("MECARD:N:Sean Owen;;", "Sean Owen", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;;", "Sean Owen\n+12125551212",
|
||||
ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;",
|
||||
"Sean Owen\n+12125551212\ngoogle.com", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\n+12125551212\nsrowen@example.org\ngoogle.com", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:ADR:76 9th Ave;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\n76 9th Ave\nsrowen@example.org\ngoogle.com", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:BDAY:19760520;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nsrowen@example.org\ngoogle.com\n19760520", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:ORG:Google;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nGoogle\nsrowen@example.org\ngoogle.com", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nsrowen@example.org\ngoogle.com\nZXing Team", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("N:Sean Owen;TEL:+12125551212;;", "N:Sean Owen;TEL:+12125551212;;",
|
||||
ParsedResultType.TEXT);
|
||||
doTestRXingResult("MECARD:N:Sean Owen;;", "Sean Owen", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:TEL:+12125551212;N:Sean Owen;;", "Sean Owen\n+12125551212",
|
||||
ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;",
|
||||
"Sean Owen\n+12125551212\ngoogle.com", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\n+12125551212\nsrowen@example.org\ngoogle.com", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:ADR:76 9th Ave;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\n76 9th Ave\nsrowen@example.org\ngoogle.com", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:BDAY:19760520;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nsrowen@example.org\ngoogle.com\n19760520", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:ORG:Google;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nGoogle\nsrowen@example.org\ngoogle.com", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;",
|
||||
"Sean Owen\nsrowen@example.org\ngoogle.com\nZXing Team", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("N:Sean Owen;TEL:+12125551212;;", "N:Sean Owen;TEL:+12125551212;;",
|
||||
ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddressBookAUType() {
|
||||
doTestResult("MEMORY:\r\n", "", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("MEMORY:foo\r\nNAME1:Sean\r\n", "Sean\nfoo", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", "+12125551212", ParsedResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MEMORY:\r\n", "", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("MEMORY:foo\r\nNAME1:Sean\r\n", "Sean\nfoo", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("TEL1:+12125551212\r\nMEMORY:\r\n", "+12125551212", ParsedRXingResultType.ADDRESSBOOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBizcard() {
|
||||
doTestResult("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12225551212;E:srowen@example.org;",
|
||||
"Sean Owen\nGoogle\n123 Main St\n+12225551212\nsrowen@example.org", ParsedResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12225551212;E:srowen@example.org;",
|
||||
"Sean Owen\nGoogle\n123 Main St\n+12225551212\nsrowen@example.org", ParsedRXingResultType.ADDRESSBOOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUPCA() {
|
||||
doTestResult("123456789012", "123456789012", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
|
||||
doTestResult("1234567890123", "1234567890123", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
|
||||
doTestResult("12345678901", "12345678901", ParsedResultType.TEXT);
|
||||
doTestRXingResult("123456789012", "123456789012", ParsedRXingResultType.PRODUCT, BarcodeFormat.UPC_A);
|
||||
doTestRXingResult("1234567890123", "1234567890123", ParsedRXingResultType.PRODUCT, BarcodeFormat.UPC_A);
|
||||
doTestRXingResult("12345678901", "12345678901", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUPCE() {
|
||||
doTestResult("01234565", "01234565", ParsedResultType.PRODUCT, BarcodeFormat.UPC_E);
|
||||
doTestRXingResult("01234565", "01234565", ParsedRXingResultType.PRODUCT, BarcodeFormat.UPC_E);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEAN() {
|
||||
doTestResult("00393157", "00393157", ParsedResultType.PRODUCT, BarcodeFormat.EAN_8);
|
||||
doTestResult("00393158", "00393158", ParsedResultType.TEXT);
|
||||
doTestResult("5051140178499", "5051140178499", ParsedResultType.PRODUCT, BarcodeFormat.EAN_13);
|
||||
doTestResult("5051140178490", "5051140178490", ParsedResultType.TEXT);
|
||||
doTestRXingResult("00393157", "00393157", ParsedRXingResultType.PRODUCT, BarcodeFormat.EAN_8);
|
||||
doTestRXingResult("00393158", "00393158", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("5051140178499", "5051140178499", ParsedRXingResultType.PRODUCT, BarcodeFormat.EAN_13);
|
||||
doTestRXingResult("5051140178490", "5051140178490", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testISBN() {
|
||||
doTestResult("9784567890123", "9784567890123", ParsedResultType.ISBN, BarcodeFormat.EAN_13);
|
||||
doTestResult("9794567890123", "9794567890123", ParsedResultType.ISBN, BarcodeFormat.EAN_13);
|
||||
doTestResult("97845678901", "97845678901", ParsedResultType.TEXT);
|
||||
doTestResult("97945678901", "97945678901", ParsedResultType.TEXT);
|
||||
doTestRXingResult("9784567890123", "9784567890123", ParsedRXingResultType.ISBN, BarcodeFormat.EAN_13);
|
||||
doTestRXingResult("9794567890123", "9794567890123", ParsedRXingResultType.ISBN, BarcodeFormat.EAN_13);
|
||||
doTestRXingResult("97845678901", "97845678901", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("97945678901", "97945678901", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testURI() {
|
||||
doTestResult("http://google.com", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("google.com", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("https://google.com", "https://google.com", ParsedResultType.URI);
|
||||
doTestResult("HTTP://google.com", "HTTP://google.com", ParsedResultType.URI);
|
||||
doTestResult("http://google.com/foobar", "http://google.com/foobar", ParsedResultType.URI);
|
||||
doTestResult("https://google.com:443/foobar", "https://google.com:443/foobar", ParsedResultType.URI);
|
||||
doTestResult("google.com:443", "http://google.com:443", ParsedResultType.URI);
|
||||
doTestResult("google.com:443/", "http://google.com:443/", ParsedResultType.URI);
|
||||
doTestResult("google.com:443/foobar", "http://google.com:443/foobar", ParsedResultType.URI);
|
||||
doTestResult("http://google.com:443/foobar", "http://google.com:443/foobar", ParsedResultType.URI);
|
||||
doTestResult("https://google.com:443/foobar", "https://google.com:443/foobar", ParsedResultType.URI);
|
||||
doTestResult("ftp://google.com/fake", "ftp://google.com/fake", ParsedResultType.URI);
|
||||
doTestResult("gopher://google.com/obsolete", "gopher://google.com/obsolete", ParsedResultType.URI);
|
||||
doTestRXingResult("http://google.com", "http://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("google.com", "http://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("https://google.com", "https://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("HTTP://google.com", "HTTP://google.com", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("http://google.com/foobar", "http://google.com/foobar", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("https://google.com:443/foobar", "https://google.com:443/foobar", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("google.com:443", "http://google.com:443", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("google.com:443/", "http://google.com:443/", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("google.com:443/foobar", "http://google.com:443/foobar", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("http://google.com:443/foobar", "http://google.com:443/foobar", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("https://google.com:443/foobar", "https://google.com:443/foobar", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("ftp://google.com/fake", "ftp://google.com/fake", ParsedRXingResultType.URI);
|
||||
doTestRXingResult("gopher://google.com/obsolete", "gopher://google.com/obsolete", ParsedRXingResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeo() {
|
||||
doTestResult("geo:1,2", "1.0, 2.0", ParsedResultType.GEO);
|
||||
doTestResult("GEO:1,2", "1.0, 2.0", ParsedResultType.GEO);
|
||||
doTestResult("geo:1,2,3", "1.0, 2.0, 3.0m", ParsedResultType.GEO);
|
||||
doTestResult("geo:80.33,-32.3344,3.35", "80.33, -32.3344, 3.35m", ParsedResultType.GEO);
|
||||
doTestResult("geo", "geo", ParsedResultType.TEXT);
|
||||
doTestResult("geography", "geography", ParsedResultType.TEXT);
|
||||
doTestRXingResult("geo:1,2", "1.0, 2.0", ParsedRXingResultType.GEO);
|
||||
doTestRXingResult("GEO:1,2", "1.0, 2.0", ParsedRXingResultType.GEO);
|
||||
doTestRXingResult("geo:1,2,3", "1.0, 2.0, 3.0m", ParsedRXingResultType.GEO);
|
||||
doTestRXingResult("geo:80.33,-32.3344,3.35", "80.33, -32.3344, 3.35m", ParsedRXingResultType.GEO);
|
||||
doTestRXingResult("geo", "geo", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("geography", "geography", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTel() {
|
||||
doTestResult("tel:+15551212", "+15551212", ParsedResultType.TEL);
|
||||
doTestResult("TEL:+15551212", "+15551212", ParsedResultType.TEL);
|
||||
doTestResult("tel:212 555 1212", "212 555 1212", ParsedResultType.TEL);
|
||||
doTestResult("tel:2125551212", "2125551212", ParsedResultType.TEL);
|
||||
doTestResult("tel:212-555-1212", "212-555-1212", ParsedResultType.TEL);
|
||||
doTestResult("tel", "tel", ParsedResultType.TEXT);
|
||||
doTestResult("telephone", "telephone", ParsedResultType.TEXT);
|
||||
doTestRXingResult("tel:+15551212", "+15551212", ParsedRXingResultType.TEL);
|
||||
doTestRXingResult("TEL:+15551212", "+15551212", ParsedRXingResultType.TEL);
|
||||
doTestRXingResult("tel:212 555 1212", "212 555 1212", ParsedRXingResultType.TEL);
|
||||
doTestRXingResult("tel:2125551212", "2125551212", ParsedRXingResultType.TEL);
|
||||
doTestRXingResult("tel:212-555-1212", "212-555-1212", ParsedRXingResultType.TEL);
|
||||
doTestRXingResult("tel", "tel", ParsedRXingResultType.TEXT);
|
||||
doTestRXingResult("telephone", "telephone", ParsedRXingResultType.TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCard() {
|
||||
doTestResult("BEGIN:VCARD\r\nEND:VCARD", "", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("BEGIN:VCARD\r\nN:Owen;Sean\r\nEND:VCARD", "Sean Owen",
|
||||
ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD", "Sean Owen",
|
||||
ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
|
||||
"Sean Owen\n123 Main St", ParsedResultType.ADDRESSBOOK);
|
||||
doTestResult("BEGIN:VCARD", "", ParsedResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BEGIN:VCARD\r\nEND:VCARD", "", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BEGIN:VCARD\r\nN:Owen;Sean\r\nEND:VCARD", "Sean Owen",
|
||||
ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BEGIN:VCARD\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD", "Sean Owen",
|
||||
ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
|
||||
"Sean Owen\n123 Main St", ParsedRXingResultType.ADDRESSBOOK);
|
||||
doTestRXingResult("BEGIN:VCARD", "", ParsedRXingResultType.ADDRESSBOOK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVEvent() {
|
||||
// UTC times
|
||||
doTestResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
|
||||
doTestRXingResult("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
|
||||
"DTEND:20080505T234555Z\r\nEND:VEVENT\r\nEND:VCALENDAR",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" + formatTime(2008, 5, 5, 23, 45, 55),
|
||||
ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
|
||||
ParsedRXingResultType.CALENDAR);
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\n" +
|
||||
"DTEND:20080505T234555Z\r\nEND:VEVENT", "foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" +
|
||||
formatTime(2008, 5, 5, 23, 45, 55),
|
||||
ParsedResultType.CALENDAR);
|
||||
ParsedRXingResultType.CALENDAR);
|
||||
// Local times
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\n" +
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\n" +
|
||||
"DTEND:20080505T234555\r\nEND:VEVENT", "foo\n" + formatTime(2008, 5, 4, 12, 34, 56) + "\n" +
|
||||
formatTime(2008, 5, 5, 23, 45, 55),
|
||||
ParsedResultType.CALENDAR);
|
||||
ParsedRXingResultType.CALENDAR);
|
||||
// Date only (all day event)
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\n" +
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\n" +
|
||||
"DTEND:20080505\r\nEND:VEVENT", "foo\n" + formatDate(2008, 5, 4) + "\n" +
|
||||
formatDate(2008, 5, 5),
|
||||
ParsedResultType.CALENDAR);
|
||||
ParsedRXingResultType.CALENDAR);
|
||||
// Start time only
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nEND:VEVENT",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\nEND:VEVENT",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\nEND:VEVENT",
|
||||
"foo\n" + formatDate(2008, 5, 4), ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT",
|
||||
"BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedResultType.TEXT);
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nEND:VEVENT",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedRXingResultType.CALENDAR);
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456\r\nEND:VEVENT",
|
||||
"foo\n" + formatTime(2008, 5, 4, 12, 34, 56), ParsedRXingResultType.CALENDAR);
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\nEND:VEVENT",
|
||||
"foo\n" + formatDate(2008, 5, 4), ParsedRXingResultType.CALENDAR);
|
||||
doTestRXingResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT",
|
||||
"BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedRXingResultType.TEXT);
|
||||
// Yeah, it's OK that this is thought of as maybe a URI as long as it's not CALENDAR
|
||||
// Make sure illegal entries without newlines don't crash
|
||||
doTestResult(
|
||||
doTestRXingResult(
|
||||
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
|
||||
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
|
||||
ParsedResultType.URI);
|
||||
ParsedRXingResultType.URI);
|
||||
}
|
||||
|
||||
private static String formatDate(int year, int month, int day) {
|
||||
@@ -263,68 +263,68 @@ public final class ParsedReaderResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testSMS() {
|
||||
doTestResult("sms:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("SMS:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("sms:+15551212;via=999333", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("sms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedResultType.SMS);
|
||||
doTestResult("sms:+15551212,+12124440101", "+15551212\n+12124440101", ParsedResultType.SMS);
|
||||
doTestRXingResult("sms:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("SMS:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("sms:+15551212;via=999333", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("sms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("sms:+15551212,+12124440101", "+15551212\n+12124440101", ParsedRXingResultType.SMS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSMSTO() {
|
||||
doTestResult("SMSTO:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("smsto:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("smsto:+15551212:subject", "+15551212\nsubject", ParsedResultType.SMS);
|
||||
doTestResult("smsto:+15551212:My message", "+15551212\nMy message", ParsedResultType.SMS);
|
||||
doTestRXingResult("SMSTO:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("smsto:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("smsto:+15551212:subject", "+15551212\nsubject", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("smsto:+15551212:My message", "+15551212\nMy message", ParsedRXingResultType.SMS);
|
||||
// Need to handle question mark in the subject
|
||||
doTestResult("smsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedResultType.SMS);
|
||||
doTestRXingResult("smsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedRXingResultType.SMS);
|
||||
// Need to handle colon in the subject
|
||||
doTestResult("smsto:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
|
||||
ParsedResultType.SMS);
|
||||
doTestResult("smsto:212-555-1212:Here's a longer message. Should be fine.",
|
||||
doTestRXingResult("smsto:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
|
||||
ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("smsto:212-555-1212:Here's a longer message. Should be fine.",
|
||||
"212-555-1212\nHere's a longer message. Should be fine.",
|
||||
ParsedResultType.SMS);
|
||||
ParsedRXingResultType.SMS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMMS() {
|
||||
doTestResult("mms:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("MMS:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mms:+15551212;via=999333", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedResultType.SMS);
|
||||
doTestResult("mms:+15551212,+12124440101", "+15551212\n+12124440101", ParsedResultType.SMS);
|
||||
doTestRXingResult("mms:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("MMS:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mms:+15551212;via=999333", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mms:+15551212?subject=foo&body=bar", "+15551212\nfoo\nbar", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mms:+15551212,+12124440101", "+15551212\n+12124440101", ParsedRXingResultType.SMS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMMSTO() {
|
||||
doTestResult("MMSTO:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212", "+15551212", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:subject", "+15551212\nsubject", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:My message", "+15551212\nMy message", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedResultType.SMS);
|
||||
doTestResult("mmsto:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
|
||||
ParsedResultType.SMS);
|
||||
doTestResult("mmsto:212-555-1212:Here's a longer message. Should be fine.",
|
||||
"212-555-1212\nHere's a longer message. Should be fine.", ParsedResultType.SMS);
|
||||
doTestRXingResult("MMSTO:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:+15551212", "+15551212", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:+15551212:subject", "+15551212\nsubject", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:+15551212:My message", "+15551212\nMy message", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:+15551212:What's up?", "+15551212\nWhat's up?", ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:+15551212:Directions: Do this", "+15551212\nDirections: Do this",
|
||||
ParsedRXingResultType.SMS);
|
||||
doTestRXingResult("mmsto:212-555-1212:Here's a longer message. Should be fine.",
|
||||
"212-555-1212\nHere's a longer message. Should be fine.", ParsedRXingResultType.SMS);
|
||||
}
|
||||
|
||||
private static void doTestResult(String contents,
|
||||
String goldenResult,
|
||||
ParsedResultType type) {
|
||||
doTestResult(contents, goldenResult, type, BarcodeFormat.QR_CODE); // QR code is arbitrary
|
||||
private static void doTestRXingResult(String contents,
|
||||
String goldenRXingResult,
|
||||
ParsedRXingResultType type) {
|
||||
doTestRXingResult(contents, goldenRXingResult, type, BarcodeFormat.QR_CODE); // QR code is arbitrary
|
||||
}
|
||||
|
||||
private static void doTestResult(String contents,
|
||||
String goldenResult,
|
||||
ParsedResultType type,
|
||||
private static void doTestRXingResult(String contents,
|
||||
String goldenRXingResult,
|
||||
ParsedRXingResultType type,
|
||||
BarcodeFormat format) {
|
||||
Result fakeResult = new Result(contents, null, null, format);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, format);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertNotNull(result);
|
||||
assertSame(type, result.getType());
|
||||
|
||||
String displayResult = result.getDisplayResult();
|
||||
assertEquals(goldenResult, displayResult);
|
||||
String displayRXingResult = result.getDisplayRXingResult();
|
||||
assertEquals(goldenRXingResult, displayRXingResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link ProductParsedResult}.
|
||||
* Tests {@link ProductParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class ProductParsedResultTestCase extends Assert {
|
||||
public final class ProductParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testProduct() {
|
||||
@@ -37,12 +37,12 @@ public final class ProductParsedResultTestCase extends Assert {
|
||||
}
|
||||
|
||||
private static void doTest(String contents, String normalized, BarcodeFormat format) {
|
||||
Result fakeResult = new Result(contents, null, null, format);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.PRODUCT, result.getType());
|
||||
ProductParsedResult productResult = (ProductParsedResult) result;
|
||||
assertEquals(contents, productResult.getProductID());
|
||||
assertEquals(normalized, productResult.getNormalizedProductID());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, format);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.PRODUCT, result.getType());
|
||||
ProductParsedRXingResult productRXingResult = (ProductParsedRXingResult) result;
|
||||
assertEquals(contents, productRXingResult.getProductID());
|
||||
assertEquals(normalized, productRXingResult.getNormalizedProductID());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link SMSParsedResult}.
|
||||
* Tests {@link SMSParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class SMSMMSParsedResultTestCase extends Assert {
|
||||
public final class SMSMMSParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testSMS() {
|
||||
@@ -52,15 +52,15 @@ public final class SMSMMSParsedResultTestCase extends Assert {
|
||||
String body,
|
||||
String via,
|
||||
String parsedURI) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.SMS, result.getType());
|
||||
SMSParsedResult smsResult = (SMSParsedResult) result;
|
||||
assertArrayEquals(new String[] { number }, smsResult.getNumbers());
|
||||
assertEquals(subject, smsResult.getSubject());
|
||||
assertEquals(body, smsResult.getBody());
|
||||
assertArrayEquals(new String[] { via }, smsResult.getVias());
|
||||
assertEquals(parsedURI, smsResult.getSMSURI());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.SMS, result.getType());
|
||||
SMSParsedRXingResult smsRXingResult = (SMSParsedRXingResult) result;
|
||||
assertArrayEquals(new String[] { number }, smsRXingResult.getNumbers());
|
||||
assertEquals(subject, smsRXingResult.getSubject());
|
||||
assertEquals(body, smsRXingResult.getBody());
|
||||
assertArrayEquals(new String[] { via }, smsRXingResult.getVias());
|
||||
assertEquals(parsedURI, smsRXingResult.getSMSURI());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link TelParsedResult}.
|
||||
* Tests {@link TelParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class TelParsedResultTestCase extends Assert {
|
||||
public final class TelParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testTel() {
|
||||
@@ -35,13 +35,13 @@ public final class TelParsedResultTestCase extends Assert {
|
||||
}
|
||||
|
||||
private static void doTest(String contents, String number, String title) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.TEL, result.getType());
|
||||
TelParsedResult telResult = (TelParsedResult) result;
|
||||
assertEquals(number, telResult.getNumber());
|
||||
assertEquals(title, telResult.getTitle());
|
||||
assertEquals("tel:" + number, telResult.getTelURI());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.TEL, result.getType());
|
||||
TelParsedRXingResult telRXingResult = (TelParsedRXingResult) result;
|
||||
assertEquals(number, telRXingResult.getNumber());
|
||||
assertEquals(title, telRXingResult.getTitle());
|
||||
assertEquals("tel:" + number, telRXingResult.getTelURI());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link URIParsedResult}.
|
||||
* Tests {@link URIParsedRXingResult}.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class URIParsedResultTestCase extends Assert {
|
||||
public final class URIParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testBookmarkDocomo() {
|
||||
@@ -116,25 +116,25 @@ public final class URIParsedResultTestCase extends Assert {
|
||||
}
|
||||
|
||||
private static void doTest(String contents, String uri, String title) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.URI, result.getType());
|
||||
URIParsedResult uriResult = (URIParsedResult) result;
|
||||
assertEquals(uri, uriResult.getURI());
|
||||
assertEquals(title, uriResult.getTitle());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.URI, result.getType());
|
||||
URIParsedRXingResult uriRXingResult = (URIParsedRXingResult) result;
|
||||
assertEquals(uri, uriRXingResult.getURI());
|
||||
assertEquals(title, uriRXingResult.getTitle());
|
||||
}
|
||||
|
||||
private static void doTestNotUri(String text) {
|
||||
Result fakeResult = new Result(text, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.TEXT, result.getType());
|
||||
assertEquals(text, result.getDisplayResult());
|
||||
RXingResult fakeRXingResult = new RXingResult(text, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.TEXT, result.getType());
|
||||
assertEquals(text, result.getDisplayRXingResult());
|
||||
}
|
||||
|
||||
private static void doTestIsPossiblyMalicious(String uri, boolean malicious) {
|
||||
Result fakeResult = new Result(uri, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(malicious ? ParsedResultType.TEXT : ParsedResultType.URI, result.getType());
|
||||
RXingResult fakeRXingResult = new RXingResult(uri, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(malicious ? ParsedRXingResultType.TEXT : ParsedRXingResultType.URI, result.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,23 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link VINParsedResult}.
|
||||
* Tests {@link VINParsedRXingResult}.
|
||||
*/
|
||||
public final class VINParsedResultTestCase extends Assert {
|
||||
public final class VINParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testNotVIN() {
|
||||
Result fakeResult = new Result("1M8GDM9A1KP042788", null, null, BarcodeFormat.CODE_39);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertEquals(ParsedResultType.TEXT, result.getType());
|
||||
fakeResult = new Result("1M8GDM9AXKP042788", null, null, BarcodeFormat.CODE_128);
|
||||
result = ResultParser.parseResult(fakeResult);
|
||||
assertEquals(ParsedResultType.TEXT, result.getType());
|
||||
RXingResult fakeRXingResult = new RXingResult("1M8GDM9A1KP042788", null, null, BarcodeFormat.CODE_39);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertEquals(ParsedRXingResultType.TEXT, result.getType());
|
||||
fakeRXingResult = new RXingResult("1M8GDM9AXKP042788", null, null, BarcodeFormat.CODE_128);
|
||||
result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertEquals(ParsedRXingResultType.TEXT, result.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,18 +53,18 @@ public final class VINParsedResultTestCase extends Assert {
|
||||
int year,
|
||||
char plant,
|
||||
String sequential) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.CODE_39);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
assertSame(ParsedResultType.VIN, result.getType());
|
||||
VINParsedResult vinResult = (VINParsedResult) result;
|
||||
assertEquals(wmi, vinResult.getWorldManufacturerID());
|
||||
assertEquals(vds, vinResult.getVehicleDescriptorSection());
|
||||
assertEquals(vis, vinResult.getVehicleIdentifierSection());
|
||||
assertEquals(country, vinResult.getCountryCode());
|
||||
assertEquals(attributes, vinResult.getVehicleAttributes());
|
||||
assertEquals(year, vinResult.getModelYear());
|
||||
assertEquals(plant, vinResult.getPlantCode());
|
||||
assertEquals(sequential, vinResult.getSequentialNumber());
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.CODE_39);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
assertSame(ParsedRXingResultType.VIN, result.getType());
|
||||
VINParsedRXingResult vinRXingResult = (VINParsedRXingResult) result;
|
||||
assertEquals(wmi, vinRXingResult.getWorldManufacturerID());
|
||||
assertEquals(vds, vinRXingResult.getVehicleDescriptorSection());
|
||||
assertEquals(vis, vinRXingResult.getVehicleIdentifierSection());
|
||||
assertEquals(country, vinRXingResult.getCountryCode());
|
||||
assertEquals(attributes, vinRXingResult.getVehicleAttributes());
|
||||
assertEquals(year, vinRXingResult.getModelYear());
|
||||
assertEquals(plant, vinRXingResult.getPlantCode());
|
||||
assertEquals(sequential, vinRXingResult.getSequentialNumber());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,16 +17,16 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link WifiParsedResult}.
|
||||
* Tests {@link WifiParsedRXingResult}.
|
||||
*
|
||||
* @author Vikram Aggarwal
|
||||
*/
|
||||
public final class WifiParsedResultTestCase extends Assert {
|
||||
public final class WifiParsedRXingResultTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testNoPassword() {
|
||||
@@ -79,15 +79,15 @@ public final class WifiParsedResultTestCase extends Assert {
|
||||
String ssid,
|
||||
String password,
|
||||
String type) {
|
||||
Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedResult result = ResultParser.parseResult(fakeResult);
|
||||
RXingResult fakeRXingResult = new RXingResult(contents, null, null, BarcodeFormat.QR_CODE);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(fakeRXingResult);
|
||||
|
||||
// Ensure it is a wifi code
|
||||
assertSame(ParsedResultType.WIFI, result.getType());
|
||||
WifiParsedResult wifiResult = (WifiParsedResult) result;
|
||||
assertSame(ParsedRXingResultType.WIFI, result.getType());
|
||||
WifiParsedRXingResult wifiRXingResult = (WifiParsedRXingResult) result;
|
||||
|
||||
assertEquals(ssid, wifiResult.getSsid());
|
||||
assertEquals(password, wifiResult.getPassword());
|
||||
assertEquals(type, wifiResult.getNetworkEncryption());
|
||||
assertEquals(ssid, wifiRXingResult.getSsid());
|
||||
assertEquals(password, wifiRXingResult.getPassword());
|
||||
assertEquals(type, wifiRXingResult.getNetworkEncryption());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.Reader;
|
||||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.RXingResultMetadataType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -61,7 +61,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||
private final Path testBase;
|
||||
private final Reader barcodeReader;
|
||||
private final BarcodeFormat expectedFormat;
|
||||
private final List<TestResult> testResults;
|
||||
private final List<TestRXingResult> testRXingResults;
|
||||
private final EnumMap<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);
|
||||
|
||||
public static Path buildTestBase(String testBasePathSuffix) {
|
||||
@@ -80,7 +80,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||
this.testBase = buildTestBase(testBasePathSuffix);
|
||||
this.barcodeReader = barcodeReader;
|
||||
this.expectedFormat = expectedFormat;
|
||||
testResults = new ArrayList<>();
|
||||
testRXingResults = new ArrayList<>();
|
||||
|
||||
System.setProperty("java.util.logging.SimpleFormatter.format", "%4$s: %5$s%6$s%n");
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||
int maxMisreads,
|
||||
int maxTryHarderMisreads,
|
||||
float rotation) {
|
||||
testResults.add(new TestResult(mustPassCount, tryHarderCount, maxMisreads, maxTryHarderMisreads, rotation));
|
||||
testRXingResults.add(new TestRXingResult(mustPassCount, tryHarderCount, maxMisreads, maxTryHarderMisreads, rotation));
|
||||
}
|
||||
|
||||
protected final List<Path> getImageFiles() throws IOException {
|
||||
@@ -132,10 +132,10 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testBlackBox() throws IOException {
|
||||
assertFalse(testResults.isEmpty());
|
||||
assertFalse(testRXingResults.isEmpty());
|
||||
|
||||
List<Path> imageFiles = getImageFiles();
|
||||
int testCount = testResults.size();
|
||||
int testCount = testRXingResults.size();
|
||||
|
||||
int[] passedCounts = new int[testCount];
|
||||
int[] misreadCounts = new int[testCount];
|
||||
@@ -168,7 +168,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||
}
|
||||
|
||||
for (int x = 0; x < testCount; x++) {
|
||||
float rotation = testResults.get(x).getRotation();
|
||||
float rotation = testRXingResults.get(x).getRotation();
|
||||
BufferedImage rotatedImage = rotateImage(image, rotation);
|
||||
LuminanceSource source = new BufferedImageLuminanceSource(rotatedImage);
|
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
@@ -199,23 +199,23 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||
int totalMisread = 0;
|
||||
int totalMaxMisread = 0;
|
||||
|
||||
for (int x = 0; x < testResults.size(); x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
log.info(String.format("Rotation %d degrees:", (int) testResult.getRotation()));
|
||||
for (int x = 0; x < testRXingResults.size(); x++) {
|
||||
TestRXingResult testRXingResult = testRXingResults.get(x);
|
||||
log.info(String.format("Rotation %d degrees:", (int) testRXingResult.getRotation()));
|
||||
log.info(String.format(" %d of %d images passed (%d required)",
|
||||
passedCounts[x], imageFiles.size(), testResult.getMustPassCount()));
|
||||
passedCounts[x], imageFiles.size(), testRXingResult.getMustPassCount()));
|
||||
int failed = imageFiles.size() - passedCounts[x];
|
||||
log.info(String.format(" %d failed due to misreads, %d not detected",
|
||||
misreadCounts[x], failed - misreadCounts[x]));
|
||||
log.info(String.format(" %d of %d images passed with try harder (%d required)",
|
||||
tryHarderCounts[x], imageFiles.size(), testResult.getTryHarderCount()));
|
||||
tryHarderCounts[x], imageFiles.size(), testRXingResult.getTryHarderCount()));
|
||||
failed = imageFiles.size() - tryHarderCounts[x];
|
||||
log.info(String.format(" %d failed due to misreads, %d not detected",
|
||||
tryHarderMisreadCounts[x], failed - tryHarderMisreadCounts[x]));
|
||||
totalFound += passedCounts[x] + tryHarderCounts[x];
|
||||
totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount();
|
||||
totalMustPass += testRXingResult.getMustPassCount() + testRXingResult.getTryHarderCount();
|
||||
totalMisread += misreadCounts[x] + tryHarderMisreadCounts[x];
|
||||
totalMaxMisread += testResult.getMaxMisreads() + testResult.getMaxTryHarderMisreads();
|
||||
totalMaxMisread += testRXingResult.getMaxMisreads() + testRXingResult.getMaxTryHarderMisreads();
|
||||
}
|
||||
|
||||
int totalTests = imageFiles.size() * testCount * 2;
|
||||
@@ -235,17 +235,17 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||
|
||||
// Then run through again and assert if any failed
|
||||
for (int x = 0; x < testCount; x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
|
||||
TestRXingResult testRXingResult = testRXingResults.get(x);
|
||||
String label = "Rotation " + testRXingResult.getRotation() + " degrees: Too many images failed";
|
||||
assertTrue(label,
|
||||
passedCounts[x] >= testResult.getMustPassCount());
|
||||
passedCounts[x] >= testRXingResult.getMustPassCount());
|
||||
assertTrue("Try harder, " + label,
|
||||
tryHarderCounts[x] >= testResult.getTryHarderCount());
|
||||
label = "Rotation " + testResult.getRotation() + " degrees: Too many images misread";
|
||||
tryHarderCounts[x] >= testRXingResult.getTryHarderCount());
|
||||
label = "Rotation " + testRXingResult.getRotation() + " degrees: Too many images misread";
|
||||
assertTrue(label,
|
||||
misreadCounts[x] <= testResult.getMaxMisreads());
|
||||
misreadCounts[x] <= testRXingResult.getMaxMisreads());
|
||||
assertTrue("Try harder, " + label,
|
||||
tryHarderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads());
|
||||
tryHarderMisreadCounts[x] <= testRXingResult.getMaxTryHarderMisreads());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||
|
||||
// Try in 'pure' mode mostly to exercise PURE_BARCODE code paths for exceptions;
|
||||
// not expected to pass, generally
|
||||
Result result = null;
|
||||
RXingResult result = null;
|
||||
try {
|
||||
Map<DecodeHintType,Object> pureHints = new EnumMap<>(hints);
|
||||
pureHints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
|
||||
@@ -290,9 +290,9 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<ResultMetadataType,?> resultMetadata = result.getResultMetadata();
|
||||
Map<RXingResultMetadataType,?> resultMetadata = result.getRXingResultMetadata();
|
||||
for (Map.Entry<?,?> metadatum : expectedMetadata.entrySet()) {
|
||||
ResultMetadataType key = ResultMetadataType.valueOf(metadatum.getKey().toString());
|
||||
RXingResultMetadataType key = RXingResultMetadataType.valueOf(metadatum.getKey().toString());
|
||||
Object expectedValue = metadatum.getValue();
|
||||
Object actualValue = resultMetadata == null ? null : resultMetadata.get(key);
|
||||
if (!expectedValue.equals(actualValue)) {
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -45,13 +45,13 @@ public abstract class AbstractNegativeBlackBoxTestCase extends AbstractBlackBoxT
|
||||
|
||||
private static final Logger log = Logger.getLogger(AbstractNegativeBlackBoxTestCase.class.getSimpleName());
|
||||
|
||||
private final List<TestResult> testResults;
|
||||
private final List<TestRXingResult> testRXingResults;
|
||||
|
||||
private static final class TestResult {
|
||||
private static final class TestRXingResult {
|
||||
private final int falsePositivesAllowed;
|
||||
private final float rotation;
|
||||
|
||||
TestResult(int falsePositivesAllowed, float rotation) {
|
||||
TestRXingResult(int falsePositivesAllowed, float rotation) {
|
||||
this.falsePositivesAllowed = falsePositivesAllowed;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
@@ -68,29 +68,29 @@ public abstract class AbstractNegativeBlackBoxTestCase extends AbstractBlackBoxT
|
||||
// Use the multiformat reader to evaluate all decoders in the system.
|
||||
protected AbstractNegativeBlackBoxTestCase(String testBasePathSuffix) {
|
||||
super(testBasePathSuffix, new MultiFormatReader(), null);
|
||||
testResults = new ArrayList<>();
|
||||
testRXingResults = new ArrayList<>();
|
||||
}
|
||||
|
||||
protected final void addTest(int falsePositivesAllowed, float rotation) {
|
||||
testResults.add(new TestResult(falsePositivesAllowed, rotation));
|
||||
testRXingResults.add(new TestRXingResult(falsePositivesAllowed, rotation));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testBlackBox() throws IOException {
|
||||
assertFalse(testResults.isEmpty());
|
||||
assertFalse(testRXingResults.isEmpty());
|
||||
|
||||
List<Path> imageFiles = getImageFiles();
|
||||
int[] falsePositives = new int[testResults.size()];
|
||||
int[] falsePositives = new int[testRXingResults.size()];
|
||||
for (Path testImage : imageFiles) {
|
||||
log.info(String.format("Starting %s", testImage));
|
||||
BufferedImage image = ImageIO.read(testImage.toFile());
|
||||
if (image == null) {
|
||||
throw new IOException("Could not read image: " + testImage);
|
||||
}
|
||||
for (int x = 0; x < testResults.size(); x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
if (!checkForFalsePositives(image, testResult.getRotation())) {
|
||||
for (int x = 0; x < testRXingResults.size(); x++) {
|
||||
TestRXingResult testRXingResult = testRXingResults.get(x);
|
||||
if (!checkForFalsePositives(image, testRXingResult.getRotation())) {
|
||||
falsePositives[x]++;
|
||||
}
|
||||
}
|
||||
@@ -99,10 +99,10 @@ public abstract class AbstractNegativeBlackBoxTestCase extends AbstractBlackBoxT
|
||||
int totalFalsePositives = 0;
|
||||
int totalAllowed = 0;
|
||||
|
||||
for (int x = 0; x < testResults.size(); x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
for (int x = 0; x < testRXingResults.size(); x++) {
|
||||
TestRXingResult testRXingResult = testRXingResults.get(x);
|
||||
totalFalsePositives += falsePositives[x];
|
||||
totalAllowed += testResult.getFalsePositivesAllowed();
|
||||
totalAllowed += testRXingResult.getFalsePositivesAllowed();
|
||||
}
|
||||
|
||||
if (totalFalsePositives < totalAllowed) {
|
||||
@@ -111,13 +111,13 @@ public abstract class AbstractNegativeBlackBoxTestCase extends AbstractBlackBoxT
|
||||
log.warning(String.format("--- Test failed by %d images", totalFalsePositives - totalAllowed));
|
||||
}
|
||||
|
||||
for (int x = 0; x < testResults.size(); x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
for (int x = 0; x < testRXingResults.size(); x++) {
|
||||
TestRXingResult testRXingResult = testRXingResults.get(x);
|
||||
log.info(String.format("Rotation %d degrees: %d of %d images were false positives (%d allowed)",
|
||||
(int) testResult.getRotation(), falsePositives[x], imageFiles.size(),
|
||||
testResult.getFalsePositivesAllowed()));
|
||||
assertTrue("Rotation " + testResult.getRotation() + " degrees: Too many false positives found",
|
||||
falsePositives[x] <= testResult.getFalsePositivesAllowed());
|
||||
(int) testRXingResult.getRotation(), falsePositives[x], imageFiles.size(),
|
||||
testRXingResult.getFalsePositivesAllowed()));
|
||||
assertTrue("Rotation " + testRXingResult.getRotation() + " degrees: Too many false positives found",
|
||||
falsePositives[x] <= testRXingResult.getFalsePositivesAllowed());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public abstract class AbstractNegativeBlackBoxTestCase extends AbstractBlackBoxT
|
||||
BufferedImage rotatedImage = rotateImage(image, rotationInDegrees);
|
||||
LuminanceSource source = new BufferedImageLuminanceSource(rotatedImage);
|
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
Result result;
|
||||
RXingResult result;
|
||||
try {
|
||||
result = getReader().decode(bitmap);
|
||||
log.info(String.format("Found false positive: '%s' with format '%s' (rotation: %d)",
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.google.zxing.common;
|
||||
/**
|
||||
* Encapsulates the result of one test over a batch of black-box images.
|
||||
*/
|
||||
public final class TestResult {
|
||||
public final class TestRXingResult {
|
||||
|
||||
private final int mustPassCount;
|
||||
private final int tryHarderCount;
|
||||
@@ -27,7 +27,7 @@ public final class TestResult {
|
||||
private final int maxTryHarderMisreads;
|
||||
private final float rotation;
|
||||
|
||||
public TestResult(int mustPassCount, int tryHarderCount, int maxMisreads, int maxTryHarderMisreads, float rotation) {
|
||||
public TestRXingResult(int mustPassCount, int tryHarderCount, int maxMisreads, int maxTryHarderMisreads, float rotation) {
|
||||
this.mustPassCount = mustPassCount;
|
||||
this.tryHarderCount = tryHarderCount;
|
||||
this.maxMisreads = maxMisreads;
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.MultiFormatReader;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
import org.junit.Assert;
|
||||
@@ -47,7 +47,7 @@ public final class MultiTestCase extends Assert {
|
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
|
||||
MultipleBarcodeReader reader = new GenericMultipleBarcodeReader(new MultiFormatReader());
|
||||
Result[] results = reader.decodeMultiple(bitmap);
|
||||
RXingResult[] results = reader.decodeMultiple(bitmap);
|
||||
assertNotNull(results);
|
||||
assertEquals(2, results.length);
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.RXingResultMetadataType;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
import com.google.zxing.multi.MultipleBarcodeReader;
|
||||
@@ -53,15 +53,15 @@ public final class MultiQRCodeTestCase extends Assert {
|
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
|
||||
MultipleBarcodeReader reader = new QRCodeMultiReader();
|
||||
Result[] results = reader.decodeMultiple(bitmap);
|
||||
RXingResult[] results = reader.decodeMultiple(bitmap);
|
||||
assertNotNull(results);
|
||||
assertEquals(4, results.length);
|
||||
|
||||
Collection<String> barcodeContents = new HashSet<>();
|
||||
for (Result result : results) {
|
||||
for (RXingResult result : results) {
|
||||
barcodeContents.add(result.getText());
|
||||
assertEquals(BarcodeFormat.QR_CODE, result.getBarcodeFormat());
|
||||
assertNotNull(result.getResultMetadata());
|
||||
assertNotNull(result.getRXingResultMetadata());
|
||||
}
|
||||
Collection<String> expectedContents = new HashSet<>();
|
||||
expectedContents.add("You earned the class a 5 MINUTE DANCE PARTY!! Awesome! Way to go! Let's boogie!");
|
||||
@@ -74,27 +74,27 @@ public final class MultiQRCodeTestCase extends Assert {
|
||||
|
||||
@Test
|
||||
public void testProcessStructuredAppend() {
|
||||
Result sa1 = new Result("SA1", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
Result sa2 = new Result("SA2", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
Result sa3 = new Result("SA3", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
sa1.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, 2);
|
||||
sa1.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
sa2.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (1 << 4) + 2);
|
||||
sa2.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
sa3.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (2 << 4) + 2);
|
||||
sa3.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
RXingResult sa1 = new RXingResult("SA1", new byte[]{}, new RXingResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
RXingResult sa2 = new RXingResult("SA2", new byte[]{}, new RXingResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
RXingResult sa3 = new RXingResult("SA3", new byte[]{}, new RXingResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
sa1.putMetadata(RXingResultMetadataType.STRUCTURED_APPEND_SEQUENCE, 2);
|
||||
sa1.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
sa2.putMetadata(RXingResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (1 << 4) + 2);
|
||||
sa2.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
sa3.putMetadata(RXingResultMetadataType.STRUCTURED_APPEND_SEQUENCE, (2 << 4) + 2);
|
||||
sa3.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
|
||||
Result nsa = new Result("NotSA", new byte[]{}, new ResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
nsa.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
RXingResult nsa = new RXingResult("NotSA", new byte[]{}, new RXingResultPoint[]{}, BarcodeFormat.QR_CODE);
|
||||
nsa.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, "L");
|
||||
|
||||
List<Result> inputs = Arrays.asList(sa3, sa1, nsa, sa2);
|
||||
List<RXingResult> inputs = Arrays.asList(sa3, sa1, nsa, sa2);
|
||||
|
||||
List<Result> results = QRCodeMultiReader.processStructuredAppend(inputs);
|
||||
List<RXingResult> results = QRCodeMultiReader.processStructuredAppend(inputs);
|
||||
assertNotNull(results);
|
||||
assertEquals(2, results.size());
|
||||
|
||||
Collection<String> barcodeContents = new HashSet<>();
|
||||
for (Result result : results) {
|
||||
for (RXingResult result : results) {
|
||||
barcodeContents.add(result.getText());
|
||||
}
|
||||
Collection<String> expectedContents = new HashSet<>();
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Test;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.Writer;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
@@ -118,12 +118,12 @@ public class Code128WriterTestCase extends Assert {
|
||||
String toEncode = "\u00f1" + "10958" + "\u00f1" + "17160526";
|
||||
String expected = "1095817160526";
|
||||
|
||||
BitMatrix encResult = encode(toEncode, false, expected);
|
||||
BitMatrix encRXingResult = encode(toEncode, false, expected);
|
||||
|
||||
int width = encResult.getWidth();
|
||||
encResult = encode(toEncode, true, expected);
|
||||
int width = encRXingResult.getWidth();
|
||||
encRXingResult = encode(toEncode, true, expected);
|
||||
//Compact encoding has one latch less and encodes as STARTA,FNC1,1,CODEC,09,58,FNC1,17,16,05,26
|
||||
assertEquals(width, encResult.getWidth() + 11);
|
||||
assertEquals(width, encRXingResult.getWidth() + 11);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -337,23 +337,23 @@ public class Code128WriterTestCase extends Assert {
|
||||
if (compact) {
|
||||
hints.put(EncodeHintType.CODE128_COMPACT, Boolean.TRUE);
|
||||
}
|
||||
BitMatrix encResult = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
BitMatrix encRXingResult = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0, hints);
|
||||
if (expectedLoopback != null) {
|
||||
BitArray row = encResult.getRow(0, null);
|
||||
Result rtResult = reader.decodeRow(0, row, null);
|
||||
String actual = rtResult.getText();
|
||||
BitArray row = encRXingResult.getRow(0, null);
|
||||
RXingResult rtRXingResult = reader.decodeRow(0, row, null);
|
||||
String actual = rtRXingResult.getText();
|
||||
assertEquals(expectedLoopback, actual);
|
||||
}
|
||||
if (compact) {
|
||||
//check that what is encoded compactly yields the same on loopback as what was encoded fast.
|
||||
BitArray row = encResult.getRow(0, null);
|
||||
Result rtResult = reader.decodeRow(0, row, null);
|
||||
String actual = rtResult.getText();
|
||||
BitMatrix encResultFast = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0);
|
||||
row = encResultFast.getRow(0, null);
|
||||
rtResult = reader.decodeRow(0, row, null);
|
||||
assertEquals(rtResult.getText(), actual);
|
||||
BitArray row = encRXingResult.getRow(0, null);
|
||||
RXingResult rtRXingResult = reader.decodeRow(0, row, null);
|
||||
String actual = rtRXingResult.getText();
|
||||
BitMatrix encRXingResultFast = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0);
|
||||
row = encRXingResultFast.getRow(0, null);
|
||||
rtRXingResult = reader.decodeRow(0, row, null);
|
||||
assertEquals(rtRXingResult.getText(), actual);
|
||||
}
|
||||
return encResult;
|
||||
return encRXingResult;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.ChecksumException;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
/**
|
||||
* @author Michael Jahn
|
||||
@@ -44,14 +44,14 @@ public final class Code39ExtendedModeTestCase extends Assert {
|
||||
"000001001011011010101001001001011001101010101001010010010110101001011010010100100101011010010110100101001001011011010010101001010010010101011001011010010100100101101011001010100101001001010110110010101001010010010101010011011010010100100101101010011010100101001001010110100110101001010010010101011001101010010100100101101010100110100101001001010110101001101001010010010110110101001010010100100101010110100110100101001001011010110100101001010010010101101101001010010100100101010101100110100101001001011010101100101001010010010101101011001010010100100101010110110010100101001001011001010101101001010010010100110101011010010100100101100110101010100101001001010010110101101001010010010110010110101010010100100101001101101010101001001001010110110100101010010010010101010110011010100100100101101010110010101001001001010110101100101010010010010101011011001010010110110100000");
|
||||
}
|
||||
|
||||
private static void doTest(String expectedResult, String encodedResult)
|
||||
private static void doTest(String expectedRXingResult, String encodedRXingResult)
|
||||
throws FormatException, ChecksumException, NotFoundException {
|
||||
Code39Reader sut = new Code39Reader(false, true);
|
||||
BitMatrix matrix = BitMatrix.parse(encodedResult, "1", "0");
|
||||
BitMatrix matrix = BitMatrix.parse(encodedRXingResult, "1", "0");
|
||||
BitArray row = new BitArray(matrix.getWidth());
|
||||
matrix.getRow(0, row);
|
||||
Result result = sut.decodeRow(0, row, null);
|
||||
assertEquals(expectedResult, result.getText());
|
||||
RXingResult result = sut.decodeRow(0, row, null);
|
||||
assertEquals(expectedRXingResult, result.getText());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.ChecksumException;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
/**
|
||||
* @author Daisuke Makiuchi
|
||||
@@ -38,14 +38,14 @@ public final class Code93ReaderTestCase extends Assert {
|
||||
"0000001010111101101000101001100101001011001001100101100101001001100101100100101000010101010000101110101101101010001001001101001101001110010101101011101011011101011101101110100101110101101001110101110110101101010001110110101100010101110110101000110101110110101000101101110110101101001101110110101100101101110110101100110101110110101011011001110110101011001101110110101001101101110110101001110101001100101101010001010111101111");
|
||||
}
|
||||
|
||||
private static void doTest(String expectedResult, String encodedResult)
|
||||
private static void doTest(String expectedRXingResult, String encodedRXingResult)
|
||||
throws FormatException, ChecksumException, NotFoundException {
|
||||
Code93Reader sut = new Code93Reader();
|
||||
BitMatrix matrix = BitMatrix.parse(encodedResult, "1", "0");
|
||||
BitMatrix matrix = BitMatrix.parse(encodedRXingResult, "1", "0");
|
||||
BitArray row = new BitArray(matrix.getWidth());
|
||||
matrix.getRow(0, row);
|
||||
Result result = sut.decodeRow(0, row, null);
|
||||
assertEquals(expectedResult, result.getText());
|
||||
RXingResult result = sut.decodeRow(0, row, null);
|
||||
assertEquals(expectedRXingResult, result.getText());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,10 +43,10 @@ import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.result.ExpandedProductParsedResult;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
import com.google.zxing.client.result.ResultParser;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.client.result.ExpandedProductParsedRXingResult;
|
||||
import com.google.zxing.client.result.ParsedRXingResult;
|
||||
import com.google.zxing.client.result.RXingResultParser;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.GlobalHistogramBinarizer;
|
||||
@@ -63,18 +63,18 @@ public final class RSSExpandedImage2resultTestCase extends Assert {
|
||||
@Test
|
||||
public void testDecodeRow2result2() throws Exception {
|
||||
// (01)90012345678908(3103)001750
|
||||
ExpandedProductParsedResult expected =
|
||||
new ExpandedProductParsedResult("(01)90012345678908(3103)001750",
|
||||
ExpandedProductParsedRXingResult expected =
|
||||
new ExpandedProductParsedRXingResult("(01)90012345678908(3103)001750",
|
||||
"90012345678908",
|
||||
null, null, null, null, null, null,
|
||||
"001750",
|
||||
ExpandedProductParsedResult.KILOGRAM,
|
||||
ExpandedProductParsedRXingResult.KILOGRAM,
|
||||
"3", null, null, null, new HashMap<>());
|
||||
|
||||
assertCorrectImage2result("2.png", expected);
|
||||
}
|
||||
|
||||
private static void assertCorrectImage2result(String fileName, ExpandedProductParsedResult expected)
|
||||
private static void assertCorrectImage2result(String fileName, ExpandedProductParsedRXingResult expected)
|
||||
throws IOException, NotFoundException {
|
||||
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
|
||||
|
||||
@@ -83,18 +83,18 @@ public final class RSSExpandedImage2resultTestCase extends Assert {
|
||||
int rowNumber = binaryMap.getHeight() / 2;
|
||||
BitArray row = binaryMap.getBlackRow(rowNumber, null);
|
||||
|
||||
Result theResult;
|
||||
RXingResult theRXingResult;
|
||||
try {
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
theResult = rssExpandedReader.decodeRow(rowNumber, row, null);
|
||||
theRXingResult = rssExpandedReader.decodeRow(rowNumber, row, null);
|
||||
} catch (ReaderException re) {
|
||||
fail(re.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
assertSame(BarcodeFormat.RSS_EXPANDED, theResult.getBarcodeFormat());
|
||||
assertSame(BarcodeFormat.RSS_EXPANDED, theRXingResult.getBarcodeFormat());
|
||||
|
||||
ParsedResult result = ResultParser.parseResult(theResult);
|
||||
ParsedRXingResult result = RXingResultParser.parseRXingResult(theRXingResult);
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.BitArray;
|
||||
import com.google.zxing.common.GlobalHistogramBinarizer;
|
||||
@@ -196,7 +196,7 @@ public final class RSSExpandedImage2stringTestCase extends Assert {
|
||||
int rowNumber = binaryMap.getHeight() / 2;
|
||||
BitArray row = binaryMap.getBlackRow(rowNumber, null);
|
||||
|
||||
Result result;
|
||||
RXingResult result;
|
||||
try {
|
||||
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
|
||||
result = rssExpandedReader.decodeRow(rowNumber, row, null);
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.junit.Test;
|
||||
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.common.BitArray;
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@ public final class RSSExpandedStackedInternalTestCase extends Assert {
|
||||
|
||||
List<ExpandedPair> totalPairs = rssExpandedReader.decodeRow2pairs(secondRowNumber, secondRow);
|
||||
|
||||
Result result = RSSExpandedReader.constructResult(totalPairs);
|
||||
RXingResult result = RSSExpandedReader.constructRXingResult(totalPairs);
|
||||
assertEquals("(01)98898765432106(3202)012345(15)991231", result.getText());
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public final class RSSExpandedStackedInternalTestCase extends Assert {
|
||||
|
||||
BinaryBitmap binaryMap = TestCaseUtil.getBinaryBitmap("src/test/resources/blackbox/rssexpandedstacked-2/1000.png");
|
||||
|
||||
Result result = rssExpandedReader.decode(binaryMap);
|
||||
RXingResult result = rssExpandedReader.decode(binaryMap);
|
||||
assertEquals("(01)98898765432106(3202)012345(15)991231", result.getText());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ import com.google.zxing.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.LuminanceSource;
|
||||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.RXingResultMetadataType;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
import com.google.zxing.common.TestResult;
|
||||
import com.google.zxing.common.TestRXingResult;
|
||||
|
||||
import com.google.zxing.multi.MultipleBarcodeReader;
|
||||
import org.junit.Test;
|
||||
@@ -59,20 +59,20 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
private final MultipleBarcodeReader barcodeReader = new PDF417Reader();
|
||||
|
||||
private final List<TestResult> testResults = new ArrayList<>();
|
||||
private final List<TestRXingResult> testRXingResults = new ArrayList<>();
|
||||
|
||||
public PDF417BlackBox4TestCase() {
|
||||
super("src/test/resources/blackbox/pdf417-4", null, BarcodeFormat.PDF_417);
|
||||
testResults.add(new TestResult(3, 3, 0, 0, 0.0f));
|
||||
testRXingResults.add(new TestRXingResult(3, 3, 0, 0, 0.0f));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testBlackBox() throws IOException {
|
||||
assertFalse(testResults.isEmpty());
|
||||
assertFalse(testRXingResults.isEmpty());
|
||||
|
||||
Map<String,List<Path>> imageFiles = getImageFileLists();
|
||||
int testCount = testResults.size();
|
||||
int testCount = testRXingResults.size();
|
||||
|
||||
int[] passedCounts = new int[testCount];
|
||||
int[] tryHarderCounts = new int[testCount];
|
||||
@@ -94,10 +94,10 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||
}
|
||||
|
||||
for (int x = 0; x < testCount; x++) {
|
||||
List<Result> results = new ArrayList<>();
|
||||
List<RXingResult> results = new ArrayList<>();
|
||||
for (Path imageFile : testImageGroup.getValue()) {
|
||||
BufferedImage image = ImageIO.read(imageFile.toFile());
|
||||
float rotation = testResults.get(x).getRotation();
|
||||
float rotation = testRXingResults.get(x).getRotation();
|
||||
BufferedImage rotatedImage = rotateImage(image, rotation);
|
||||
LuminanceSource source = new BufferedImageLuminanceSource(rotatedImage);
|
||||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
|
||||
@@ -108,11 +108,11 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
results.sort(Comparator.comparingInt((Result r) -> getMeta(r).getSegmentIndex()));
|
||||
results.sort(Comparator.comparingInt((RXingResult r) -> getMeta(r).getSegmentIndex()));
|
||||
StringBuilder resultText = new StringBuilder();
|
||||
String fileId = null;
|
||||
for (Result result : results) {
|
||||
PDF417ResultMetadata resultMetadata = getMeta(result);
|
||||
for (RXingResult result : results) {
|
||||
PDF417RXingResultMetadata resultMetadata = getMeta(result);
|
||||
assertNotNull("resultMetadata", resultMetadata);
|
||||
if (fileId == null) {
|
||||
fileId = resultMetadata.getFileId();
|
||||
@@ -131,15 +131,15 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||
int totalMustPass = 0;
|
||||
|
||||
int numberOfTests = imageFiles.keySet().size();
|
||||
for (int x = 0; x < testResults.size(); x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
log.info(String.format("Rotation %d degrees:", (int) testResult.getRotation()));
|
||||
for (int x = 0; x < testRXingResults.size(); x++) {
|
||||
TestRXingResult testRXingResult = testRXingResults.get(x);
|
||||
log.info(String.format("Rotation %d degrees:", (int) testRXingResult.getRotation()));
|
||||
log.info(String.format(" %d of %d images passed (%d required)", passedCounts[x], numberOfTests,
|
||||
testResult.getMustPassCount()));
|
||||
testRXingResult.getMustPassCount()));
|
||||
log.info(String.format(" %d of %d images passed with try harder (%d required)", tryHarderCounts[x],
|
||||
numberOfTests, testResult.getTryHarderCount()));
|
||||
numberOfTests, testRXingResult.getTryHarderCount()));
|
||||
totalFound += passedCounts[x] + tryHarderCounts[x];
|
||||
totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount();
|
||||
totalMustPass += testRXingResult.getMustPassCount() + testRXingResult.getTryHarderCount();
|
||||
}
|
||||
|
||||
int totalTests = numberOfTests * testCount * 2;
|
||||
@@ -154,19 +154,19 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||
|
||||
// Then run through again and assert if any failed
|
||||
for (int x = 0; x < testCount; x++) {
|
||||
TestResult testResult = testResults.get(x);
|
||||
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
|
||||
assertTrue(label, passedCounts[x] >= testResult.getMustPassCount());
|
||||
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testResult.getTryHarderCount());
|
||||
TestRXingResult testRXingResult = testRXingResults.get(x);
|
||||
String label = "Rotation " + testRXingResult.getRotation() + " degrees: Too many images failed";
|
||||
assertTrue(label, passedCounts[x] >= testRXingResult.getMustPassCount());
|
||||
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testRXingResult.getTryHarderCount());
|
||||
}
|
||||
}
|
||||
|
||||
private static PDF417ResultMetadata getMeta(Result result) {
|
||||
return result.getResultMetadata() == null ? null : (PDF417ResultMetadata) result.getResultMetadata().get(
|
||||
ResultMetadataType.PDF417_EXTRA_METADATA);
|
||||
private static PDF417RXingResultMetadata getMeta(RXingResult result) {
|
||||
return result.getRXingResultMetadata() == null ? null : (PDF417RXingResultMetadata) result.getRXingResultMetadata().get(
|
||||
RXingResultMetadataType.PDF417_EXTRA_METADATA);
|
||||
}
|
||||
|
||||
private Result[] decode(BinaryBitmap source, boolean tryHarder) throws ReaderException {
|
||||
private RXingResult[] decode(BinaryBitmap source, boolean tryHarder) throws ReaderException {
|
||||
Map<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);
|
||||
if (tryHarder) {
|
||||
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.google.zxing.pdf417.decoder;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.pdf417.PDF417ResultMetadata;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.pdf417.PDF417RXingResultMetadata;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import com.google.zxing.pdf417.encoder.Compaction;
|
||||
import com.google.zxing.pdf417.encoder.PDF417HighLevelEncoderTestAdapter;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class PDF417DecoderTestCase extends Assert {
|
||||
*/
|
||||
@Test
|
||||
public void testStandardSample1() throws FormatException {
|
||||
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
|
||||
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
|
||||
int[] sampleCodes = {20, 928, 111, 100, 17, 53, 923, 1, 111, 104, 923, 3, 64, 416, 34, 923, 4, 258, 446, 67,
|
||||
// we should never reach these
|
||||
1000, 1000, 1000};
|
||||
@@ -66,7 +66,7 @@ public class PDF417DecoderTestCase extends Assert {
|
||||
*/
|
||||
@Test
|
||||
public void testStandardSample2() throws FormatException {
|
||||
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
|
||||
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
|
||||
int[] sampleCodes = {11, 928, 111, 103, 17, 53, 923, 1, 111, 104, 922,
|
||||
// we should never reach these
|
||||
1000, 1000, 1000};
|
||||
@@ -93,7 +93,7 @@ public class PDF417DecoderTestCase extends Assert {
|
||||
*/
|
||||
@Test
|
||||
public void testStandardSample3() throws FormatException {
|
||||
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
|
||||
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
|
||||
int[] sampleCodes = {7, 928, 111, 100, 100, 200, 300,
|
||||
0}; // Final dummy ECC codeword required to avoid ArrayIndexOutOfBounds
|
||||
|
||||
@@ -108,9 +108,9 @@ public class PDF417DecoderTestCase extends Assert {
|
||||
assertNull(resultMetadata.getOptionalData());
|
||||
|
||||
// Check that symbol containing no data except Macro is accepted (see note in Annex H.2)
|
||||
DecoderResult decoderResult = DecodedBitStreamParser.decode(sampleCodes, "0");
|
||||
assertEquals("", decoderResult.getText());
|
||||
assertNotNull(decoderResult.getOther());
|
||||
DecoderRXingResult decoderRXingResult = DecodedBitStreamParser.decode(sampleCodes, "0");
|
||||
assertEquals("", decoderRXingResult.getText());
|
||||
assertNotNull(decoderRXingResult.getOther());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +118,7 @@ public class PDF417DecoderTestCase extends Assert {
|
||||
int[] sampleCodes = {23, 477, 928, 111, 100, 0, 252, 21, 86, 923, 0, 815, 251, 133, 12, 148, 537, 593,
|
||||
599, 923, 1, 111, 102, 98, 311, 355, 522, 920, 779, 40, 628, 33, 749, 267, 506, 213, 928, 465, 248,
|
||||
493, 72, 780, 699, 780, 493, 755, 84, 198, 628, 368, 156, 198, 809, 19, 113};
|
||||
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
|
||||
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
|
||||
|
||||
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 3, resultMetadata);
|
||||
|
||||
@@ -135,7 +135,7 @@ public class PDF417DecoderTestCase extends Assert {
|
||||
public void testSampleWithNumericValues() throws FormatException {
|
||||
int[] sampleCodes = {25, 477, 928, 111, 100, 0, 252, 21, 86, 923, 2, 2, 0, 1, 0, 0, 0, 923, 5, 130, 923,
|
||||
6, 1, 500, 13, 0};
|
||||
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
|
||||
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
|
||||
|
||||
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 3, resultMetadata);
|
||||
|
||||
@@ -151,7 +151,7 @@ public class PDF417DecoderTestCase extends Assert {
|
||||
@Test
|
||||
public void testSampleWithMacroTerminatorOnly() throws FormatException {
|
||||
int[] sampleCodes = {7, 477, 928, 222, 198, 0, 922};
|
||||
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
|
||||
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
|
||||
|
||||
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 3, resultMetadata);
|
||||
|
||||
@@ -165,14 +165,14 @@ public class PDF417DecoderTestCase extends Assert {
|
||||
@Test(expected = FormatException.class)
|
||||
public void testSampleWithBadSequenceIndexMacro() throws FormatException {
|
||||
int[] sampleCodes = {3, 928, 222, 0};
|
||||
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
|
||||
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
|
||||
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 2, resultMetadata);
|
||||
}
|
||||
|
||||
@Test(expected = FormatException.class)
|
||||
public void testSampleWithNoFileIdMacro() throws FormatException {
|
||||
int[] sampleCodes = {4, 928, 222, 198, 0};
|
||||
PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
|
||||
PDF417RXingResultMetadata resultMetadata = new PDF417RXingResultMetadata();
|
||||
DecodedBitStreamParser.decodeMacroBlock(sampleCodes, 2, resultMetadata);
|
||||
}
|
||||
|
||||
@@ -405,9 +405,9 @@ public class PDF417DecoderTestCase extends Assert {
|
||||
}
|
||||
}
|
||||
|
||||
private static void performDecodeTest(int[] codewords, String expectedResult) throws FormatException {
|
||||
DecoderResult result = DecodedBitStreamParser.decode(codewords, "0");
|
||||
assertEquals(expectedResult, result.getText());
|
||||
private static void performDecodeTest(int[] codewords, String expectedRXingResult) throws FormatException {
|
||||
DecoderRXingResult result = DecodedBitStreamParser.decode(codewords, "0");
|
||||
assertEquals(expectedRXingResult, result.getText());
|
||||
}
|
||||
|
||||
private static void performECITest(char[] chars,
|
||||
|
||||
@@ -110,18 +110,18 @@ public final class QRCodeWriterTestCase extends Assert {
|
||||
|
||||
BufferedImage image = loadImage(fileName);
|
||||
assertNotNull(image);
|
||||
BitMatrix goldenResult = createMatrixFromImage(image);
|
||||
assertNotNull(goldenResult);
|
||||
BitMatrix goldenRXingResult = createMatrixFromImage(image);
|
||||
assertNotNull(goldenRXingResult);
|
||||
|
||||
Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class);
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, ecLevel);
|
||||
Writer writer = new QRCodeWriter();
|
||||
BitMatrix generatedResult = writer.encode(contents, BarcodeFormat.QR_CODE, resolution,
|
||||
BitMatrix generatedRXingResult = writer.encode(contents, BarcodeFormat.QR_CODE, resolution,
|
||||
resolution, hints);
|
||||
|
||||
assertEquals(resolution, generatedResult.getWidth());
|
||||
assertEquals(resolution, generatedResult.getHeight());
|
||||
assertEquals(goldenResult, generatedResult);
|
||||
assertEquals(resolution, generatedRXingResult.getWidth());
|
||||
assertEquals(resolution, generatedRXingResult.getHeight());
|
||||
assertEquals(goldenRXingResult, generatedRXingResult);
|
||||
}
|
||||
|
||||
// Golden images are generated with "qrcode_sample.cc". The images are checked with both eye balls
|
||||
|
||||
@@ -905,11 +905,11 @@ public final class EncoderTestCase extends Assert {
|
||||
".a.a.)", null, false);
|
||||
}
|
||||
|
||||
static void verifyMinimalEncoding(String input, String expectedResult, Charset priorityCharset, boolean isGS1)
|
||||
static void verifyMinimalEncoding(String input, String expectedRXingResult, Charset priorityCharset, boolean isGS1)
|
||||
throws Exception {
|
||||
MinimalEncoder.ResultList result = MinimalEncoder.encode(input, null, priorityCharset, isGS1,
|
||||
MinimalEncoder.RXingResultList result = MinimalEncoder.encode(input, null, priorityCharset, isGS1,
|
||||
ErrorCorrectionLevel.L);
|
||||
assertEquals(result.toString(), expectedResult);
|
||||
assertEquals(result.toString(), expectedRXingResult);
|
||||
}
|
||||
|
||||
private static void verifyGS1EncodedData(QRCode qrCode) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIResultHandler.java
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIRXingResultHandler.java
|
||||
@@ -1 +1 @@
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIResultHandler.java
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIRXingResultHandler.java
|
||||
@@ -1 +1 @@
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIResultHandler.java
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIRXingResultHandler.java
|
||||
@@ -1 +1 @@
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIResultHandler.java
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIRXingResultHandler.java
|
||||
@@ -1 +1 @@
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIResultHandler.java
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIRXingResultHandler.java
|
||||
@@ -1 +1 @@
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIResultHandler.java
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIRXingResultHandler.java
|
||||
@@ -1 +1 @@
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIResultHandler.java
|
||||
http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/URIRXingResultHandler.java
|
||||
@@ -83,10 +83,10 @@ public enum DecodeHintType {
|
||||
RETURN_CODABAR_START_END(Void.class),
|
||||
|
||||
/**
|
||||
* The caller needs to be notified via callback when a possible {@link ResultPoint}
|
||||
* is found. Maps to a {@link ResultPointCallback}.
|
||||
* The caller needs to be notified via callback when a possible {@link RXingResultPoint}
|
||||
* is found. Maps to a {@link RXingResultPointCallback}.
|
||||
*/
|
||||
NEED_RESULT_POINT_CALLBACK(ResultPointCallback.class),
|
||||
NEED_RESULT_POINT_CALLBACK(RXingResultPointCallback.class),
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,7 +52,7 @@ public final class MultiFormatReader implements Reader {
|
||||
* @throws NotFoundException Any errors which occurred
|
||||
*/
|
||||
@Override
|
||||
public Result decode(BinaryBitmap image) throws NotFoundException {
|
||||
public RXingResult decode(BinaryBitmap image) throws NotFoundException {
|
||||
setHints(null);
|
||||
return decodeInternal(image);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public final class MultiFormatReader implements Reader {
|
||||
* @throws NotFoundException Any errors which occurred
|
||||
*/
|
||||
@Override
|
||||
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException {
|
||||
public RXingResult decode(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException {
|
||||
setHints(hints);
|
||||
return decodeInternal(image);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public final class MultiFormatReader implements Reader {
|
||||
* @return The contents of the image
|
||||
* @throws NotFoundException Any errors which occurred
|
||||
*/
|
||||
public Result decodeWithState(BinaryBitmap image) throws NotFoundException {
|
||||
public RXingResult decodeWithState(BinaryBitmap image) throws NotFoundException {
|
||||
// Make sure to set up the default state so we don't crash
|
||||
if (readers == null) {
|
||||
setHints(null);
|
||||
@@ -166,7 +166,7 @@ public final class MultiFormatReader implements Reader {
|
||||
}
|
||||
}
|
||||
|
||||
private Result decodeInternal(BinaryBitmap image) throws NotFoundException {
|
||||
private RXingResult decodeInternal(BinaryBitmap image) throws NotFoundException {
|
||||
if (readers != null) {
|
||||
for (Reader reader : readers) {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
|
||||
@@ -41,7 +41,7 @@ public interface Reader {
|
||||
* @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
|
||||
*/
|
||||
Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException;
|
||||
RXingResult decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException;
|
||||
|
||||
/**
|
||||
* Locates and decodes a barcode in some format within an image. This method also accepts
|
||||
@@ -57,7 +57,7 @@ public interface Reader {
|
||||
* @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
|
||||
*/
|
||||
Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||
RXingResult decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||
throws NotFoundException, ChecksumException, FormatException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,36 +24,36 @@ import java.util.Map;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class Result {
|
||||
public final class RXingResult {
|
||||
|
||||
private final String text;
|
||||
private final byte[] rawBytes;
|
||||
private final int numBits;
|
||||
private ResultPoint[] resultPoints;
|
||||
private RXingResultPoint[] resultPoints;
|
||||
private final BarcodeFormat format;
|
||||
private Map<ResultMetadataType,Object> resultMetadata;
|
||||
private Map<RXingResultMetadataType,Object> resultMetadata;
|
||||
private final long timestamp;
|
||||
|
||||
public Result(String text,
|
||||
public RXingResult(String text,
|
||||
byte[] rawBytes,
|
||||
ResultPoint[] resultPoints,
|
||||
RXingResultPoint[] resultPoints,
|
||||
BarcodeFormat format) {
|
||||
this(text, rawBytes, resultPoints, format, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public Result(String text,
|
||||
public RXingResult(String text,
|
||||
byte[] rawBytes,
|
||||
ResultPoint[] resultPoints,
|
||||
RXingResultPoint[] resultPoints,
|
||||
BarcodeFormat format,
|
||||
long timestamp) {
|
||||
this(text, rawBytes, rawBytes == null ? 0 : 8 * rawBytes.length,
|
||||
resultPoints, format, timestamp);
|
||||
}
|
||||
|
||||
public Result(String text,
|
||||
public RXingResult(String text,
|
||||
byte[] rawBytes,
|
||||
int numBits,
|
||||
ResultPoint[] resultPoints,
|
||||
RXingResultPoint[] resultPoints,
|
||||
BarcodeFormat format,
|
||||
long timestamp) {
|
||||
this.text = text;
|
||||
@@ -92,7 +92,7 @@ public final class Result {
|
||||
* identifying finder patterns or the corners of the barcode. The exact meaning is
|
||||
* specific to the type of barcode that was decoded.
|
||||
*/
|
||||
public ResultPoint[] getResultPoints() {
|
||||
public RXingResultPoint[] getRXingResultPoints() {
|
||||
return resultPoints;
|
||||
}
|
||||
|
||||
@@ -104,22 +104,22 @@ public final class Result {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link Map} mapping {@link ResultMetadataType} keys to values. May be
|
||||
* @return {@link Map} mapping {@link RXingResultMetadataType} keys to values. May be
|
||||
* {@code null}. This contains optional metadata about what was detected about the barcode,
|
||||
* like orientation.
|
||||
*/
|
||||
public Map<ResultMetadataType,Object> getResultMetadata() {
|
||||
public Map<RXingResultMetadataType,Object> getRXingResultMetadata() {
|
||||
return resultMetadata;
|
||||
}
|
||||
|
||||
public void putMetadata(ResultMetadataType type, Object value) {
|
||||
public void putMetadata(RXingResultMetadataType type, Object value) {
|
||||
if (resultMetadata == null) {
|
||||
resultMetadata = new EnumMap<>(ResultMetadataType.class);
|
||||
resultMetadata = new EnumMap<>(RXingResultMetadataType.class);
|
||||
}
|
||||
resultMetadata.put(type, value);
|
||||
}
|
||||
|
||||
public void putAllMetadata(Map<ResultMetadataType,Object> metadata) {
|
||||
public void putAllMetadata(Map<RXingResultMetadataType,Object> metadata) {
|
||||
if (metadata != null) {
|
||||
if (resultMetadata == null) {
|
||||
resultMetadata = metadata;
|
||||
@@ -129,12 +129,12 @@ public final class Result {
|
||||
}
|
||||
}
|
||||
|
||||
public void addResultPoints(ResultPoint[] newPoints) {
|
||||
ResultPoint[] oldPoints = resultPoints;
|
||||
public void addRXingResultPoints(RXingResultPoint[] newPoints) {
|
||||
RXingResultPoint[] oldPoints = resultPoints;
|
||||
if (oldPoints == null) {
|
||||
resultPoints = newPoints;
|
||||
} else if (newPoints != null && newPoints.length > 0) {
|
||||
ResultPoint[] allPoints = new ResultPoint[oldPoints.length + newPoints.length];
|
||||
RXingResultPoint[] allPoints = new RXingResultPoint[oldPoints.length + newPoints.length];
|
||||
System.arraycopy(oldPoints, 0, allPoints, 0, oldPoints.length);
|
||||
System.arraycopy(newPoints, 0, allPoints, oldPoints.length, newPoints.length);
|
||||
resultPoints = allPoints;
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.google.zxing;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public enum ResultMetadataType {
|
||||
public enum RXingResultMetadataType {
|
||||
|
||||
/**
|
||||
* Unspecified, application-specific metadata. Maps to an unspecified {@link Object}.
|
||||
@@ -40,7 +40,7 @@ public enum ResultMetadataType {
|
||||
|
||||
/**
|
||||
* <p>2D barcode formats typically encode text, but allow for a sort of 'byte mode'
|
||||
* which is sometimes used to encode binary data. While {@link Result} makes available
|
||||
* which is sometimes used to encode binary data. While {@link RXingResult} makes available
|
||||
* the complete raw bytes in the barcode for these formats, it does not offer the bytes
|
||||
* from the byte segments alone.</p>
|
||||
*
|
||||
|
||||
@@ -24,12 +24,12 @@ import com.google.zxing.common.detector.MathUtils;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public class ResultPoint {
|
||||
public class RXingResultPoint {
|
||||
|
||||
private final float x;
|
||||
private final float y;
|
||||
|
||||
public ResultPoint(float x, float y) {
|
||||
public RXingResultPoint(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
@@ -44,8 +44,8 @@ public class ResultPoint {
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object other) {
|
||||
if (other instanceof ResultPoint) {
|
||||
ResultPoint otherPoint = (ResultPoint) other;
|
||||
if (other instanceof RXingResultPoint) {
|
||||
RXingResultPoint otherPoint = (RXingResultPoint) other;
|
||||
return x == otherPoint.x && y == otherPoint.y;
|
||||
}
|
||||
return false;
|
||||
@@ -62,21 +62,21 @@ public class ResultPoint {
|
||||
}
|
||||
|
||||
/**
|
||||
* Orders an array of three ResultPoints in an order [A,B,C] such that AB is less than AC
|
||||
* Orders an array of three RXingResultPoints in an order [A,B,C] such that AB is less than AC
|
||||
* and BC is less than AC, and the angle between BC and BA is less than 180 degrees.
|
||||
*
|
||||
* @param patterns array of three {@code ResultPoint} to order
|
||||
* @param patterns array of three {@code RXingResultPoint} to order
|
||||
*/
|
||||
public static void orderBestPatterns(ResultPoint[] patterns) {
|
||||
public static void orderBestPatterns(RXingResultPoint[] patterns) {
|
||||
|
||||
// Find distances between pattern centers
|
||||
float zeroOneDistance = distance(patterns[0], patterns[1]);
|
||||
float oneTwoDistance = distance(patterns[1], patterns[2]);
|
||||
float zeroTwoDistance = distance(patterns[0], patterns[2]);
|
||||
|
||||
ResultPoint pointA;
|
||||
ResultPoint pointB;
|
||||
ResultPoint pointC;
|
||||
RXingResultPoint pointA;
|
||||
RXingResultPoint pointB;
|
||||
RXingResultPoint pointC;
|
||||
// Assume one closest to other two is B; A and C will just be guesses at first
|
||||
if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance) {
|
||||
pointB = patterns[0];
|
||||
@@ -97,7 +97,7 @@ public class ResultPoint {
|
||||
// we want for A, B, C. If it's negative, then we've got it flipped around and
|
||||
// should swap A and C.
|
||||
if (crossProductZ(pointA, pointB, pointC) < 0.0f) {
|
||||
ResultPoint temp = pointA;
|
||||
RXingResultPoint temp = pointA;
|
||||
pointA = pointC;
|
||||
pointC = temp;
|
||||
}
|
||||
@@ -112,16 +112,16 @@ public class ResultPoint {
|
||||
* @param pattern2 second pattern
|
||||
* @return distance between two points
|
||||
*/
|
||||
public static float distance(ResultPoint pattern1, ResultPoint pattern2) {
|
||||
public static float distance(RXingResultPoint pattern1, RXingResultPoint pattern2) {
|
||||
return MathUtils.distance(pattern1.x, pattern1.y, pattern2.x, pattern2.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the z component of the cross product between vectors BC and BA.
|
||||
*/
|
||||
private static float crossProductZ(ResultPoint pointA,
|
||||
ResultPoint pointB,
|
||||
ResultPoint pointC) {
|
||||
private static float crossProductZ(RXingResultPoint pointA,
|
||||
RXingResultPoint pointB,
|
||||
RXingResultPoint pointC) {
|
||||
float bX = pointB.x;
|
||||
float bY = pointB.y;
|
||||
return ((pointC.x - bX) * (pointA.y - bY)) - ((pointC.y - bY) * (pointA.x - bX));
|
||||
|
||||
@@ -22,8 +22,8 @@ package com.google.zxing;
|
||||
*
|
||||
* @see DecodeHintType#NEED_RESULT_POINT_CALLBACK
|
||||
*/
|
||||
public interface ResultPointCallback {
|
||||
public interface RXingResultPointCallback {
|
||||
|
||||
void foundPossibleResultPoint(ResultPoint point);
|
||||
void foundPossibleRXingResultPoint(RXingResultPoint point);
|
||||
|
||||
}
|
||||
|
||||
@@ -16,24 +16,24 @@
|
||||
|
||||
package com.google.zxing.aztec;
|
||||
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DetectorResult;
|
||||
import com.google.zxing.common.DetectorRXingResult;
|
||||
|
||||
/**
|
||||
* <p>Extends {@link DetectorResult} with more information specific to the Aztec format,
|
||||
* <p>Extends {@link DetectorRXingResult} with more information specific to the Aztec format,
|
||||
* like the number of layers and whether it's compact.</p>
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class AztecDetectorResult extends DetectorResult {
|
||||
public final class AztecDetectorRXingResult extends DetectorRXingResult {
|
||||
|
||||
private final boolean compact;
|
||||
private final int nbDatablocks;
|
||||
private final int nbLayers;
|
||||
|
||||
public AztecDetectorResult(BitMatrix bits,
|
||||
ResultPoint[] points,
|
||||
public AztecDetectorRXingResult(BitMatrix bits,
|
||||
RXingResultPoint[] points,
|
||||
boolean compact,
|
||||
int nbDatablocks,
|
||||
int nbLayers) {
|
||||
|
||||
@@ -22,13 +22,13 @@ import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Reader;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.ResultPointCallback;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.RXingResultMetadataType;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.RXingResultPointCallback;
|
||||
import com.google.zxing.aztec.decoder.Decoder;
|
||||
import com.google.zxing.aztec.detector.Detector;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -48,33 +48,33 @@ public final class AztecReader implements Reader {
|
||||
* @throws FormatException if a Data Matrix code cannot be decoded
|
||||
*/
|
||||
@Override
|
||||
public Result decode(BinaryBitmap image) throws NotFoundException, FormatException {
|
||||
public RXingResult decode(BinaryBitmap image) throws NotFoundException, FormatException {
|
||||
return decode(image, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||
public RXingResult decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||
throws NotFoundException, FormatException {
|
||||
|
||||
NotFoundException notFoundException = null;
|
||||
FormatException formatException = null;
|
||||
Detector detector = new Detector(image.getBlackMatrix());
|
||||
ResultPoint[] points = null;
|
||||
DecoderResult decoderResult = null;
|
||||
RXingResultPoint[] points = null;
|
||||
DecoderRXingResult decoderRXingResult = null;
|
||||
try {
|
||||
AztecDetectorResult detectorResult = detector.detect(false);
|
||||
points = detectorResult.getPoints();
|
||||
decoderResult = new Decoder().decode(detectorResult);
|
||||
AztecDetectorRXingResult detectorRXingResult = detector.detect(false);
|
||||
points = detectorRXingResult.getPoints();
|
||||
decoderRXingResult = new Decoder().decode(detectorRXingResult);
|
||||
} catch (NotFoundException e) {
|
||||
notFoundException = e;
|
||||
} catch (FormatException e) {
|
||||
formatException = e;
|
||||
}
|
||||
if (decoderResult == null) {
|
||||
if (decoderRXingResult == null) {
|
||||
try {
|
||||
AztecDetectorResult detectorResult = detector.detect(true);
|
||||
points = detectorResult.getPoints();
|
||||
decoderResult = new Decoder().decode(detectorResult);
|
||||
AztecDetectorRXingResult detectorRXingResult = detector.detect(true);
|
||||
points = detectorRXingResult.getPoints();
|
||||
decoderRXingResult = new Decoder().decode(detectorRXingResult);
|
||||
} catch (NotFoundException | FormatException e) {
|
||||
if (notFoundException != null) {
|
||||
throw notFoundException;
|
||||
@@ -87,30 +87,30 @@ public final class AztecReader implements Reader {
|
||||
}
|
||||
|
||||
if (hints != null) {
|
||||
ResultPointCallback rpcb = (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
|
||||
RXingResultPointCallback rpcb = (RXingResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
|
||||
if (rpcb != null) {
|
||||
for (ResultPoint point : points) {
|
||||
rpcb.foundPossibleResultPoint(point);
|
||||
for (RXingResultPoint point : points) {
|
||||
rpcb.foundPossibleRXingResultPoint(point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Result result = new Result(decoderResult.getText(),
|
||||
decoderResult.getRawBytes(),
|
||||
decoderResult.getNumBits(),
|
||||
RXingResult result = new RXingResult(decoderRXingResult.getText(),
|
||||
decoderRXingResult.getRawBytes(),
|
||||
decoderRXingResult.getNumBits(),
|
||||
points,
|
||||
BarcodeFormat.AZTEC,
|
||||
System.currentTimeMillis());
|
||||
|
||||
List<byte[]> byteSegments = decoderResult.getByteSegments();
|
||||
List<byte[]> byteSegments = decoderRXingResult.getByteSegments();
|
||||
if (byteSegments != null) {
|
||||
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
|
||||
result.putMetadata(RXingResultMetadataType.BYTE_SEGMENTS, byteSegments);
|
||||
}
|
||||
String ecLevel = decoderResult.getECLevel();
|
||||
String ecLevel = decoderRXingResult.getECLevel();
|
||||
if (ecLevel != null) {
|
||||
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
|
||||
result.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
|
||||
}
|
||||
result.putMetadata(ResultMetadataType.SYMBOLOGY_IDENTIFIER, "]z" + decoderResult.getSymbologyModifier());
|
||||
result.putMetadata(RXingResultMetadataType.SYMBOLOGY_IDENTIFIER, "]z" + decoderRXingResult.getSymbologyModifier());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -62,10 +62,10 @@ public final class AztecWriter implements Writer {
|
||||
throw new IllegalArgumentException("Can only encode AZTEC, but got " + format);
|
||||
}
|
||||
AztecCode aztec = Encoder.encode(contents, eccPercent, layers, charset);
|
||||
return renderResult(aztec, width, height);
|
||||
return renderRXingResult(aztec, width, height);
|
||||
}
|
||||
|
||||
private static BitMatrix renderResult(AztecCode code, int width, int height) {
|
||||
private static BitMatrix renderRXingResult(AztecCode code, int width, int height) {
|
||||
BitMatrix input = code.getMatrix();
|
||||
if (input == null) {
|
||||
throw new IllegalStateException();
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
package com.google.zxing.aztec.decoder;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.aztec.AztecDetectorResult;
|
||||
import com.google.zxing.aztec.AztecDetectorRXingResult;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.CharacterSetECI;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import com.google.zxing.common.reedsolomon.GenericGF;
|
||||
import com.google.zxing.common.reedsolomon.ReedSolomonDecoder;
|
||||
import com.google.zxing.common.reedsolomon.ReedSolomonException;
|
||||
@@ -75,19 +75,19 @@ public final class Decoder {
|
||||
|
||||
private static final Charset DEFAULT_ENCODING = StandardCharsets.ISO_8859_1;
|
||||
|
||||
private AztecDetectorResult ddata;
|
||||
private AztecDetectorRXingResult ddata;
|
||||
|
||||
public DecoderResult decode(AztecDetectorResult detectorResult) throws FormatException {
|
||||
ddata = detectorResult;
|
||||
BitMatrix matrix = detectorResult.getBits();
|
||||
public DecoderRXingResult decode(AztecDetectorRXingResult detectorRXingResult) throws FormatException {
|
||||
ddata = detectorRXingResult;
|
||||
BitMatrix matrix = detectorRXingResult.getBits();
|
||||
boolean[] rawbits = extractBits(matrix);
|
||||
CorrectedBitsResult correctedBits = correctBits(rawbits);
|
||||
CorrectedBitsRXingResult correctedBits = correctBits(rawbits);
|
||||
byte[] rawBytes = convertBoolArrayToByteArray(correctedBits.correctBits);
|
||||
String result = getEncodedData(correctedBits.correctBits);
|
||||
DecoderResult decoderResult =
|
||||
new DecoderResult(rawBytes, result, null, String.format("%d%%", correctedBits.ecLevel));
|
||||
decoderResult.setNumBits(correctedBits.correctBits.length);
|
||||
return decoderResult;
|
||||
DecoderRXingResult decoderRXingResult =
|
||||
new DecoderRXingResult(rawBytes, result, null, String.format("%d%%", correctedBits.ecLevel));
|
||||
decoderRXingResult.setNumBits(correctedBits.correctBits.length);
|
||||
return decoderRXingResult;
|
||||
}
|
||||
|
||||
// This method is used for testing the high-level encoder
|
||||
@@ -262,11 +262,11 @@ public final class Decoder {
|
||||
}
|
||||
}
|
||||
|
||||
static final class CorrectedBitsResult {
|
||||
static final class CorrectedBitsRXingResult {
|
||||
private final boolean[] correctBits;
|
||||
private final int ecLevel;
|
||||
|
||||
CorrectedBitsResult(boolean[] correctBits, int ecLevel) {
|
||||
CorrectedBitsRXingResult(boolean[] correctBits, int ecLevel) {
|
||||
this.correctBits = correctBits;
|
||||
this.ecLevel = ecLevel;
|
||||
}
|
||||
@@ -278,7 +278,7 @@ public final class Decoder {
|
||||
* @return the corrected array
|
||||
* @throws FormatException if the input contains too many errors
|
||||
*/
|
||||
private CorrectedBitsResult correctBits(boolean[] rawbits) throws FormatException {
|
||||
private CorrectedBitsRXingResult correctBits(boolean[] rawbits) throws FormatException {
|
||||
GenericGF gf;
|
||||
int codewordSize;
|
||||
|
||||
@@ -343,7 +343,7 @@ public final class Decoder {
|
||||
}
|
||||
}
|
||||
|
||||
return new CorrectedBitsResult(correctedBits, 100 * (numCodewords - numDataCodewords) / numCodewords);
|
||||
return new CorrectedBitsRXingResult(correctedBits, 100 * (numCodewords - numDataCodewords) / numCodewords);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package com.google.zxing.aztec.detector;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.aztec.AztecDetectorResult;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.aztec.AztecDetectorRXingResult;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.GridSampler;
|
||||
import com.google.zxing.common.detector.MathUtils;
|
||||
@@ -55,7 +55,7 @@ public final class Detector {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public AztecDetectorResult detect() throws NotFoundException {
|
||||
public AztecDetectorRXingResult detect() throws NotFoundException {
|
||||
return detect(false);
|
||||
}
|
||||
|
||||
@@ -63,20 +63,20 @@ public final class Detector {
|
||||
* Detects an Aztec Code in an image.
|
||||
*
|
||||
* @param isMirror if true, image is a mirror-image of original
|
||||
* @return {@link AztecDetectorResult} encapsulating results of detecting an Aztec Code
|
||||
* @return {@link AztecDetectorRXingResult} encapsulating results of detecting an Aztec Code
|
||||
* @throws NotFoundException if no Aztec Code can be found
|
||||
*/
|
||||
public AztecDetectorResult detect(boolean isMirror) throws NotFoundException {
|
||||
public AztecDetectorRXingResult detect(boolean isMirror) throws NotFoundException {
|
||||
|
||||
// 1. Get the center of the aztec matrix
|
||||
Point pCenter = getMatrixCenter();
|
||||
|
||||
// 2. Get the center points of the four diagonal points just outside the bull's eye
|
||||
// [topRight, bottomRight, bottomLeft, topLeft]
|
||||
ResultPoint[] bullsEyeCorners = getBullsEyeCorners(pCenter);
|
||||
RXingResultPoint[] bullsEyeCorners = getBullsEyeCorners(pCenter);
|
||||
|
||||
if (isMirror) {
|
||||
ResultPoint temp = bullsEyeCorners[0];
|
||||
RXingResultPoint temp = bullsEyeCorners[0];
|
||||
bullsEyeCorners[0] = bullsEyeCorners[2];
|
||||
bullsEyeCorners[2] = temp;
|
||||
}
|
||||
@@ -92,9 +92,9 @@ public final class Detector {
|
||||
bullsEyeCorners[(shift + 3) % 4]);
|
||||
|
||||
// 5. Get the corners of the matrix.
|
||||
ResultPoint[] corners = getMatrixCornerPoints(bullsEyeCorners);
|
||||
RXingResultPoint[] corners = getMatrixCornerPoints(bullsEyeCorners);
|
||||
|
||||
return new AztecDetectorResult(bits, corners, compact, nbDataBlocks, nbLayers);
|
||||
return new AztecDetectorRXingResult(bits, corners, compact, nbDataBlocks, nbLayers);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +103,7 @@ public final class Detector {
|
||||
* @param bullsEyeCorners the array of bull's eye corners
|
||||
* @throws NotFoundException in case of too many errors or invalid parameters
|
||||
*/
|
||||
private void extractParameters(ResultPoint[] bullsEyeCorners) throws NotFoundException {
|
||||
private void extractParameters(RXingResultPoint[] bullsEyeCorners) throws NotFoundException {
|
||||
if (!isValid(bullsEyeCorners[0]) || !isValid(bullsEyeCorners[1]) ||
|
||||
!isValid(bullsEyeCorners[2]) || !isValid(bullsEyeCorners[3])) {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
@@ -232,7 +232,7 @@ public final class Detector {
|
||||
* @return The corners of the bull-eye
|
||||
* @throws NotFoundException If no valid bull-eye can be found
|
||||
*/
|
||||
private ResultPoint[] getBullsEyeCorners(Point pCenter) throws NotFoundException {
|
||||
private RXingResultPoint[] getBullsEyeCorners(Point pCenter) throws NotFoundException {
|
||||
|
||||
Point pina = pCenter;
|
||||
Point pinb = pCenter;
|
||||
@@ -274,14 +274,14 @@ public final class Detector {
|
||||
|
||||
// Expand the square by .5 pixel in each direction so that we're on the border
|
||||
// between the white square and the black square
|
||||
ResultPoint pinax = new ResultPoint(pina.getX() + 0.5f, pina.getY() - 0.5f);
|
||||
ResultPoint pinbx = new ResultPoint(pinb.getX() + 0.5f, pinb.getY() + 0.5f);
|
||||
ResultPoint pincx = new ResultPoint(pinc.getX() - 0.5f, pinc.getY() + 0.5f);
|
||||
ResultPoint pindx = new ResultPoint(pind.getX() - 0.5f, pind.getY() - 0.5f);
|
||||
RXingResultPoint pinax = new RXingResultPoint(pina.getX() + 0.5f, pina.getY() - 0.5f);
|
||||
RXingResultPoint pinbx = new RXingResultPoint(pinb.getX() + 0.5f, pinb.getY() + 0.5f);
|
||||
RXingResultPoint pincx = new RXingResultPoint(pinc.getX() - 0.5f, pinc.getY() + 0.5f);
|
||||
RXingResultPoint pindx = new RXingResultPoint(pind.getX() - 0.5f, pind.getY() - 0.5f);
|
||||
|
||||
// Expand the square so that its corners are the centers of the points
|
||||
// just outside the bull's eye.
|
||||
return expandSquare(new ResultPoint[]{pinax, pinbx, pincx, pindx},
|
||||
return expandSquare(new RXingResultPoint[]{pinax, pinbx, pincx, pindx},
|
||||
2 * nbCenterLayers - 3,
|
||||
2 * nbCenterLayers);
|
||||
}
|
||||
@@ -293,15 +293,15 @@ public final class Detector {
|
||||
*/
|
||||
private Point getMatrixCenter() {
|
||||
|
||||
ResultPoint pointA;
|
||||
ResultPoint pointB;
|
||||
ResultPoint pointC;
|
||||
ResultPoint pointD;
|
||||
RXingResultPoint pointA;
|
||||
RXingResultPoint pointB;
|
||||
RXingResultPoint pointC;
|
||||
RXingResultPoint pointD;
|
||||
|
||||
//Get a white rectangle that can be the border of the matrix in center bull's eye or
|
||||
try {
|
||||
|
||||
ResultPoint[] cornerPoints = new WhiteRectangleDetector(image).detect();
|
||||
RXingResultPoint[] cornerPoints = new WhiteRectangleDetector(image).detect();
|
||||
pointA = cornerPoints[0];
|
||||
pointB = cornerPoints[1];
|
||||
pointC = cornerPoints[2];
|
||||
@@ -313,10 +313,10 @@ public final class Detector {
|
||||
// In that case, surely in the bull's eye, we try to expand the rectangle.
|
||||
int cx = image.getWidth() / 2;
|
||||
int cy = image.getHeight() / 2;
|
||||
pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toResultPoint();
|
||||
pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toResultPoint();
|
||||
pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toResultPoint();
|
||||
pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toResultPoint();
|
||||
pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toRXingResultPoint();
|
||||
pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toRXingResultPoint();
|
||||
pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toRXingResultPoint();
|
||||
pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toRXingResultPoint();
|
||||
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ public final class Detector {
|
||||
// This will ensure that we end up with a white rectangle in center bull's eye
|
||||
// in order to compute a more accurate center.
|
||||
try {
|
||||
ResultPoint[] cornerPoints = new WhiteRectangleDetector(image, 15, cx, cy).detect();
|
||||
RXingResultPoint[] cornerPoints = new WhiteRectangleDetector(image, 15, cx, cy).detect();
|
||||
pointA = cornerPoints[0];
|
||||
pointB = cornerPoints[1];
|
||||
pointC = cornerPoints[2];
|
||||
@@ -336,10 +336,10 @@ public final class Detector {
|
||||
} catch (NotFoundException e) {
|
||||
// This exception can be in case the initial rectangle is white
|
||||
// In that case we try to expand the rectangle.
|
||||
pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toResultPoint();
|
||||
pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toResultPoint();
|
||||
pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toResultPoint();
|
||||
pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toResultPoint();
|
||||
pointA = getFirstDifferent(new Point(cx + 7, cy - 7), false, 1, -1).toRXingResultPoint();
|
||||
pointB = getFirstDifferent(new Point(cx + 7, cy + 7), false, 1, 1).toRXingResultPoint();
|
||||
pointC = getFirstDifferent(new Point(cx - 7, cy + 7), false, -1, 1).toRXingResultPoint();
|
||||
pointD = getFirstDifferent(new Point(cx - 7, cy - 7), false, -1, -1).toRXingResultPoint();
|
||||
}
|
||||
|
||||
// Recompute the center of the rectangle
|
||||
@@ -355,7 +355,7 @@ public final class Detector {
|
||||
* @param bullsEyeCorners the array of bull's eye corners
|
||||
* @return the array of aztec code corners
|
||||
*/
|
||||
private ResultPoint[] getMatrixCornerPoints(ResultPoint[] bullsEyeCorners) {
|
||||
private RXingResultPoint[] getMatrixCornerPoints(RXingResultPoint[] bullsEyeCorners) {
|
||||
return expandSquare(bullsEyeCorners, 2 * nbCenterLayers, getDimension());
|
||||
}
|
||||
|
||||
@@ -365,10 +365,10 @@ public final class Detector {
|
||||
* diagonal just outside the bull's eye.
|
||||
*/
|
||||
private BitMatrix sampleGrid(BitMatrix image,
|
||||
ResultPoint topLeft,
|
||||
ResultPoint topRight,
|
||||
ResultPoint bottomRight,
|
||||
ResultPoint bottomLeft) throws NotFoundException {
|
||||
RXingResultPoint topLeft,
|
||||
RXingResultPoint topRight,
|
||||
RXingResultPoint bottomRight,
|
||||
RXingResultPoint bottomLeft) throws NotFoundException {
|
||||
|
||||
GridSampler sampler = GridSampler.getInstance();
|
||||
int dimension = getDimension();
|
||||
@@ -397,7 +397,7 @@ public final class Detector {
|
||||
* @param size number of bits
|
||||
* @return the array of bits as an int (first bit is high-order bit of result)
|
||||
*/
|
||||
private int sampleLine(ResultPoint p1, ResultPoint p2, int size) {
|
||||
private int sampleLine(RXingResultPoint p1, RXingResultPoint p2, int size) {
|
||||
int result = 0;
|
||||
|
||||
float d = distance(p1, p2);
|
||||
@@ -529,31 +529,31 @@ public final class Detector {
|
||||
* @param newSide the new length of the size of the square in the target bit matrix
|
||||
* @return the corners of the expanded square
|
||||
*/
|
||||
private static ResultPoint[] expandSquare(ResultPoint[] cornerPoints, int oldSide, int newSide) {
|
||||
private static RXingResultPoint[] expandSquare(RXingResultPoint[] cornerPoints, int oldSide, int newSide) {
|
||||
float ratio = newSide / (2.0f * oldSide);
|
||||
float dx = cornerPoints[0].getX() - cornerPoints[2].getX();
|
||||
float dy = cornerPoints[0].getY() - cornerPoints[2].getY();
|
||||
float centerx = (cornerPoints[0].getX() + cornerPoints[2].getX()) / 2.0f;
|
||||
float centery = (cornerPoints[0].getY() + cornerPoints[2].getY()) / 2.0f;
|
||||
|
||||
ResultPoint result0 = new ResultPoint(centerx + ratio * dx, centery + ratio * dy);
|
||||
ResultPoint result2 = new ResultPoint(centerx - ratio * dx, centery - ratio * dy);
|
||||
RXingResultPoint result0 = new RXingResultPoint(centerx + ratio * dx, centery + ratio * dy);
|
||||
RXingResultPoint result2 = new RXingResultPoint(centerx - ratio * dx, centery - ratio * dy);
|
||||
|
||||
dx = cornerPoints[1].getX() - cornerPoints[3].getX();
|
||||
dy = cornerPoints[1].getY() - cornerPoints[3].getY();
|
||||
centerx = (cornerPoints[1].getX() + cornerPoints[3].getX()) / 2.0f;
|
||||
centery = (cornerPoints[1].getY() + cornerPoints[3].getY()) / 2.0f;
|
||||
ResultPoint result1 = new ResultPoint(centerx + ratio * dx, centery + ratio * dy);
|
||||
ResultPoint result3 = new ResultPoint(centerx - ratio * dx, centery - ratio * dy);
|
||||
RXingResultPoint result1 = new RXingResultPoint(centerx + ratio * dx, centery + ratio * dy);
|
||||
RXingResultPoint result3 = new RXingResultPoint(centerx - ratio * dx, centery - ratio * dy);
|
||||
|
||||
return new ResultPoint[]{result0, result1, result2, result3};
|
||||
return new RXingResultPoint[]{result0, result1, result2, result3};
|
||||
}
|
||||
|
||||
private boolean isValid(int x, int y) {
|
||||
return x >= 0 && x < image.getWidth() && y >= 0 && y < image.getHeight();
|
||||
}
|
||||
|
||||
private boolean isValid(ResultPoint point) {
|
||||
private boolean isValid(RXingResultPoint point) {
|
||||
int x = MathUtils.round(point.getX());
|
||||
int y = MathUtils.round(point.getY());
|
||||
return isValid(x, y);
|
||||
@@ -563,7 +563,7 @@ public final class Detector {
|
||||
return MathUtils.distance(a.getX(), a.getY(), b.getX(), b.getY());
|
||||
}
|
||||
|
||||
private static float distance(ResultPoint a, ResultPoint b) {
|
||||
private static float distance(RXingResultPoint a, RXingResultPoint b) {
|
||||
return MathUtils.distance(a.getX(), a.getY(), b.getX(), b.getY());
|
||||
}
|
||||
|
||||
@@ -578,8 +578,8 @@ public final class Detector {
|
||||
private final int x;
|
||||
private final int y;
|
||||
|
||||
ResultPoint toResultPoint() {
|
||||
return new ResultPoint(x, y);
|
||||
RXingResultPoint toRXingResultPoint() {
|
||||
return new RXingResultPoint(x, y);
|
||||
}
|
||||
|
||||
Point(int x, int y) {
|
||||
|
||||
@@ -26,7 +26,7 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
abstract class AbstractDoCoMoResultParser extends ResultParser {
|
||||
abstract class AbstractDoCoMoRXingResultParser extends RXingResultParser {
|
||||
|
||||
static String[] matchDoCoMoPrefixedField(String prefix, String rawText) {
|
||||
return matchPrefixedField(prefix, rawText, ';', true);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -29,10 +29,10 @@ import java.util.List;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class AddressBookAUResultParser extends ResultParser {
|
||||
public final class AddressBookAURXingResultParser extends RXingResultParser {
|
||||
|
||||
@Override
|
||||
public AddressBookParsedResult parse(Result result) {
|
||||
public AddressBookParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
// MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF
|
||||
if (!rawText.contains("MEMORY") || !rawText.contains("\r\n")) {
|
||||
@@ -49,7 +49,7 @@ public final class AddressBookAUResultParser extends ResultParser {
|
||||
String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
|
||||
String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
|
||||
String[] addresses = address == null ? null : new String[] {address};
|
||||
return new AddressBookParsedResult(maybeWrap(name),
|
||||
return new AddressBookParsedRXingResult(maybeWrap(name),
|
||||
null,
|
||||
pronunciation,
|
||||
phoneNumbers,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
/**
|
||||
* Implements the "MECARD" address book entry format.
|
||||
@@ -33,10 +33,10 @@ import com.google.zxing.Result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
||||
public final class AddressBookDoCoMoRXingResultParser extends AbstractDoCoMoRXingResultParser {
|
||||
|
||||
@Override
|
||||
public AddressBookParsedResult parse(Result result) {
|
||||
public AddressBookParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("MECARD:")) {
|
||||
return null;
|
||||
@@ -62,7 +62,7 @@ public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultPar
|
||||
// honor it when found in the wild.
|
||||
String org = matchSingleDoCoMoPrefixedField("ORG:", rawText, true);
|
||||
|
||||
return new AddressBookParsedResult(maybeWrap(name),
|
||||
return new AddressBookParsedRXingResult(maybeWrap(name),
|
||||
null,
|
||||
pronunciation,
|
||||
phoneNumbers,
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class AddressBookParsedResult extends ParsedResult {
|
||||
public final class AddressBookParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String[] names;
|
||||
private final String[] nicknames;
|
||||
@@ -41,7 +41,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
||||
private final String[] urls;
|
||||
private final String[] geo;
|
||||
|
||||
public AddressBookParsedResult(String[] names,
|
||||
public AddressBookParsedRXingResult(String[] names,
|
||||
String[] phoneNumbers,
|
||||
String[] phoneTypes,
|
||||
String[] emails,
|
||||
@@ -66,7 +66,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
||||
null);
|
||||
}
|
||||
|
||||
public AddressBookParsedResult(String[] names,
|
||||
public AddressBookParsedRXingResult(String[] names,
|
||||
String[] nicknames,
|
||||
String pronunciation,
|
||||
String[] phoneNumbers,
|
||||
@@ -82,7 +82,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
||||
String title,
|
||||
String[] urls,
|
||||
String[] geo) {
|
||||
super(ParsedResultType.ADDRESSBOOK);
|
||||
super(ParsedRXingResultType.ADDRESSBOOK);
|
||||
if (phoneNumbers != null && phoneTypes != null && phoneNumbers.length != phoneTypes.length) {
|
||||
throw new IllegalArgumentException("Phone numbers and types lengths differ");
|
||||
}
|
||||
@@ -199,7 +199,7 @@ public final class AddressBookParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
StringBuilder result = new StringBuilder(100);
|
||||
maybeAppend(names, result);
|
||||
maybeAppend(nicknames, result);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -28,14 +28,14 @@ import java.util.List;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class BizcardResultParser extends AbstractDoCoMoResultParser {
|
||||
public final class BizcardRXingResultParser extends AbstractDoCoMoRXingResultParser {
|
||||
|
||||
// Yes, we extend AbstractDoCoMoResultParser since the format is very much
|
||||
// Yes, we extend AbstractDoCoMoRXingResultParser since the format is very much
|
||||
// like the DoCoMo MECARD format, but this is not technically one of
|
||||
// DoCoMo's proposed formats
|
||||
|
||||
@Override
|
||||
public AddressBookParsedResult parse(Result result) {
|
||||
public AddressBookParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("BIZCARD:")) {
|
||||
return null;
|
||||
@@ -51,7 +51,7 @@ public final class BizcardResultParser extends AbstractDoCoMoResultParser {
|
||||
String phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);
|
||||
String email = matchSingleDoCoMoPrefixedField("E:", rawText, true);
|
||||
|
||||
return new AddressBookParsedResult(maybeWrap(fullName),
|
||||
return new AddressBookParsedRXingResult(maybeWrap(fullName),
|
||||
null,
|
||||
null,
|
||||
buildPhoneNumbers(phoneNumber1, phoneNumber2, phoneNumber3),
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class BookmarkDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
||||
public final class BookmarkDoCoMoRXingResultParser extends AbstractDoCoMoRXingResultParser {
|
||||
|
||||
@Override
|
||||
public URIParsedResult parse(Result result) {
|
||||
public URIParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith("MEBKM:")) {
|
||||
return null;
|
||||
@@ -35,7 +35,7 @@ public final class BookmarkDoCoMoResultParser extends AbstractDoCoMoResultParser
|
||||
return null;
|
||||
}
|
||||
String uri = rawUri[0];
|
||||
return URIResultParser.isBasicallyValidURI(uri) ? new URIParsedResult(uri, title) : null;
|
||||
return URIRXingResultParser.isBasicallyValidURI(uri) ? new URIParsedRXingResult(uri, title) : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class CalendarParsedResult extends ParsedResult {
|
||||
public final class CalendarParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private static final Pattern RFC2445_DURATION =
|
||||
Pattern.compile("P(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?");
|
||||
@@ -59,7 +59,7 @@ public final class CalendarParsedResult extends ParsedResult {
|
||||
private final double latitude;
|
||||
private final double longitude;
|
||||
|
||||
public CalendarParsedResult(String summary,
|
||||
public CalendarParsedRXingResult(String summary,
|
||||
String startString,
|
||||
String endString,
|
||||
String durationString,
|
||||
@@ -69,7 +69,7 @@ public final class CalendarParsedResult extends ParsedResult {
|
||||
String description,
|
||||
double latitude,
|
||||
double longitude) {
|
||||
super(ParsedResultType.CALENDAR);
|
||||
super(ParsedRXingResultType.CALENDAR);
|
||||
this.summary = summary;
|
||||
|
||||
try {
|
||||
@@ -177,7 +177,7 @@ public final class CalendarParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
StringBuilder result = new StringBuilder(100);
|
||||
maybeAppend(summary, result);
|
||||
maybeAppend(format(startAllDay, start), result);
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EmailAddressParsedResult extends ParsedResult {
|
||||
public final class EmailAddressParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String[] tos;
|
||||
private final String[] ccs;
|
||||
@@ -30,16 +30,16 @@ public final class EmailAddressParsedResult extends ParsedResult {
|
||||
private final String subject;
|
||||
private final String body;
|
||||
|
||||
EmailAddressParsedResult(String to) {
|
||||
EmailAddressParsedRXingResult(String to) {
|
||||
this(new String[] {to}, null, null, null, null);
|
||||
}
|
||||
|
||||
EmailAddressParsedResult(String[] tos,
|
||||
EmailAddressParsedRXingResult(String[] tos,
|
||||
String[] ccs,
|
||||
String[] bccs,
|
||||
String subject,
|
||||
String body) {
|
||||
super(ParsedResultType.EMAIL_ADDRESS);
|
||||
super(ParsedRXingResultType.EMAIL_ADDRESS);
|
||||
this.tos = tos;
|
||||
this.ccs = ccs;
|
||||
this.bccs = bccs;
|
||||
@@ -86,7 +86,7 @@ public final class EmailAddressParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
StringBuilder result = new StringBuilder(30);
|
||||
maybeAppend(tos, result);
|
||||
maybeAppend(ccs, result);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -27,12 +27,12 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EmailAddressResultParser extends ResultParser {
|
||||
public final class EmailAddressRXingResultParser extends RXingResultParser {
|
||||
|
||||
private static final Pattern COMMA = Pattern.compile(",");
|
||||
|
||||
@Override
|
||||
public EmailAddressParsedResult parse(Result result) {
|
||||
public EmailAddressParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (rawText.startsWith("mailto:") || rawText.startsWith("MAILTO:")) {
|
||||
// If it starts with mailto:, assume it is definitely trying to be an email address
|
||||
@@ -73,12 +73,12 @@ public final class EmailAddressResultParser extends ResultParser {
|
||||
subject = nameValues.get("subject");
|
||||
body = nameValues.get("body");
|
||||
}
|
||||
return new EmailAddressParsedResult(tos, ccs, bccs, subject, body);
|
||||
return new EmailAddressParsedRXingResult(tos, ccs, bccs, subject, body);
|
||||
} else {
|
||||
if (!EmailDoCoMoResultParser.isBasicallyValidEmailAddress(rawText)) {
|
||||
if (!EmailDoCoMoRXingResultParser.isBasicallyValidEmailAddress(rawText)) {
|
||||
return null;
|
||||
}
|
||||
return new EmailAddressParsedResult(rawText);
|
||||
return new EmailAddressParsedRXingResult(rawText);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -27,12 +27,12 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class EmailDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
||||
public final class EmailDoCoMoRXingResultParser extends AbstractDoCoMoRXingResultParser {
|
||||
|
||||
private static final Pattern ATEXT_ALPHANUMERIC = Pattern.compile("[a-zA-Z0-9@.!#$%&'*+\\-/=?^_`{|}~]+");
|
||||
|
||||
@Override
|
||||
public EmailAddressParsedResult parse(Result result) {
|
||||
public EmailAddressParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("MATMSG:")) {
|
||||
return null;
|
||||
@@ -48,7 +48,7 @@ public final class EmailDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
||||
}
|
||||
String subject = matchSingleDoCoMoPrefixedField("SUB:", rawText, false);
|
||||
String body = matchSingleDoCoMoPrefixedField("BODY:", rawText, false);
|
||||
return new EmailAddressParsedResult(tos, null, null, subject, body);
|
||||
return new EmailAddressParsedRXingResult(tos, null, null, subject, body);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.Objects;
|
||||
* @author Antonio Manuel Benjumea Conde, Servinform, S.A.
|
||||
* @author Agustín Delgado, Servinform, S.A.
|
||||
*/
|
||||
public final class ExpandedProductParsedResult extends ParsedResult {
|
||||
public final class ExpandedProductParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
public static final String KILOGRAM = "KG";
|
||||
public static final String POUND = "LB";
|
||||
@@ -58,7 +58,7 @@ public final class ExpandedProductParsedResult extends ParsedResult {
|
||||
// For AIS that not exist in this object
|
||||
private final Map<String,String> uncommonAIs;
|
||||
|
||||
public ExpandedProductParsedResult(String rawText,
|
||||
public ExpandedProductParsedRXingResult(String rawText,
|
||||
String productID,
|
||||
String sscc,
|
||||
String lotNumber,
|
||||
@@ -73,7 +73,7 @@ public final class ExpandedProductParsedResult extends ParsedResult {
|
||||
String priceIncrement,
|
||||
String priceCurrency,
|
||||
Map<String,String> uncommonAIs) {
|
||||
super(ParsedResultType.PRODUCT);
|
||||
super(ParsedRXingResultType.PRODUCT);
|
||||
this.rawText = rawText;
|
||||
this.productID = productID;
|
||||
this.sscc = sscc;
|
||||
@@ -93,11 +93,11 @@ public final class ExpandedProductParsedResult extends ParsedResult {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof ExpandedProductParsedResult)) {
|
||||
if (!(o instanceof ExpandedProductParsedRXingResult)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ExpandedProductParsedResult other = (ExpandedProductParsedResult) o;
|
||||
ExpandedProductParsedRXingResult other = (ExpandedProductParsedRXingResult) o;
|
||||
|
||||
return Objects.equals(productID, other.productID)
|
||||
&& Objects.equals(sscc, other.sscc)
|
||||
@@ -193,7 +193,7 @@ public final class ExpandedProductParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
return String.valueOf(rawText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
/**
|
||||
* Parses strings of digits that represent a RSS Extended code.
|
||||
@@ -38,13 +38,13 @@ import com.google.zxing.Result;
|
||||
* @author Antonio Manuel Benjumea Conde, Servinform, S.A.
|
||||
* @author Agustín Delgado, Servinform, S.A.
|
||||
*/
|
||||
public final class ExpandedProductResultParser extends ResultParser {
|
||||
public final class ExpandedProductRXingResultParser extends RXingResultParser {
|
||||
|
||||
@Override
|
||||
public ExpandedProductParsedResult parse(Result result) {
|
||||
public ExpandedProductParsedRXingResult parse(RXingResult result) {
|
||||
BarcodeFormat format = result.getBarcodeFormat();
|
||||
if (format != BarcodeFormat.RSS_EXPANDED) {
|
||||
// ExtendedProductParsedResult NOT created. Not a RSS Expanded barcode
|
||||
// ExtendedProductParsedRXingResult NOT created. Not a RSS Expanded barcode
|
||||
return null;
|
||||
}
|
||||
String rawText = getMassagedText(result);
|
||||
@@ -70,7 +70,7 @@ public final class ExpandedProductResultParser extends ResultParser {
|
||||
String ai = findAIvalue(i, rawText);
|
||||
if (ai == null) {
|
||||
// Error. Code doesn't match with RSS expanded pattern
|
||||
// ExtendedProductParsedResult NOT created. Not match with RSS Expanded pattern
|
||||
// ExtendedProductParsedRXingResult NOT created. Not match with RSS Expanded pattern
|
||||
return null;
|
||||
}
|
||||
i += ai.length() + 2;
|
||||
@@ -110,7 +110,7 @@ public final class ExpandedProductResultParser extends ResultParser {
|
||||
case "3108":
|
||||
case "3109":
|
||||
weight = value;
|
||||
weightType = ExpandedProductParsedResult.KILOGRAM;
|
||||
weightType = ExpandedProductParsedRXingResult.KILOGRAM;
|
||||
weightIncrement = ai.substring(3);
|
||||
break;
|
||||
case "3200":
|
||||
@@ -124,7 +124,7 @@ public final class ExpandedProductResultParser extends ResultParser {
|
||||
case "3208":
|
||||
case "3209":
|
||||
weight = value;
|
||||
weightType = ExpandedProductParsedResult.POUND;
|
||||
weightType = ExpandedProductParsedRXingResult.POUND;
|
||||
weightIncrement = ai.substring(3);
|
||||
break;
|
||||
case "3920":
|
||||
@@ -141,7 +141,7 @@ public final class ExpandedProductResultParser extends ResultParser {
|
||||
if (value.length() < 4) {
|
||||
// The value must have more of 3 symbols (3 for currency and
|
||||
// 1 at least for the price)
|
||||
// ExtendedProductParsedResult NOT created. Not match with RSS Expanded pattern
|
||||
// ExtendedProductParsedRXingResult NOT created. Not match with RSS Expanded pattern
|
||||
return null;
|
||||
}
|
||||
price = value.substring(3);
|
||||
@@ -155,7 +155,7 @@ public final class ExpandedProductResultParser extends ResultParser {
|
||||
}
|
||||
}
|
||||
|
||||
return new ExpandedProductParsedResult(rawText,
|
||||
return new ExpandedProductParsedRXingResult(rawText,
|
||||
productID,
|
||||
sscc,
|
||||
lotNumber,
|
||||
|
||||
@@ -22,15 +22,15 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class GeoParsedResult extends ParsedResult {
|
||||
public final class GeoParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final double latitude;
|
||||
private final double longitude;
|
||||
private final double altitude;
|
||||
private final String query;
|
||||
|
||||
GeoParsedResult(double latitude, double longitude, double altitude, String query) {
|
||||
super(ParsedResultType.GEO);
|
||||
GeoParsedRXingResult(double latitude, double longitude, double altitude, String query) {
|
||||
super(ParsedRXingResultType.GEO);
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.altitude = altitude;
|
||||
@@ -83,7 +83,7 @@ public final class GeoParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
StringBuilder result = new StringBuilder(20);
|
||||
result.append(latitude);
|
||||
result.append(", ");
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -29,13 +29,13 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class GeoResultParser extends ResultParser {
|
||||
public final class GeoRXingResultParser extends RXingResultParser {
|
||||
|
||||
private static final Pattern GEO_URL_PATTERN =
|
||||
Pattern.compile("geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@Override
|
||||
public GeoParsedResult parse(Result result) {
|
||||
public GeoParsedRXingResult parse(RXingResult result) {
|
||||
CharSequence rawText = getMassagedText(result);
|
||||
Matcher matcher = GEO_URL_PATTERN.matcher(rawText);
|
||||
if (!matcher.matches()) {
|
||||
@@ -67,7 +67,7 @@ public final class GeoResultParser extends ResultParser {
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
return new GeoParsedResult(latitude, longitude, altitude, query);
|
||||
return new GeoParsedRXingResult(latitude, longitude, altitude, query);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,12 +21,12 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author jbreiden@google.com (Jeff Breidenbach)
|
||||
*/
|
||||
public final class ISBNParsedResult extends ParsedResult {
|
||||
public final class ISBNParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String isbn;
|
||||
|
||||
ISBNParsedResult(String isbn) {
|
||||
super(ParsedResultType.ISBN);
|
||||
ISBNParsedRXingResult(String isbn) {
|
||||
super(ParsedRXingResultType.ISBN);
|
||||
this.isbn = isbn;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public final class ISBNParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
return isbn;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,20 +17,20 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
/**
|
||||
* Parses strings of digits that represent a ISBN.
|
||||
*
|
||||
* @author jbreiden@google.com (Jeff Breidenbach)
|
||||
*/
|
||||
public final class ISBNResultParser extends ResultParser {
|
||||
public final class ISBNRXingResultParser extends RXingResultParser {
|
||||
|
||||
/**
|
||||
* See <a href="http://www.bisg.org/isbn-13/for.dummies.html">ISBN-13 For Dummies</a>
|
||||
*/
|
||||
@Override
|
||||
public ISBNParsedResult parse(Result result) {
|
||||
public ISBNParsedRXingResult parse(RXingResult result) {
|
||||
BarcodeFormat format = result.getBarcodeFormat();
|
||||
if (format != BarcodeFormat.EAN_13) {
|
||||
return null;
|
||||
@@ -44,7 +44,7 @@ public final class ISBNResultParser extends ResultParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ISBNParsedResult(rawText);
|
||||
return new ISBNParsedRXingResult(rawText);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.google.zxing.client.result;
|
||||
/**
|
||||
* <p>Abstract class representing the result of decoding a barcode, as more than
|
||||
* a String -- as some type of structured data. This might be a subclass which represents
|
||||
* a URL, or an e-mail address. {@link ResultParser#parseResult(com.google.zxing.Result)} will turn a raw
|
||||
* a URL, or an e-mail address. {@link RXingResultParser#parseRXingResult(com.google.zxing.RXingResult)} will turn a raw
|
||||
* decoded string into the most appropriate type of structured representation.</p>
|
||||
*
|
||||
* <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
|
||||
@@ -27,23 +27,23 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public abstract class ParsedResult {
|
||||
public abstract class ParsedRXingResult {
|
||||
|
||||
private final ParsedResultType type;
|
||||
private final ParsedRXingResultType type;
|
||||
|
||||
protected ParsedResult(ParsedResultType type) {
|
||||
protected ParsedRXingResult(ParsedRXingResultType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public final ParsedResultType getType() {
|
||||
public final ParsedRXingResultType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public abstract String getDisplayResult();
|
||||
public abstract String getDisplayRXingResult();
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return getDisplayResult();
|
||||
return getDisplayRXingResult();
|
||||
}
|
||||
|
||||
public static void maybeAppend(String value, StringBuilder result) {
|
||||
|
||||
@@ -22,7 +22,7 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public enum ParsedResultType {
|
||||
public enum ParsedRXingResultType {
|
||||
|
||||
ADDRESSBOOK,
|
||||
EMAIL_ADDRESS,
|
||||
|
||||
@@ -21,17 +21,17 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class ProductParsedResult extends ParsedResult {
|
||||
public final class ProductParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String productID;
|
||||
private final String normalizedProductID;
|
||||
|
||||
ProductParsedResult(String productID) {
|
||||
ProductParsedRXingResult(String productID) {
|
||||
this(productID, productID);
|
||||
}
|
||||
|
||||
ProductParsedResult(String productID, String normalizedProductID) {
|
||||
super(ParsedResultType.PRODUCT);
|
||||
ProductParsedRXingResult(String productID, String normalizedProductID) {
|
||||
super(ParsedRXingResultType.PRODUCT);
|
||||
this.productID = productID;
|
||||
this.normalizedProductID = normalizedProductID;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public final class ProductParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
return productID;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.oned.UPCEReader;
|
||||
|
||||
/**
|
||||
@@ -25,11 +25,11 @@ import com.google.zxing.oned.UPCEReader;
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class ProductResultParser extends ResultParser {
|
||||
public final class ProductRXingResultParser extends RXingResultParser {
|
||||
|
||||
// Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes.
|
||||
@Override
|
||||
public ProductParsedResult parse(Result result) {
|
||||
public ProductParsedRXingResult parse(RXingResult result) {
|
||||
BarcodeFormat format = result.getBarcodeFormat();
|
||||
if (!(format == BarcodeFormat.UPC_A || format == BarcodeFormat.UPC_E ||
|
||||
format == BarcodeFormat.EAN_8 || format == BarcodeFormat.EAN_13)) {
|
||||
@@ -49,7 +49,7 @@ public final class ProductResultParser extends ResultParser {
|
||||
normalizedProductID = rawText;
|
||||
}
|
||||
|
||||
return new ProductParsedResult(rawText, normalizedProductID);
|
||||
return new ProductParsedRXingResult(rawText, normalizedProductID);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
@@ -29,7 +29,7 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* <p>Abstract class representing the result of decoding a barcode, as more than
|
||||
* a String -- as some type of structured data. This might be a subclass which represents
|
||||
* a URL, or an e-mail address. {@link #parseResult(Result)} will turn a raw
|
||||
* a URL, or an e-mail address. {@link #parseRXingResult(RXingResult)} will turn a raw
|
||||
* decoded string into the most appropriate type of structured representation.</p>
|
||||
*
|
||||
* <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
|
||||
@@ -37,29 +37,29 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public abstract class ResultParser {
|
||||
public abstract class RXingResultParser {
|
||||
|
||||
private static final ResultParser[] PARSERS = {
|
||||
new BookmarkDoCoMoResultParser(),
|
||||
new AddressBookDoCoMoResultParser(),
|
||||
new EmailDoCoMoResultParser(),
|
||||
new AddressBookAUResultParser(),
|
||||
new VCardResultParser(),
|
||||
new BizcardResultParser(),
|
||||
new VEventResultParser(),
|
||||
new EmailAddressResultParser(),
|
||||
new SMTPResultParser(),
|
||||
new TelResultParser(),
|
||||
new SMSMMSResultParser(),
|
||||
new SMSTOMMSTOResultParser(),
|
||||
new GeoResultParser(),
|
||||
new WifiResultParser(),
|
||||
new URLTOResultParser(),
|
||||
new URIResultParser(),
|
||||
new ISBNResultParser(),
|
||||
new ProductResultParser(),
|
||||
new ExpandedProductResultParser(),
|
||||
new VINResultParser(),
|
||||
private static final RXingResultParser[] PARSERS = {
|
||||
new BookmarkDoCoMoRXingResultParser(),
|
||||
new AddressBookDoCoMoRXingResultParser(),
|
||||
new EmailDoCoMoRXingResultParser(),
|
||||
new AddressBookAURXingResultParser(),
|
||||
new VCardRXingResultParser(),
|
||||
new BizcardRXingResultParser(),
|
||||
new VEventRXingResultParser(),
|
||||
new EmailAddressRXingResultParser(),
|
||||
new SMTPRXingResultParser(),
|
||||
new TelRXingResultParser(),
|
||||
new SMSMMSRXingResultParser(),
|
||||
new SMSTOMMSTORXingResultParser(),
|
||||
new GeoRXingResultParser(),
|
||||
new WifiRXingResultParser(),
|
||||
new URLTORXingResultParser(),
|
||||
new URIRXingResultParser(),
|
||||
new ISBNRXingResultParser(),
|
||||
new ProductRXingResultParser(),
|
||||
new ExpandedProductRXingResultParser(),
|
||||
new VINRXingResultParser(),
|
||||
};
|
||||
|
||||
private static final Pattern DIGITS = Pattern.compile("\\d+");
|
||||
@@ -70,16 +70,16 @@ public abstract class ResultParser {
|
||||
static final String[] EMPTY_STR_ARRAY = new String[0];
|
||||
|
||||
/**
|
||||
* Attempts to parse the raw {@link Result}'s contents as a particular type
|
||||
* of information (email, URL, etc.) and return a {@link ParsedResult} encapsulating
|
||||
* Attempts to parse the raw {@link RXingResult}'s contents as a particular type
|
||||
* of information (email, URL, etc.) and return a {@link ParsedRXingResult} encapsulating
|
||||
* the result of parsing.
|
||||
*
|
||||
* @param theResult the raw {@link Result} to parse
|
||||
* @return {@link ParsedResult} encapsulating the parsing result
|
||||
* @param theRXingResult the raw {@link RXingResult} to parse
|
||||
* @return {@link ParsedRXingResult} encapsulating the parsing result
|
||||
*/
|
||||
public abstract ParsedResult parse(Result theResult);
|
||||
public abstract ParsedRXingResult parse(RXingResult theRXingResult);
|
||||
|
||||
protected static String getMassagedText(Result result) {
|
||||
protected static String getMassagedText(RXingResult result) {
|
||||
String text = result.getText();
|
||||
if (text.startsWith(BYTE_ORDER_MARK)) {
|
||||
text = text.substring(1);
|
||||
@@ -87,14 +87,14 @@ public abstract class ResultParser {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static ParsedResult parseResult(Result theResult) {
|
||||
for (ResultParser parser : PARSERS) {
|
||||
ParsedResult result = parser.parse(theResult);
|
||||
public static ParsedRXingResult parseRXingResult(RXingResult theRXingResult) {
|
||||
for (RXingResultParser parser : PARSERS) {
|
||||
ParsedRXingResult result = parser.parse(theRXingResult);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return new TextParsedResult(theResult.getText(), null);
|
||||
return new TextParsedRXingResult(theRXingResult.getText(), null);
|
||||
}
|
||||
|
||||
protected static void maybeAppend(String value, StringBuilder result) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -38,10 +38,10 @@ import java.util.Map;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class SMSMMSResultParser extends ResultParser {
|
||||
public final class SMSMMSRXingResultParser extends RXingResultParser {
|
||||
|
||||
@Override
|
||||
public SMSParsedResult parse(Result result) {
|
||||
public SMSParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (!(rawText.startsWith("sms:") || rawText.startsWith("SMS:") ||
|
||||
rawText.startsWith("mms:") || rawText.startsWith("MMS:"))) {
|
||||
@@ -80,7 +80,7 @@ public final class SMSMMSResultParser extends ResultParser {
|
||||
}
|
||||
addNumberVia(numbers, vias, smsURIWithoutQuery.substring(lastComma + 1));
|
||||
|
||||
return new SMSParsedResult(numbers.toArray(EMPTY_STR_ARRAY),
|
||||
return new SMSParsedRXingResult(numbers.toArray(EMPTY_STR_ARRAY),
|
||||
vias.toArray(EMPTY_STR_ARRAY),
|
||||
subject,
|
||||
body);
|
||||
|
||||
@@ -22,29 +22,29 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class SMSParsedResult extends ParsedResult {
|
||||
public final class SMSParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String[] numbers;
|
||||
private final String[] vias;
|
||||
private final String subject;
|
||||
private final String body;
|
||||
|
||||
public SMSParsedResult(String number,
|
||||
public SMSParsedRXingResult(String number,
|
||||
String via,
|
||||
String subject,
|
||||
String body) {
|
||||
super(ParsedResultType.SMS);
|
||||
super(ParsedRXingResultType.SMS);
|
||||
this.numbers = new String[] {number};
|
||||
this.vias = new String[] {via};
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public SMSParsedResult(String[] numbers,
|
||||
public SMSParsedRXingResult(String[] numbers,
|
||||
String[] vias,
|
||||
String subject,
|
||||
String body) {
|
||||
super(ParsedResultType.SMS);
|
||||
super(ParsedRXingResultType.SMS);
|
||||
this.numbers = numbers;
|
||||
this.vias = vias;
|
||||
this.subject = subject;
|
||||
@@ -103,7 +103,7 @@ public final class SMSParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
StringBuilder result = new StringBuilder(100);
|
||||
maybeAppend(numbers, result);
|
||||
maybeAppend(subject, result);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
/**
|
||||
* <p>Parses an "smsto:" URI result, whose format is not standardized but appears to be like:
|
||||
@@ -28,10 +28,10 @@ import com.google.zxing.Result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class SMSTOMMSTOResultParser extends ResultParser {
|
||||
public final class SMSTOMMSTORXingResultParser extends RXingResultParser {
|
||||
|
||||
@Override
|
||||
public SMSParsedResult parse(Result result) {
|
||||
public SMSParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (!(rawText.startsWith("smsto:") || rawText.startsWith("SMSTO:") ||
|
||||
rawText.startsWith("mmsto:") || rawText.startsWith("MMSTO:"))) {
|
||||
@@ -46,7 +46,7 @@ public final class SMSTOMMSTOResultParser extends ResultParser {
|
||||
body = number.substring(bodyStart + 1);
|
||||
number = number.substring(0, bodyStart);
|
||||
}
|
||||
return new SMSParsedResult(number, null, null, body);
|
||||
return new SMSParsedRXingResult(number, null, null, body);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
/**
|
||||
* <p>Parses an "smtp:" URI result, whose format is not standardized but appears to be like:
|
||||
@@ -24,10 +24,10 @@ import com.google.zxing.Result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class SMTPResultParser extends ResultParser {
|
||||
public final class SMTPRXingResultParser extends RXingResultParser {
|
||||
|
||||
@Override
|
||||
public EmailAddressParsedResult parse(Result result) {
|
||||
public EmailAddressParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (!(rawText.startsWith("smtp:") || rawText.startsWith("SMTP:"))) {
|
||||
return null;
|
||||
@@ -45,7 +45,7 @@ public final class SMTPResultParser extends ResultParser {
|
||||
subject = subject.substring(0, colon);
|
||||
}
|
||||
}
|
||||
return new EmailAddressParsedResult(new String[] {emailAddress},
|
||||
return new EmailAddressParsedRXingResult(new String[] {emailAddress},
|
||||
null,
|
||||
null,
|
||||
subject,
|
||||
|
||||
@@ -21,14 +21,14 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class TelParsedResult extends ParsedResult {
|
||||
public final class TelParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String number;
|
||||
private final String telURI;
|
||||
private final String title;
|
||||
|
||||
public TelParsedResult(String number, String telURI, String title) {
|
||||
super(ParsedResultType.TEL);
|
||||
public TelParsedRXingResult(String number, String telURI, String title) {
|
||||
super(ParsedRXingResultType.TEL);
|
||||
this.number = number;
|
||||
this.telURI = telURI;
|
||||
this.title = title;
|
||||
@@ -47,7 +47,7 @@ public final class TelParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
StringBuilder result = new StringBuilder(20);
|
||||
maybeAppend(number, result);
|
||||
maybeAppend(title, result);
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
/**
|
||||
* Parses a "tel:" URI result, which specifies a phone number.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class TelResultParser extends ResultParser {
|
||||
public final class TelRXingResultParser extends RXingResultParser {
|
||||
|
||||
@Override
|
||||
public TelParsedResult parse(Result result) {
|
||||
public TelParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("tel:") && !rawText.startsWith("TEL:")) {
|
||||
return null;
|
||||
@@ -36,7 +36,7 @@ public final class TelResultParser extends ResultParser {
|
||||
// Drop tel, query portion
|
||||
int queryStart = rawText.indexOf('?', 4);
|
||||
String number = queryStart < 0 ? rawText.substring(4) : rawText.substring(4, queryStart);
|
||||
return new TelParsedResult(number, telURI, null);
|
||||
return new TelParsedRXingResult(number, telURI, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,13 +22,13 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class TextParsedResult extends ParsedResult {
|
||||
public final class TextParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String text;
|
||||
private final String language;
|
||||
|
||||
public TextParsedResult(String text, String language) {
|
||||
super(ParsedResultType.TEXT);
|
||||
public TextParsedRXingResult(String text, String language) {
|
||||
super(ParsedRXingResultType.TEXT);
|
||||
this.text = text;
|
||||
this.language = language;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public final class TextParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class URIParsedResult extends ParsedResult {
|
||||
public final class URIParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String uri;
|
||||
private final String title;
|
||||
|
||||
public URIParsedResult(String uri, String title) {
|
||||
super(ParsedResultType.URI);
|
||||
public URIParsedRXingResult(String uri, String title) {
|
||||
super(ParsedRXingResultType.URI);
|
||||
this.uri = massageURI(uri);
|
||||
this.title = title;
|
||||
}
|
||||
@@ -43,15 +43,15 @@ public final class URIParsedResult extends ParsedResult {
|
||||
/**
|
||||
* @return true if the URI contains suspicious patterns that may suggest it intends to
|
||||
* mislead the user about its true nature
|
||||
* @deprecated see {@link URIResultParser#isPossiblyMaliciousURI(String)}
|
||||
* @deprecated see {@link URIRXingResultParser#isPossiblyMaliciousURI(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isPossiblyMaliciousURI() {
|
||||
return URIResultParser.isPossiblyMaliciousURI(uri);
|
||||
return URIRXingResultParser.isPossiblyMaliciousURI(uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
StringBuilder result = new StringBuilder(30);
|
||||
maybeAppend(title, result);
|
||||
maybeAppend(uri, result);
|
||||
@@ -79,7 +79,7 @@ public final class URIParsedResult extends ParsedResult {
|
||||
if (nextSlash < 0) {
|
||||
nextSlash = uri.length();
|
||||
}
|
||||
return ResultParser.isSubstringOfDigits(uri, start, nextSlash - start);
|
||||
return RXingResultParser.isSubstringOfDigits(uri, start, nextSlash - start);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -26,7 +26,7 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class URIResultParser extends ResultParser {
|
||||
public final class URIRXingResultParser extends RXingResultParser {
|
||||
|
||||
private static final Pattern ALLOWED_URI_CHARS_PATTERN =
|
||||
Pattern.compile("[-._~:/?#\\[\\]@!$&'()*+,;=%A-Za-z0-9]+");
|
||||
@@ -39,18 +39,18 @@ public final class URIResultParser extends ResultParser {
|
||||
"(/|\\?|$)"); // query, path or nothing
|
||||
|
||||
@Override
|
||||
public URIParsedResult parse(Result result) {
|
||||
public URIParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
// We specifically handle the odd "URL" scheme here for simplicity and add "URI" for fun
|
||||
// Assume anything starting this way really means to be a URI
|
||||
if (rawText.startsWith("URL:") || rawText.startsWith("URI:")) {
|
||||
return new URIParsedResult(rawText.substring(4).trim(), null);
|
||||
return new URIParsedRXingResult(rawText.substring(4).trim(), null);
|
||||
}
|
||||
rawText = rawText.trim();
|
||||
if (!isBasicallyValidURI(rawText) || isPossiblyMaliciousURI(rawText)) {
|
||||
return null;
|
||||
}
|
||||
return new URIParsedResult(rawText, null);
|
||||
return new URIParsedRXingResult(rawText, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
/**
|
||||
* Parses the "URLTO" result format, which is of the form "URLTO:[title]:[url]".
|
||||
@@ -25,10 +25,10 @@ import com.google.zxing.Result;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class URLTOResultParser extends ResultParser {
|
||||
public final class URLTORXingResultParser extends RXingResultParser {
|
||||
|
||||
@Override
|
||||
public URIParsedResult parse(Result result) {
|
||||
public URIParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("urlto:") && !rawText.startsWith("URLTO:")) {
|
||||
return null;
|
||||
@@ -39,7 +39,7 @@ public final class URLTOResultParser extends ResultParser {
|
||||
}
|
||||
String title = titleEnd <= 6 ? null : rawText.substring(6, titleEnd);
|
||||
String uri = rawText.substring(titleEnd + 1);
|
||||
return new URIParsedResult(uri, title);
|
||||
return new URIParsedRXingResult(uri, title);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -34,7 +34,7 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class VCardResultParser extends ResultParser {
|
||||
public final class VCardRXingResultParser extends RXingResultParser {
|
||||
|
||||
private static final Pattern BEGIN_VCARD = Pattern.compile("BEGIN:VCARD", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern VCARD_LIKE_DATE = Pattern.compile("\\d{4}-?\\d{2}-?\\d{2}");
|
||||
@@ -48,7 +48,7 @@ public final class VCardResultParser extends ResultParser {
|
||||
private static final Pattern SEMICOLON_OR_COMMA = Pattern.compile("[;,]");
|
||||
|
||||
@Override
|
||||
public AddressBookParsedResult parse(Result result) {
|
||||
public AddressBookParsedRXingResult parse(RXingResult result) {
|
||||
// Although we should insist on the raw text ending with "END:VCARD", there's no reason
|
||||
// to throw out everything else we parsed just because this was omitted. In fact, Eclair
|
||||
// is doing just that, and we can't parse its contacts without this leniency.
|
||||
@@ -82,7 +82,7 @@ public final class VCardResultParser extends ResultParser {
|
||||
if (geo != null && geo.length != 2) {
|
||||
geo = null;
|
||||
}
|
||||
return new AddressBookParsedResult(toPrimaryValues(names),
|
||||
return new AddressBookParsedRXingResult(toPrimaryValues(names),
|
||||
nicknames,
|
||||
null,
|
||||
toPrimaryValues(phoneNumbers),
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,10 +26,10 @@ import java.util.List;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class VEventResultParser extends ResultParser {
|
||||
public final class VEventRXingResultParser extends RXingResultParser {
|
||||
|
||||
@Override
|
||||
public CalendarParsedResult parse(Result result) {
|
||||
public CalendarParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
int vEventStart = rawText.indexOf("BEGIN:VEVENT");
|
||||
if (vEventStart < 0) {
|
||||
@@ -74,7 +74,7 @@ public final class VEventResultParser extends ResultParser {
|
||||
}
|
||||
|
||||
try {
|
||||
return new CalendarParsedResult(summary,
|
||||
return new CalendarParsedRXingResult(summary,
|
||||
start,
|
||||
end,
|
||||
duration,
|
||||
@@ -91,12 +91,12 @@ public final class VEventResultParser extends ResultParser {
|
||||
|
||||
private static String matchSingleVCardPrefixedField(CharSequence prefix,
|
||||
String rawText) {
|
||||
List<String> values = VCardResultParser.matchSingleVCardPrefixedField(prefix, rawText, true, false);
|
||||
List<String> values = VCardRXingResultParser.matchSingleVCardPrefixedField(prefix, rawText, true, false);
|
||||
return values == null || values.isEmpty() ? null : values.get(0);
|
||||
}
|
||||
|
||||
private static String[] matchVCardPrefixedField(CharSequence prefix, String rawText) {
|
||||
List<List<String>> values = VCardResultParser.matchVCardPrefixedField(prefix, rawText, true, false);
|
||||
List<List<String>> values = VCardRXingResultParser.matchVCardPrefixedField(prefix, rawText, true, false);
|
||||
if (values == null || values.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ package com.google.zxing.client.result;
|
||||
/**
|
||||
* Represents a parsed result that encodes a Vehicle Identification Number (VIN).
|
||||
*/
|
||||
public final class VINParsedResult extends ParsedResult {
|
||||
public final class VINParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String vin;
|
||||
private final String worldManufacturerID;
|
||||
@@ -32,7 +32,7 @@ public final class VINParsedResult extends ParsedResult {
|
||||
private final char plantCode;
|
||||
private final String sequentialNumber;
|
||||
|
||||
public VINParsedResult(String vin,
|
||||
public VINParsedRXingResult(String vin,
|
||||
String worldManufacturerID,
|
||||
String vehicleDescriptorSection,
|
||||
String vehicleIdentifierSection,
|
||||
@@ -41,7 +41,7 @@ public final class VINParsedResult extends ParsedResult {
|
||||
int modelYear,
|
||||
char plantCode,
|
||||
String sequentialNumber) {
|
||||
super(ParsedResultType.VIN);
|
||||
super(ParsedRXingResultType.VIN);
|
||||
this.vin = vin;
|
||||
this.worldManufacturerID = worldManufacturerID;
|
||||
this.vehicleDescriptorSection = vehicleDescriptorSection;
|
||||
@@ -90,7 +90,7 @@ public final class VINParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
StringBuilder result = new StringBuilder(50);
|
||||
result.append(worldManufacturerID).append(' ');
|
||||
result.append(vehicleDescriptorSection).append(' ');
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -26,13 +26,13 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class VINResultParser extends ResultParser {
|
||||
public final class VINRXingResultParser extends RXingResultParser {
|
||||
|
||||
private static final Pattern IOQ = Pattern.compile("[IOQ]");
|
||||
private static final Pattern AZ09 = Pattern.compile("[A-Z0-9]{17}");
|
||||
|
||||
@Override
|
||||
public VINParsedResult parse(Result result) {
|
||||
public VINParsedRXingResult parse(RXingResult result) {
|
||||
if (result.getBarcodeFormat() != BarcodeFormat.CODE_39) {
|
||||
return null;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public final class VINResultParser extends ResultParser {
|
||||
return null;
|
||||
}
|
||||
String wmi = rawText.substring(0, 3);
|
||||
return new VINParsedResult(rawText,
|
||||
return new VINParsedRXingResult(rawText,
|
||||
wmi,
|
||||
rawText.substring(3, 9),
|
||||
rawText.substring(9, 17),
|
||||
|
||||
@@ -21,7 +21,7 @@ package com.google.zxing.client.result;
|
||||
*
|
||||
* @author Vikram Aggarwal
|
||||
*/
|
||||
public final class WifiParsedResult extends ParsedResult {
|
||||
public final class WifiParsedRXingResult extends ParsedRXingResult {
|
||||
|
||||
private final String ssid;
|
||||
private final String networkEncryption;
|
||||
@@ -32,15 +32,15 @@ public final class WifiParsedResult extends ParsedResult {
|
||||
private final String eapMethod;
|
||||
private final String phase2Method;
|
||||
|
||||
public WifiParsedResult(String networkEncryption, String ssid, String password) {
|
||||
public WifiParsedRXingResult(String networkEncryption, String ssid, String password) {
|
||||
this(networkEncryption, ssid, password, false);
|
||||
}
|
||||
|
||||
public WifiParsedResult(String networkEncryption, String ssid, String password, boolean hidden) {
|
||||
public WifiParsedRXingResult(String networkEncryption, String ssid, String password, boolean hidden) {
|
||||
this(networkEncryption, ssid, password, hidden, null, null, null, null);
|
||||
}
|
||||
|
||||
public WifiParsedResult(String networkEncryption,
|
||||
public WifiParsedRXingResult(String networkEncryption,
|
||||
String ssid,
|
||||
String password,
|
||||
boolean hidden,
|
||||
@@ -48,7 +48,7 @@ public final class WifiParsedResult extends ParsedResult {
|
||||
String anonymousIdentity,
|
||||
String eapMethod,
|
||||
String phase2Method) {
|
||||
super(ParsedResultType.WIFI);
|
||||
super(ParsedRXingResultType.WIFI);
|
||||
this.ssid = ssid;
|
||||
this.networkEncryption = networkEncryption;
|
||||
this.password = password;
|
||||
@@ -92,7 +92,7 @@ public final class WifiParsedResult extends ParsedResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayResult() {
|
||||
public String getDisplayRXingResult() {
|
||||
StringBuilder result = new StringBuilder(80);
|
||||
maybeAppend(ssid, result);
|
||||
maybeAppend(networkEncryption, result);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.RXingResult;
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
/**
|
||||
@@ -36,10 +36,10 @@ import com.google.zxing.Result;
|
||||
* @author Sean Owen
|
||||
* @author Steffen Kieß
|
||||
*/
|
||||
public final class WifiResultParser extends ResultParser {
|
||||
public final class WifiRXingResultParser extends RXingResultParser {
|
||||
|
||||
@Override
|
||||
public WifiParsedResult parse(Result result) {
|
||||
public WifiParsedRXingResult parse(RXingResult result) {
|
||||
String rawText = getMassagedText(result);
|
||||
if (!rawText.startsWith("WIFI:")) {
|
||||
return null;
|
||||
@@ -74,6 +74,6 @@ public final class WifiResultParser extends ResultParser {
|
||||
String anonymousIdentity = matchSinglePrefixedField("A:", rawText, ';', false);
|
||||
String eapMethod = matchSinglePrefixedField("E:", rawText, ';', false);
|
||||
|
||||
return new WifiParsedResult(type, ssid, pass, hidden, identity, anonymousIdentity, eapMethod, phase2Method);
|
||||
return new WifiParsedRXingResult(type, ssid, pass, hidden, identity, anonymousIdentity, eapMethod, phase2Method);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class DecoderResult {
|
||||
public final class DecoderRXingResult {
|
||||
|
||||
private final byte[] rawBytes;
|
||||
private int numBits;
|
||||
@@ -39,14 +39,14 @@ public final class DecoderResult {
|
||||
private final int structuredAppendSequenceNumber;
|
||||
private final int symbologyModifier;
|
||||
|
||||
public DecoderResult(byte[] rawBytes,
|
||||
public DecoderRXingResult(byte[] rawBytes,
|
||||
String text,
|
||||
List<byte[]> byteSegments,
|
||||
String ecLevel) {
|
||||
this(rawBytes, text, byteSegments, ecLevel, -1, -1, 0);
|
||||
}
|
||||
|
||||
public DecoderResult(byte[] rawBytes,
|
||||
public DecoderRXingResult(byte[] rawBytes,
|
||||
String text,
|
||||
List<byte[]> byteSegments,
|
||||
String ecLevel,
|
||||
@@ -54,7 +54,7 @@ public final class DecoderResult {
|
||||
this(rawBytes, text, byteSegments, ecLevel, -1, -1, symbologyModifier);
|
||||
}
|
||||
|
||||
public DecoderResult(byte[] rawBytes,
|
||||
public DecoderRXingResult(byte[] rawBytes,
|
||||
String text,
|
||||
List<byte[]> byteSegments,
|
||||
String ecLevel,
|
||||
@@ -63,7 +63,7 @@ public final class DecoderResult {
|
||||
this(rawBytes, text, byteSegments, ecLevel, saSequence, saParity, 0);
|
||||
}
|
||||
|
||||
public DecoderResult(byte[] rawBytes,
|
||||
public DecoderRXingResult(byte[] rawBytes,
|
||||
String text,
|
||||
List<byte[]> byteSegments,
|
||||
String ecLevel,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.zxing.common;
|
||||
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
|
||||
/**
|
||||
* <p>Encapsulates the result of detecting a barcode in an image. This includes the raw
|
||||
@@ -25,12 +25,12 @@ import com.google.zxing.ResultPoint;
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public class DetectorResult {
|
||||
public class DetectorRXingResult {
|
||||
|
||||
private final BitMatrix bits;
|
||||
private final ResultPoint[] points;
|
||||
private final RXingResultPoint[] points;
|
||||
|
||||
public DetectorResult(BitMatrix bits, ResultPoint[] points) {
|
||||
public DetectorRXingResult(BitMatrix bits, RXingResultPoint[] points) {
|
||||
this.bits = bits;
|
||||
this.points = points;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class DetectorResult {
|
||||
return bits;
|
||||
}
|
||||
|
||||
public final ResultPoint[] getPoints() {
|
||||
public final RXingResultPoint[] getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
//package com.google.zxing.common.detector;
|
||||
use crate::{NotFoundException,ResultPoint};
|
||||
use crate::{NotFoundException,RXingResultPoint};
|
||||
use crate::common::BitMatrix;
|
||||
|
||||
|
||||
@@ -42,13 +42,13 @@ public final class MonochromeRectangleDetector {
|
||||
* <p>Detects a rectangular region of black and white -- mostly black -- with a region of mostly
|
||||
* white, in an image.</p>
|
||||
*
|
||||
* @return {@link ResultPoint}[] describing the corners of the rectangular region. The first and
|
||||
* @return {@link RXingResultPoint}[] describing the corners of the rectangular region. The first and
|
||||
* last points are opposed on the diagonal, as are the second and third. The first point will be
|
||||
* the topmost point and the last, the bottommost. The second point will be leftmost and the
|
||||
* third, the rightmost
|
||||
* @throws NotFoundException if no Data Matrix Code can be found
|
||||
*/
|
||||
public ResultPoint[] detect() throws NotFoundException {
|
||||
public RXingResultPoint[] detect() throws NotFoundException {
|
||||
int height = image.getHeight();
|
||||
int width = image.getWidth();
|
||||
int halfHeight = height / 2;
|
||||
@@ -60,16 +60,16 @@ public final class MonochromeRectangleDetector {
|
||||
int bottom = height;
|
||||
int left = 0;
|
||||
int right = width;
|
||||
ResultPoint pointA = findCornerFromCenter(halfWidth, 0, left, right,
|
||||
RXingResultPoint pointA = findCornerFromCenter(halfWidth, 0, left, right,
|
||||
halfHeight, -deltaY, top, bottom, halfWidth / 2);
|
||||
top = (int) pointA.getY() - 1;
|
||||
ResultPoint pointB = findCornerFromCenter(halfWidth, -deltaX, left, right,
|
||||
RXingResultPoint pointB = findCornerFromCenter(halfWidth, -deltaX, left, right,
|
||||
halfHeight, 0, top, bottom, halfHeight / 2);
|
||||
left = (int) pointB.getX() - 1;
|
||||
ResultPoint pointC = findCornerFromCenter(halfWidth, deltaX, left, right,
|
||||
RXingResultPoint pointC = findCornerFromCenter(halfWidth, deltaX, left, right,
|
||||
halfHeight, 0, top, bottom, halfHeight / 2);
|
||||
right = (int) pointC.getX() + 1;
|
||||
ResultPoint pointD = findCornerFromCenter(halfWidth, 0, left, right,
|
||||
RXingResultPoint pointD = findCornerFromCenter(halfWidth, 0, left, right,
|
||||
halfHeight, deltaY, top, bottom, halfWidth / 2);
|
||||
bottom = (int) pointD.getY() + 1;
|
||||
|
||||
@@ -77,7 +77,7 @@ public final class MonochromeRectangleDetector {
|
||||
pointA = findCornerFromCenter(halfWidth, 0, left, right,
|
||||
halfHeight, -deltaY, top, bottom, halfWidth / 4);
|
||||
|
||||
return new ResultPoint[] { pointA, pointB, pointC, pointD };
|
||||
return new RXingResultPoint[] { pointA, pointB, pointC, pointD };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,10 +95,10 @@ public final class MonochromeRectangleDetector {
|
||||
* @param bottom maximum value of y
|
||||
* @param maxWhiteRun maximum run of white pixels that can still be considered to be within
|
||||
* the barcode
|
||||
* @return a {@link ResultPoint} encapsulating the corner that was found
|
||||
* @return a {@link RXingResultPoint} encapsulating the corner that was found
|
||||
* @throws NotFoundException if such a point cannot be found
|
||||
*/
|
||||
private ResultPoint findCornerFromCenter(int centerX,
|
||||
private RXingResultPoint findCornerFromCenter(int centerX,
|
||||
int deltaX,
|
||||
int left,
|
||||
int right,
|
||||
@@ -129,21 +129,21 @@ public final class MonochromeRectangleDetector {
|
||||
if (lastRange[0] < centerX) {
|
||||
if (lastRange[1] > centerX) {
|
||||
// straddle, choose one or the other based on direction
|
||||
return new ResultPoint(lastRange[deltaY > 0 ? 0 : 1], lastY);
|
||||
return new RXingResultPoint(lastRange[deltaY > 0 ? 0 : 1], lastY);
|
||||
}
|
||||
return new ResultPoint(lastRange[0], lastY);
|
||||
return new RXingResultPoint(lastRange[0], lastY);
|
||||
} else {
|
||||
return new ResultPoint(lastRange[1], lastY);
|
||||
return new RXingResultPoint(lastRange[1], lastY);
|
||||
}
|
||||
} else {
|
||||
int lastX = x - deltaX;
|
||||
if (lastRange[0] < centerY) {
|
||||
if (lastRange[1] > centerY) {
|
||||
return new ResultPoint(lastX, lastRange[deltaX < 0 ? 0 : 1]);
|
||||
return new RXingResultPoint(lastX, lastRange[deltaX < 0 ? 0 : 1]);
|
||||
}
|
||||
return new ResultPoint(lastX, lastRange[0]);
|
||||
return new RXingResultPoint(lastX, lastRange[0]);
|
||||
} else {
|
||||
return new ResultPoint(lastX, lastRange[1]);
|
||||
return new RXingResultPoint(lastX, lastRange[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.google.zxing.common.detector;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
/**
|
||||
@@ -75,14 +75,14 @@ public final class WhiteRectangleDetector {
|
||||
* region until it finds a white rectangular region.
|
||||
* </p>
|
||||
*
|
||||
* @return {@link ResultPoint}[] describing the corners of the rectangular
|
||||
* @return {@link RXingResultPoint}[] describing the corners of the rectangular
|
||||
* region. The first and last points are opposed on the diagonal, as
|
||||
* are the second and third. The first point will be the topmost
|
||||
* point and the last, the bottommost. The second point will be
|
||||
* leftmost and the third, the rightmost
|
||||
* @throws NotFoundException if no Data Matrix Code can be found
|
||||
*/
|
||||
public ResultPoint[] detect() throws NotFoundException {
|
||||
public RXingResultPoint[] detect() throws NotFoundException {
|
||||
|
||||
int left = leftInit;
|
||||
int right = rightInit;
|
||||
@@ -186,7 +186,7 @@ public final class WhiteRectangleDetector {
|
||||
|
||||
int maxSize = right - left;
|
||||
|
||||
ResultPoint z = null;
|
||||
RXingResultPoint z = null;
|
||||
for (int i = 1; z == null && i < maxSize; i++) {
|
||||
z = getBlackPointOnSegment(left, down - i, left + i, down);
|
||||
}
|
||||
@@ -195,7 +195,7 @@ public final class WhiteRectangleDetector {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
ResultPoint t = null;
|
||||
RXingResultPoint t = null;
|
||||
//go down right
|
||||
for (int i = 1; t == null && i < maxSize; i++) {
|
||||
t = getBlackPointOnSegment(left, up + i, left + i, up);
|
||||
@@ -205,7 +205,7 @@ public final class WhiteRectangleDetector {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
ResultPoint x = null;
|
||||
RXingResultPoint x = null;
|
||||
//go down left
|
||||
for (int i = 1; x == null && i < maxSize; i++) {
|
||||
x = getBlackPointOnSegment(right, up + i, right - i, up);
|
||||
@@ -215,7 +215,7 @@ public final class WhiteRectangleDetector {
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
ResultPoint y = null;
|
||||
RXingResultPoint y = null;
|
||||
//go up left
|
||||
for (int i = 1; y == null && i < maxSize; i++) {
|
||||
y = getBlackPointOnSegment(right, down - i, right - i, down);
|
||||
@@ -232,7 +232,7 @@ public final class WhiteRectangleDetector {
|
||||
}
|
||||
}
|
||||
|
||||
private ResultPoint getBlackPointOnSegment(float aX, float aY, float bX, float bY) {
|
||||
private RXingResultPoint getBlackPointOnSegment(float aX, float aY, float bX, float bY) {
|
||||
int dist = MathUtils.round(MathUtils.distance(aX, aY, bX, bY));
|
||||
float xStep = (bX - aX) / dist;
|
||||
float yStep = (bY - aY) / dist;
|
||||
@@ -241,7 +241,7 @@ public final class WhiteRectangleDetector {
|
||||
int x = MathUtils.round(aX + i * xStep);
|
||||
int y = MathUtils.round(aY + i * yStep);
|
||||
if (image.get(x, y)) {
|
||||
return new ResultPoint(x, y);
|
||||
return new RXingResultPoint(x, y);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -254,14 +254,14 @@ public final class WhiteRectangleDetector {
|
||||
* @param z left most point
|
||||
* @param x right most point
|
||||
* @param t top most point
|
||||
* @return {@link ResultPoint}[] describing the corners of the rectangular
|
||||
* @return {@link RXingResultPoint}[] describing the corners of the rectangular
|
||||
* region. The first and last points are opposed on the diagonal, as
|
||||
* are the second and third. The first point will be the topmost
|
||||
* point and the last, the bottommost. The second point will be
|
||||
* leftmost and the third, the rightmost
|
||||
*/
|
||||
private ResultPoint[] centerEdges(ResultPoint y, ResultPoint z,
|
||||
ResultPoint x, ResultPoint t) {
|
||||
private RXingResultPoint[] centerEdges(RXingResultPoint y, RXingResultPoint z,
|
||||
RXingResultPoint x, RXingResultPoint t) {
|
||||
|
||||
//
|
||||
// t t
|
||||
@@ -280,17 +280,17 @@ public final class WhiteRectangleDetector {
|
||||
float tj = t.getY();
|
||||
|
||||
if (yi < width / 2.0f) {
|
||||
return new ResultPoint[]{
|
||||
new ResultPoint(ti - CORR, tj + CORR),
|
||||
new ResultPoint(zi + CORR, zj + CORR),
|
||||
new ResultPoint(xi - CORR, xj - CORR),
|
||||
new ResultPoint(yi + CORR, yj - CORR)};
|
||||
return new RXingResultPoint[]{
|
||||
new RXingResultPoint(ti - CORR, tj + CORR),
|
||||
new RXingResultPoint(zi + CORR, zj + CORR),
|
||||
new RXingResultPoint(xi - CORR, xj - CORR),
|
||||
new RXingResultPoint(yi + CORR, yj - CORR)};
|
||||
} else {
|
||||
return new ResultPoint[]{
|
||||
new ResultPoint(ti + CORR, tj + CORR),
|
||||
new ResultPoint(zi + CORR, zj - CORR),
|
||||
new ResultPoint(xi - CORR, xj + CORR),
|
||||
new ResultPoint(yi - CORR, yj - CORR)};
|
||||
return new RXingResultPoint[]{
|
||||
new RXingResultPoint(ti + CORR, tj + CORR),
|
||||
new RXingResultPoint(zi + CORR, zj - CORR),
|
||||
new RXingResultPoint(xi - CORR, xj + CORR),
|
||||
new RXingResultPoint(yi - CORR, yj - CORR)};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Reader;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.RXingResultMetadataType;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DetectorResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import com.google.zxing.common.DetectorRXingResult;
|
||||
import com.google.zxing.datamatrix.decoder.Decoder;
|
||||
import com.google.zxing.datamatrix.detector.Detector;
|
||||
|
||||
@@ -42,7 +42,7 @@ import java.util.Map;
|
||||
*/
|
||||
public final class DataMatrixReader implements Reader {
|
||||
|
||||
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
|
||||
private static final RXingResultPoint[] NO_POINTS = new RXingResultPoint[0];
|
||||
|
||||
private final Decoder decoder = new Decoder();
|
||||
|
||||
@@ -55,35 +55,35 @@ public final class DataMatrixReader implements Reader {
|
||||
* @throws ChecksumException if error correction fails
|
||||
*/
|
||||
@Override
|
||||
public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException {
|
||||
public RXingResult decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException {
|
||||
return decode(image, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||
public RXingResult decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||
throws NotFoundException, ChecksumException, FormatException {
|
||||
DecoderResult decoderResult;
|
||||
ResultPoint[] points;
|
||||
DecoderRXingResult decoderRXingResult;
|
||||
RXingResultPoint[] points;
|
||||
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
|
||||
BitMatrix bits = extractPureBits(image.getBlackMatrix());
|
||||
decoderResult = decoder.decode(bits);
|
||||
decoderRXingResult = decoder.decode(bits);
|
||||
points = NO_POINTS;
|
||||
} else {
|
||||
DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
|
||||
decoderResult = decoder.decode(detectorResult.getBits());
|
||||
points = detectorResult.getPoints();
|
||||
DetectorRXingResult detectorRXingResult = new Detector(image.getBlackMatrix()).detect();
|
||||
decoderRXingResult = decoder.decode(detectorRXingResult.getBits());
|
||||
points = detectorRXingResult.getPoints();
|
||||
}
|
||||
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
|
||||
RXingResult result = new RXingResult(decoderRXingResult.getText(), decoderRXingResult.getRawBytes(), points,
|
||||
BarcodeFormat.DATA_MATRIX);
|
||||
List<byte[]> byteSegments = decoderResult.getByteSegments();
|
||||
List<byte[]> byteSegments = decoderRXingResult.getByteSegments();
|
||||
if (byteSegments != null) {
|
||||
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
|
||||
result.putMetadata(RXingResultMetadataType.BYTE_SEGMENTS, byteSegments);
|
||||
}
|
||||
String ecLevel = decoderResult.getECLevel();
|
||||
String ecLevel = decoderRXingResult.getECLevel();
|
||||
if (ecLevel != null) {
|
||||
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
|
||||
result.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
|
||||
}
|
||||
result.putMetadata(ResultMetadataType.SYMBOLOGY_IDENTIFIER, "]d" + decoderResult.getSymbologyModifier());
|
||||
result.putMetadata(RXingResultMetadataType.SYMBOLOGY_IDENTIFIER, "]d" + decoderRXingResult.getSymbologyModifier());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,12 +57,12 @@ final class DataBlock {
|
||||
|
||||
// Now establish DataBlocks of the appropriate size and number of data codewords
|
||||
DataBlock[] result = new DataBlock[totalBlocks];
|
||||
int numResultBlocks = 0;
|
||||
int numRXingResultBlocks = 0;
|
||||
for (Version.ECB ecBlock : ecBlockArray) {
|
||||
for (int i = 0; i < ecBlock.getCount(); i++) {
|
||||
int numDataCodewords = ecBlock.getDataCodewords();
|
||||
int numBlockCodewords = ecBlocks.getECCodewords() + numDataCodewords;
|
||||
result[numResultBlocks++] = new DataBlock(numDataCodewords, new byte[numBlockCodewords]);
|
||||
result[numRXingResultBlocks++] = new DataBlock(numDataCodewords, new byte[numBlockCodewords]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,14 +78,14 @@ final class DataBlock {
|
||||
// first fill out as many elements as all of them have minus 1
|
||||
int rawCodewordsOffset = 0;
|
||||
for (int i = 0; i < shorterBlocksNumDataCodewords; i++) {
|
||||
for (int j = 0; j < numResultBlocks; j++) {
|
||||
for (int j = 0; j < numRXingResultBlocks; j++) {
|
||||
result[j].codewords[i] = rawCodewords[rawCodewordsOffset++];
|
||||
}
|
||||
}
|
||||
|
||||
// Fill out the last data block in the longer ones
|
||||
boolean specialVersion = version.getVersionNumber() == 24;
|
||||
int numLongerBlocks = specialVersion ? 8 : numResultBlocks;
|
||||
int numLongerBlocks = specialVersion ? 8 : numRXingResultBlocks;
|
||||
for (int j = 0; j < numLongerBlocks; j++) {
|
||||
result[j].codewords[longerBlocksNumDataCodewords - 1] = rawCodewords[rawCodewordsOffset++];
|
||||
}
|
||||
@@ -93,8 +93,8 @@ final class DataBlock {
|
||||
// Now add in error correction blocks
|
||||
int max = result[0].codewords.length;
|
||||
for (int i = longerBlocksNumDataCodewords; i < max; i++) {
|
||||
for (int j = 0; j < numResultBlocks; j++) {
|
||||
int jOffset = specialVersion ? (j + 8) % numResultBlocks : j;
|
||||
for (int j = 0; j < numRXingResultBlocks; j++) {
|
||||
int jOffset = specialVersion ? (j + 8) % numRXingResultBlocks : j;
|
||||
int iOffset = specialVersion && jOffset > 7 ? i - 1 : i;
|
||||
result[jOffset].codewords[iOffset] = rawCodewords[rawCodewordsOffset++];
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.google.zxing.datamatrix.decoder;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.common.BitSource;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import com.google.zxing.common.ECIStringBuilder;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -86,7 +86,7 @@ final class DecodedBitStreamParser {
|
||||
private DecodedBitStreamParser() {
|
||||
}
|
||||
|
||||
static DecoderResult decode(byte[] bytes) throws FormatException {
|
||||
static DecoderRXingResult decode(byte[] bytes) throws FormatException {
|
||||
BitSource bits = new BitSource(bytes);
|
||||
ECIStringBuilder result = new ECIStringBuilder(100);
|
||||
StringBuilder resultTrailer = new StringBuilder(0);
|
||||
@@ -149,7 +149,7 @@ final class DecodedBitStreamParser {
|
||||
}
|
||||
}
|
||||
|
||||
return new DecoderResult(bytes,
|
||||
return new DecoderRXingResult(bytes,
|
||||
result.toString(),
|
||||
byteSegments.isEmpty() ? null : byteSegments,
|
||||
null,
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.google.zxing.datamatrix.decoder;
|
||||
import com.google.zxing.ChecksumException;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import com.google.zxing.common.reedsolomon.GenericGF;
|
||||
import com.google.zxing.common.reedsolomon.ReedSolomonDecoder;
|
||||
import com.google.zxing.common.reedsolomon.ReedSolomonException;
|
||||
@@ -47,7 +47,7 @@ public final class Decoder {
|
||||
* @throws FormatException if the Data Matrix Code cannot be decoded
|
||||
* @throws ChecksumException if error correction fails
|
||||
*/
|
||||
public DecoderResult decode(boolean[][] image) throws FormatException, ChecksumException {
|
||||
public DecoderRXingResult decode(boolean[][] image) throws FormatException, ChecksumException {
|
||||
return decode(BitMatrix.parse(image));
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public final class Decoder {
|
||||
* @throws FormatException if the Data Matrix Code cannot be decoded
|
||||
* @throws ChecksumException if error correction fails
|
||||
*/
|
||||
public DecoderResult decode(BitMatrix bits) throws FormatException, ChecksumException {
|
||||
public DecoderRXingResult decode(BitMatrix bits) throws FormatException, ChecksumException {
|
||||
|
||||
// Construct a parser and read version, error-correction level
|
||||
BitMatrixParser parser = new BitMatrixParser(bits);
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
package com.google.zxing.datamatrix.detector;
|
||||
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DetectorResult;
|
||||
import com.google.zxing.common.DetectorRXingResult;
|
||||
import com.google.zxing.common.GridSampler;
|
||||
import com.google.zxing.common.detector.WhiteRectangleDetector;
|
||||
|
||||
@@ -42,14 +42,14 @@ public final class Detector {
|
||||
/**
|
||||
* <p>Detects a Data Matrix Code in an image.</p>
|
||||
*
|
||||
* @return {@link DetectorResult} encapsulating results of detecting a Data Matrix Code
|
||||
* @return {@link DetectorRXingResult} encapsulating results of detecting a Data Matrix Code
|
||||
* @throws NotFoundException if no Data Matrix Code can be found
|
||||
*/
|
||||
public DetectorResult detect() throws NotFoundException {
|
||||
public DetectorRXingResult detect() throws NotFoundException {
|
||||
|
||||
ResultPoint[] cornerPoints = rectangleDetector.detect();
|
||||
RXingResultPoint[] cornerPoints = rectangleDetector.detect();
|
||||
|
||||
ResultPoint[] points = detectSolid1(cornerPoints);
|
||||
RXingResultPoint[] points = detectSolid1(cornerPoints);
|
||||
points = detectSolid2(points);
|
||||
points[3] = correctTopRight(points);
|
||||
if (points[3] == null) {
|
||||
@@ -57,10 +57,10 @@ public final class Detector {
|
||||
}
|
||||
points = shiftToModuleCenter(points);
|
||||
|
||||
ResultPoint topLeft = points[0];
|
||||
ResultPoint bottomLeft = points[1];
|
||||
ResultPoint bottomRight = points[2];
|
||||
ResultPoint topRight = points[3];
|
||||
RXingResultPoint topLeft = points[0];
|
||||
RXingResultPoint bottomLeft = points[1];
|
||||
RXingResultPoint bottomRight = points[2];
|
||||
RXingResultPoint topRight = points[3];
|
||||
|
||||
int dimensionTop = transitionsBetween(topLeft, topRight) + 1;
|
||||
int dimensionRight = transitionsBetween(bottomRight, topRight) + 1;
|
||||
@@ -84,16 +84,16 @@ public final class Detector {
|
||||
dimensionTop,
|
||||
dimensionRight);
|
||||
|
||||
return new DetectorResult(bits, new ResultPoint[]{topLeft, bottomLeft, bottomRight, topRight});
|
||||
return new DetectorRXingResult(bits, new RXingResultPoint[]{topLeft, bottomLeft, bottomRight, topRight});
|
||||
}
|
||||
|
||||
private static ResultPoint shiftPoint(ResultPoint point, ResultPoint to, int div) {
|
||||
private static RXingResultPoint shiftPoint(RXingResultPoint point, RXingResultPoint to, int div) {
|
||||
float x = (to.getX() - point.getX()) / (div + 1);
|
||||
float y = (to.getY() - point.getY()) / (div + 1);
|
||||
return new ResultPoint(point.getX() + x, point.getY() + y);
|
||||
return new RXingResultPoint(point.getX() + x, point.getY() + y);
|
||||
}
|
||||
|
||||
private static ResultPoint moveAway(ResultPoint point, float fromX, float fromY) {
|
||||
private static RXingResultPoint moveAway(RXingResultPoint point, float fromX, float fromY) {
|
||||
float x = point.getX();
|
||||
float y = point.getY();
|
||||
|
||||
@@ -109,19 +109,19 @@ public final class Detector {
|
||||
y += 1;
|
||||
}
|
||||
|
||||
return new ResultPoint(x, y);
|
||||
return new RXingResultPoint(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect a solid side which has minimum transition.
|
||||
*/
|
||||
private ResultPoint[] detectSolid1(ResultPoint[] cornerPoints) {
|
||||
private RXingResultPoint[] detectSolid1(RXingResultPoint[] cornerPoints) {
|
||||
// 0 2
|
||||
// 1 3
|
||||
ResultPoint pointA = cornerPoints[0];
|
||||
ResultPoint pointB = cornerPoints[1];
|
||||
ResultPoint pointC = cornerPoints[3];
|
||||
ResultPoint pointD = cornerPoints[2];
|
||||
RXingResultPoint pointA = cornerPoints[0];
|
||||
RXingResultPoint pointB = cornerPoints[1];
|
||||
RXingResultPoint pointC = cornerPoints[3];
|
||||
RXingResultPoint pointD = cornerPoints[2];
|
||||
|
||||
int trAB = transitionsBetween(pointA, pointB);
|
||||
int trBC = transitionsBetween(pointB, pointC);
|
||||
@@ -132,7 +132,7 @@ public final class Detector {
|
||||
// : :
|
||||
// 1--2
|
||||
int min = trAB;
|
||||
ResultPoint[] points = {pointD, pointA, pointB, pointC};
|
||||
RXingResultPoint[] points = {pointD, pointA, pointB, pointC};
|
||||
if (min > trBC) {
|
||||
min = trBC;
|
||||
points[0] = pointA;
|
||||
@@ -160,20 +160,20 @@ public final class Detector {
|
||||
/**
|
||||
* Detect a second solid side next to first solid side.
|
||||
*/
|
||||
private ResultPoint[] detectSolid2(ResultPoint[] points) {
|
||||
private RXingResultPoint[] detectSolid2(RXingResultPoint[] points) {
|
||||
// A..D
|
||||
// : :
|
||||
// B--C
|
||||
ResultPoint pointA = points[0];
|
||||
ResultPoint pointB = points[1];
|
||||
ResultPoint pointC = points[2];
|
||||
ResultPoint pointD = points[3];
|
||||
RXingResultPoint pointA = points[0];
|
||||
RXingResultPoint pointB = points[1];
|
||||
RXingResultPoint pointC = points[2];
|
||||
RXingResultPoint pointD = points[3];
|
||||
|
||||
// Transition detection on the edge is not stable.
|
||||
// To safely detect, shift the points to the module center.
|
||||
int tr = transitionsBetween(pointA, pointD);
|
||||
ResultPoint pointBs = shiftPoint(pointB, pointC, (tr + 1) * 4);
|
||||
ResultPoint pointCs = shiftPoint(pointC, pointB, (tr + 1) * 4);
|
||||
RXingResultPoint pointBs = shiftPoint(pointB, pointC, (tr + 1) * 4);
|
||||
RXingResultPoint pointCs = shiftPoint(pointC, pointB, (tr + 1) * 4);
|
||||
int trBA = transitionsBetween(pointBs, pointA);
|
||||
int trCD = transitionsBetween(pointCs, pointD);
|
||||
|
||||
@@ -200,28 +200,28 @@ public final class Detector {
|
||||
/**
|
||||
* Calculates the corner position of the white top right module.
|
||||
*/
|
||||
private ResultPoint correctTopRight(ResultPoint[] points) {
|
||||
private RXingResultPoint correctTopRight(RXingResultPoint[] points) {
|
||||
// A..D
|
||||
// | :
|
||||
// B--C
|
||||
ResultPoint pointA = points[0];
|
||||
ResultPoint pointB = points[1];
|
||||
ResultPoint pointC = points[2];
|
||||
ResultPoint pointD = points[3];
|
||||
RXingResultPoint pointA = points[0];
|
||||
RXingResultPoint pointB = points[1];
|
||||
RXingResultPoint pointC = points[2];
|
||||
RXingResultPoint pointD = points[3];
|
||||
|
||||
// shift points for safe transition detection.
|
||||
int trTop = transitionsBetween(pointA, pointD);
|
||||
int trRight = transitionsBetween(pointB, pointD);
|
||||
ResultPoint pointAs = shiftPoint(pointA, pointB, (trRight + 1) * 4);
|
||||
ResultPoint pointCs = shiftPoint(pointC, pointB, (trTop + 1) * 4);
|
||||
RXingResultPoint pointAs = shiftPoint(pointA, pointB, (trRight + 1) * 4);
|
||||
RXingResultPoint pointCs = shiftPoint(pointC, pointB, (trTop + 1) * 4);
|
||||
|
||||
trTop = transitionsBetween(pointAs, pointD);
|
||||
trRight = transitionsBetween(pointCs, pointD);
|
||||
|
||||
ResultPoint candidate1 = new ResultPoint(
|
||||
RXingResultPoint candidate1 = new RXingResultPoint(
|
||||
pointD.getX() + (pointC.getX() - pointB.getX()) / (trTop + 1),
|
||||
pointD.getY() + (pointC.getY() - pointB.getY()) / (trTop + 1));
|
||||
ResultPoint candidate2 = new ResultPoint(
|
||||
RXingResultPoint candidate2 = new RXingResultPoint(
|
||||
pointD.getX() + (pointA.getX() - pointB.getX()) / (trRight + 1),
|
||||
pointD.getY() + (pointA.getY() - pointB.getY()) / (trRight + 1));
|
||||
|
||||
@@ -248,22 +248,22 @@ public final class Detector {
|
||||
/**
|
||||
* Shift the edge points to the module center.
|
||||
*/
|
||||
private ResultPoint[] shiftToModuleCenter(ResultPoint[] points) {
|
||||
private RXingResultPoint[] shiftToModuleCenter(RXingResultPoint[] points) {
|
||||
// A..D
|
||||
// | :
|
||||
// B--C
|
||||
ResultPoint pointA = points[0];
|
||||
ResultPoint pointB = points[1];
|
||||
ResultPoint pointC = points[2];
|
||||
ResultPoint pointD = points[3];
|
||||
RXingResultPoint pointA = points[0];
|
||||
RXingResultPoint pointB = points[1];
|
||||
RXingResultPoint pointC = points[2];
|
||||
RXingResultPoint pointD = points[3];
|
||||
|
||||
// calculate pseudo dimensions
|
||||
int dimH = transitionsBetween(pointA, pointD) + 1;
|
||||
int dimV = transitionsBetween(pointC, pointD) + 1;
|
||||
|
||||
// shift points for safe dimension detection
|
||||
ResultPoint pointAs = shiftPoint(pointA, pointB, dimV * 4);
|
||||
ResultPoint pointCs = shiftPoint(pointC, pointB, dimH * 4);
|
||||
RXingResultPoint pointAs = shiftPoint(pointA, pointB, dimV * 4);
|
||||
RXingResultPoint pointCs = shiftPoint(pointC, pointB, dimH * 4);
|
||||
|
||||
// calculate more precise dimensions
|
||||
dimH = transitionsBetween(pointAs, pointD) + 1;
|
||||
@@ -284,8 +284,8 @@ public final class Detector {
|
||||
pointC = moveAway(pointC, centerX, centerY);
|
||||
pointD = moveAway(pointD, centerX, centerY);
|
||||
|
||||
ResultPoint pointBs;
|
||||
ResultPoint pointDs;
|
||||
RXingResultPoint pointBs;
|
||||
RXingResultPoint pointDs;
|
||||
|
||||
// shift points to the center of each modules
|
||||
pointAs = shiftPoint(pointA, pointB, dimV * 4);
|
||||
@@ -297,18 +297,18 @@ public final class Detector {
|
||||
pointDs = shiftPoint(pointD, pointC, dimV * 4);
|
||||
pointDs = shiftPoint(pointDs, pointA, dimH * 4);
|
||||
|
||||
return new ResultPoint[]{pointAs, pointBs, pointCs, pointDs};
|
||||
return new RXingResultPoint[]{pointAs, pointBs, pointCs, pointDs};
|
||||
}
|
||||
|
||||
private boolean isValid(ResultPoint p) {
|
||||
private boolean isValid(RXingResultPoint p) {
|
||||
return p.getX() >= 0 && p.getX() <= image.getWidth() - 1 && p.getY() > 0 && p.getY() <= image.getHeight() - 1;
|
||||
}
|
||||
|
||||
private static BitMatrix sampleGrid(BitMatrix image,
|
||||
ResultPoint topLeft,
|
||||
ResultPoint bottomLeft,
|
||||
ResultPoint bottomRight,
|
||||
ResultPoint topRight,
|
||||
RXingResultPoint topLeft,
|
||||
RXingResultPoint bottomLeft,
|
||||
RXingResultPoint bottomRight,
|
||||
RXingResultPoint topRight,
|
||||
int dimensionX,
|
||||
int dimensionY) throws NotFoundException {
|
||||
|
||||
@@ -338,7 +338,7 @@ public final class Detector {
|
||||
/**
|
||||
* Counts the number of black/white transitions between two points, using something like Bresenham's algorithm.
|
||||
*/
|
||||
private int transitionsBetween(ResultPoint from, ResultPoint to) {
|
||||
private int transitionsBetween(RXingResultPoint from, RXingResultPoint to) {
|
||||
// See QR Code Detector, sizeOfBlackWhiteBlackRun()
|
||||
int fromX = (int) from.getX();
|
||||
int fromY = (int) from.getY();
|
||||
|
||||
@@ -251,7 +251,7 @@ public final class MinimalEncoder {
|
||||
addEdge(edges, new Edge(input, Mode.EDF, from, 4, previous));
|
||||
}
|
||||
}
|
||||
static Result encodeMinimally(Input input) {
|
||||
static RXingResult encodeMinimally(Input input) {
|
||||
|
||||
@SuppressWarnings("checkstyle:lineLength")
|
||||
/* The minimal encoding is computed by Dijkstra. The acyclic graph is modeled as follows:
|
||||
@@ -474,7 +474,7 @@ public final class MinimalEncoder {
|
||||
if (minimalJ < 0) {
|
||||
throw new RuntimeException("Internal error: failed to encode \"" + input + "\"");
|
||||
}
|
||||
return new Result(edges[inputLength][minimalJ]);
|
||||
return new RXingResult(edges[inputLength][minimalJ]);
|
||||
}
|
||||
|
||||
private static final class Edge {
|
||||
@@ -926,11 +926,11 @@ public final class MinimalEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class Result {
|
||||
private static final class RXingResult {
|
||||
|
||||
private final byte[] bytes;
|
||||
|
||||
Result(Edge solution) {
|
||||
RXingResult(Edge solution) {
|
||||
Input input = solution.input;
|
||||
int size = 0;
|
||||
List<Byte> bytesAL = new ArrayList<>();
|
||||
|
||||
@@ -23,11 +23,11 @@ import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.NotFoundException;
|
||||
import com.google.zxing.Reader;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.RXingResult;
|
||||
import com.google.zxing.RXingResultMetadataType;
|
||||
import com.google.zxing.RXingResultPoint;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import com.google.zxing.maxicode.decoder.Decoder;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -37,7 +37,7 @@ import java.util.Map;
|
||||
*/
|
||||
public final class MaxiCodeReader implements Reader {
|
||||
|
||||
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
|
||||
private static final RXingResultPoint[] NO_POINTS = new RXingResultPoint[0];
|
||||
private static final int MATRIX_WIDTH = 30;
|
||||
private static final int MATRIX_HEIGHT = 33;
|
||||
|
||||
@@ -52,22 +52,22 @@ public final class MaxiCodeReader implements Reader {
|
||||
* @throws ChecksumException if error correction fails
|
||||
*/
|
||||
@Override
|
||||
public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException {
|
||||
public RXingResult decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException {
|
||||
return decode(image, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||
public RXingResult decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
|
||||
throws NotFoundException, ChecksumException, FormatException {
|
||||
// Note that MaxiCode reader effectively always assumes PURE_BARCODE mode
|
||||
// and can't detect it in an image
|
||||
BitMatrix bits = extractPureBits(image.getBlackMatrix());
|
||||
DecoderResult decoderResult = decoder.decode(bits, hints);
|
||||
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), NO_POINTS, BarcodeFormat.MAXICODE);
|
||||
DecoderRXingResult decoderRXingResult = decoder.decode(bits, hints);
|
||||
RXingResult result = new RXingResult(decoderRXingResult.getText(), decoderRXingResult.getRawBytes(), NO_POINTS, BarcodeFormat.MAXICODE);
|
||||
|
||||
String ecLevel = decoderResult.getECLevel();
|
||||
String ecLevel = decoderRXingResult.getECLevel();
|
||||
if (ecLevel != null) {
|
||||
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
|
||||
result.putMetadata(RXingResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.google.zxing.maxicode.decoder;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
@@ -84,7 +84,7 @@ final class DecodedBitStreamParser {
|
||||
private DecodedBitStreamParser() {
|
||||
}
|
||||
|
||||
static DecoderResult decode(byte[] bytes, int mode) throws FormatException {
|
||||
static DecoderRXingResult decode(byte[] bytes, int mode) throws FormatException {
|
||||
StringBuilder result = new StringBuilder(144);
|
||||
switch (mode) {
|
||||
case 2:
|
||||
@@ -118,7 +118,7 @@ final class DecodedBitStreamParser {
|
||||
result.append(getMessage(bytes, 1, 77));
|
||||
break;
|
||||
}
|
||||
return new DecoderResult(bytes, result.toString(), null, String.valueOf(mode));
|
||||
return new DecoderRXingResult(bytes, result.toString(), null, String.valueOf(mode));
|
||||
}
|
||||
|
||||
private static int getBit(int bit, byte[] bytes) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.google.zxing.ChecksumException;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.common.DecoderResult;
|
||||
import com.google.zxing.common.DecoderRXingResult;
|
||||
import com.google.zxing.common.reedsolomon.GenericGF;
|
||||
import com.google.zxing.common.reedsolomon.ReedSolomonDecoder;
|
||||
import com.google.zxing.common.reedsolomon.ReedSolomonException;
|
||||
@@ -45,11 +45,11 @@ public final class Decoder {
|
||||
rsDecoder = new ReedSolomonDecoder(GenericGF.MAXICODE_FIELD_64);
|
||||
}
|
||||
|
||||
public DecoderResult decode(BitMatrix bits) throws ChecksumException, FormatException {
|
||||
public DecoderRXingResult decode(BitMatrix bits) throws ChecksumException, FormatException {
|
||||
return decode(bits, null);
|
||||
}
|
||||
|
||||
public DecoderResult decode(BitMatrix bits,
|
||||
public DecoderRXingResult decode(BitMatrix bits,
|
||||
Map<DecodeHintType,?> hints) throws FormatException, ChecksumException {
|
||||
BitMatrixParser parser = new BitMatrixParser(bits);
|
||||
byte[] codewords = parser.readCodewords();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user