}
if (level < Log.VERBOSE || level > Log.ASSERT) {
throw new IllegalArgumentException("Level is out of range ["
- + Log.VERBOSE + ".." + Log.ASSERT + "]");
+ + Log.VERBOSE + ".." + Log.ASSERT + ']');
}
curlConfiguration = new LoggingConfiguration(name, level);
}
if (mCopyToClipboard) {
- ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
+ ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(displayContents);
}
}
mStatusView.setBackgroundColor(getResources().getColor(R.color.transparent));
if (mCopyToClipboard) {
- ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
+ ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(resultHandler.getDisplayContents());
}
mMediaPlayer.start();
}
if (mVibrate) {
- Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
+ Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_DURATION);
}
}
public final class Contents {
+ private Contents() {
+ }
+
/**
* All the formats we know about.
*/
public static final String CODE_39 = "CODE_39";
public static final String CODE_128 = "CODE_128";
public static final String QR_CODE = "QR_CODE";
+ private Format() {
+ }
}
public static final class Type {
* intent.putExtra(Intents.Encode.DATA, bundle);
*/
public static final String LOCATION = "LOCATION_TYPE";
+
+ private Type() {
+ }
}
// These are new constants in Contacts.Intents.Insert for Android 1.1.
public final class Intents {
+ private Intents() {
+ }
+
public static final class Scan {
/**
* Send this intent to open the Barcodes app in scanning mode, find a barcode, and return
* See Contents.Format for possible values.
*/
public static final String RESULT_FORMAT = "SCAN_RESULT_FORMAT";
+
+ private Scan() {
+ }
}
public static final class Encode {
* Contents.Type.
*/
public static final String TYPE = "ENCODE_TYPE";
+
+ private Encode() {
+ }
}
public static final class SearchBookContents {
* An optional field which is the text to search for.
*/
public static final String QUERY = "QUERY";
+
+ private SearchBookContents() {
+ }
}
public static final class Share {
* display onscreen for a friend to scan with their phone.
*/
public static final String ACTION = "com.google.zxing.client.android.SHARE";
+
+ private Share() {
+ }
}
}
public final class QRCodeEncoder {
- private static final String TAG = "QRCodeEncoder";
-
private final Activity mActivity;
private String mContents;
private String mDisplayContents;
}
if (type.equals(Contents.Type.TEXT)) {
- String string = intent.getStringExtra(Intents.Encode.DATA);
- if (string != null && string.length() > 0) {
- mContents = string;
- mDisplayContents = string;
+ String data = intent.getStringExtra(Intents.Encode.DATA);
+ if (data != null && data.length() > 0) {
+ mContents = data;
+ mDisplayContents = data;
mTitle = mActivity.getString(R.string.contents_text);
}
} else if (type.equals(Contents.Type.EMAIL)) {
- String string = intent.getStringExtra(Intents.Encode.DATA);
- if (string != null && string.length() > 0) {
- mContents = "mailto:" + string;
- mDisplayContents = string;
+ String data = intent.getStringExtra(Intents.Encode.DATA);
+ if (data != null && data.length() > 0) {
+ mContents = "mailto:" + data;
+ mDisplayContents = data;
mTitle = mActivity.getString(R.string.contents_email);
}
} else if (type.equals(Contents.Type.PHONE)) {
- String string = intent.getStringExtra(Intents.Encode.DATA);
- if (string != null && string.length() > 0) {
- mContents = "tel:" + string;
- mDisplayContents = PhoneNumberUtils.formatNumber(string);
+ String data = intent.getStringExtra(Intents.Encode.DATA);
+ if (data != null && data.length() > 0) {
+ mContents = "tel:" + data;
+ mDisplayContents = PhoneNumberUtils.formatNumber(data);
mTitle = mActivity.getString(R.string.contents_phone);
}
} else if (type.equals(Contents.Type.SMS)) {
- String string = intent.getStringExtra(Intents.Encode.DATA);
- if (string != null && string.length() > 0) {
- mContents = "sms:" + string;
- mDisplayContents = PhoneNumberUtils.formatNumber(string);
+ String data = intent.getStringExtra(Intents.Encode.DATA);
+ if (data != null && data.length() > 0) {
+ mContents = "sms:" + data;
+ mDisplayContents = PhoneNumberUtils.formatNumber(data);
mTitle = mActivity.getString(R.string.contents_sms);
}
} else if (type.equals(Contents.Type.CONTACT)) {
if (bundle != null) {
String name = bundle.getString(Contacts.Intents.Insert.NAME);
if (name != null && name.length() > 0) {
- mContents = "MECARD:N:" + name + ";";
+ mContents = "MECARD:N:" + name + ';';
mDisplayContents = name;
String address = bundle.getString(Contacts.Intents.Insert.POSTAL);
if (address != null && address.length() > 0) {
- mContents += "ADR:" + address + ";";
- mDisplayContents += "\n" + address;
+ mContents += "ADR:" + address + ';';
+ mDisplayContents += '\n' + address;
}
for (int x = 0; x < Contents.PHONE_KEYS.length; x++) {
String phone = bundle.getString(Contents.PHONE_KEYS[x]);
if (phone != null && phone.length() > 0) {
- mContents += "TEL:" + phone + ";";
- mDisplayContents += "\n" + PhoneNumberUtils.formatNumber(phone);
+ mContents += "TEL:" + phone + ';';
+ mDisplayContents += '\n' + PhoneNumberUtils.formatNumber(phone);
}
}
for (int x = 0; x < Contents.EMAIL_KEYS.length; x++) {
String email = bundle.getString(Contents.EMAIL_KEYS[x]);
if (email != null && email.length() > 0) {
- mContents += "EMAIL:" + email + ";";
- mDisplayContents += "\n" + email;
+ mContents += "EMAIL:" + email + ';';
+ mDisplayContents += '\n' + email;
}
}
mContents += ";";
} else if (type.equals(Contents.Type.LOCATION)) {
Bundle bundle = intent.getBundleExtra(Intents.Encode.DATA);
if (bundle != null) {
- float latitude = bundle.getFloat("LAT", Float.MAX_VALUE);
- float longitude = bundle.getFloat("LONG", Float.MAX_VALUE);
- if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) {
- mContents = "geo:" + latitude + "," + longitude;
+ double latitude = bundle.getDouble("LAT", Double.NaN);
+ double longitude = bundle.getDouble("LONG", Double.NaN);
+ if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
+ mContents = "geo:" + latitude + ',' + longitude;
mDisplayContents = latitude + "," + longitude;
mTitle = mActivity.getString(R.string.contents_location);
}
private static final class EncodeThread extends Thread {
+ private static final String TAG = "EncodeThread";
+
private final String mContents;
private final Handler mHandler;
private final int mPixelResolution;
- public EncodeThread(String contents, Handler handler, int pixelResolution) {
+ EncodeThread(String contents, Handler handler, int pixelResolution) {
mContents = contents;
mHandler = handler;
mPixelResolution = pixelResolution;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int grey = array[y][x] & 0xff;
- pixels[y * width + x] = (0xff << 24) | (grey << 16) | (grey << 8) | grey;
+ //pixels[y * width + x] = (0xff << 24) | (grey << 16) | (grey << 8) | grey;
+ pixels[y * width + x] = 0xff000000 | (0x00010101 * grey);
}
}
try {
String pageNumber = json.getString("page_number");
if (pageNumber.length() > 0) {
- pageNumber = getString(R.string.msg_sbc_page) + " " + pageNumber;
+ pageNumber = getString(R.string.msg_sbc_page) + ' ' + pageNumber;
} else {
// This can happen for text on the jacket, and possibly other reasons.
pageNumber = getString(R.string.msg_sbc_unknown_page);
snippet = snippet.replaceAll("'", "'");
snippet = snippet.replaceAll(""", "\"");
} else {
- snippet = "(" + getString(R.string.msg_sbc_snippet_unavailable) + ")";
+ snippet = '(' + getString(R.string.msg_sbc_snippet_unavailable) + ')';
valid = false;
}
return new SearchBookContentsResult(pageNumber, snippet, valid);
private final Handler mHandler;
private final String mUserAgent;
- public NetworkThread(String isbn, String query, Handler handler, String userAgent) {
+ NetworkThread(String isbn, String query, Handler handler, String userAgent) {
mISBN = isbn;
mQuery = query;
mHandler = handler;
return cookie;
}
- private String getEncoding(HttpEntity entity) {
+ private static String getEncoding(HttpEntity entity) {
// FIXME: The server is returning ISO-8859-1 but the content is actually windows-1252.
// Once Jeff fixes the HTTP response, remove this hardcoded value and go back to getting
// the encoding dynamically.
assert (crop.height() <= dataHeight);
}
+ @Override
public int getHeight() {
return mCrop.height();
}
+ @Override
public int getWidth() {
return mCrop.width();
}
* @param y The y coordinate to fetch within crop
* @return The luminance as an int, from 0-255
*/
+ @Override
protected int getLuminance(int x, int y) {
return mYUVData[(y + mCrop.top) * mDataWidth + x + mCrop.left] & 0xff;
}
+ @Override
protected int[] getLuminanceRow(int y, int[] row) {
int width = getWidth();
if (row == null || row.length < width) {
return row;
}
+ @Override
protected int[] getLuminanceColumn(int x, int[] column) {
int height = getHeight();
if (column == null || column.length < height) {
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
private final boolean[] mFields;
- private int mButtonCount;
+ private final int mButtonCount;
// This takes all the work out of figuring out which buttons/actions should be in which
// positions, based on which fields are present in this barcode.
if (pronunciation != null && pronunciation.length() > 0) {
contents.append("\n(");
contents.append(pronunciation);
- contents.append(")");
+ contents.append(')');
}
ParsedResult.maybeAppend(result.getTitle(), contents);
protected final ParsedResult mResult;
private final Activity mActivity;
- public ResultHandler(Activity activity, ParsedResult result) {
+ protected ResultHandler(Activity activity, ParsedResult result) {
mResult = result;
mActivity = activity;
}
launchIntent(intent);
}
- private long calculateMilliseconds(String when) {
+ private static long calculateMilliseconds(String when) {
if (when.length() == 8) {
// Only contains year/month/day
Date date;
public final void searchMap(String address, String title) {
String query = address;
if (title != null && title.length() > 0) {
- query = query + " (" + title + ")";
+ query = query + " (" + title + ')';
}
launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + Uri.encode(query))));
}
public final void getDirections(float latitude, float longitude) {
launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google." +
- LocaleManager.getCountryTLD() + "/maps?f=d&daddr=" + latitude + "," + longitude)));
+ LocaleManager.getCountryTLD() + "/maps?f=d&daddr=" + latitude + ',' + longitude)));
}
public final void openProductSearch(String upc) {
public final class ResultHandlerFactory {
+ private ResultHandlerFactory() {
+ }
+
public static ResultHandler makeResultHandler(Activity activity, Result rawResult) {
ParsedResult result = parseResult(rawResult);
ParsedResultType type = result.getType();
}
};
- private void handleBenchmarkDone(Message message) {
+ private static void handleBenchmarkDone(Message message) {
List<BenchmarkItem> items = (List<BenchmarkItem>) message.obj;
int count = 0;
for (int x = 0; x < items.size(); x++) {
public final class BenchmarkItem {
private final String mPath;
- private int[] mTimes;
+ private final int[] mTimes;
private int mPosition;
private boolean mDecoded;
private BarcodeFormat mFormat;
@Override
public String toString() {
- StringBuffer result = new StringBuffer();
+ StringBuilder result = new StringBuilder();
result.append(mDecoded ? ("DECODED " + mFormat.toString() + ": ") : "FAILED: ");
result.append(mPath);
result.append(" (");
String[] files = file.list();
Arrays.sort(files);
for (int x = 0; x < files.length; x++) {
- walkTree(file.getAbsolutePath() + "/" + files[x], items);
+ walkTree(file.getAbsolutePath() + '/' + files[x], items);
}
} else {
BenchmarkItem item = decode(path);
public final class RGBMonochromeBitmapSource extends BaseMonochromeBitmapSource {
- private int mWidth;
- private int mHeight;
- private byte[] mLuminances;
+ private final int mWidth;
+ private final int mHeight;
+ private final byte[] mLuminances;
public RGBMonochromeBitmapSource(String path) throws FileNotFoundException {
Bitmap bitmap = BitmapFactory.decodeFile(path);
}
}
+ @Override
public int getHeight() {
return mHeight;
}
+ @Override
public int getWidth() {
return mWidth;
}
+ @Override
protected int getLuminance(int x, int y) {
return mLuminances[y * mWidth + x] & 0xff;
}
+ @Override
protected int[] getLuminanceRow(int y, int[] row) {
int width = mWidth;
if (row == null || row.length < width) {
return row;
}
+ @Override
protected int[] getLuminanceColumn(int x, int[] column) {
int width = mWidth;
int height = mHeight;
message.sendToTarget();
}
- private OutputStream getNewPhotoOutputStream() {
+ private static OutputStream getNewPhotoOutputStream() {
File sdcard = new File("/sdcard");
if (sdcard.exists()) {
File barcodes = new File(sdcard, "barcodes");
public final class GeoParsedResult extends ParsedResult {
private final String geoURI;
- private final float latitude;
- private final float longitude;
- private final float altitude;
+ private final double latitude;
+ private final double longitude;
+ private final double altitude;
- GeoParsedResult(String geoURI, float latitude, float longitude, float altitude) {
+ GeoParsedResult(String geoURI, double latitude, double longitude, double altitude) {
super(ParsedResultType.GEO);
this.geoURI = geoURI;
this.latitude = latitude;
/**
* @return latitude in degrees
*/
- public float getLatitude() {
+ public double getLatitude() {
return latitude;
}
/**
* @return longitude in degrees
*/
- public float getLongitude() {
+ public double getLongitude() {
return longitude;
}
/**
* @return altitude in meters. If not specified, in the geo URI, returns 0.0
*/
- public float getAltitude() {
+ public double getAltitude() {
return altitude;
}
if (altitude > 0.0f) {
// Map altitude to zoom level, cleverly. Roughly, zoom level 19 is like a
// view from 1000ft, 18 is like 2000ft, 17 like 4000ft, and so on.
- float altitudeInFeet = altitude * 3.28f;
- int altitudeInKFeet = (int) (altitudeInFeet / 1000.0f);
+ double altitudeInFeet = altitude * 3.28;
+ int altitudeInKFeet = (int) (altitudeInFeet / 1000.0);
// No Math.log() available here, so compute log base 2 the old fashioned way
// Here logBaseTwo will take on a value between 0 and 18 actually
int logBaseTwo = 0;
if (latitudeEnd < 0) {
return null;
}
- float latitude = Float.parseFloat(geoURIWithoutQuery.substring(0, latitudeEnd));
+ double latitude = Double.parseDouble(geoURIWithoutQuery.substring(0, latitudeEnd));
int longitudeEnd = geoURIWithoutQuery.indexOf(',', latitudeEnd + 1);
- float longitude;
- float altitude; // in meters
+ double longitude;
+ double altitude; // in meters
if (longitudeEnd < 0) {
- longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1));
- altitude = 0.0f;
+ longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1));
+ altitude = 0.0;
} else {
- longitude = Float.parseFloat(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd));
- altitude = Float.parseFloat(geoURIWithoutQuery.substring(longitudeEnd + 1));
+ longitude = Double.parseDouble(geoURIWithoutQuery.substring(latitudeEnd + 1, longitudeEnd));
+ altitude = Double.parseDouble(geoURIWithoutQuery.substring(longitudeEnd + 1));
}
return new GeoParsedResult(rawText, latitude, longitude, altitude);
}
if (titleEnd < 0) {
return null;
}
- String title = rawText.substring(6, titleEnd);
+ String title = titleEnd <= 6 ? null : rawText.substring(6, titleEnd);
String uri = rawText.substring(titleEnd + 1);
return new URIParsedResult(uri, title);
}
* @return index of the first black line.\r
* @throws ReaderException Throws exception if no black lines are found in the row\r
*/\r
- private int skipWhiteSpace(BitArray row) throws ReaderException {\r
+ private static int skipWhiteSpace(BitArray row) throws ReaderException {\r
int width = row.getSize();\r
int endStart = 0;\r
while (endStart < width) {\r
* ints\r
* @throws ReaderException if pattern is not found\r
*/\r
- int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws ReaderException {\r
+ static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws ReaderException {\r
\r
// TODO: This is very similar to implementation in AbstractUPCEANReader. Consider if they can be merged to\r
// a single method.\r
return doDecodeFormatInformation(rawFormatInfo ^ FORMAT_INFO_MASK_QR);
}
- private static FormatInformation doDecodeFormatInformation(int rawFormatInfo) throws ReaderException {
+ private static FormatInformation doDecodeFormatInformation(int rawFormatInfo) {
// Unmask:
int unmaskedFormatInfo = rawFormatInfo ^ FORMAT_INFO_MASK_QR;
// Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing
--- /dev/null
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.client.result;
+
+import junit.framework.TestCase;
+import com.google.zxing.Result;
+import com.google.zxing.BarcodeFormat;
+
+import java.util.Arrays;
+
+/**
+ * Tests {@link AddressBookParsedResult}.
+ *
+ * @author Sean Owen
+ */
+public final class AddressBookParsedResultTestCase extends TestCase {
+
+ public void testAddressBookDocomo() {
+ doTest("MECARD:N:Sean Owen;;", null, new String[] {"Sean Owen"}, null, null, null, null, null, null, null, null);
+ doTest("MECARD:NOTE:ZXing Team;N:Sean Owen;URL:google.com;EMAIL:srowen@example.org;;",
+ null, new String[] {"Sean Owen"}, null, null, new String[] {"srowen@example.org"}, null, null,
+ "google.com", null, "ZXing Team");
+ }
+
+ public void testAddressBookAU() {
+ doTest("MEMORY:foo\r\nNAME1:Sean\r\nTEL1:+12125551212\r\n",
+ null, new String[] {"Sean"}, null, null, null, new String[] {"+12125551212"}, null, null, null, "foo");
+ }
+
+ public void testVCard() {
+ doTest("BEGIN:VCARD\r\nADR;HOME:123 Main St\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
+ null, new String[] {"Sean Owen"}, null, "123 Main St", null, null, null, null, null, null);
+ }
+
+ public void testBizcard() {
+ doTest("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12125551212;E:srowen@example.org;",
+ null, new String[] {"Sean Owen"}, null, "123 Main St", new String[] {"srowen@example.org"},
+ new String[] {"+12125551212"}, "Google", null, null, null);
+ }
+
+ private static void doTest(String contents,
+ String title,
+ String[] names,
+ String pronunciation,
+ String address,
+ String[] emails,
+ String[] phoneNumbers,
+ String org,
+ String url,
+ String birthday,
+ String note) {
+ Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
+ ParsedResult result = ResultParser.parseResult(fakeResult);
+ assertEquals(ParsedResultType.ADDRESSBOOK, result.getType());
+ AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
+ assertEquals(title, addressResult.getTitle());
+ assertTrue(Arrays.equals(names, addressResult.getNames()));
+ assertEquals(pronunciation, addressResult.getPronunciation());
+ assertEquals(address, addressResult.getAddress());
+ assertTrue(Arrays.equals(emails, addressResult.getEmails()));
+ assertTrue(Arrays.equals(phoneNumbers, addressResult.getPhoneNumbers()));
+ assertEquals(org, addressResult.getOrg());
+ assertEquals(url, addressResult.getURL());
+ assertEquals(birthday, addressResult.getBirthday());
+ assertEquals(note, addressResult.getNote());
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.client.result;
+
+import junit.framework.TestCase;
+import com.google.zxing.Result;
+import com.google.zxing.BarcodeFormat;
+
+/**
+ * Tests {@link CalendarParsedResult}.
+ *
+ * @author Sean Owen
+ */
+public final class CalendarParsedResultTestCase extends TestCase {
+
+ public void testVEvent() {
+ doTest(
+ "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504T123456Z\r\nDTEND:20080505T234555Z\r\n" +
+ "END:VEVENT\r\nEND:VCALENDAR",
+ null, "foo", null, "20080504T123456Z", "20080505T234555Z", null);
+ }
+
+ private static void doTest(String contents,
+ String title,
+ String summary,
+ String location,
+ String start,
+ String end,
+ String attendee) {
+ Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
+ ParsedResult result = ResultParser.parseResult(fakeResult);
+ assertEquals(ParsedResultType.CALENDAR, result.getType());
+ CalendarParsedResult calResult = (CalendarParsedResult) result;
+ assertEquals(title, calResult.getTitle());
+ assertEquals(summary, calResult.getSummary());
+ assertEquals(location, calResult.getLocation());
+ assertEquals(start, calResult.getStart());
+ assertEquals(end, calResult.getEnd());
+ assertEquals(attendee, calResult.getAttendee());
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.client.result;
+
+import junit.framework.TestCase;
+import com.google.zxing.Result;
+import com.google.zxing.BarcodeFormat;
+
+/**
+ * Tests {@link EmailAddressParsedResult}.
+ *
+ * @author Sean Owen
+ */
+public final class EmailAddressParsedResultTestCase extends TestCase {
+
+ public void testEmailAddress() {
+ doTest("srowen@example.org", "srowen@example.org", null, null);
+ doTest("mailto:srowen@example.org", "srowen@example.org", null, null);
+ }
+
+ public void testEmailDocomo() {
+ doTest("MATMSG:TO:srowen@example.org;;", "srowen@example.org", null, null);
+ doTest("MATMSG:TO:srowen@example.org;SUB:Stuff;;", "srowen@example.org", "Stuff", null);
+ doTest("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", "srowen@example.org",
+ "Stuff", "This is some text");
+ }
+
+ private static void doTest(String contents, String email, String subject, String body) {
+ Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
+ ParsedResult result = ResultParser.parseResult(fakeResult);
+ assertEquals(ParsedResultType.EMAIL_ADDRESS, result.getType());
+ EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result;
+ assertEquals(email, emailResult.getEmailAddress());
+ assertEquals("mailto:" + email, emailResult.getMailtoURI());
+ assertEquals(subject, emailResult.getSubject());
+ assertEquals(body, emailResult.getBody());
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.client.result;
+
+import junit.framework.TestCase;
+import com.google.zxing.Result;
+import com.google.zxing.BarcodeFormat;
+
+/**
+ * Tests {@link com.google.zxing.client.result.GeoParsedResult}.
+ *
+ * @author Sean Owen
+ */
+public final class GeoParsedResultTestCase extends TestCase {
+
+ public void testGeo() {
+ doTest("geo:1,2", 1.0, 2.0, 0.0);
+ doTest("geo:100.33,-32.3344,3.35", 100.33, -32.3344, 3.35);
+ }
+
+ private static void doTest(String contents, double latitude, double longitude, double altitude) {
+ Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
+ ParsedResult result = ResultParser.parseResult(fakeResult);
+ assertEquals(ParsedResultType.GEO, result.getType());
+ GeoParsedResult geoResult = (GeoParsedResult) result;
+ assertEquals(latitude, geoResult.getLatitude());
+ assertEquals(longitude, geoResult.getLongitude());
+ assertEquals(altitude, geoResult.getAltitude());
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.client.result;
+
+import junit.framework.TestCase;
+import com.google.zxing.Result;
+import com.google.zxing.BarcodeFormat;
+
+/**
+ * Tests {@link ISBNParsedResult}.
+ *
+ * @author Sean Owen
+ */
+public final class ISBNParsedResultTestCase extends TestCase {
+
+ public void testISBN() {
+ doTest("9784567890123");
+ }
+
+ private static void doTest(String contents) {
+ Result fakeResult = new Result(contents, null, null, BarcodeFormat.EAN_13);
+ ParsedResult result = ResultParser.parseResult(fakeResult);
+ assertEquals(ParsedResultType.ISBN, result.getType());
+ ISBNParsedResult isbnResult = (ISBNParsedResult) result;
+ assertEquals(contents, isbnResult.getISBN());
+ }
+
+}
\ No newline at end of file
doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", "+12125551212", ParsedResultType.ADDRESSBOOK);
}
- public void testUPC() {
+ 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);
+ }
+
+ public void testUPCA() {
doTestResult("123456789012", "123456789012", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
doTestResult("1234567890123", "1234567890123", ParsedResultType.PRODUCT, BarcodeFormat.UPC_A);
doTestResult("12345678901", "12345678901", ParsedResultType.TEXT);
}
+ public void testUPCE() {
+ doTestResult("01234565", "01234565", ParsedResultType.PRODUCT, BarcodeFormat.UPC_E);
+ }
+
public void testEAN() {
doTestResult("00393157", "00393157", ParsedResultType.PRODUCT, BarcodeFormat.EAN_8);
doTestResult("00393158", "00393158", ParsedResultType.TEXT);
--- /dev/null
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.client.result;
+
+import junit.framework.TestCase;
+import com.google.zxing.Result;
+import com.google.zxing.BarcodeFormat;
+
+/**
+ * Tests {@link ProductParsedResult}.
+ *
+ * @author Sean Owen
+ */
+public final class ProductParsedResultTestCase extends TestCase {
+
+ public void testProduct() {
+ doTest("123456789012", "123456789012", BarcodeFormat.UPC_A);
+ doTest("00393157", "00393157", BarcodeFormat.EAN_8);
+ doTest("5051140178499", "5051140178499", BarcodeFormat.EAN_13);
+ doTest("01234565", "012345000065", BarcodeFormat.UPC_E);
+ }
+
+ private static void doTest(String contents, String normalized, BarcodeFormat format) {
+ Result fakeResult = new Result(contents, null, null, format);
+ ParsedResult result = ResultParser.parseResult(fakeResult);
+ assertEquals(ParsedResultType.PRODUCT, result.getType());
+ ProductParsedResult productResult = (ProductParsedResult) result;
+ assertEquals(contents, productResult.getProductID());
+ assertEquals(normalized, productResult.getNormalizedProductID());
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.client.result;
+
+import junit.framework.TestCase;
+import com.google.zxing.Result;
+import com.google.zxing.BarcodeFormat;
+
+/**
+ * Tests {@link SMSParsedResult}.
+ *
+ * @author Sean Owen
+ */
+public final class SMSMMSParsedResultTestCase extends TestCase {
+
+ public void testSMS() {
+ doTest("sms:+15551212", "+15551212", null, null, null);
+ doTest("sms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null);
+ doTest("sms:+15551212;via=999333", "+15551212", null, null, "999333");
+ }
+
+ public void testMMS() {
+ doTest("mms:+15551212", "+15551212", null, null, null);
+ doTest("mms:+15551212?subject=foo&body=bar", "+15551212", "foo", "bar", null);
+ doTest("mms:+15551212;via=999333", "+15551212", null, null, "999333");
+ }
+
+ private static void doTest(String contents, String number, String subject, String body, String via) {
+ Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
+ ParsedResult result = ResultParser.parseResult(fakeResult);
+ assertEquals(ParsedResultType.SMS, result.getType());
+ SMSParsedResult smsResult = (SMSParsedResult) result;
+ assertEquals(number, smsResult.getNumber());
+ assertEquals(subject, smsResult.getSubject());
+ assertEquals(body, smsResult.getBody());
+ assertEquals(via, smsResult.getVia());
+ assertEquals("sms:" + number, smsResult.getSMSURI());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.client.result;
+
+import junit.framework.TestCase;
+import com.google.zxing.Result;
+import com.google.zxing.BarcodeFormat;
+
+/**
+ * Tests {@link TelParsedResult}.
+ *
+ * @author Sean Owen
+ */
+public final class TelParsedResultTestCase extends TestCase {
+
+ public void testTel() {
+ doTest("tel:+15551212", "+15551212", null);
+ doTest("tel:2125551212", "2125551212", null);
+ }
+
+ 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);
+ assertEquals(ParsedResultType.TEL, result.getType());
+ TelParsedResult telResult = (TelParsedResult) result;
+ assertEquals(number, telResult.getNumber());
+ assertEquals(title, telResult.getTitle());
+ assertEquals("tel:" + number, telResult.getTelURI());
+ }
+
+}
\ No newline at end of file
package com.google.zxing.client.result;
import junit.framework.TestCase;
+import com.google.zxing.Result;
+import com.google.zxing.BarcodeFormat;
/**
- * Tests {@link com.google.zxing.client.result.URIParsedResult}.
+ * Tests {@link URIParsedResult}.
*
* @author Sean Owen
*/
public final class URIParsedResultTestCase extends TestCase {
+ public void testBookmarkDocomo() {
+ doTest("MEBKM:URL:google.com;;", "http://google.com", null);
+ doTest("MEBKM:URL:http://google.com;;", "http://google.com", null);
+ doTest("MEBKM:URL:google.com;TITLE:Google;", "http://google.com", "Google");
+ }
+
+ public void testURI() {
+ doTest("google.com", "http://google.com", null);
+ doTest("http://google.com", "http://google.com", null);
+ doTest("https://google.com", "https://google.com", null);
+ doTest("google.com:443", "http://google.com:443", null);
+ }
+
+ public void testURLTO() {
+ doTest("urlto::bar.com", "http://bar.com", null);
+ doTest("urlto::http://bar.com", "http://bar.com", null);
+ doTest("urlto:foo:bar.com", "http://bar.com", "foo");
+ }
+
public void testIsPossiblyMalicious() {
doTestIsPossiblyMalicious("http://google.com", false);
doTestIsPossiblyMalicious("http://google.com@evil.com", true);
doTestIsPossiblyMalicious("http://google.com/foo@bar", false);
}
- private void doTestIsPossiblyMalicious(String uri, boolean expected) {
+ 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);
+ assertEquals(ParsedResultType.URI, result.getType());
+ URIParsedResult uriResult = (URIParsedResult) result;
+ assertEquals(uri, uriResult.getURI());
+ assertEquals(title, uriResult.getTitle());
+ }
+
+ private static void doTestIsPossiblyMalicious(String uri, boolean expected) {
URIParsedResult result = new URIParsedResult(uri, null);
assertEquals(expected, result.isPossiblyMaliciousURI());
}
if (!expectedFormat.equals(result.getBarcodeFormat())) {
System.out.println("Format mismatch: expected '" + expectedFormat + "' but got '" +
- result.getBarcodeFormat() + "'" + suffix);
+ result.getBarcodeFormat() + '\'' + suffix);
return false;
}
String resultText = result.getText();
if (!expectedText.equals(resultText)) {
System.out.println("Mismatch: expected '" + expectedText + "' but got '" + resultText +
- "'" + suffix);
+ '\'' + suffix);
return false;
}
return true;
* Tests example given in ISO 18004, Annex I
*/
public void testISO18004Example() {
- int[] dataBytes = new int[] {
+ int[] dataBytes = {
0x10, 0x20, 0x0C, 0x56, 0x61, 0x80, 0xEC, 0x11,
0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11, 0xEC, 0x11 };
- int[] expectedECBytes = new int[] {
+ int[] expectedECBytes = {
0xA5, 0x24, 0xD4, 0xC1, 0xED, 0x36, 0xC7, 0x87,
0x2C, 0x55 };
doTestQRCodeEncoding(dataBytes, expectedECBytes);
assertNotNull(goldenResult);
QRCodeWriter writer = new QRCodeWriter();
- Hashtable hints = new Hashtable();
+ Hashtable<EncodeHintType,Object> hints = new Hashtable<EncodeHintType,Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, ecLevel);
ByteMatrix generatedResult = writer.encode(contents, BarcodeFormat.QR_CODE, resolution,
resolution, hints);
// Golden images are generated with "qrcode_sample.cc". The images are checked with both eye balls
// and cell phones. We expect pixel-perfect results, because the error correction level is known,
// and the pixel dimensions matches exactly.
- public void testRegressionTest() throws WriterException, IOException {
+ public void testRegressionTest() throws WriterException {
compareToGoldenFile("http://www.google.com/", ErrorCorrectionLevel.M, 99,
"renderer-test-01.png");
}
}
- private static interface MaskCondition {
+ private interface MaskCondition {
boolean isMasked(int i, int j);
}
}
}
- public void testDecodeVersionInformation() throws ReaderException {
+ public void testDecodeVersionInformation() {
// Spot check
assertEquals(7, Version.decodeVersionInformation(0x07C94).getVersionNumber());
assertEquals(12, Version.decodeVersionInformation(0x0C762).getVersionNumber());
assertEquals(expected, qrCode.toString());
}
- public void testAppendModeInfo() throws WriterException {
+ public void testAppendModeInfo() {
BitVector bits = new BitVector();
Encoder.appendModeInfo(Mode.NUMERIC, bits);
assertEquals("0001", bits.toString());
// http://www.swetake.com/qr/qr9.html
public void testGenerateECBytes() {
{
- final byte[] dataBytes = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236};
+ byte[] dataBytes = {32, 65, (byte)205, 69, 41, (byte)220, 46, (byte)128, (byte)236};
ByteArray ecBytes = Encoder.generateECBytes(new ByteArray(dataBytes), 17);
- final int[] expected = {
+ int[] expected = {
42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61
};
assertEquals(expected.length, ecBytes.size());
}
}
{
- final byte[] dataBytes = {67, 70, 22, 38, 54, 70, 86, 102, 118,
+ byte[] dataBytes = {67, 70, 22, 38, 54, 70, 86, 102, 118,
(byte)134, (byte)150, (byte)166, (byte)182, (byte)198, (byte)214};
ByteArray ecBytes = Encoder.generateECBytes(new ByteArray(dataBytes), 18);
- final int[] expected = {
+ int[] expected = {
175, 80, 155, 64, 178, 45, 214, 233, 65, 209, 12, 155, 117, 31, 140, 214, 27, 187
};
assertEquals(expected.length, ecBytes.size());
}
{
// High-order zero cofficient case.
- final byte[] dataBytes = {32, 49, (byte)205, 69, 42, 20, 0, (byte)236, 17};
+ byte[] dataBytes = {32, 49, (byte)205, 69, 42, 20, 0, (byte)236, 17};
ByteArray ecBytes = Encoder.generateECBytes(new ByteArray(dataBytes), 17);
- final int[] expected = {
+ int[] expected = {
0, 3, 130, 179, 194, 0, 55, 211, 110, 79, 98, 72, 170, 96, 211, 137, 213
};
assertEquals(expected.length, ecBytes.size());
name = name.substring(0, dotpos);
}
String suffix = (sMethod == BlackPointEstimationMethod.ROW_SAMPLING) ? "row" : "2d";
- result = new File(name + "_converted_" + suffix + "." + FORMAT);
+ result = new File(name + "_converted_" + suffix + '.' + FORMAT);
}
return result;
}