net.sf.javaocr.demos.android.utils.camera
Class CameraManager

java.lang.Object
  extended by net.sf.javaocr.demos.android.utils.camera.CameraManager
All Implemented Interfaces:
android.hardware.Camera.AutoFocusCallback, android.hardware.Camera.PreviewCallback

public class CameraManager
extends Object
implements android.hardware.Camera.AutoFocusCallback, android.hardware.Camera.PreviewCallback

android camera manager encapsulating camera management and image acquisition

Author:
Konstantin Pribluda

Field Summary
(package private)  android.hardware.Camera camera
           
(package private)  boolean cameraActive
           
(package private)  boolean focusState
           
private static String LOG_TAG
           
static int MIN_PREVIEW_WIDTH
           
(package private)  boolean previewActive
           
(package private)  byte[] previewImage
           
private  android.hardware.Camera.Size previewSize
           
(package private)  boolean waitingForFocus
           
(package private)  boolean waitingForPreview
           
 
Constructor Summary
CameraManager()
           
 
Method Summary
 boolean doAutofocus()
          acquire autofocus.
 android.hardware.Camera getCamera()
          return camera object of any
 byte[] getPreviewFrame()
          acquires preview frame.
 android.hardware.Camera.Size getPreviewSize()
          preview size ist read only
 boolean isCameraActive()
          whether we are active at the moment
 void onAutoFocus(boolean b, android.hardware.Camera camera)
          synchronize on object itself to prevent race condition
 void onPreviewFrame(byte[] bytes, android.hardware.Camera camera)
          save data to pointer and wake up sleeping thread.
 void start(android.view.SurfaceHolder holder)
          start camera manager (call it in onStart() )
private  void startPreview(android.view.SurfaceHolder holder)
          configure camera, start preview and pipe it to surface holder use it to whenever you are starting preview - in resume - when surface changed - on config changes etc
 void stop()
          stop camera manager and give up resources (shall be called from onPause() )
private  void stopPreview()
          stop preview before starting it again
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_TAG

private static final String LOG_TAG
See Also:
Constant Field Values

camera

android.hardware.Camera camera

cameraActive

boolean cameraActive

previewActive

boolean previewActive

previewSize

private android.hardware.Camera.Size previewSize

MIN_PREVIEW_WIDTH

public static final int MIN_PREVIEW_WIDTH
See Also:
Constant Field Values

focusState

boolean focusState

waitingForFocus

boolean waitingForFocus

waitingForPreview

boolean waitingForPreview

previewImage

byte[] previewImage
Constructor Detail

CameraManager

public CameraManager()
Method Detail

getPreviewSize

public android.hardware.Camera.Size getPreviewSize()
preview size ist read only

Returns:

start

public void start(android.view.SurfaceHolder holder)
           throws IOException
start camera manager (call it in onStart() )

Throws:
IOException

stop

public void stop()
stop camera manager and give up resources (shall be called from onPause() )


startPreview

private void startPreview(android.view.SurfaceHolder holder)
                   throws IOException
configure camera, start preview and pipe it to surface holder use it to whenever you are starting preview - in resume - when surface changed - on config changes etc

Parameters:
holder -
Throws:
IOException

stopPreview

private void stopPreview()
stop preview before starting it again


getCamera

public android.hardware.Camera getCamera()
return camera object of any

Returns:

isCameraActive

public boolean isCameraActive()
whether we are active at the moment

Returns:

doAutofocus

public boolean doAutofocus()
acquire autofocus. this method blocks current thread until autofocus callback is called.

Returns:
autofocus callback

getPreviewFrame

public byte[] getPreviewFrame()
acquires preview frame. thread is blocked until callback is fired

Returns:
byte data of preview frame, null is not successfull

onAutoFocus

public void onAutoFocus(boolean b,
                        android.hardware.Camera camera)
synchronize on object itself to prevent race condition

Specified by:
onAutoFocus in interface android.hardware.Camera.AutoFocusCallback
Parameters:
b - status of ayto focus
camera - camera acquiring focus

onPreviewFrame

public void onPreviewFrame(byte[] bytes,
                           android.hardware.Camera camera)
save data to pointer and wake up sleeping thread.

Specified by:
onPreviewFrame in interface android.hardware.Camera.PreviewCallback
Parameters:
bytes - byte array containig image data
camera - camera object


Copyright © -2012. All Rights Reserved.