OSDN Git Service

Fix face view in simple camera
authorDoris Liu <tianliu@google.com>
Wed, 15 Jan 2014 01:51:32 +0000 (17:51 -0800)
committerDoris Liu <tianliu@google.com>
Wed, 15 Jan 2014 02:15:10 +0000 (18:15 -0800)
Part II at ag/407562

Bug: 12460604
Change-Id: I9532d5dae7c156568fef944b81127c6ff194a394

src/com/android/camera/PhotoModule.java
src/com/android/camera/PhotoUI.java
src/com/android/camera/ui/FaceView.java

index 95bc8f0..6bfc07e 100644 (file)
@@ -1176,6 +1176,12 @@ public class PhotoModule
             // preview area size change later in the initialization.
             mAppController.addPreviewAreaSizeChangedListener(mFocusManager);
         }
+
+        if (mUI.getPreviewAreaSizeChangedListener() != null) {
+            mAppController.addPreviewAreaSizeChangedListener(
+                    mUI.getPreviewAreaSizeChangedListener());
+        }
+
         // Add delay on resume from lock screen only, in order to to speed up
         // the onResume --> onPause --> onResume cycle from lock screen.
         // Don't do always because letting go of thread can cause delay.
@@ -1244,6 +1250,10 @@ public class PhotoModule
         }
         getServices().getMemoryManager().removeListener(this);
         mAppController.removePreviewAreaSizeChangedListener(mFocusManager);
+        if (mUI.getPreviewAreaSizeChangedListener() != null) {
+            mAppController.removePreviewAreaSizeChangedListener(
+                    mUI.getPreviewAreaSizeChangedListener());
+        }
 
         SettingsManager settingsManager = mActivity.getSettingsManager();
         settingsManager.removeListener(this);
index 3bc2beb..b34c108 100644 (file)
@@ -31,15 +31,11 @@ import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.view.ViewStub;
-import android.widget.Toast;
 
 import com.android.camera.FocusOverlayManager.FocusUI;
 import com.android.camera.app.CameraAppUI;
 import com.android.camera.app.CameraManager;
-import com.android.camera.settings.SettingsManager;
 import com.android.camera.ui.FaceView;
-import com.android.camera.ui.FocusIndicator;
-import com.android.camera.ui.ModeListView;
 import com.android.camera.ui.PreviewOverlay;
 import com.android.camera.ui.PreviewStatusListener;
 import com.android.camera.util.CameraUtil;
@@ -64,19 +60,13 @@ public class PhotoUI implements PreviewStatusListener,
 
     private FaceView mFaceView;
     private DecodeImageForReview mDecodeTaskForReview = null;
-    private Toast mNotSelectableToast;
 
     private int mZoomMax;
     private List<Integer> mZoomRatios;
 
     private int mPreviewWidth = 0;
     private int mPreviewHeight = 0;
-    private float mSurfaceTextureUncroppedWidth;
-    private float mSurfaceTextureUncroppedHeight;
-
-    private SurfaceTextureSizeChangedListener mSurfaceTextureSizeListener;
     private TextureView mTextureView;
-    private Matrix mMatrix = null;
     private float mAspectRatio = UNSET;
     private final Object mSurfaceTextureLock = new Object();
 
@@ -120,10 +110,6 @@ public class PhotoUI implements PreviewStatusListener,
         return mPreviewGestureListener;
     }
 
-    public interface SurfaceTextureSizeChangedListener {
-        public void onSurfaceTextureSizeChanged(int uncroppedWidth, int uncroppedHeight);
-    }
-
     @Override
     public void onPreviewLayoutChanged(View v, int left, int top, int right,
             int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
@@ -212,7 +198,6 @@ public class PhotoUI implements PreviewStatusListener,
         if (faceViewStub != null) {
             faceViewStub.inflate();
             mFaceView = (FaceView) mRootView.findViewById(R.id.face_view);
-            setSurfaceTextureSizeChangedListener(mFaceView);
         }
         mFocusUI = (FocusUI) mRootView.findViewById(R.id.focus_overlay);
         mPreviewOverlay = (PreviewOverlay) mRootView.findViewById(R.id.preview_overlay);
@@ -222,10 +207,6 @@ public class PhotoUI implements PreviewStatusListener,
         return mFocusUI;
     }
 
