summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWu-cheng Li <wuchengli@google.com>2011-08-15 04:34:23 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-08-15 04:34:23 -0700
commitfbfd6d187b46cab35be980c586962d027e4a2409 (patch)
tree49bfb0bbd1be9652b5e99408437a22d19181349b /src
parenta24cd1882d1fc4cd10c681ffb88360c1f2f41842 (diff)
parent41ecefdc167ca88d785e6a1d58b706cc7f03c2bd (diff)
downloadLegacyCamera-fbfd6d187b46cab35be980c586962d027e4a2409.zip
LegacyCamera-fbfd6d187b46cab35be980c586962d027e4a2409.tar.gz
LegacyCamera-fbfd6d187b46cab35be980c586962d027e4a2409.tar.bz2
Merge "Draw all the faces on one face view."
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/Camera.java32
-rw-r--r--src/com/android/camera/FaceListener.java120
-rw-r--r--src/com/android/camera/ui/FaceView.java98
3 files changed, 118 insertions, 132 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index ae883b8..fee97cc 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -17,6 +17,7 @@
package com.android.camera;
import com.android.camera.ui.CameraPicker;
+import com.android.camera.ui.FaceView;
import com.android.camera.ui.FocusRectangle;
import com.android.camera.ui.IndicatorControl;
import com.android.camera.ui.RotateImageView;
@@ -35,6 +36,8 @@ import android.graphics.Bitmap;
import android.graphics.Rect;
import android.hardware.Camera.Area;
import android.hardware.Camera.CameraInfo;
+import android.hardware.Camera.Face;
+import android.hardware.Camera.FaceDetectionListener;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.Size;
@@ -86,7 +89,8 @@ import java.util.List;
/** The Camera activity which can preview and take pictures. */
public class Camera extends ActivityBase implements View.OnClickListener,
View.OnTouchListener, ShutterButton.OnShutterButtonListener,
- SurfaceHolder.Callback, ModePicker.OnModeChangeListener {
+ SurfaceHolder.Callback, ModePicker.OnModeChangeListener,
+ FaceDetectionListener {
private static final String TAG = "camera";
@@ -164,6 +168,7 @@ public class Camera extends ActivityBase implements View.OnClickListener,
// An imageview showing showing the last captured picture thumbnail.
private RotateImageView mThumbnailView;
private ModePicker mModePicker;
+ private FaceView mFaceView;
// mCropValue and mSaveUri are used only if isImageCaptureIntent() is true.
private String mCropValue;
@@ -219,7 +224,6 @@ public class Camera extends ActivityBase implements View.OnClickListener,
private final AutoFocusCallback mAutoFocusCallback =
new AutoFocusCallback();
private final ZoomListener mZoomListener = new ZoomListener();
- private FaceListener mFaceListener;
private final CameraErrorCallback mErrorCallback = new CameraErrorCallback();
private long mFocusStartTime;
@@ -514,13 +518,12 @@ public class Camera extends ActivityBase implements View.OnClickListener,
private void startFaceDetection() {
if (mParameters.getMaxNumDetectedFaces() > 0) {
- if (mFaceListener == null) {
- mFaceListener = new FaceListener(this,
- (ViewGroup) findViewById(R.id.frame), mDisplayOrientation);
- }
+ mFaceView = (FaceView) findViewById(R.id.face_view);
+ mFaceView.setVisibility(View.VISIBLE);
+ mFaceView.setDisplayOrientation(mDisplayOrientation);
CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
- mFaceListener.setMirror(info.facing == CameraInfo.CAMERA_FACING_FRONT);
- mCameraDevice.setFaceDetectionListener(mFaceListener);
+ mFaceView.setMirror(info.facing == CameraInfo.CAMERA_FACING_FRONT);
+ mCameraDevice.setFaceDetectionListener(this);
mCameraDevice.startFaceDetection();
}
}
@@ -529,7 +532,7 @@ public class Camera extends ActivityBase implements View.OnClickListener,
if (mParameters.getMaxNumDetectedFaces() > 0) {
mCameraDevice.setFaceDetectionListener(null);
mCameraDevice.stopFaceDetection();
- if (mFaceListener != null) mFaceListener.clearFaces();
+ if (mFaceView != null) mFaceView.clearFaces();
}
}
@@ -1522,7 +1525,7 @@ public class Camera extends ActivityBase implements View.OnClickListener,
private void updateFocusUI() {
// Do not show focus rectangle if there is any face rectangle.
- if (mFaceListener != null && mFaceListener.faceExists()) return;
+ if (mFaceView != null && mFaceView.faceExists()) return;
if (mCameraState == FOCUSING || mCameraState == FOCUSING_SNAP_ON_FINISH) {
mFocusRectangle.showStart();
@@ -1840,8 +1843,8 @@ public class Camera extends ActivityBase implements View.OnClickListener,
mDisplayRotation = Util.getDisplayRotation(this);
mDisplayOrientation = Util.getDisplayOrientation(mDisplayRotation, mCameraId);
mCameraDevice.setDisplayOrientation(mDisplayOrientation);
- if (mFaceListener != null) {
- mFaceListener.setDisplayOrientation(mDisplayOrientation);
+ if (mFaceView != null) {
+ mFaceView.setDisplayOrientation(mDisplayOrientation);
}
setCameraParameters(UPDATE_PARAM_ALL);
@@ -2377,4 +2380,9 @@ public class Camera extends ActivityBase implements View.OnClickListener,
Camera.this.onSharedPreferenceChanged();
}
}
+
+ @Override
+ public void onFaceDetection(Face[] faces, android.hardware.Camera camera) {
+ mFaceView.setFaces(faces);
+ }
}
diff --git a/src/com/android/camera/FaceListener.java b/src/com/android/camera/FaceListener.java
deleted file mode 100644
index dae0bda..0000000
--- a/src/com/android/camera/FaceListener.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.camera;
-
-import android.content.Context;
-import android.graphics.Matrix;
-import android.graphics.RectF;
-import android.hardware.Camera.Face;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.RelativeLayout;
-
-class FaceListener implements android.hardware.Camera.FaceDetectionListener {
- private final String TAG = "FaceListener";
- private final boolean LOGV = false;
- private final int MAX_NUM_FACES = 10; // Show 10 faces at most.
- private final Context mContext;
- private final ViewGroup mFrame;
- private int mDisplayOrientation;
- private boolean mMirror;
- private View mFaces[] = new View[MAX_NUM_FACES];
- private Matrix mMatrix = new Matrix();
- private RectF mRect = new RectF();
-
- public FaceListener(Context context, ViewGroup frame, int orientation) {
- mContext = context;
- mFrame = frame;
- setDisplayOrientation(orientation);
- }
-
- @Override
- public void onFaceDetection(Face[] faces, android.hardware.Camera camera) {
- if (LOGV) Log.v(TAG, "Num of faces=" + faces.length);
-
- // Prepare the matrix.
- Util.prepareMatrix(mMatrix, mMirror, mDisplayOrientation, mFrame.getWidth(),
- mFrame.getHeight());
- showFaces(faces);
- }
-
- public void setDisplayOrientation(int orientation) {
- mDisplayOrientation = orientation;
- if (LOGV) Log.v(TAG, "mDisplayOrientation=" + orientation);
- }
-
- public void setMirror(boolean mirror) {
- mMirror = mirror;
- if (LOGV) Log.v(TAG, "mMirror=" + mirror);
- }
-
- public boolean faceExists() {
- if (mFaces[0] == null) return false;
- if (mFaces[0].getVisibility() == View.VISIBLE) {
- return true;
- } else {
- return false;
- }
- }
-
- public void clearFaces() {
- for (int i = 0; i < MAX_NUM_FACES; i++) {
- if (mFaces[i] == null) break;
- if (mFaces[i].getVisibility() != View.VISIBLE) break;
- mFaces[i].setVisibility(View.GONE);
- }
- }
-
- private void showFaces(Face[] faces) {
- for (int i = 0; i < MAX_NUM_FACES; i++) {
- if (i < faces.length) {
- // Inflate the view if it's not done yet.
- if (mFaces[i] == null) {
- LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
- Context.LAYOUT_INFLATER_SERVICE);
- mFaces[i] = inflater.inflate(R.layout.face, null);
- mFrame.addView(mFaces[i]);
- }
-
- // Transform the coordinates.
- mRect.set(faces[i].rect);
- if (LOGV) dumpRect(mRect, "Original rect");
- mMatrix.mapRect(mRect);
- if (LOGV) dumpRect(mRect, "Transformed rect");
-
- // Set width, height, and margin.
- RelativeLayout.LayoutParams p =
- (RelativeLayout.LayoutParams) mFaces[i].getLayoutParams();
- p.width = Math.round(mRect.width());
- p.height = Math.round(mRect.height());
- p.setMargins(Math.round(mRect.left), Math.round(mRect.top), 0, 0);
- mFaces[i].setLayoutParams(p);
- mFaces[i].setVisibility(View.VISIBLE);
- mFaces[i].requestLayout();
- } else {
- if (mFaces[i] != null) mFaces[i].setVisibility(View.GONE);
- }
- }
- }
-
- private void dumpRect(RectF rect, String msg) {
- Log.v(TAG, msg + "=(" + rect.left + "," + rect.top
- + "," + rect.right + "," + rect.bottom + ")");
- }
-}
diff --git a/src/com/android/camera/ui/FaceView.java b/src/com/android/camera/ui/FaceView.java
new file mode 100644
index 0000000..2b76255
--- /dev/null
+++ b/src/com/android/camera/ui/FaceView.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.camera.ui;
+
+import com.android.camera.R;
+import com.android.camera.Util;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Matrix;
+import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
+import android.hardware.Camera.Face;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+
+public class FaceView extends View {
+ private final String TAG = "FaceView";
+ private final boolean LOGV = false;
+ private int mDisplayOrientation;
+ private boolean mMirror;
+ private Matrix mMatrix = new Matrix();
+ private RectF mRect = new RectF();
+ private Face[] mFaces;
+ private Drawable mFaceRect;
+
+ public FaceView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mFaceRect = getResources().getDrawable(R.drawable.focus_focused);
+ }
+
+ public void setFaces(Face[] faces) {
+ if (LOGV) Log.v(TAG, "Num of faces=" + faces.length);
+ mFaces = faces;
+ invalidate();
+ }
+
+ public void setDisplayOrientation(int orientation) {
+ mDisplayOrientation = orientation;
+ if (LOGV) Log.v(TAG, "mDisplayOrientation=" + orientation);
+ }
+
+ public void setMirror(boolean mirror) {
+ mMirror = mirror;
+ if (LOGV) Log.v(TAG, "mMirror=" + mirror);
+ }
+
+ public boolean faceExists() {
+ return (mFaces != null && mFaces.length > 0);
+ }
+
+ public void clearFaces() {
+ mFaces = null;
+ invalidate();
+ }
+
+ private void dumpRect(RectF rect, String msg) {
+ Log.v(TAG, msg + "=(" + rect.left + "," + rect.top
+ + "," + rect.right + "," + rect.bottom + ")");
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (mFaces != null && mFaces.length > 0) {
+ // Prepare the matrix.
+ Util.prepareMatrix(mMatrix, mMirror, mDisplayOrientation, getWidth(),
+ getHeight());
+
+ for (int i = 0; i < mFaces.length; i++) {
+ // Transform the coordinates.
+ mRect.set(mFaces[i].rect);
+ if (LOGV) dumpRect(mRect, "Original rect");
+ mMatrix.mapRect(mRect);
+ if (LOGV) dumpRect(mRect, "Transformed rect");
+
+ mFaceRect.setBounds(Math.round(mRect.left), Math.round(mRect.top),
+ Math.round(mRect.right), Math.round(mRect.bottom));
+ mFaceRect.draw(canvas);
+ }
+ }
+ super.onDraw(canvas);
+ }
+}