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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -16,7 +16,7 @@ import android.graphics.Canvas;
public interface CameraSource {
static final String LOG_TAG = "camera";
String LOG_TAG = "camera";
/**
* 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, ';');
}
static String[] matchPrefixedField(String prefix, String rawText, char endChar) {
private static String[] matchPrefixedField(String prefix, String rawText, char endChar) {
Vector matches = null;
int i = 0;
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;
public ParsedReaderResult(ParsedReaderResultType type) {
protected ParsedReaderResult(ParsedReaderResultType type) {
this.type = type;
}

View file

@ -40,7 +40,7 @@ final class BitMatrixParser {
}
version = readVersion(bitMatrix);
this.mappingBitMatrix = extractDataRegion(bitMatrix, version);
this.mappingBitMatrix = extractDataRegion(bitMatrix);
// TODO(bbrown): Make this work for rectangular symbols
this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.getDimension());
}
@ -394,10 +394,9 @@ final class BitMatrixParser {
* alignment patterns.</p>
*
* @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
*/
BitMatrix extractDataRegion(BitMatrix bitMatrix, Version version) {
BitMatrix extractDataRegion(BitMatrix bitMatrix) {
int symbolSizeRows = version.getSymbolSizeRows();
int symbolSizeColumns = version.getSymbolSizeColumns();
@ -413,32 +412,28 @@ final class BitMatrixParser {
int numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns;
int sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows;
int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;
//int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns;
// TODO(bbrown): Make this work with rectangular codes
BitMatrix mappingBitMatrix = new BitMatrix(sizeDataRegionRow);
int readRowOffset = 0;
int readColumnOffset = 0;
int writeRowOffset = 0;
int writeColumnOffset = 0;
BitMatrix bitMatrixWithoutAlignment = new BitMatrix(sizeDataRegionRow);
for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) {
for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) {
for (int i = 0; i < dataRegionSizeRows; ++i) {
for (int j = 0; j < dataRegionSizeColumns; ++j) {
readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;
readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;
writeRowOffset = dataRegionRow * dataRegionSizeRows + i;
writeColumnOffset = dataRegionColumn * dataRegionSizeColumns + j;
int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i;
int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j;
int writeRowOffset = dataRegionRow * dataRegionSizeRows + i;
int writeColumnOffset = dataRegionColumn * dataRegionSizeColumns + j;
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
};
static final int PAD_ENCODE = 0; // Not really an encoding
static final int ASCII_ENCODE = 1;
static final int C40_ENCODE = 2;
static final int TEXT_ENCODE = 3;
static final int ANSIX12_ENCODE = 4;
static final int EDIFACT_ENCODE = 5;
static final int BASE256_ENCODE = 6;
private static final int PAD_ENCODE = 0; // Not really an encoding
private static final int ASCII_ENCODE = 1;
private static final int C40_ENCODE = 2;
private static final int TEXT_ENCODE = 3;
private static final int ANSIX12_ENCODE = 4;
private static final int EDIFACT_ENCODE = 5;
private static final int BASE256_ENCODE = 6;
private DecodedBitStreamParser() {
}
@ -384,8 +384,7 @@ final class DecodedBitStreamParser {
/**
* See ISO 16022:2006, 5.2.8 and Annex C Table C.3
*/
private static int decodeEdifactSegment(BitSource bits,
StringBuffer result) throws ReaderException {
private static int decodeEdifactSegment(BitSource bits, StringBuffer result) {
boolean unlatch = false;
do {
// 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
*/
private static int decodeBase256Segment(BitSource bits,
StringBuffer result) throws ReaderException {
private static int decodeBase256Segment(BitSource bits, StringBuffer result) {
// Figure out how long the Base 256 Segment is.
char d1 = (char) bits.readBits(8);
int count;

View file

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

View file

@ -40,7 +40,8 @@ public final class Detector {
* @return {@link DetectorResult} encapsulating results of detecting a QR Code
* @throws ReaderException if no Data Matrix Code can be found
*/
public DetectorResult detect() throws ReaderException {
public DetectorResult detect() {
// TODO
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
* @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;
for (int i = 0; i < numCounters; i++) {
counters[i] = 0;
@ -186,7 +186,7 @@ public abstract class AbstractOneDReader implements OneDReader {
* @param pattern expected 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 numCounters = counters.length;
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;
int[] startRange = null;
int nextStart = 0;

View file

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

View file

@ -55,7 +55,7 @@ public final class ZXingMIDlet extends MIDlet {
private Player player;
private VideoControl videoControl;
Canvas getCanvas() {
Displayable getCanvas() {
return canvas;
}
@ -141,7 +141,7 @@ public final class ZXingMIDlet extends MIDlet {
// 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.setTimeout(Alert.FOREVER);
Command yes = new Command("Yes", Command.OK, 1);

View file

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