-    public void setSurfaceTextureSizeChangedListener(SurfaceTextureSizeChangedListener listener) {
-        mSurfaceTextureSizeListener = listener;
-    }
-
     public void updatePreviewAspectRatio(float aspectRatio) {
         if (aspectRatio <= 0) {
             Log.e(TAG, "Invalid aspect ratio: " + aspectRatio);
@@ -491,4 +472,12 @@ public class PhotoUI implements PreviewStatusListener,
         mFaceView.setFaces(faces);
     }
 
+    /**
+     * Returns a {@link com.android.camera.ui.PreviewStatusListener.PreviewAreaSizeChangedListener}
+     * that should be registered to listen to preview area change.
+     */
+    public PreviewAreaSizeChangedListener getPreviewAreaSizeChangedListener() {
+        return mFaceView;
+    }
+
 }
index d6209c3..a47a0fc 100644 (file)
@@ -36,7 +36,7 @@ import com.android.camera2.R;
 
 public class FaceView extends View
     implements FocusIndicator, Rotatable,
-    PhotoUI.SurfaceTextureSizeChangedListener {
+    PreviewStatusListener.PreviewAreaSizeChangedListener {
     private static final String TAG = "CAM FaceView";
     private final boolean LOGV = false;
     // The value for android.hardware.Camera.setDisplayOrientation.
@@ -61,8 +61,6 @@ public class FaceView extends View
     private Paint mPaint;
     private volatile boolean mBlocked;
 
-    private int mUncroppedWidth;
-    private int mUncroppedHeight;
     private static final int MSG_SWITCH_FACES = 1;
     private static final int SWITCH_DELAY = 70;
     private boolean mStateSwitchPending = false;
@@ -78,6 +76,7 @@ public class FaceView extends View
             }
         }
     };
+    private final RectF mPreviewArea = new RectF();
 
     public FaceView(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -92,12 +91,6 @@ public class FaceView extends View
         mPaint.setStrokeWidth(res.getDimension(R.dimen.face_circle_stroke));
     }
 
-    @Override
-    public void onSurfaceTextureSizeChanged(int uncroppedWidth, int uncroppedHeight) {
-        mUncroppedWidth = uncroppedWidth;
-        mUncroppedHeight = uncroppedHeight;
-    }
-
     public void setFaces(Face[] faces) {
         if (LOGV) Log.v(TAG, "Num of faces=" + faces.length);
         if (mPause) return;
@@ -185,8 +178,8 @@ public class FaceView extends View
     protected void onDraw(Canvas canvas) {
         if (!mBlocked && (mFaces != null) && (mFaces.length > 0)) {
             int rw, rh;
-            rw = mUncroppedWidth;
-            rh = mUncroppedHeight;
+            rw = (int) mPreviewArea.width();
+            rh = (int) mPreviewArea.height();
             // Prepare the matrix.
             if (((rh > rw) && ((mDisplayOrientation == 0) || (mDisplayOrientation == 180)))
                     || ((rw > rh) && ((mDisplayOrientation == 90) || (mDisplayOrientation == 270)))) {
@@ -210,10 +203,16 @@ public class FaceView extends View
                 mMatrix.mapRect(mRect);
                 if (LOGV) CameraUtil.dumpRect(mRect, "Transformed rect");
                 mPaint.setColor(mColor);
+                mRect.offset(mPreviewArea.left, mPreviewArea.top);
                 canvas.drawOval(mRect, mPaint);
             }
             canvas.restore();
         }
         super.onDraw(canvas);
     }
+
+    @Override
+    public void onPreviewAreaSizeChanged(RectF previewArea) {
+        mPreviewArea.set(previewArea);
+    }
 }