OSDN Git Service

Fix the flash mode transition in video mode
[android-x86/packages-apps-Camera2.git] / src / com / android / camera / PhotoUI.java
index 1f5ae24..de55548 100644 (file)
@@ -26,10 +26,7 @@ import android.graphics.SurfaceTexture;
 import android.graphics.drawable.ColorDrawable;
 import android.hardware.Camera;
 import android.hardware.Camera.Face;
-import android.hardware.Camera.Size;
 import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.Message;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.TextureView;
@@ -45,12 +42,11 @@ import android.widget.Toast;
 
 import com.android.camera.CameraPreference.OnPreferenceChangedListener;
 import com.android.camera.FocusOverlayManager.FocusUI;
+import com.android.camera.ui.ModuleSwitcher;
 import com.android.camera.util.ApiHelper;
 import com.android.camera.ui.AbstractSettingPopup;
 import com.android.camera.ui.CameraControls;
 import com.android.camera.ui.CameraRootView;
-import com.android.camera.ui.CameraSwitcher;
-import com.android.camera.ui.CameraSwitcher.CameraSwitchListener;
 import com.android.camera.ui.CountDownView;
 import com.android.camera.ui.CountDownView.OnCountDownFinishedListener;
 import com.android.camera.ui.FaceView;
@@ -92,7 +88,7 @@ public class PhotoUI implements PieListener,
 
     private View mMenuButton;
     private PhotoMenu mMenu;
-    private CameraSwitcher mSwitcher;
+    private ModuleSwitcher mSwitcher;
     private CameraControls mCameraControls;
     private AlertDialog mLocationDialog;
 
@@ -129,7 +125,7 @@ public class PhotoUI implements PieListener,
                 int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
             int width = right - left;
             int height = bottom - top;
-            // Full-screen screennail
+            // Full-screen preview
             int w = width;
             int h = height;
             if (CameraUtil.getDisplayRotation(mActivity) % 180 != 0) {
@@ -139,6 +135,7 @@ public class PhotoUI implements PieListener,
             if (mPreviewWidth != width || mPreviewHeight != height) {
                 mPreviewWidth = width;
                 mPreviewHeight = height;
+                setTransformMatrix(width, height);
                 mController.onScreenSizeChanged(width, height, w, h);
             }
         }
@@ -146,15 +143,30 @@ public class PhotoUI implements PieListener,
 
     private class DecodeTask extends AsyncTask<Integer, Void, Bitmap> {
         private final byte [] mData;
+        private int mOrientation;
+        private boolean mMirror;
 
-        public DecodeTask(byte[] data) {
+        public DecodeTask(byte[] data, int orientation, boolean mirror) {
             mData = data;
+            mOrientation = orientation;
+            mMirror = mirror;
         }
 
         @Override
         protected Bitmap doInBackground(Integer... params) {
             // Decode image in background.
-            return CameraUtil.downSample(mData, DOWN_SAMPLE_FACTOR);
+            Bitmap bitmap = CameraUtil.downSample(mData, DOWN_SAMPLE_FACTOR);
+            if (mOrientation != 0 || mMirror) {
+                Matrix m = new Matrix();
+                m.preRotate(mOrientation);
+                if (mMirror) {
+                    // Flip horizontally
+                    m.setScale(-1f, 1f);
+                }
+                return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m,
+                        false);
+            }
+            return bitmap;
         }
 
         @Override
@@ -180,8 +192,8 @@ public class PhotoUI implements PieListener,
         initIndicators();
 
         mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button);
