From abe2decb9e7a6a60039c4dd367ef76bf13c2c22c Mon Sep 17 00:00:00 2001 From: Sparky Rhode Date: Thu, 15 Dec 2011 16:53:35 -0800 Subject: Remove references to sample application Change-Id: If8d6d0a3cc59bd3d3462aa066c861fbcae51baf1 --- docs/html/training/camera/cameradirect.jd | 51 +++++++++---------------------- docs/html/training/camera/index.jd | 2 +- 2 files changed, 16 insertions(+), 37 deletions(-) (limited to 'docs/html') diff --git a/docs/html/training/camera/cameradirect.jd b/docs/html/training/camera/cameradirect.jd index d37f2c4..1e25d4f 100644 --- a/docs/html/training/camera/cameradirect.jd +++ b/docs/html/training/camera/cameradirect.jd @@ -45,29 +45,11 @@ or something fully integrated in your app UI, this lesson shows you how.

process of directly controlling the camera. As Android's own Camera application does, the recommended way to access the camera is to open {@link android.hardware.Camera} on a separate thread that's launched from {@link android.app.Activity#onCreate onCreate()}. This approach is a good idea -since it can take a while and might bog down the UI thread. However, in the sample application -associated with this lesson, opening the camera is deferred to the {@link +since it can take a while and might bog down the UI thread. In a more basic implementation, +opening the camera can be deferred to the {@link android.app.Activity#onResume onResume()} method to facilitate code reuse and keep the flow of control simple.

-
-private void openCameraPerIdAndSetPreview() {
-    if (! safeCameraOpen(mCameraId)) {
-        mCameraId = getFirstRearCameraID();
-        safeCameraOpen(mCameraId);
-    }
-
-    mPreview.setCamera(mCamera);
-}
-
- -

Since API level 9, the camera framework supports multiple cameras. If you use the -legacy API and call {@link android.hardware.Camera#open open()} without an -argument, you get the first rear-facing camera. Dealing with multiple cameras -is an advanced topic and beyond the scope of this lesson. If you are really -interested, check out the implementation of {@code getFirstRearCameraID()} in -the sample app (downloadable at the top).

-

Calling {@link android.hardware.Camera#open Camera.open()} throws an exception if the camera is already in use by another application, so we wrap it in a {@code try} block.

@@ -78,7 +60,7 @@ private boolean safeCameraOpen(int id) { try { releaseCameraAndPreview(); - mCamera = Camera.open(mCameraId); + mCamera = Camera.open(id); qOpened = (mCamera != null); } catch (Exception e) { Log.e(getString(R.string.app_name), "failed to open Camera"); @@ -97,6 +79,10 @@ private void releaseCameraAndPreview() { } +

Since API level 9, the camera framework supports multiple cameras. If you use the +legacy API and call {@link android.hardware.Camera#open open()} without an +argument, you get the first rear-facing camera.

+

Create the Camera Preview

@@ -113,13 +99,10 @@ data from the camera hardware the application.

 class Preview extends ViewGroup implements SurfaceHolder.Callback {
-...
 
     SurfaceView mSurfaceView;
     SurfaceHolder mHolder;
 
-...
-
     Preview(Context context) {
         super(context);
 
@@ -137,14 +120,13 @@ class Preview extends ViewGroup implements SurfaceHolder.Callback {
 

The preview class must be passed to the {@link android.hardware.Camera} object before the live -image preview can be started, as seen in {@code setCamera()} method of the sample, -as shown in the next section.

+image preview can be started, as shown in the next section.

Set and Start the Preview

A camera instance and its related preview must be created in a specific -order, with the camera object being first. In the sample application, the +order, with the camera object being first. In the snippet below, the process of initializing the camera is encapsulated so that {@link android.hardware.Camera#startPreview Camera.startPreview()} is called by the {@code setCamera()} method, whenever the user does something to change the @@ -183,9 +165,8 @@ public void setCamera(Camera camera) {

Modify Camera Settings

Camera settings change the way that the camera takes pictures, from the zoom -level to exposure compensation. This example doesn’t do a whole lot with camera -settings, but the APIs provide a wide array of options. The {@code surfaceChanged()} method in the -sample app demonstrates how to get and set camera parameters:

+level to exposure compensation. This example changes only the preview size; +see the source code of the Camera application for many more.

 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
@@ -221,9 +202,7 @@ to API level 14, you must stop your preview before changing the orientation and
 method to take a picture once the preview is started. You can create {@link
 android.hardware.Camera.PictureCallback} and {@link
 android.hardware.Camera.ShutterCallback} objects and pass them into {@link
-android.hardware.Camera#takePicture Camera.takePicture()}.  Since the Android
-Camera application already does a great job capturing JPEG images, you should
-probably implement the raw-image callback.

+android.hardware.Camera#takePicture Camera.takePicture()}.

If you want to grab images continously, you can create a {@link android.hardware.Camera.PreviewCallback} that implements {@link @@ -236,8 +215,8 @@ takePicture()}.

Restart the Preview

After a picture is taken, you must to restart the preview before the user -can take another picture. In the example, the restart is done by overloading -the shutter button, as shown below.

+can take another picture. In this example, the restart is done by overloading +the shutter button.

 @Override
@@ -302,7 +281,7 @@ private void stopPreviewAndFreeCamera() {
 }
 
-

In the example application, this procedure is also part of the {@code +

Earlier in the lesson, this procedure was also part of the {@code setCamera()} method, so initializing a camera always begins with stopping the preview.

diff --git a/docs/html/training/camera/index.jd b/docs/html/training/camera/index.jd index 400f636..31adfe8 100644 --- a/docs/html/training/camera/index.jd +++ b/docs/html/training/camera/index.jd @@ -28,7 +28,7 @@ next.link=photobasics.html

Try it out

- Download the Intent sample + Download the sample

PhotoIntentActivity.zip

-- cgit v1.1