}
};
+ /**
+ * Autofocus callbacks arrive here, and are dispatched to the Handler which requested them.
+ */
private final Camera.AutoFocusCallback autoFocusCallback = new Camera.AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
if (autoFocusHandler != null) {
}
};
+ /**
+ * Initializes this static object with the Context of the calling Activity.
+ *
+ * @param context The Activity which wants to use the camera.
+ */
public static void init(Context context) {
if (cameraManager == null) {
cameraManager = new CameraManager(context);
}
}
+ /**
+ * Gets the CameraManager singleton instance.
+ *
+ * @return A reference to the CameraManager singleton.
+ */
public static CameraManager get() {
return cameraManager;
}
previewing = false;
}
+ /**
+ * Opens the camera driver and initializes the hardware parameters.
+ *
+ * @param holder The surface object which the camera will draw preview frames into.
+ * @throws IOException Indicates the camera driver failed to open.
+ */
public void openDriver(SurfaceHolder holder) throws IOException {
if (camera == null) {
camera = Camera.open();
}
}
+ /**
+ * Closes the camera driver if still in use.
+ */
public void closeDriver() {
if (camera != null) {
camera.release();
}
}
+ /**
+ * Asks the camera hardware to begin drawing preview frames to the screen.
+ */
public void startPreview() {
if (camera != null && !previewing) {
camera.startPreview();
}
}
+ /**
+ * Tells the camera to stop drawing preview frames.
+ */
public void stopPreview() {
if (camera != null && previewing) {
camera.setPreviewCallback(null);
}
}
+ /**
+ * Asks the camera hardware to perform an autofocus.
+ *
+ * @param handler The Handler to notify when the autofocus completes.
+ * @param message The message to deliver.
+ */
public void requestAutoFocus(Handler handler, int message) {
if (camera != null && previewing) {
autoFocusHandler = handler;
}
/**
- * Sets the camera up to take preview images which are used for both preview and decoding. We're
- * counting on the default YUV420 semi-planar data. If that changes in the future, we'll need to
- * specify it explicitly with setPreviewFormat().
+ * Sets the camera up to take preview images which are used for both preview and decoding.
+ * We detect the preview format here so that buildLuminanceSource() can build an appropriate
+ * LuminanceSource subclass. In the future we may want to force YUV420SP as it's the smallest,
+ * and the planar Y can be used for barcode scanning without a copy in some cases.
*/
private void setCameraParameters() {
Camera.Parameters parameters = camera.getParameters();