Skip to content

Commit

Permalink
Update all Java code to use Java 6
Browse files Browse the repository at this point in the history
git-svn-id: https://zxing.googlecode.com/svn/trunk@2002 59b500cc-1b3d-0410-9834-0bbf25fbcc57
  • Loading branch information
srowen committed Nov 2, 2011
1 parent 8683a96 commit db60385
Show file tree
Hide file tree
Showing 320 changed files with 3,108 additions and 8,427 deletions.
11 changes: 0 additions & 11 deletions README

This file was deleted.

4 changes: 2 additions & 2 deletions android-integration/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<mkdir dir="build"/>
<javac srcdir="src"
destdir="build"
source="1.5"
target="1.5"
source="6"
target="6"
optimize="true"
debug="true"
deprecation="true"
Expand Down
2 changes: 1 addition & 1 deletion android-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<artifactId>android-integration</artifactId>
<packaging>jar</packaging>
<name>ZXing Android Integration lib</name>
<version>1.6-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<description>Integration helper classes for Android applications wanting to create/scan bar codes</description>
<url>http://code.google.com/p/zxing/</url>
<inceptionYear>2007</inceptionYear>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public final class IntentIntegrator {
static {
Method temp;
try {
temp = Intent.class.getMethod("setPackage", new Class[] {String.class});
temp = Intent.class.getMethod("setPackage", String.class);
} catch (NoSuchMethodException nsme) {
temp = null;
}
Expand Down Expand Up @@ -212,6 +212,7 @@ private static AlertDialog showDownloadDialog(final Activity activity,
downloadDialog.setTitle(stringTitle);
downloadDialog.setMessage(stringMessage);
downloadDialog.setPositiveButton(stringButtonYes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Uri uri = Uri.parse("market://search?q=pname:" + PACKAGE);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
Expand All @@ -224,6 +225,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
}
});
downloadDialog.setNegativeButton(stringButtonNo, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {}
});
return downloadDialog.show();
Expand Down
2 changes: 1 addition & 1 deletion android/assets/html-en/scanning.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<link rel="stylesheet" href="../style.css" type="text/css"/>
</head>
<body>
<p>Barcode Scanner continuously scans a square region shown on your screen &mdash; just line up the
<p>Barcode Scanner continuously scans a square region shown on your screen -- just line up the
phone so the barcode is completely inside the viewfinder rectangle:</p>
<p style="text-align:center">
<img src="../images/demo-yes.png" alt="Yes"/>&nbsp;&nbsp;&nbsp;<img src="../images/demo-no.png" alt="No"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private static MediaPlayer buildMediaPlayer(Context activity) {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// When the beep has finished playing, rewind to queue up another one.
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer player) {
player.seekTo(0);
}
Expand Down
50 changes: 21 additions & 29 deletions android/src/com/google/zxing/client/android/CaptureActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@

import java.io.IOException;
import java.text.DateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

