com.google.zxing.client.android.camera
Class CameraManager

java.lang.Object
  extended by com.google.zxing.client.android.camera.CameraManager

public final class CameraManager
extends java.lang.Object

This object wraps the Camera service object and expects to be the only one talking to it. The implementation encapsulates the steps needed to take preview-sized images, which are used for both preview and decoding.

Author:
dswitkin@google.com (Daniel Switkin)

Constructor Summary
CameraManager(android.content.Context context)
           
 
Method Summary
 PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height)
          A factory method to build the appropriate LuminanceSource object based on the format of the preview buffers, as described by Camera.Parameters.
 void closeDriver()
          Closes the camera driver if still in use.
 android.graphics.Rect getFramingRect()
          Calculates the framing rect which the UI should draw to show the user where to place the barcode.
 android.graphics.Rect getFramingRectInPreview()
          Like getFramingRect() but coordinates are in terms of the preview frame, not UI / screen.
 void openDriver(android.view.SurfaceHolder holder)
          Opens the camera driver and initializes the hardware parameters.
 void requestAutoFocus(android.os.Handler handler, int message)
          Asks the camera hardware to perform an autofocus.
 void requestPreviewFrame(android.os.Handler handler, int message)
          A single preview frame will be returned to the handler supplied.
 void setManualFramingRect(int width, int height)
          Allows third party apps to specify the scanning rectangle dimensions, rather than determine them automatically based on screen resolution.
 void startPreview()
          Asks the camera hardware to begin drawing preview frames to the screen.
 void stopPreview()
          Tells the camera to stop drawing preview frames.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CameraManager

public CameraManager(android.content.Context context)
Method Detail

openDriver

public void openDriver(android.view.SurfaceHolder holder)
                throws java.io.IOException
Opens the camera driver and initializes the hardware parameters.

Parameters:
holder - The surface object which the camera will draw preview frames into.
Throws:
java.io.IOException - Indicates the camera driver failed to open.

closeDriver

public void closeDriver()
Closes the camera driver if still in use.


startPreview

public void startPreview()
Asks the camera hardware to begin drawing preview frames to the screen.


stopPreview

public void stopPreview()
Tells the camera to stop drawing preview frames.


requestPreviewFrame

public void requestPreviewFrame(android.os.Handler handler,
                                int message)
A single preview frame will be returned to the handler supplied. The data will arrive as byte[] in the message.obj field, with width and height encoded as message.arg1 and message.arg2, respectively.

Parameters:
handler - The handler to send the message to.
message - The what field of the message to be sent.

requestAutoFocus

public void requestAutoFocus(android.os.Handler handler,
                             int message)
Asks the camera hardware to perform an autofocus.

Parameters:
handler - The Handler to notify when the autofocus completes.
message - The message to deliver.

getFramingRect

public android.graphics.Rect getFramingRect()
Calculates the framing rect which the UI should draw to show the user where to place the barcode. 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.

Returns:
The rectangle to draw on screen in window coordinates.

getFramingRectInPreview

public android.graphics.Rect getFramingRectInPreview()
Like getFramingRect() but coordinates are in terms of the preview frame, not UI / screen.


setManualFramingRect

public void setManualFramingRect(int width,
                                 int height)
Allows third party apps to specify the scanning rectangle dimensions, rather than determine them automatically based on screen resolution.

Parameters:
width - The width in pixels to scan.
height - The height in pixels to scan.

buildLuminanceSource

public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data,
                                                     int width,
                                                     int height)
A factory method to build the appropriate LuminanceSource object based on the format of the preview buffers, as described by Camera.Parameters.

Parameters:
data - A preview frame.
width - The width of the image.
height - The height of the image.
Returns:
A PlanarYUVLuminanceSource instance.