mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Added latency measurement in milliseconds to the Android client.
git-svn-id: https://zxing.googlecode.com/svn/trunk@334 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
410b5b4e92
commit
0e2defcf66
|
@ -32,6 +32,8 @@ import com.google.zxing.ResultPoint;
|
||||||
import com.google.zxing.client.result.ParsedReaderResult;
|
import com.google.zxing.client.result.ParsedReaderResult;
|
||||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The barcode reader activity itself. This is loosely based on the CameraPreview
|
* The barcode reader activity itself. This is loosely based on the CameraPreview
|
||||||
* example included in the Android SDK.
|
* example included in the Android SDK.
|
||||||
|
@ -44,6 +46,7 @@ public final class BarcodeReaderCaptureActivity extends Activity {
|
||||||
private CameraManager cameraManager;
|
private CameraManager cameraManager;
|
||||||
private CameraSurfaceView surfaceView;
|
private CameraSurfaceView surfaceView;
|
||||||
private WorkerThread workerThread;
|
private WorkerThread workerThread;
|
||||||
|
private Date decodeStart;
|
||||||
|
|
||||||
private static final int ABOUT_ID = Menu.FIRST;
|
private static final int ABOUT_ID = Menu.FIRST;
|
||||||
|
|
||||||
|
@ -101,10 +104,13 @@ 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_DPAD_CENTER) {
|
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
|
||||||
|
decodeStart = new Date();
|
||||||
workerThread.requestStillAndDecode();
|
workerThread.requestStillAndDecode();
|
||||||
} else if (keyCode == KeyEvent.KEYCODE_Q) {
|
} else if (keyCode == KeyEvent.KEYCODE_Q) {
|
||||||
|
decodeStart = new Date();
|
||||||
workerThread.requestStillAndDecodeQR();
|
workerThread.requestStillAndDecodeQR();
|
||||||
} else if (keyCode == KeyEvent.KEYCODE_U) {
|
} else if (keyCode == KeyEvent.KEYCODE_U) {
|
||||||
|
decodeStart = new Date();
|
||||||
workerThread.requestStillAndDecode1D();
|
workerThread.requestStillAndDecode1D();
|
||||||
} else if (keyCode == KeyEvent.KEYCODE_C) {
|
} else if (keyCode == KeyEvent.KEYCODE_C) {
|
||||||
workerThread.requestStillAndSave();
|
workerThread.requestStillAndSave();
|
||||||
|
@ -137,14 +143,17 @@ public final class BarcodeReaderCaptureActivity extends Activity {
|
||||||
private final Handler messageHandler = new Handler() {
|
private final Handler messageHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
|
Date now = new Date();
|
||||||
|
long duration = now.getTime() - decodeStart.getTime();
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case R.id.decoding_succeeded_message:
|
case R.id.decoding_succeeded_message:
|
||||||
handleDecode((Result) message.obj);
|
handleDecode((Result) message.obj, duration);
|
||||||
break;
|
break;
|
||||||
case R.id.decoding_failed_message:
|
case R.id.decoding_failed_message:
|
||||||
Context context = getApplication();
|
Context context = getApplication();
|
||||||
showAlert(context.getString(R.string.title_no_barcode_detected),
|
String title = context.getString(R.string.title_no_barcode_detected) +
|
||||||
context.getString(R.string.msg_no_barcode_detected),
|
" (" + duration + " ms)";
|
||||||
|
showAlert(title, context.getString(R.string.msg_no_barcode_detected),
|
||||||
context.getString(R.string.button_ok), null, true, null);
|
context.getString(R.string.button_ok), null, true, null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -156,7 +165,7 @@ public final class BarcodeReaderCaptureActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(dswitkin): These deprecated showAlert calls need to be updated.
|
// TODO(dswitkin): These deprecated showAlert calls need to be updated.
|
||||||
private void handleDecode(Result rawResult) {
|
private void handleDecode(Result rawResult, long duration) {
|
||||||
ResultPoint[] points = rawResult.getResultPoints();
|
ResultPoint[] points = rawResult.getResultPoints();
|
||||||
if (points != null && points.length > 0) {
|
if (points != null && points.length > 0) {
|
||||||
surfaceView.drawResultPoints(points);
|
surfaceView.drawResultPoints(points);
|
||||||
|
@ -170,15 +179,17 @@ public final class BarcodeReaderCaptureActivity extends Activity {
|
||||||
// proceed first though
|
// proceed first though
|
||||||
Message yesMessage = handler.obtainMessage(R.string.button_yes);
|
Message yesMessage = handler.obtainMessage(R.string.button_yes);
|
||||||
Message noMessage = handler.obtainMessage(R.string.button_no);
|
Message noMessage = handler.obtainMessage(R.string.button_no);
|
||||||
showAlert(context.getString(getDialogTitleID(readerResult.getType())),
|
String title = context.getString(getDialogTitleID(readerResult.getType())) +
|
||||||
readerResult.getDisplayResult(), context.getString(R.string.button_yes),
|
" (" + duration + " ms)";
|
||||||
|
showAlert(title, readerResult.getDisplayResult(), context.getString(R.string.button_yes),
|
||||||
yesMessage, context.getString(R.string.button_no), noMessage, true, noMessage);
|
yesMessage, context.getString(R.string.button_no), noMessage, true, noMessage);
|
||||||
} else {
|
} else {
|
||||||
// Just show information to user
|
// Just show information to user
|
||||||
Message okMessage = handler.obtainMessage(R.string.button_ok);
|
Message okMessage = handler.obtainMessage(R.string.button_ok);
|
||||||
showAlert(context.getString(R.string.title_barcode_detected),
|
String title = context.getString(R.string.title_barcode_detected) +
|
||||||
readerResult.getDisplayResult(), context.getString(R.string.button_ok), okMessage, null,
|
" (" + duration + " ms)";
|
||||||
null, true, okMessage);
|
showAlert(title, readerResult.getDisplayResult(), context.getString(R.string.button_ok),
|
||||||
|
okMessage, null, null, true, okMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue