Many more little tweaks from IntelliJ inspections

git-svn-id: https://zxing.googlecode.com/svn/trunk@382 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-05-02 19:18:14 +00:00
parent dee32b1323
commit 635d904283
22 changed files with 113 additions and 373 deletions

View file

@ -30,7 +30,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.view.WindowManager.LayoutParams; import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import com.google.zxing.Result; import com.google.zxing.Result;
import com.google.zxing.ResultPoint; import com.google.zxing.ResultPoint;
@ -111,22 +110,30 @@ public final class BarcodeReaderCaptureActivity extends Activity {
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_A) { switch (keyCode) {
case KeyEvent.KEYCODE_A:
cameraThread.setDecodeAllMode(); cameraThread.setDecodeAllMode();
} else if (keyCode == KeyEvent.KEYCODE_C) { break;
case KeyEvent.KEYCODE_C:
Message save = Message.obtain(cameraThread.handler, R.id.save); Message save = Message.obtain(cameraThread.handler, R.id.save);
save.sendToTarget(); save.sendToTarget();
} else if (keyCode == KeyEvent.KEYCODE_P) { break;
case KeyEvent.KEYCODE_P:
cameraManager.setUsePreviewForDecode(true); cameraManager.setUsePreviewForDecode(true);
} else if (keyCode == KeyEvent.KEYCODE_Q) { break;
case KeyEvent.KEYCODE_Q:
cameraThread.setDecodeQRMode(); cameraThread.setDecodeQRMode();
} else if (keyCode == KeyEvent.KEYCODE_S) { break;
case KeyEvent.KEYCODE_S:
cameraManager.setUsePreviewForDecode(false); cameraManager.setUsePreviewForDecode(false);
} else if (keyCode == KeyEvent.KEYCODE_T) { break;
case KeyEvent.KEYCODE_T:
cameraThread.toggleTracing(); cameraThread.toggleTracing();
} else if (keyCode == KeyEvent.KEYCODE_U) { break;
case KeyEvent.KEYCODE_U:
cameraThread.setDecode1DMode(); cameraThread.setDecode1DMode();
} else { break;
default:
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
return true; return true;
@ -173,7 +180,7 @@ public final class BarcodeReaderCaptureActivity extends Activity {
} }
}; };
public void restartPreview() { void restartPreview() {
resetStatusViewColor(); resetStatusViewColor();
Message restart = Message.obtain(cameraThread.handler, R.id.restart_preview); Message restart = Message.obtain(cameraThread.handler, R.id.restart_preview);
restart.sendToTarget(); restart.sendToTarget();
@ -193,12 +200,12 @@ public final class BarcodeReaderCaptureActivity extends Activity {
ParsedReaderResult readerResult = parseReaderResult(rawResult); ParsedReaderResult readerResult = parseReaderResult(rawResult);
textView.setText(readerResult.getDisplayResult() + " (" + duration + " ms)"); textView.setText(readerResult.getDisplayResult() + " (" + duration + " ms)");
Button actionButton = (Button) findViewById(R.id.status_action_button); TextView actionButton = (TextView) findViewById(R.id.status_action_button);
int buttonText = getActionButtonText(readerResult.getType()); int buttonText = getActionButtonText(readerResult.getType());
if (buttonText != 0) { if (buttonText != 0) {
actionButton.setVisibility(View.VISIBLE); actionButton.setVisibility(View.VISIBLE);
actionButton.setText(buttonText); actionButton.setText(buttonText);
ResultHandler handler = new ResultHandler(this, readerResult); View.OnClickListener handler = new ResultHandler(this, readerResult);
actionButton.setOnClickListener(handler); actionButton.setOnClickListener(handler);
actionButton.requestFocus(); actionButton.requestFocus();
} else { } else {
@ -226,7 +233,7 @@ public final class BarcodeReaderCaptureActivity extends Activity {
resetStatusViewColor(); resetStatusViewColor();
TextView textView = (TextView) findViewById(R.id.status_text_view); TextView textView = (TextView) findViewById(R.id.status_text_view);
textView.setText(R.string.msg_default_status); textView.setText(R.string.msg_default_status);
Button actionButton = (Button) findViewById(R.id.status_action_button); View actionButton = findViewById(R.id.status_action_button);
actionButton.setVisibility(View.GONE); actionButton.setVisibility(View.GONE);
lastResult = ""; lastResult = "";
} }

View file

@ -57,6 +57,7 @@ final class CameraThread extends Thread {
public void run() { public void run() {
Looper.prepare(); Looper.prepare();
handler = new Handler() { handler = new Handler() {
@Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
switch (message.what) { switch (message.what) {
case R.id.preview: case R.id.preview:

View file

@ -66,6 +66,7 @@ final class DecodeThread extends Thread {
public void run() { public void run() {
Looper.prepare(); Looper.prepare();
handler = new Handler() { handler = new Handler() {
@Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
switch (message.what) { switch (message.what) {
case R.id.decode: case R.id.decode:

View file

@ -27,7 +27,6 @@ import android.view.Menu;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import com.google.zxing.Result; import com.google.zxing.Result;
import com.google.zxing.ResultPoint; import com.google.zxing.ResultPoint;
@ -94,22 +93,30 @@ public final class BarcodeReaderCaptureActivity extends Activity {
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_A) { switch (keyCode) {
case KeyEvent.KEYCODE_A:
cameraThread.setDecodeAllMode(); cameraThread.setDecodeAllMode();
} else if (keyCode == KeyEvent.KEYCODE_C) { break;
case KeyEvent.KEYCODE_C:
Message save = Message.obtain(cameraThread.handler, R.id.save); Message save = Message.obtain(cameraThread.handler, R.id.save);
save.sendToTarget(); save.sendToTarget();
} else if (keyCode == KeyEvent.KEYCODE_P) { break;
case KeyEvent.KEYCODE_P:
cameraManager.setUsePreviewForDecode(true); cameraManager.setUsePreviewForDecode(true);
} else if (keyCode == KeyEvent.KEYCODE_Q) { break;
case KeyEvent.KEYCODE_Q:
cameraThread.setDecodeQRMode(); cameraThread.setDecodeQRMode();
} else if (keyCode == KeyEvent.KEYCODE_S) { break;
case KeyEvent.KEYCODE_S:
cameraManager.setUsePreviewForDecode(false); cameraManager.setUsePreviewForDecode(false);
} else if (keyCode == KeyEvent.KEYCODE_T) { break;
case KeyEvent.KEYCODE_T:
cameraThread.toggleTracing(); cameraThread.toggleTracing();
} else if (keyCode == KeyEvent.KEYCODE_U) { break;
case KeyEvent.KEYCODE_U:
cameraThread.setDecode1DMode(); cameraThread.setDecode1DMode();
} else { break;
default:
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
return true; return true;
@ -157,7 +164,7 @@ public final class BarcodeReaderCaptureActivity extends Activity {
} }
}; };
public void restartPreview() { void restartPreview() {
Message restart = Message.obtain(cameraThread.handler, R.id.restart_preview); Message restart = Message.obtain(cameraThread.handler, R.id.restart_preview);
restart.sendToTarget(); restart.sendToTarget();
} }
@ -175,12 +182,12 @@ public final class BarcodeReaderCaptureActivity extends Activity {
ParsedReaderResult readerResult = parseReaderResult(rawResult); ParsedReaderResult readerResult = parseReaderResult(rawResult);
textView.setText(readerResult.getDisplayResult() + " (" + duration + " ms)"); textView.setText(readerResult.getDisplayResult() + " (" + duration + " ms)");
Button actionButton = (Button) findViewById(R.id.status_action_button); TextView actionButton = (TextView) findViewById(R.id.status_action_button);
int buttonText = getActionButtonText(readerResult.getType()); int buttonText = getActionButtonText(readerResult.getType());
if (buttonText != 0) { if (buttonText != 0) {
actionButton.setVisibility(View.VISIBLE); actionButton.setVisibility(View.VISIBLE);
actionButton.setText(buttonText); actionButton.setText(buttonText);
ResultHandler handler = new ResultHandler(this, readerResult); View.OnClickListener handler = new ResultHandler(this, readerResult);
actionButton.setOnClickListener(handler); actionButton.setOnClickListener(handler);
actionButton.requestFocus(); actionButton.requestFocus();
} else { } else {
@ -198,7 +205,7 @@ public final class BarcodeReaderCaptureActivity extends Activity {
private void resetStatusView() { private void resetStatusView() {
TextView textView = (TextView) findViewById(R.id.status_text_view); TextView textView = (TextView) findViewById(R.id.status_text_view);
textView.setText(R.string.msg_default_status); textView.setText(R.string.msg_default_status);
Button actionButton = (Button) findViewById(R.id.status_action_button); View actionButton = findViewById(R.id.status_action_button);
actionButton.setVisibility(View.GONE); actionButton.setVisibility(View.GONE);
lastResult = ""; lastResult = "";
} }

View file

@ -57,6 +57,7 @@ final class CameraThread extends Thread {
public void run() { public void run() {
Looper.prepare(); Looper.prepare();
handler = new Handler() { handler = new Handler() {
@Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
switch (message.what) { switch (message.what) {
case R.id.preview: case R.id.preview:

View file

@ -66,6 +66,7 @@ final class DecodeThread extends Thread {
public void run() { public void run() {
Looper.prepare(); Looper.prepare();
handler = new Handler() { handler = new Handler() {
@Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
switch (message.what) { switch (message.what) {
case R.id.decode: case R.id.decode:

View file

@ -44,8 +44,6 @@ import com.google.zxing.client.result.URLTOParsedResult;
*/ */
final class ResultHandler implements Button.OnClickListener { final class ResultHandler implements Button.OnClickListener {
private static final String TAG = "ResultHandler";
private final Intent intent; private final Intent intent;
private final BarcodeReaderCaptureActivity captureActivity; private final BarcodeReaderCaptureActivity captureActivity;

View file

@ -16,7 +16,7 @@ import android.graphics.Canvas;
public interface CameraSource { public interface CameraSource {
static final String LOG_TAG = "camera"; String LOG_TAG = "camera";
/** /**
* Open the camera source for subsequent use via calls to capture(). * Open the camera source for subsequent use via calls to capture().

View file

@ -41,7 +41,7 @@ abstract class AbstractDoCoMoParsedResult extends ParsedReaderResult {
return matchPrefixedField(prefix, rawText, ';'); return matchPrefixedField(prefix, rawText, ';');
} }
static String[] matchPrefixedField(String prefix, String rawText, char endChar) { private static String[] matchPrefixedField(String prefix, String rawText, char endChar) {
Vector matches = null; Vector matches = null;
int i = 0; int i = 0;
int max = rawText.length(); int max = rawText.length();

View file

@ -1,47 +0,0 @@
/*
* Copyright 2008 Google Inc.
*
* 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 java.io.UnsupportedEncodingException;
/**
* <p>Superclass for classes encapsulating results in the NDEF format.
* See <a href="http://www.nfc-forum.org/specs/">http://www.nfc-forum.org/specs/</a>.</p>
*
* <p>This code supports a limited subset of NDEF messages, ones that are plausibly
* useful in 2D barcode formats. This generally includes 1-record messages, no chunking,
* "short record" syntax, no ID field.</p>
*
* @author srowen@google.com (Sean Owen)
*/
abstract class AbstractNDEFParsedResult extends ParsedReaderResult {
AbstractNDEFParsedResult(ParsedReaderResultType type) {
super(type);
}
static String bytesToString(byte[] bytes, int offset, int length, String encoding) {
try {
return new String(bytes, offset, length, encoding);
} catch (UnsupportedEncodingException uee) {
// This should only be used when 'encoding' is an encoding that must necessarily
// be supported by the JVM, like UTF-8
throw new RuntimeException("Platform does not support required encoding: " + uee);
}
}
}

View file

@ -1,112 +0,0 @@
/*
* Copyright 2008 Google Inc.
*
* 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 com.google.zxing.Result;
/**
* <p>Recognizes an NDEF message that encodes information according to the
* "Smart Poster Record Type Definition" specification.</p>
*
* <p>This actually only supports some parts of the Smart Poster format: title,
* URI, and action records. Icon records are not supported because the size
* of these records are infeasibly large for barcodes. Size and type records
* are not supported. Multiple titles are not supported.</p>
*
* @author srowen@google.com (Sean Owen)
*/
public final class NDEFSmartPosterParsedResult extends AbstractNDEFParsedResult {
public static final int ACTION_UNSPECIFIED = -1;
public static final int ACTION_DO = 0;
public static final int ACTION_SAVE = 1;
public static final int ACTION_OPEN = 2;
private String title;
private String uri;
private int action;
private NDEFSmartPosterParsedResult() {
super(ParsedReaderResultType.NDEF_SMART_POSTER);
action = ACTION_UNSPECIFIED;
}
public static NDEFSmartPosterParsedResult parse(Result result) {
byte[] bytes = result.getRawBytes();
if (bytes == null) {
return null;
}
NDEFRecord headerRecord = NDEFRecord.readRecord(bytes, 0);
// Yes, header record starts and ends a message
if (headerRecord == null || !headerRecord.isMessageBegin() || !headerRecord.isMessageEnd()) {
return null;
}
if (!headerRecord.getType().equals(NDEFRecord.SMART_POSTER_WELL_KNOWN_TYPE)) {
return null;
}
int offset = 0;
int recordNumber = 0;
NDEFRecord ndefRecord = null;
byte[] payload = headerRecord.getPayload();
NDEFSmartPosterParsedResult smartPosterParsedResult = new NDEFSmartPosterParsedResult();
while (offset < payload.length && (ndefRecord = NDEFRecord.readRecord(payload, offset)) != null) {
if (recordNumber == 0 && !ndefRecord.isMessageBegin()) {
return null;
}
String type = ndefRecord.getType();
if (NDEFRecord.TEXT_WELL_KNOWN_TYPE.equals(type)) {
String[] languageText = NDEFTextParsedResult.decodeTextPayload(ndefRecord.getPayload());
smartPosterParsedResult.title = languageText[1];
} else if (NDEFRecord.URI_WELL_KNOWN_TYPE.equals(type)) {
smartPosterParsedResult.uri = NDEFURIParsedResult.decodeURIPayload(ndefRecord.getPayload());
} else if (NDEFRecord.ACTION_WELL_KNOWN_TYPE.equals(type)) {
smartPosterParsedResult.action = ndefRecord.getPayload()[0];
}
recordNumber++;
offset += ndefRecord.getTotalRecordLength();
}
if (recordNumber == 0 || (ndefRecord != null && !ndefRecord.isMessageEnd())) {
return null;
}
return smartPosterParsedResult;
}
public String getTitle() {
return title;
}
public String getURI() {
return uri;
}
public int getAction() {
return action;
}
public String getDisplayResult() {
if (title == null) {
return uri;
} else {
return title + '\n' + uri;
}
}
}

View file

@ -1,109 +0,0 @@
/*
* Copyright 2008 Google Inc.
*
* 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 com.google.zxing.Result;
/**
* Recognizes an NDEF message that encodes a URI according to the
* "URI Record Type Definition" specification.
*
* @author srowen@google.com (Sean Owen)
*/
public final class NDEFURIParsedResult extends AbstractNDEFParsedResult {
private static final String[] URI_PREFIXES = {
null,
"http://www.",
"https://www.",
"http://",
"https://",
"tel:",
"mailto:",
"ftp://anonymous:anonymous@",
"ftp://ftp.",
"ftps://",
"sftp://",
"smb://",
"nfs://",
"ftp://",
"dav://",
"news:",
"telnet://",
"imap:",
"rtsp://",
"urn:",
"pop:",
"sip:",
"sips:",
"tftp:",
"btspp://",
"btl2cap://",
"btgoep://",
"tcpobex://",
"irdaobex://",
"file://",
"urn:epc:id:",
"urn:epc:tag:",
"urn:epc:pat:",
"urn:epc:raw:",
"urn:epc:",
"urn:nfc:",
};
private final String uri;
private NDEFURIParsedResult(String uri) {
super(ParsedReaderResultType.NDEF_URI);
this.uri = uri;
}
public static NDEFURIParsedResult parse(Result result) {
byte[] bytes = result.getRawBytes();
if (bytes == null) {
return null;
}
NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0);
if (ndefRecord == null || !ndefRecord.isMessageBegin() || !ndefRecord.isMessageEnd()) {
return null;
}
if (!ndefRecord.getType().equals(NDEFRecord.URI_WELL_KNOWN_TYPE)) {
return null;
}
String fullURI = decodeURIPayload(ndefRecord.getPayload());
return new NDEFURIParsedResult(fullURI);
}
static String decodeURIPayload(byte[] payload) {
int identifierCode = payload[0] & 0xFF;
String prefix = null;
if (identifierCode < URI_PREFIXES.length) {
prefix = URI_PREFIXES[identifierCode];
}
String restOfURI = bytesToString(payload, 1, payload.length - 1, "UTF-8");
return prefix == null ? restOfURI : prefix + restOfURI;
}
public String getURI() {
return uri;
}
public String getDisplayResult() {
return uri;
}
}

View file

@ -33,7 +33,7 @@ public abstract class ParsedReaderResult {
private final ParsedReaderResultType type; private final ParsedReaderResultType type;
public ParsedReaderResult(ParsedReaderResultType type) { protected ParsedReaderResult(ParsedReaderResultType type) {
this.type = type; this.type = type;
} }

View file

@ -40,7 +40,7 @@ final class BitMatrixParser {
} }
version = readVersion(bitMatrix); version = readVersion(bitMatrix);
this.mappingBitMatrix = extractDataRegion(bitMatrix, version); this.mappingBitMatrix = extractDataRegion(bitMatrix);
// TODO(bbrown): Make this work for rectangular symbols // TODO(bbrown): Make this work for rectangular symbols
this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.getDimension()); this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.getDimension());
} }
@ -394,10 +394,9 @@ final class BitMatrixParser {
* alignment patterns.</p> * alignment patterns.</p>
* *
* @param bitMatrix Original {@link BitMatrix} with alignment patterns * @param bitMatrix Original {@link BitMatrix} with alignment patterns
* @param version {@link Version} information corresponding with the bitMatrix
* @return BitMatrix that has the alignment patterns removed * @return BitMatrix that has the alignment patterns removed
*/ */
BitMatrix extractDataRegion(BitMatrix bitMatrix, Version version) { BitMatrix extractDataRegion(BitMatrix bitMatrix) {
int symbolSizeRows = version.getSymbolSizeRows(); int symbolSizeRows = version.getSymbolSizeRows();
int symbolSizeColumns = version.getSymbolSizeColumns(); int symbolSizeColumns = version.getSymbolSizeColumns();
@ -413,32 +412,28 @@ final class BitMatrixParser {
int numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns; int numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns;
int sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows; int sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows;
int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns; //int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;
// TODO(bbrown): Make this work with rectangular codes // TODO(bbrown): Make this work with rectangular codes
BitMatrix mappingBitMatrix = new BitMatrix(sizeDataRegionRow); BitMatrix bitMatrixWithoutAlignment = new BitMatrix(sizeDataRegionRow);
int readRowOffset = 0;
int readColumnOffset = 0;
int writeRowOffset = 0;
int writeColumnOffset = 0;
for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) { for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) {
for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) { for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) {
for (int i = 0; i < dataRegionSizeRows; ++i) { for (int i = 0; i < dataRegionSizeRows; ++i) {
for (int j = 0; j < dataRegionSizeColumns; ++j) { for (int j = 0; j < dataRegionSizeColumns; ++j) {
readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i; int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;
readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j; int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;
writeRowOffset = dataRegionRow * dataRegionSizeRows + i; int writeRowOffset = dataRegionRow * dataRegionSizeRows + i;
writeColumnOffset = dataRegionColumn * dataRegionSizeColumns + j; int writeColumnOffset = dataRegionColumn * dataRegionSizeColumns + j;
if (bitMatrix.get(readRowOffset, readColumnOffset)) { if (bitMatrix.get(readRowOffset, readColumnOffset)) {
mappingBitMatrix.set(writeRowOffset, writeColumnOffset); bitMatrixWithoutAlignment.set(writeRowOffset, writeColumnOffset);
} }
} }
} }
} }
} }
return mappingBitMatrix; return bitMatrixWithoutAlignment;
} }
} }

View file

@ -59,13 +59,13 @@ final class DecodedBitStreamParser {
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', 127 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', 127
}; };
static final int PAD_ENCODE = 0; // Not really an encoding private static final int PAD_ENCODE = 0; // Not really an encoding
static final int ASCII_ENCODE = 1; private static final int ASCII_ENCODE = 1;
static final int C40_ENCODE = 2; private static final int C40_ENCODE = 2;
static final int TEXT_ENCODE = 3; private static final int TEXT_ENCODE = 3;
static final int ANSIX12_ENCODE = 4; private static final int ANSIX12_ENCODE = 4;
static final int EDIFACT_ENCODE = 5; private static final int EDIFACT_ENCODE = 5;
static final int BASE256_ENCODE = 6; private static final int BASE256_ENCODE = 6;
private DecodedBitStreamParser() { private DecodedBitStreamParser() {
} }
@ -384,8 +384,7 @@ final class DecodedBitStreamParser {
/** /**
* See ISO 16022:2006, 5.2.8 and Annex C Table C.3 * See ISO 16022:2006, 5.2.8 and Annex C Table C.3
*/ */
private static int decodeEdifactSegment(BitSource bits, private static int decodeEdifactSegment(BitSource bits, StringBuffer result) {
StringBuffer result) throws ReaderException {
boolean unlatch = false; boolean unlatch = false;
do { do {
// If there is only two or less bytes left then it will be encoded as ASCII // If there is only two or less bytes left then it will be encoded as ASCII
@ -418,8 +417,7 @@ final class DecodedBitStreamParser {
/** /**
* See ISO 16022:2006, 5.2.9 and Annex B, B.2 * See ISO 16022:2006, 5.2.9 and Annex B, B.2
*/ */
private static int decodeBase256Segment(BitSource bits, private static int decodeBase256Segment(BitSource bits, StringBuffer result) {
StringBuffer result) throws ReaderException {
// Figure out how long the Base 256 Segment is. // Figure out how long the Base 256 Segment is.
char d1 = (char) bits.readBits(8); char d1 = (char) bits.readBits(8);
int count; int count;

View file

@ -122,8 +122,8 @@ public final class Version {
* will be the same across all blocks within one version.</p> * will be the same across all blocks within one version.</p>
*/ */
static final class ECBlocks { static final class ECBlocks {
private int ecCodewords; private final int ecCodewords;
private ECB[] ecBlocks; private final ECB[] ecBlocks;
private ECBlocks(int ecCodewords, ECB ecBlocks) { private ECBlocks(int ecCodewords, ECB ecBlocks) {
this.ecCodewords = ecCodewords; this.ecCodewords = ecCodewords;
@ -150,8 +150,8 @@ public final class Version {
* parameters is used consecutively in the Data Matrix code version's format.</p> * parameters is used consecutively in the Data Matrix code version's format.</p>
*/ */
static final class ECB { static final class ECB {
private int count; private final int count;
private int dataCodewords; private final int dataCodewords;
private ECB(int count, int dataCodewords) { private ECB(int count, int dataCodewords) {
this.count = count; this.count = count;

View file

@ -40,7 +40,8 @@ public final class Detector {
* @return {@link DetectorResult} encapsulating results of detecting a QR Code * @return {@link DetectorResult} encapsulating results of detecting a QR Code
* @throws ReaderException if no Data Matrix Code can be found * @throws ReaderException if no Data Matrix Code can be found
*/ */
public DetectorResult detect() throws ReaderException { public DetectorResult detect() {
// TODO
return new DetectorResult(null, null); return new DetectorResult(null, null);
} }

View file

@ -143,7 +143,7 @@ public abstract class AbstractOneDReader implements OneDReader {
* @param counters array into which to record counts * @param counters array into which to record counts
* @throws ReaderException if counters cannot be filled entirely from row before running out of pixels * @throws ReaderException if counters cannot be filled entirely from row before running out of pixels
*/ */
public static void recordPattern(BitArray row, int start, int[] counters) throws ReaderException { static void recordPattern(BitArray row, int start, int[] counters) throws ReaderException {
int numCounters = counters.length; int numCounters = counters.length;
for (int i = 0; i < numCounters; i++) { for (int i = 0; i < numCounters; i++) {
counters[i] = 0; counters[i] = 0;
@ -186,7 +186,7 @@ public abstract class AbstractOneDReader implements OneDReader {
* @param pattern expected pattern * @param pattern expected pattern
* @return average variance between counters and pattern * @return average variance between counters and pattern
*/ */
public static float patternMatchVariance(int[] counters, int[] pattern) { static float patternMatchVariance(int[] counters, int[] pattern) {
int total = 0; int total = 0;
int numCounters = counters.length; int numCounters = counters.length;
int patternLength = 0; int patternLength = 0;

View file

@ -83,7 +83,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements
} }
} }
static int[] findStartGuardPattern(final BitArray row) throws ReaderException { static int[] findStartGuardPattern(BitArray row) throws ReaderException {
boolean foundStart = false; boolean foundStart = false;
int[] startRange = null; int[] startRange = null;
int nextStart = 0; int nextStart = 0;

View file

@ -28,18 +28,17 @@ public final class CollectionsTestCase extends TestCase {
public void testSort() { public void testSort() {
Random r = new Random(0xDEADBEEFL); Random r = new Random(0xDEADBEEFL);
Vector v = new Vector(); Vector<Integer> v = new Vector<Integer>(100);
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
v.addElement(new Integer(r.nextInt(1000))); v.addElement(r.nextInt(1000));
} }
Collections.insertionSort(v, new Comparator() { Collections.insertionSort(v, new Comparator() {
public int compare(Object o1, Object o2) { public int compare(Object o1, Object o2) {
return ((Integer) o1).intValue() - ((Integer) o2).intValue(); return (Integer) o1 - (Integer) o2;
} }
}); });
for (int i = 1; i < 100; i++) { for (int i = 1; i < 100; i++) {
assertTrue("Element " + i, ((Integer) v.elementAt(i - 1)).intValue() <= assertTrue("Element " + i, v.elementAt(i - 1) <= v.elementAt(i));
((Integer) v.elementAt(i)).intValue());
} }
} }

View file

@ -55,7 +55,7 @@ public final class ZXingMIDlet extends MIDlet {
private Player player; private Player player;
private VideoControl videoControl; private VideoControl videoControl;
Canvas getCanvas() { Displayable getCanvas() {
return canvas; return canvas;
} }
@ -141,7 +141,7 @@ public final class ZXingMIDlet extends MIDlet {
// Convenience methods to show dialogs // Convenience methods to show dialogs
private void showOpenURL(String title, final String display, final String uri) { private void showOpenURL(String title, String display, final String uri) {
Alert alert = new Alert(title, display, null, AlertType.CONFIRMATION); Alert alert = new Alert(title, display, null, AlertType.CONFIRMATION);
alert.setTimeout(Alert.FOREVER); alert.setTimeout(Alert.FOREVER);
Command yes = new Command("Yes", Command.OK, 1); Command yes = new Command("Yes", Command.OK, 1);

View file

@ -38,29 +38,28 @@ import java.util.Hashtable;
*/ */
public final class CommandLineRunner { public final class CommandLineRunner {
private static Hashtable<DecodeHintType, Object> hints = null;
private CommandLineRunner() { private CommandLineRunner() {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
for (int x = 0; x < args.length; x++) { Hashtable<DecodeHintType, Object> hints = null;
if (args[x].equals("--try_harder")) { for (String arg : args) {
if ("--try_harder".equals(arg)) {
hints = new Hashtable<DecodeHintType, Object>(3); hints = new Hashtable<DecodeHintType, Object>(3);
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
} else if (args[x].startsWith("--")) { } else if (arg.startsWith("--")) {
System.out.println("Unknown command line option " + args[x]); System.out.println("Unknown command line option " + arg);
return; return;
} }
} }
for (int x = 0; x < args.length; x++) { for (String arg : args) {
if (!args[x].startsWith("--")) { if (!arg.startsWith("--")) {
decodeOneArgument(args[x]); decodeOneArgument(arg, hints);
} }
} }
} }
private static void decodeOneArgument(String argument) throws Exception { private static void decodeOneArgument(String argument, Hashtable<DecodeHintType, Object> hints) throws Exception {
File inputFile = new File(argument); File inputFile = new File(argument);
if (inputFile.exists()) { if (inputFile.exists()) {
if (inputFile.isDirectory()) { if (inputFile.isDirectory()) {
@ -72,7 +71,7 @@ public final class CommandLineRunner {
if (filename.startsWith(".") || filename.endsWith(".txt")) { if (filename.startsWith(".") || filename.endsWith(".txt")) {
continue; continue;
} }
if (decode(input.toURI())) { if (decode(input.toURI(), hints)) {
successful++; successful++;
} }
total++; total++;
@ -80,14 +79,14 @@ public final class CommandLineRunner {
System.out.println("\nDecoded " + successful + " files out of " + total + System.out.println("\nDecoded " + successful + " files out of " + total +
" successfully (" + (successful * 100 / total) + "%)\n"); " successfully (" + (successful * 100 / total) + "%)\n");
} else { } else {
decode(inputFile.toURI()); decode(inputFile.toURI(), hints);
} }
} else { } else {
decode(new URI(argument)); decode(new URI(argument), hints);
} }
} }
private static boolean decode(URI uri) throws IOException { private static boolean decode(URI uri, Hashtable<DecodeHintType, Object> hints) throws IOException {
BufferedImage image = ImageIO.read(uri.toURL()); BufferedImage image = ImageIO.read(uri.toURL());
if (image == null) { if (image == null) {
System.err.println(uri.toString() + ": Could not load image"); System.err.println(uri.toString() + ": Could not load image");