-        mSwitcher = (CameraSwitcher) mRootView.findViewById(R.id.camera_switcher);
-        mSwitcher.setCurrentIndex(CameraSwitcher.PHOTO_MODULE_INDEX);
+        mSwitcher = (ModuleSwitcher) mRootView.findViewById(R.id.camera_switcher);
+        mSwitcher.setCurrentIndex(ModuleSwitcher.PHOTO_MODULE_INDEX);
         mSwitcher.setSwitchListener(mActivity);
         mMenuButton = mRootView.findViewById(R.id.menu);
         if (ApiHelper.HAS_FACE_DETECTION) {
@@ -204,7 +216,6 @@ public class PhotoUI implements PieListener,
 
     private void setTransformMatrix(int width, int height) {
         mMatrix = mTextureView.getTransform(mMatrix);
-        int orientation = CameraUtil.getDisplayRotation(mActivity);
         float scaleX = 1f, scaleY = 1f;
         float scaledTextureWidth, scaledTextureHeight;
         if (width > height) {
@@ -254,6 +265,7 @@ public class PhotoUI implements PieListener,
         return true;
     }
 
+    @Override
     public void onSurfaceTextureUpdated(SurfaceTexture surface) {
         // Do nothing.
     }
@@ -299,9 +311,9 @@ public class PhotoUI implements PieListener,
         updateOnScreenIndicators(params, prefGroup, prefs);
     }
 
-    public void animateCapture(final byte[] jpegData) {
+    public void animateCapture(final byte[] jpegData, int orientation, boolean mirror) {
         // Decode jpeg byte array and then animate the jpeg
-        DecodeTask task = new DecodeTask(jpegData);
+        DecodeTask task = new DecodeTask(jpegData, orientation, mirror);
         task.execute();
     }
 
@@ -321,8 +333,7 @@ public class PhotoUI implements PieListener,
         mPreviewThumb.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
-                // TODO: go to filmstrip
-                // mActivity.gotoGallery();
+                mActivity.gotoGallery();
             }
         });
         mMenuButton = mRootView.findViewById(R.id.menu);
@@ -444,8 +455,10 @@ public class PhotoUI implements PieListener,
         }
     }
 
+    @Override
     public void showGpsOnScreenIndicator(boolean hasSignal) { }
 
+    @Override
     public void hideGpsOnScreenIndicator() { }
 
     public void overrideSettings(final String ... keyvalues) {
@@ -508,27 +521,27 @@ public class PhotoUI implements PieListener,
         }
     }
 
-    public void onSwitchMode(boolean toCamera) {
-        if (toCamera) {
+    public void onPreviewFocusChanged(boolean previewFocused) {
+        if (previewFocused) {
             showUI();
         } else {
             hideUI();
         }
         if (mFaceView != null) {
-            mFaceView.setBlockDraw(!toCamera);
+            mFaceView.setBlockDraw(!previewFocused);
         }
         if (mGestures != null) {
-            mGestures.setEnabled(toCamera);
+            mGestures.setEnabled(previewFocused);
         }
         if (mRenderOverlay != null) {
             // this can not happen in capture mode
-            mRenderOverlay.setVisibility(toCamera ? View.VISIBLE : View.GONE);
+            mRenderOverlay.setVisibility(previewFocused ? View.VISIBLE : View.GONE);
         }
         if (mPieRenderer != null) {
-            mPieRenderer.setBlockFocus(!toCamera);
+            mPieRenderer.setBlockFocus(!previewFocused);
         }
-        setShowMenu(toCamera);
-        if (!toCamera && mCountDownView != null) mCountDownView.cancelCountDown();
+        setShowMenu(previewFocused);
+        if (!previewFocused && mCountDownView != null) mCountDownView.cancelCountDown();
     }
 
     public void showPopup(AbstractSettingPopup popup) {
@@ -615,6 +628,9 @@ public class PhotoUI implements PieListener,
         return mShutterButton.isPressed();
     }
 
+    /**
+     * Enables or disables the shutter button.
+     */
     public void enableShutter(boolean enabled) {
         if (mShutterButton != null) {
             mShutterButton.setEnabled(enabled);
@@ -788,6 +804,7 @@ public class PhotoUI implements PieListener,
         mFaceView.setFaces(faces);
     }
 
+    @Override
     public void onDisplayChanged() {
         mCameraControls.checkLayoutFlip();
         mController.updateCameraOrientation();