diff options
| author | srowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57> | 2008-02-14 23:25:54 +0300 |
|---|---|---|
| committer | srowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57> | 2008-02-14 23:25:54 +0300 |
| commit | ce3587fd96aaf00a4f797e4d10d1419766e347b0 (patch) | |
| tree | 60fdaf0161e26a86372cb2c3ede5e57ec057ce5c | |
| parent | db874904f50b37ae42e73d1cb00aa00cb57011ba (diff) | |
| download | zxing-android-embedded-ce3587fd96aaf00a4f797e4d10d1419766e347b0.tar.xz | |
Biiig standardization of whitespace. 2 space indents now, no tabs.
git-svn-id: http://zxing.googlecode.com/svn/trunk/android@191 59b500cc-1b3d-0410-9834-0bbf25fbcc57
| -rw-r--r-- | AndroidManifest.xml | 22 | ||||
| -rw-r--r-- | build.xml | 2 | ||||
| -rw-r--r-- | res/layout/main.xml | 6 | ||||
| -rw-r--r-- | res/values/strings.xml | 2 | ||||
| -rw-r--r-- | src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java | 52 | ||||
| -rw-r--r-- | src/com/google/zxing/client/android/CameraManager.java | 67 | ||||
| -rw-r--r-- | src/com/google/zxing/client/android/CameraSurfaceView.java | 121 | ||||
| -rwxr-xr-x | src/com/google/zxing/client/android/ResultHandler.java | 12 | ||||
| -rw-r--r-- | src/com/google/zxing/client/android/WorkerThread.java | 28 | ||||
| -rwxr-xr-x | src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java | 9 |
10 files changed, 160 insertions, 161 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index dab57cf0..8f925eb8 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,14 +1,14 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.google.zxing.client.android"> - <application android:icon="@drawable/icon"> - <activity class=".BarcodeReaderCaptureActivity" android:label="@string/app_name"> - <intent-filter> - <action android:value="android.intent.action.MAIN" /> - <category android:value="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - </application> - <uses-permission id="android.permission.READ_CONTACTS" /> - <uses-permission id="android.permission.WRITE_CONTACTS" /> + package="com.google.zxing.client.android"> + <application android:icon="@drawable/icon"> + <activity class=".BarcodeReaderCaptureActivity" android:label="@string/app_name"> + <intent-filter> + <action android:value="android.intent.action.MAIN"/> + <category android:value="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> + </application> + <uses-permission id="android.permission.READ_CONTACTS"/> + <uses-permission id="android.permission.WRITE_CONTACTS"/> </manifest>
\ No newline at end of file @@ -65,7 +65,7 @@ </not> </condition> </fail> - <fail message="Please build 'core' first"> + <fail message="Please build 'core' first"> <condition> <not> <available file="../core/core.jar" type="file"/> diff --git a/res/layout/main.xml b/res/layout/main.xml index 4361cfe8..83333674 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent" > </LinearLayout> diff --git a/res/values/strings.xml b/res/values/strings.xml index d0f6af78..ed0e1ebb 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Barcode Reader</string> - <string name="button_no">No</string> + <string name="button_no">No</string> <string name="button_ok">OK</string> <string name="button_yes">Yes</string> <string name="menu_about">About...</string> diff --git a/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java b/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java index 6f7e24ff..38a48ee5 100644 --- a/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java +++ b/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java @@ -34,18 +34,18 @@ import com.google.zxing.client.result.ParsedReaderResultType; /** * The barcode reader activity itself. This is loosely based on the CameraPreview * example included in the Android SDK. - * + * * @author dswitkin@google.com (Daniel Switkin) * @author Android Team (for CameraPreview example) */ public final class BarcodeReaderCaptureActivity extends Activity { - + private CameraManager cameraManager; private CameraSurfaceView surfaceView; private WorkerThread workerThread; - + private static final int ABOUT_ID = Menu.FIRST; - + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -64,7 +64,7 @@ public final class BarcodeReaderCaptureActivity extends Activity { workerThread.requestPreviewLoop(); workerThread.start(); } - + @Override protected boolean isFullscreenOpaque() { // Our main window is set to translucent, but we know that we will @@ -103,14 +103,14 @@ public final class BarcodeReaderCaptureActivity extends Activity { return super.onKeyDown(keyCode, event); } } - + @Override public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - menu.add(0, ABOUT_ID, R.string.menu_about); - return true; + super.onCreateOptionsMenu(menu); + menu.add(0, ABOUT_ID, R.string.menu_about); + return true; } - + @Override public boolean onOptionsItemSelected(Menu.Item item) { switch (item.getId()) { @@ -120,31 +120,31 @@ public final class BarcodeReaderCaptureActivity extends Activity { context.getString(R.string.msg_about), context.getString(R.string.button_ok), null, true, null); break; - } - return super.onOptionsItemSelected(item); + } + return super.onOptionsItemSelected(item); } - - Handler messageHandler = new Handler() { + + private final Handler messageHandler = new Handler() { @Override public void handleMessage(Message message) { switch (message.what) { - case R.id.decoding_succeeded_message: - handleDecode((Result)message.obj); - break; - case R.id.decoding_failed_message: - Context context = getApplication(); - showAlert(context.getString(R.string.title_no_barcode_detected), - context.getString(R.string.msg_no_barcode_detected), - context.getString(R.string.button_ok), null, true, null); - break; + case R.id.decoding_succeeded_message: + handleDecode((Result) message.obj); + break; + case R.id.decoding_failed_message: + Context context = getApplication(); + showAlert(context.getString(R.string.title_no_barcode_detected), + context.getString(R.string.msg_no_barcode_detected), + context.getString(R.string.button_ok), null, true, null); + break; } } }; - + public void restartPreview() { workerThread.requestPreviewLoop(); } - + // TODO(dswitkin): These deprecated showAlert calls need to be updated. private void handleDecode(Result rawResult) { ResultPoint[] points = rawResult.getResultPoints(); @@ -191,5 +191,5 @@ public final class BarcodeReaderCaptureActivity extends Activity { return R.string.title_barcode_detected; } } - + }
\ No newline at end of file diff --git a/src/com/google/zxing/client/android/CameraManager.java b/src/com/google/zxing/client/android/CameraManager.java index 60e78638..ce7a6cb1 100644 --- a/src/com/google/zxing/client/android/CameraManager.java +++ b/src/com/google/zxing/client/android/CameraManager.java @@ -16,8 +16,6 @@ package com.google.zxing.client.android; -import com.google.zxing.ResultPoint; - import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -27,18 +25,19 @@ import android.hardware.CameraDevice; import android.util.Log; import android.view.Display; import android.view.WindowManager; +import com.google.zxing.ResultPoint; /** * This object wraps the CameraDevice and expects to be the only one talking to it. The * implementation encapsulates the steps needed to take preview-sized images and well as high * resolution stills. - * + * * @author dswitkin@google.com (Daniel Switkin) */ final class CameraManager { - + private static final String TAG = "CameraManager"; - + private Context context; private Point cameraResolution; private Point stillResolution; @@ -49,7 +48,7 @@ final class CameraManager { private CameraDevice camera; private CameraDevice.CaptureParams params; private boolean previewMode; - + CameraManager(Context context) { this.context = context; calculateStillResolution(); @@ -60,38 +59,38 @@ final class CameraManager { previewMode = false; setPreviewMode(true); } - + public void openDriver() { if (camera == null) { camera = CameraDevice.open(); } } - + public void closeDriver() { if (camera != null) { camera.close(); camera = null; } } - + public void capturePreview(Canvas canvas) { setPreviewMode(true); camera.capture(canvas); } - + public Bitmap captureStill() { setPreviewMode(false); Canvas canvas = new Canvas(bitmap); camera.capture(canvas); return bitmap; } - + /** * Calculates the framing rect which the UI should draw to show the user where to place the * barcode. The actual captured image should be a bit larger than indicated because they might * frame the shot too tightly. This target helps with alignment as well as forces the user to hold * the device far enough away to ensure the image will be in focus. - * + * * @return The rectangle to draw on screen in window coordinates. */ public Rect getFramingRect() { @@ -103,10 +102,10 @@ final class CameraManager { } return framingRect; } - + /** * Converts the result points from still resolution coordinates to screen coordinates. - * + * * @param points The points returned by the Reader subclass through Result.getResultPoints(). * @return An array of Points scaled to the size of the framing rect and offset appropriately * so they can be drawn in screen coordinates. @@ -118,25 +117,25 @@ final class CameraManager { Point[] output = new Point[count]; for (int x = 0; x < count; x++) { output[x] = new Point(); - output[x].x = frame.left + (int)(points[x].getX() * frameSize / stillResolution.x + 0.5f); - output[x].y = frame.top + (int)(points[x].getY() * frameSize / stillResolution.y + 0.5f); + output[x].x = frame.left + (int) (points[x].getX() * frameSize / stillResolution.x + 0.5f); + output[x].y = frame.top + (int) (points[x].getY() * frameSize / stillResolution.y + 0.5f); } return output; } - + /** * Images for the live preview are taken at low resolution in RGB. The final stills for the * decoding step are taken in YUV, since we only need the luminance channel. Other code depends * on the ability to call this method for free if the correct mode is already set. - * + * * @param on Setting on true will engage preview mode, setting it false will request still mode. */ private void setPreviewMode(boolean on) { if (on != previewMode) { if (on) { params.type = 1; // preview - if (cameraResolution.x / (float)cameraResolution.y < - screenResolution.x / (float)screenResolution.y) { + if (cameraResolution.x / (float) cameraResolution.y < + screenResolution.x / (float) screenResolution.y) { params.srcWidth = cameraResolution.x; params.srcHeight = cameraResolution.x * screenResolution.y / screenResolution.x; params.leftPixel = 0; @@ -169,7 +168,7 @@ final class CameraManager { previewMode = on; } } - + /** * This method determines how to take the highest quality image (i.e. the one which has the best * chance of being decoded) given the capabilities of the camera. It is a balancing act between @@ -183,65 +182,65 @@ final class CameraManager { cameraResolution = getMaximumCameraResolution(); int minDimension = (cameraResolution.x < cameraResolution.y) ? cameraResolution.x : cameraResolution.y; - int diagonalResolution = (int)Math.sqrt(cameraResolution.x * cameraResolution.x + + int diagonalResolution = (int) Math.sqrt(cameraResolution.x * cameraResolution.x + cameraResolution.y * cameraResolution.y); float diagonalFov = getFieldOfView(); - + // Determine the field of view in the smaller dimension, then calculate how large an object // would be at the minimum focus distance. float fov = diagonalFov * minDimension / diagonalResolution; double objectSize = Math.tan(Math.toRadians(fov / 2.0)) * getMinimumFocusDistance() * 2; - + // Let's assume the largest barcode we might photograph at this distance is 3 inches across. By // cropping to this size, we can avoid processing surrounding pixels, which helps with speed and // accuracy. // TODO(dswitkin): Handle a device with a great macro mode where objectSize < 4 inches. double crop = 3.0 / objectSize; - int nativeResolution = (int)(minDimension * crop); - + int nativeResolution = (int) (minDimension * crop); + // The camera driver can only capture images which are a multiple of eight, so it's necessary to // round up. nativeResolution = (nativeResolution + 7) / 8 * 8; if (nativeResolution > minDimension) { nativeResolution = minDimension; } - + // There's no point in capturing too much detail, so ask the driver to downsample. I haven't // tried a non-integer multiple, but it seems unlikely to work. double dpi = nativeResolution / objectSize; stillMultiplier = 1; if (dpi > 200) { - stillMultiplier = (int)(dpi / 200 + 1); + stillMultiplier = (int) (dpi / 200 + 1); } stillResolution = new Point(nativeResolution, nativeResolution); Log.v(TAG, "FOV " + fov + " objectSize " + objectSize + " crop " + crop + " dpi " + dpi + " nativeResolution " + nativeResolution + " stillMultiplier " + stillMultiplier); } - + // FIXME(dswitkin): These three methods have temporary constants until the new Camera API can // provide the real values for the current device. // Temporary: the camera's maximum resolution in pixels. private static Point getMaximumCameraResolution() { return new Point(1280, 1024); } - + // Temporary: the diagonal field of view in degrees. private static float getFieldOfView() { return 60.0f; } - + // Temporary: the minimum focus distance in inches. private static float getMinimumFocusDistance() { return 12.0f; } - + private Point getScreenResolution() { if (screenResolution == null) { - WindowManager manager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); + WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); screenResolution = new Point(display.getWidth(), display.getHeight()); } return screenResolution; } - + } diff --git a/src/com/google/zxing/client/android/CameraSurfaceView.java b/src/com/google/zxing/client/android/CameraSurfaceView.java index a07baaf8..06132cd6 100644 --- a/src/com/google/zxing/client/android/CameraSurfaceView.java +++ b/src/com/google/zxing/client/android/CameraSurfaceView.java @@ -16,8 +16,6 @@ package com.google.zxing.client.android; -import com.google.zxing.ResultPoint; - import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; @@ -26,66 +24,67 @@ import android.graphics.Point; import android.graphics.Rect; import android.view.SurfaceHolder; import android.view.SurfaceView; +import com.google.zxing.ResultPoint; /** * @author dswitkin@google.com (Daniel Switkin) */ final class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback { - private static int[] SCANNER_ALPHA = { 0, 64, 128, 192, 255, 192, 128, 64 }; - + private static int[] SCANNER_ALPHA = {0, 64, 128, 192, 255, 192, 128, 64}; + private CameraManager cameraManager; private SurfaceHolder surfaceHolder; private boolean hasSurface; private int scannerAlpha; - - CameraSurfaceView(Context context, CameraManager cameraManager) { - super(context); - this.cameraManager = cameraManager; - - // Install a SurfaceHolder.Callback so we get notified when the underlying surface is created - // and destroyed. - surfaceHolder = getHolder(); - surfaceHolder.setCallback(this); - hasSurface = false; - scannerAlpha = 0; - - // FIXME(dswitkin): This resolution needs to be made dynamic to handle different devices and - // orientations. - surfaceHolder.setFixedSize(320, 240); - } - public boolean surfaceCreated(SurfaceHolder holder) { - hasSurface = true; + CameraSurfaceView(Context context, CameraManager cameraManager) { + super(context); + this.cameraManager = cameraManager; - // Tell the system that we filled the surface in this call. This is a lie to prevent the system - // from filling the surface for us automatically. THIS IS REQUIRED because otherwise we'll - // access the Surface object from 2 different threads which is not allowed. - return true; - } + // Install a SurfaceHolder.Callback so we get notified when the underlying surface is created + // and destroyed. + surfaceHolder = getHolder(); + surfaceHolder.setCallback(this); + hasSurface = false; + scannerAlpha = 0; - public void surfaceDestroyed(SurfaceHolder holder) { - // FIXME(dswitkin): The docs say this surface will be destroyed when this method returns. In - // practice this has not been a problem so far. I need to investigate. - hasSurface = false; - } + // FIXME(dswitkin): This resolution needs to be made dynamic to handle different devices and + // orientations. + surfaceHolder.setFixedSize(320, 240); + } - public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { - // Surface size or format has changed. This won't happen because of the setFixedSize() call. - } - - /** - * This method is only called from the WorkerThread. It's job is to grab the next preview frame - * from the camera, draw the framing rectangle, and blit everything to the screen. - */ - public void capturePreviewAndDraw() { + public boolean surfaceCreated(SurfaceHolder holder) { + hasSurface = true; + + // Tell the system that we filled the surface in this call. This is a lie to prevent the system + // from filling the surface for us automatically. THIS IS REQUIRED because otherwise we'll + // access the Surface object from 2 different threads which is not allowed. + return true; + } + + public void surfaceDestroyed(SurfaceHolder holder) { + // FIXME(dswitkin): The docs say this surface will be destroyed when this method returns. In + // practice this has not been a problem so far. I need to investigate. + hasSurface = false; + } + + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + // Surface size or format has changed. This won't happen because of the setFixedSize() call. + } + + /** + * This method is only called from the WorkerThread. It's job is to grab the next preview frame + * from the camera, draw the framing rectangle, and blit everything to the screen. + */ + public void capturePreviewAndDraw() { if (hasSurface) { Canvas canvas = surfaceHolder.lockCanvas(); cameraManager.capturePreview(canvas); Rect frame = cameraManager.getFramingRect(); int width = canvas.getBitmapWidth(); int height = canvas.getBitmapHeight(); - + // Draw the exterior (i.e. outside the framing rect) as half darkened Paint paint = new Paint(); paint.setColor(Color.BLACK); @@ -98,7 +97,7 @@ final class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callb canvas.drawRect(box, paint); box.set(0, frame.bottom + 1, width, height); canvas.drawRect(box, paint); - + // Draw a two pixel solid black border inside the framing rect paint.setAlpha(255); box.set(frame.left, frame.top, frame.right + 1, frame.top + 2); @@ -109,38 +108,38 @@ final class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callb canvas.drawRect(box, paint); box.set(frame.left, frame.bottom - 1, frame.right + 1, frame.bottom + 1); canvas.drawRect(box, paint); - + // Draw a red "laser scanner" line through the middle paint.setColor(Color.RED); paint.setAlpha(SCANNER_ALPHA[scannerAlpha]); int middle = frame.height() / 2 + frame.top; box.set(frame.left + 2, middle - 1, frame.right - 1, middle + 2); canvas.drawRect(box, paint); - + surfaceHolder.unlockCanvasAndPost(canvas); - + // This cheap animation is tied to the rate at which we pull previews from the camera. scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length; } - } - - /** - * Draw a line for 1D barcodes (which return two points) or otherwise a set of points returned - * from the decoder to indicate what we found. - * TODO(dswitkin): It might be nice to clear the framing rect and zoom in on the actual still that - * was captured, then paint the green points on it. This would also clear the red scanner line - * which doesn't make sense after the capture. - * - * @param resultPoints An array of points from the decoder, whose coordinates are expressed - * relative to the still image from the camera. - */ - public void drawResultPoints(ResultPoint[] resultPoints) { + } + + /** + * Draw a line for 1D barcodes (which return two points) or otherwise a set of points returned + * from the decoder to indicate what we found. + * TODO(dswitkin): It might be nice to clear the framing rect and zoom in on the actual still that + * was captured, then paint the green points on it. This would also clear the red scanner line + * which doesn't make sense after the capture. + * + * @param resultPoints An array of points from the decoder, whose coordinates are expressed + * relative to the still image from the camera. + */ + public void drawResultPoints(ResultPoint[] resultPoints) { if (hasSurface) { Canvas canvas = surfaceHolder.lockCanvas(); Paint paint = new Paint(); paint.setColor(Color.GREEN); paint.setAlpha(128); - + Point[] points = cameraManager.convertResultPoints(resultPoints); if (points.length == 2) { paint.setStrokeWidth(4); @@ -151,7 +150,7 @@ final class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callb canvas.drawPoint(points[x].x, points[x].y, paint); } } - + surfaceHolder.unlockCanvasAndPost(canvas); } } diff --git a/src/com/google/zxing/client/android/ResultHandler.java b/src/com/google/zxing/client/android/ResultHandler.java index 540cf81c..de09fc09 100755 --- a/src/com/google/zxing/client/android/ResultHandler.java +++ b/src/com/google/zxing/client/android/ResultHandler.java @@ -55,7 +55,7 @@ final class ResultHandler extends Handler { Intent intent = null; ParsedReaderResultType type = result.getType(); if (type == ParsedReaderResultType.ADDRESSBOOK) { - AddressBookDoCoMoResult addressResult = (AddressBookDoCoMoResult)result; + AddressBookDoCoMoResult addressResult = (AddressBookDoCoMoResult) result; intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI); putExtra(intent, Contacts.Intents.Insert.NAME, addressResult.getName()); putExtra(intent, Contacts.Intents.Insert.PHONE, addressResult.getPhoneNumbers()[0]); @@ -66,12 +66,12 @@ final class ResultHandler extends Handler { // For now, we can only open the browser, and not actually add a bookmark try { intent = new Intent(Intent.VIEW_ACTION, - new ContentURI(((BookmarkDoCoMoResult)result).getURI())); + new ContentURI(((BookmarkDoCoMoResult) result).getURI())); } catch (URISyntaxException e) { return; } } else if (type == ParsedReaderResultType.EMAIL) { - EmailDoCoMoResult emailResult = (EmailDoCoMoResult)result; + EmailDoCoMoResult emailResult = (EmailDoCoMoResult) result; try { intent = new Intent(Intent.SENDTO_ACTION, new ContentURI(emailResult.getTo())); } catch (URISyntaxException e) { @@ -80,14 +80,14 @@ final class ResultHandler extends Handler { putExtra(intent, "subject", emailResult.getSubject()); putExtra(intent, "body", emailResult.getBody()); } else if (type == ParsedReaderResultType.EMAIL_ADDRESS) { - EmailAddressResult emailResult = (EmailAddressResult)result; + EmailAddressResult emailResult = (EmailAddressResult) result; try { intent = new Intent(Intent.SENDTO_ACTION, new ContentURI(emailResult.getEmailAddress())); } catch (URISyntaxException e) { return; } } else if (type == ParsedReaderResultType.UPC) { - UPCParsedResult upcResult = (UPCParsedResult)result; + UPCParsedResult upcResult = (UPCParsedResult) result; try { ContentURI uri = new ContentURI("http://www.upcdatabase.com/item.asp?upc=" + upcResult.getUPC()); @@ -96,7 +96,7 @@ final class ResultHandler extends Handler { return; } } else if (type == ParsedReaderResultType.URI) { - URIParsedResult uriResult = (URIParsedResult)result; + URIParsedResult uriResult = (URIParsedResult) result; try { intent = new Intent(Intent.VIEW_ACTION, new ContentURI(uriResult.getURI())); } catch (URISyntaxException e) { diff --git a/src/com/google/zxing/client/android/WorkerThread.java b/src/com/google/zxing/client/android/WorkerThread.java index e5667ca1..7c47a07e 100644 --- a/src/com/google/zxing/client/android/WorkerThread.java +++ b/src/com/google/zxing/client/android/WorkerThread.java @@ -16,41 +16,42 @@ package com.google.zxing.client.android; +import android.graphics.Bitmap; +import android.os.Handler; +import android.os.Message; import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.MultiFormatReader; import com.google.zxing.ReaderException; import com.google.zxing.Result; -import android.graphics.Bitmap; -import android.os.Handler; -import android.os.Message; - /** * This thread does all the heavy lifting, both during preview and for the final capture and * decoding. That leaves the main thread free to handle UI tasks. - * + * * @author dswitkin@google.com (Daniel Switkin) */ final class WorkerThread extends Thread { - + private CameraSurfaceView surfaceView; private CameraManager cameraManager; private Handler handler; + private enum State { IDLE, PREVIEW_LOOP, STILL_AND_DECODE, DONE } + private State state; - + WorkerThread(CameraSurfaceView surfaceView, CameraManager cameraManager, Handler handler) { this.surfaceView = surfaceView; this.cameraManager = cameraManager; this.handler = handler; state = State.IDLE; } - + @Override public void run() { while (true) { @@ -58,7 +59,8 @@ final class WorkerThread extends Thread { case IDLE: try { sleep(50); - } catch (InterruptedException e) { } + } catch (InterruptedException e) { + } break; case PREVIEW_LOOP: surfaceView.capturePreviewAndDraw(); @@ -84,15 +86,15 @@ final class WorkerThread extends Thread { } } } - + public void requestPreviewLoop() { state = State.PREVIEW_LOOP; } - + public void requestStillAndDecode() { state = State.STILL_AND_DECODE; } - + public void requestExitAndWait() { state = State.DONE; try { @@ -100,5 +102,5 @@ final class WorkerThread extends Thread { } catch (InterruptedException e) { } } - + } diff --git a/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java b/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java index 5a357690..9daafdc8 100755 --- a/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java +++ b/src/com/google/zxing/client/android/YUVMonochromeBitmapSource.java @@ -16,19 +16,18 @@ package com.google.zxing.client.android; -import com.google.zxing.MonochromeBitmapSource; +import android.graphics.Bitmap; import com.google.zxing.BlackPointEstimationMethod; +import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.common.BitArray; import com.google.zxing.common.BlackPointEstimator; -import android.graphics.Bitmap; - /** * This object implements MonochromeBitmapSource around an Android Bitmap. Rather than capturing an * RGB image and calculating the grey value at each pixel, we ask the camera driver for YUV data and * strip out the luminance channel directly. This should be faster but provides fewer bits, i.e. * fewer grey levels. - * + * * @author dswitkin@google.com (Daniel Switkin) * @author srowen@google.com (Sean Owen) */ @@ -41,7 +40,7 @@ final class YUVMonochromeBitmapSource implements MonochromeBitmapSource { private int blackPoint; private BlackPointEstimationMethod lastMethod; private int lastArgument; - + private static final int LUMINANCE_BITS = 5; private static final int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS; private static final int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS; |
