summaryrefslogtreecommitdiffstats
path: root/core/java/android/hardware
diff options
context:
space:
mode:
authorDave Sparks <davidsparks@android.com>2009-07-14 10:35:40 -0700
committerDave Sparks <davidsparks@android.com>2009-07-17 17:24:07 -0700
commite8b26e197f7c5e4acbdf8a5cd3f014fbc242c8ab (patch)
treea8568dfa985bab0097586e5905c162b3a5cb3871 /core/java/android/hardware
parentc634fdd8035cc06c34663b77ab199d29697273b4 (diff)
downloadframeworks_base-e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8ab.zip
frameworks_base-e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8ab.tar.gz
frameworks_base-e8b26e197f7c5e4acbdf8a5cd3f014fbc242c8ab.tar.bz2
Add zoom and postview callbacks to Camera. This patch
adds a zoom callback to the Java layer. If the hardware supports a smooth zoom function, this provides a way to update the UI as the zoom is moving from its original setting to the new commanded setting. This postview callback supports receive a processed image before the JPEG encode completes. This allows the display to be rotated without losing the final preview frame.
Diffstat (limited to 'core/java/android/hardware')
-rw-r--r--core/java/android/hardware/Camera.java80
1 files changed, 75 insertions, 5 deletions
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index 091bc17..40d2c86 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -56,7 +56,9 @@ public class Camera {
private PictureCallback mRawImageCallback;
private PictureCallback mJpegCallback;
private PreviewCallback mPreviewCallback;
+ private PictureCallback mPostviewCallback;
private AutoFocusCallback mAutoFocusCallback;
+ private ZoomCallback mZoomCallback;
private ErrorCallback mErrorCallback;
private boolean mOneShot;
@@ -72,6 +74,8 @@ public class Camera {
mRawImageCallback = null;
mJpegCallback = null;
mPreviewCallback = null;
+ mPostviewCallback = null;
+ mZoomCallback = null;
Looper looper;
if ((looper = Looper.myLooper()) != null) {
@@ -245,13 +249,15 @@ public class Camera {
return;
case CAMERA_MSG_RAW_IMAGE:
- if (mRawImageCallback != null)
+ if (mRawImageCallback != null) {
mRawImageCallback.onPictureTaken((byte[])msg.obj, mCamera);
+ }
return;
case CAMERA_MSG_COMPRESSED_IMAGE:
- if (mJpegCallback != null)
+ if (mJpegCallback != null) {
mJpegCallback.onPictureTaken((byte[])msg.obj, mCamera);
+ }
return;
case CAMERA_MSG_PREVIEW_FRAME:
@@ -263,15 +269,29 @@ public class Camera {
}
return;
+ case CAMERA_MSG_POSTVIEW_FRAME:
+ if (mPostviewCallback != null) {
+ mPostviewCallback.onPictureTaken((byte[])msg.obj, mCamera);
+ }
+ return;
+
case CAMERA_MSG_FOCUS:
- if (mAutoFocusCallback != null)
+ if (mAutoFocusCallback != null) {
mAutoFocusCallback.onAutoFocus(msg.arg1 == 0 ? false : true, mCamera);
+ }
+ return;
+
+ case CAMERA_MSG_ZOOM:
+ if (mZoomCallback != null) {
+ mZoomCallback.onZoomUpdate(msg.arg1, mCamera);
+ }
return;
case CAMERA_MSG_ERROR :
Log.e(TAG, "Error " + msg.arg1);
- if (mErrorCallback != null)
+ if (mErrorCallback != null) {
mErrorCallback.onError(msg.arg1, mCamera);
+ }
return;
default:
@@ -364,13 +384,63 @@ public class Camera {
*/
public final void takePicture(ShutterCallback shutter, PictureCallback raw,
PictureCallback jpeg) {
+ takePicture(shutter, raw, null, jpeg);
+ }
+ private native final void native_takePicture();
+
+ /**
+ * Triggers an asynchronous image capture. The camera service
+ * will initiate a series of callbacks to the application as the
+ * image capture progresses. The shutter callback occurs after
+ * the image is captured. This can be used to trigger a sound
+ * to let the user know that image has been captured. The raw
+ * callback occurs when the raw image data is available. The
+ * postview callback occurs when a scaled, fully processed
+ * postview image is available (NOTE: not all hardware supports
+ * this). The jpeg callback occurs when the compressed image is
+ * available. If the application does not need a particular
+ * callback, a null can be passed instead of a callback method.
+ *
+ * @param shutter callback after the image is captured, may be null
+ * @param raw callback with raw image data, may be null
+ * @param postview callback with postview image data, may be null
+ * @param jpeg callback with jpeg image data, may be null
+ */
+ public final void takePicture(ShutterCallback shutter, PictureCallback raw,
+ PictureCallback postview, PictureCallback jpeg) {
mShutterCallback = shutter;
mRawImageCallback = raw;
+ mPostviewCallback = postview;
mJpegCallback = jpeg;
native_takePicture();
}
- private native final void native_takePicture();
+ /**
+ * Handles the zoom callback.
+ */
+ public interface ZoomCallback
+ {
+ /**
+ * Callback for zoom updates
+ * @param zoomLevel new zoom level in 1/1000 increments,
+ * e.g. a zoom of 3.2x is stored as 3200. Accuracy of the
+ * value is dependent on the hardware implementation. Not
+ * all devices will generate this callback.
+ * @param camera the Camera service object
+ */
+ void onZoomUpdate(int zoomLevel, Camera camera);
+ };
+
+ /**
+ * Registers a callback to be invoked when the zoom
+ * level is updated by the camera driver.
+ * @param cb the callback to run
+ */
+ public final void setZoomCallback(ZoomCallback cb)
+ {
+ mZoomCallback = cb;
+ }
+
// These match the enum in include/ui/Camera.h
/** Unspecified camerar error. @see #ErrorCallback */
public static final int CAMERA_ERROR_UNKNOWN = 1;