/**
* This activity opens the camera and does the actual scanning on a background thread. It draws a
Expand Down Expand Up @@ -97,14 +97,11 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private static final String RETURN_CODE_PLACEHOLDER = "{CODE}";
private static final String RETURN_URL_PARAM = "ret";

private static final Set<ResultMetadataType> DISPLAYABLE_METADATA_TYPES;
static {
DISPLAYABLE_METADATA_TYPES = new HashSet<ResultMetadataType>(5);
DISPLAYABLE_METADATA_TYPES.add(ResultMetadataType.ISSUE_NUMBER);
DISPLAYABLE_METADATA_TYPES.add(ResultMetadataType.SUGGESTED_PRICE);
DISPLAYABLE_METADATA_TYPES.add(ResultMetadataType.ERROR_CORRECTION_LEVEL);
DISPLAYABLE_METADATA_TYPES.add(ResultMetadataType.POSSIBLE_COUNTRY);
}
private static final Set<ResultMetadataType> DISPLAYABLE_METADATA_TYPES =
EnumSet.of(ResultMetadataType.ISSUE_NUMBER,
ResultMetadataType.SUGGESTED_PRICE,
ResultMetadataType.ERROR_CORRECTION_LEVEL,
ResultMetadataType.POSSIBLE_COUNTRY);

private enum Source {
NATIVE_APP_INTENT,
Expand All @@ -123,7 +120,7 @@ private enum Source {
private Source source;
private String sourceUrl;
private String returnUrlTemplate;
private Vector<BarcodeFormat> decodeFormats;
private Collection<BarcodeFormat> decodeFormats;
private String characterSet;
private String versionName;
private HistoryManager historyManager;
Expand All @@ -132,6 +129,7 @@ private enum Source {

private final DialogInterface.OnClickListener aboutListener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.zxing_url)));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
Expand Down Expand Up @@ -313,33 +311,25 @@ public boolean onPrepareOptionsMenu(Menu menu) {

@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
switch (item.getItemId()) {
case SHARE_ID: {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
case SHARE_ID:
intent.setClassName(this, ShareActivity.class.getName());
startActivity(intent);
break;
}
case HISTORY_ID: {
case HISTORY_ID:
AlertDialog historyAlert = historyManager.buildAlert();
historyAlert.show();
break;
}
case SETTINGS_ID: {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
case SETTINGS_ID:
intent.setClassName(this, PreferencesActivity.class.getName());
startActivity(intent);
break;
}
case HELP_ID: {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
case HELP_ID:
intent.setClassName(this, HelpActivity.class.getName());
startActivity(intent);
break;
}
case ABOUT_ID:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.title_about) + versionName);
Expand All @@ -353,6 +343,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
if (holder == null) {
Log.e(TAG, "*** WARNING *** surfaceCreated() gave us a null surface!");
Expand All @@ -363,10 +354,12 @@ public void surfaceCreated(SurfaceHolder holder) {
}
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
hasSurface = false;
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

}
Expand Down Expand Up @@ -440,8 +433,8 @@ private void drawResultPoints(Bitmap barcode, Result rawResult) {
paint.setStrokeWidth(4.0f);
drawLine(canvas, paint, points[0], points[1]);
} else if (points.length == 4 &&
(rawResult.getBarcodeFormat().equals(BarcodeFormat.UPC_A) ||
rawResult.getBarcodeFormat().equals(BarcodeFormat.EAN_13))) {
(rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A ||
rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
// Hacky special case -- draw two lines, for the barcode and metadata
drawLine(canvas, paint, points[0], points[1]);
drawLine(canvas, paint, points[2], points[3]);
Expand Down Expand Up @@ -488,8 +481,7 @@ private void handleDecodeInternally(Result rawResult, ResultHandler resultHandle
View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
metaTextView.setVisibility(View.GONE);
metaTextViewLabel.setVisibility(View.GONE);
Map<ResultMetadataType,Object> metadata =
(Map<ResultMetadataType,Object>) rawResult.getResultMetadata();
Map<ResultMetadataType,Object> metadata = rawResult.getResultMetadata();
if (metadata != null) {
StringBuilder metadataText = new StringBuilder(20);
for (Map.Entry<ResultMetadataType,Object> entry : metadata.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import android.os.Message;
import android.util.Log;

import java.util.Vector;
import java.util.Collection;

/**
* This class handles all the messaging which comprises the state machine for capture.
Expand All @@ -50,7 +50,7 @@ private enum State {
DONE
}

CaptureActivityHandler(CaptureActivity activity, Vector<BarcodeFormat> decodeFormats,
CaptureActivityHandler(CaptureActivity activity, Collection<BarcodeFormat> decodeFormats,
String characterSet) {
this.activity = activity;
decodeThread = new DecodeThread(activity, decodeFormats, characterSet,
Expand Down Expand Up @@ -112,7 +112,8 @@ public void quitSynchronously() {
Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
quit.sendToTarget();
try {
decodeThread.join();
// Wait at most half a second; should be enough time, and onPause() will timeout quickly
decodeThread.join(500L);
} catch (InterruptedException e) {
// continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package com.google.zxing.client.android;

import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.Vector;
import java.util.regex.Pattern;

import android.content.Intent;
Expand All @@ -29,32 +30,26 @@ final class DecodeFormatManager {

private static final Pattern COMMA_PATTERN = Pattern.compile(",");

static final Vector<BarcodeFormat> PRODUCT_FORMATS;
static final Vector<BarcodeFormat> ONE_D_FORMATS;
static final Vector<BarcodeFormat> QR_CODE_FORMATS;
static final Vector<BarcodeFormat> DATA_MATRIX_FORMATS;
static final Collection<BarcodeFormat> PRODUCT_FORMATS;
static final Collection<BarcodeFormat> ONE_D_FORMATS;
static final Collection<BarcodeFormat> QR_CODE_FORMATS = EnumSet.of(BarcodeFormat.QR_CODE);
static final Collection<BarcodeFormat> DATA_MATRIX_FORMATS = EnumSet.of(BarcodeFormat.DATA_MATRIX);
static {
PRODUCT_FORMATS = new Vector<BarcodeFormat>(5);
PRODUCT_FORMATS.add(BarcodeFormat.UPC_A);
PRODUCT_FORMATS.add(BarcodeFormat.UPC_E);
PRODUCT_FORMATS.add(BarcodeFormat.EAN_13);
PRODUCT_FORMATS.add(BarcodeFormat.EAN_8);
PRODUCT_FORMATS.add(BarcodeFormat.RSS_14);
ONE_D_FORMATS = new Vector<BarcodeFormat>(PRODUCT_FORMATS.size() + 4);
PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A,
BarcodeFormat.UPC_E,
BarcodeFormat.EAN_13,
BarcodeFormat.EAN_8,
BarcodeFormat.RSS_14);
ONE_D_FORMATS = EnumSet.of(BarcodeFormat.CODE_39,
BarcodeFormat.CODE_93,
BarcodeFormat.CODE_128,
BarcodeFormat.ITF);
ONE_D_FORMATS.addAll(PRODUCT_FORMATS);
ONE_D_FORMATS.add(BarcodeFormat.CODE_39);
ONE_D_FORMATS.add(BarcodeFormat.CODE_93);
ONE_D_FORMATS.add(BarcodeFormat.CODE_128);
ONE_D_FORMATS.add(BarcodeFormat.ITF);
QR_CODE_FORMATS = new Vector<BarcodeFormat>(1);
QR_CODE_FORMATS.add(BarcodeFormat.QR_CODE);
DATA_MATRIX_FORMATS = new Vector<BarcodeFormat>(1);
DATA_MATRIX_FORMATS.add(BarcodeFormat.DATA_MATRIX);
}

private DecodeFormatManager() {}

static Vector<BarcodeFormat> parseDecodeFormats(Intent intent) {
static Collection<BarcodeFormat> parseDecodeFormats(Intent intent) {
List<String> scanFormats = null;
String scanFormatsString = intent.getStringExtra(Intents.Scan.FORMATS);
if (scanFormatsString != null) {
Expand All @@ -63,18 +58,18 @@ static Vector<BarcodeFormat> parseDecodeFormats(Intent intent) {
return parseDecodeFormats(scanFormats, intent.getStringExtra(Intents.Scan.MODE));
}

static Vector<BarcodeFormat> parseDecodeFormats(Uri inputUri) {
static Collection<BarcodeFormat> parseDecodeFormats(Uri inputUri) {
List<String> formats = inputUri.getQueryParameters(Intents.Scan.FORMATS);
if (formats != null && formats.size() == 1 && formats.get(0) != null){
formats = Arrays.asList(COMMA_PATTERN.split(formats.get(0)));
}
return parseDecodeFormats(formats, inputUri.getQueryParameter(Intents.Scan.MODE));
}

private static Vector<BarcodeFormat> parseDecodeFormats(Iterable<String> scanFormats,
String decodeMode) {
private static Collection<BarcodeFormat> parseDecodeFormats(Iterable<String> scanFormats,
String decodeMode) {
if (scanFormats != null) {
Vector<BarcodeFormat> formats = new Vector<BarcodeFormat>();
Collection<BarcodeFormat> formats = EnumSet.noneOf(BarcodeFormat.class);
try {
for (String format : scanFormats) {
formats.add(BarcodeFormat.valueOf(format));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import android.os.Message;
import android.util.Log;

import java.util.Hashtable;
import java.util.Map;

final class DecodeHandler extends Handler {

Expand All @@ -40,7 +40,7 @@ final class DecodeHandler extends Handler {
private final MultiFormatReader multiFormatReader;
private boolean running = true;

DecodeHandler(CaptureActivity activity, Hashtable<DecodeHintType, Object> hints) {
DecodeHandler(CaptureActivity activity, Map<DecodeHintType,Object> hints) {
multiFormatReader = new MultiFormatReader();
multiFormatReader.setHints(hints);
this.activity = activity;
Expand Down
14 changes: 8 additions & 6 deletions android/src/com/google/zxing/client/android/DecodeThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import android.os.Looper;
import android.preference.PreferenceManager;

import java.util.Hashtable;
import java.util.Vector;
import java.util.Collection;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

/**
Expand All @@ -39,24 +41,24 @@ final class DecodeThread extends Thread {
public static final String BARCODE_BITMAP = "barcode_bitmap";

private final CaptureActivity activity;
private final Hashtable<DecodeHintType, Object> hints;
private final Map<DecodeHintType,Object> hints;
private Handler handler;
private final CountDownLatch handlerInitLatch;

DecodeThread(CaptureActivity activity,
Vector<BarcodeFormat> decodeFormats,
Collection<BarcodeFormat> decodeFormats,
String characterSet,
ResultPointCallback resultPointCallback) {

this.activity = activity;
handlerInitLatch = new CountDownLatch(1);

hints = new Hashtable<DecodeHintType, Object>(3);
hints = new EnumMap<DecodeHintType,Object>(DecodeHintType.class);

// The prefs can't change while the thread is running, so pick them up once here.
if (decodeFormats == null || decodeFormats.isEmpty()) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
decodeFormats = new Vector<BarcodeFormat>();
decodeFormats = EnumSet.noneOf(BarcodeFormat.class);
if (prefs.getBoolean(PreferencesActivity.KEY_DECODE_1D, true)) {
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ public FinishListener(Activity activityToFinish) {
this.activityToFinish = activityToFinish;
}

@Override
public void onCancel(DialogInterface dialogInterface) {
run();
}

@Override
public void onClick(DialogInterface dialogInterface, int i) {
run();
}

@Override
public void run() {
activityToFinish.finish();
}
Expand Down
Loading

0 comments on commit db60385

Please sign in to comment.