From 7b265a6b2f55c6ae7afc30e63ba324c4084a5d8e Mon Sep 17 00:00:00 2001 From: ztenghui Date: Mon, 9 Sep 2013 14:58:44 -0700 Subject: Fix the flash mode transition in video mode onSwitchMode is wrongly overloaded, now is fixed. Basically, onCurrentDataChanged will handle the switching in and out of Camera. onDataFullScreenChange will handle full screen change on non-preview data. bug:10610967 Change-Id: I199a20d40d66b78302e90e0f96826d03076b0e39 --- src/com/android/camera/CameraActivity.java | 36 +++++------ src/com/android/camera/CameraModule.java | 5 +- src/com/android/camera/PhotoModule.java | 12 ++-- src/com/android/camera/PhotoUI.java | 20 +++--- src/com/android/camera/VideoModule.java | 74 ++++++++++++---------- src/com/android/camera/VideoUI.java | 11 ++-- .../android/camera/WideAnglePanoramaModule.java | 8 +-- src/com/android/camera/ui/FilmStripView.java | 18 +----- 8 files changed, 87 insertions(+), 97 deletions(-) diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java index 672801579..bbe0ebb08 100644 --- a/src/com/android/camera/CameraActivity.java +++ b/src/com/android/camera/CameraActivity.java @@ -232,15 +232,10 @@ public class CameraActivity extends Activity @Override public void onDataFullScreenChange(int dataID, boolean full) { - } - - @Override - public void onSwitchMode(boolean toCamera) { - mCurrentModule.onSwitchMode(toCamera); - if (toCamera) { - setActionBarVisibilityAndLightsOut(true); - } else { - setActionBarVisibilityAndLightsOut(false); + boolean isCameraID = mDataAdapter.getLocalData(dataID).getLocalDataType() == + LocalData.LOCAL_CAMERA_PREVIEW; + if (!isCameraID) { + setActionBarVisibilityAndLightsOut(full); } } @@ -249,18 +244,23 @@ public class CameraActivity extends Activity runOnUiThread(new Runnable() { @Override public void run() { + LocalData currentData = mDataAdapter.getLocalData(dataID); + if (currentData == null) { + Log.w(TAG, "Current data ID not found."); + hidePanoStitchingProgress(); + return; + } + boolean isCameraID = currentData.getLocalDataType() == + LocalData.LOCAL_CAMERA_PREVIEW; if (!current) { + if (isCameraID) { + mCurrentModule.onPreviewFocusChanged(false); + setActionBarVisibilityAndLightsOut(false); + } hidePanoStitchingProgress(); } else { - LocalData currentData = mDataAdapter.getLocalData(dataID); - if (currentData == null) { - Log.w(TAG, "Current data ID not found."); - hidePanoStitchingProgress(); - return; - } - - if (currentData.getLocalDataType() == - LocalData.LOCAL_CAMERA_PREVIEW) { + if (isCameraID) { + mCurrentModule.onPreviewFocusChanged(true); // Don't show the action bar in Camera preview. setActionBarVisibilityAndLightsOut(true); } else { diff --git a/src/com/android/camera/CameraModule.java b/src/com/android/camera/CameraModule.java index bcfe98d65..1283a982c 100644 --- a/src/com/android/camera/CameraModule.java +++ b/src/com/android/camera/CameraModule.java @@ -19,14 +19,13 @@ package com.android.camera; import android.content.Intent; import android.content.res.Configuration; import android.view.KeyEvent; -import android.view.MotionEvent; import android.view.View; public interface CameraModule { public void init(CameraActivity activity, View frame); - public void onSwitchMode(boolean toCamera); + public void onPreviewFocusChanged(boolean previewFocused); public void onPauseBeforeSuper(); @@ -60,8 +59,6 @@ public interface CameraModule { public boolean updateStorageHintOnResume(); - public void updateCameraAppView(); - public void onOrientationChanged(int orientation); public void onShowSwitcherPopup(); diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index 8e03131c4..789446dcd 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -406,6 +406,7 @@ public class PhotoModule mUI.showLocationDialog(); } + @Override public void enableRecordingLocation(boolean enable) { setLocationPreference(enable ? RecordLocationPreference.VALUE_ON : RecordLocationPreference.VALUE_OFF); @@ -505,6 +506,7 @@ public class PhotoModule } + @Override public void onScreenSizeChanged(int width, int height, int previewWidth, int previewHeight) { if (mFocusManager != null) mFocusManager.setPreviewSize(width, height); } @@ -1159,10 +1161,6 @@ public class PhotoModule return mFirstTimeInitialized; } - @Override - public void updateCameraAppView() { - } - @Override public void onResumeBeforeSuper() { mPaused = false; @@ -1768,6 +1766,7 @@ public class PhotoModule } } + @Override public boolean isCameraIdle() { return (mCameraState == IDLE) || (mCameraState == PREVIEW_STOPPED) || @@ -1775,6 +1774,7 @@ public class PhotoModule && (mCameraState != SWITCHING_CAMERA)); } + @Override public boolean isImageCaptureIntent() { String action = mActivity.getIntent().getAction(); return (MediaStore.ACTION_IMAGE_CAPTURE.equals(action) @@ -1941,8 +1941,8 @@ public class PhotoModule } @Override - public void onSwitchMode(boolean toCamera) { - mUI.onSwitchMode(toCamera); + public void onPreviewFocusChanged(boolean previewFocused) { + mUI.onPreviewFocusChanged(previewFocused); } /* Below is no longer needed, except to get rid of compile error diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java index 73840ab06..de555485c 100644 --- a/src/com/android/camera/PhotoUI.java +++ b/src/com/android/camera/PhotoUI.java @@ -265,6 +265,7 @@ public class PhotoUI implements PieListener, return true; } + @Override public void onSurfaceTextureUpdated(SurfaceTexture surface) { // Do nothing. } @@ -454,8 +455,10 @@ public class PhotoUI implements PieListener, } } + @Override public void showGpsOnScreenIndicator(boolean hasSignal) { } + @Override public void hideGpsOnScreenIndicator() { } public void overrideSettings(final String ... keyvalues) { @@ -518,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) { @@ -801,6 +804,7 @@ public class PhotoUI implements PieListener, mFaceView.setFaces(faces); } + @Override public void onDisplayChanged() { mCameraControls.checkLayoutFlip(); mController.updateCameraOrientation(); diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java index 2173c9fb2..56882e1cf 100644 --- a/src/com/android/camera/VideoModule.java +++ b/src/com/android/camera/VideoModule.java @@ -463,17 +463,20 @@ public class VideoModule implements CameraModule, } } + @Override @OnClickAttr public void onReviewPlayClicked(View v) { startPlayVideoActivity(); } + @Override @OnClickAttr public void onReviewDoneClicked(View v) { mIsInReviewMode = false; doReturnToCaller(true); } + @Override @OnClickAttr public void onReviewCancelClicked(View v) { mIsInReviewMode = false; @@ -1490,25 +1493,7 @@ public class VideoModule implements CameraModule, mParameters.setPreviewFrameRate(mProfile.videoFrameRate); } - // Set flash mode. - String flashMode; - if (mUI.isVisible()) { - flashMode = mPreferences.getString( - CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE, - mActivity.getString(R.string.pref_camera_video_flashmode_default)); - } else { - flashMode = Parameters.FLASH_MODE_OFF; - } - List supportedFlash = mParameters.getSupportedFlashModes(); - if (isSupported(flashMode, supportedFlash)) { - mParameters.setFlashMode(flashMode); - } else { - flashMode = mParameters.getFlashMode(); - if (flashMode == null) { - flashMode = mActivity.getString( - R.string.pref_camera_flashmode_no_flash); - } - } + forceFlashOffIfSupported(!mUI.isVisible()); // Set white balance parameter. String whiteBalance = mPreferences.getString( @@ -1711,27 +1696,46 @@ public class VideoModule implements CameraModule, } } - @Override - public void updateCameraAppView() { - if (!mPreviewing || mParameters.getFlashMode() == null) return; - - // When going to and back from gallery, we need to turn off/on the flash. - if (!mUI.isVisible()) { - if (mParameters.getFlashMode().equals(Parameters.FLASH_MODE_OFF)) { - mRestoreFlash = false; - return; + private void forceFlashOffIfSupported(boolean forceOff) { + String flashMode; + if (!forceOff) { + flashMode = mPreferences.getString( + CameraSettings.KEY_VIDEOCAMERA_FLASH_MODE, + mActivity.getString(R.string.pref_camera_video_flashmode_default)); + } else { + flashMode = Parameters.FLASH_MODE_OFF; + } + List supportedFlash = mParameters.getSupportedFlashModes(); + if (isSupported(flashMode, supportedFlash)) { + mParameters.setFlashMode(flashMode); + } else { + flashMode = mParameters.getFlashMode(); + if (flashMode == null) { + flashMode = mActivity.getString( + R.string.pref_camera_flashmode_no_flash); } - mRestoreFlash = true; - setCameraParameters(); - } else if (mRestoreFlash) { - mRestoreFlash = false; - setCameraParameters(); } } + /** + * Used to update the flash mode. Video mode can turn on the flash as torch + * mode, which we would like to turn on and off when we switching in and + * out to the preview. + * + * @param forceOff whether we want to force the flash off. + */ + private void forceFlashOff(boolean forceOff) { + if (!mPreviewing || mParameters.getFlashMode() == null) { + return; + } + forceFlashOffIfSupported(forceOff); + mCameraDevice.setParameters(mParameters); + } + @Override - public void onSwitchMode(boolean toCamera) { - mUI.onSwitchMode(toCamera); + public void onPreviewFocusChanged(boolean previewFocused) { + mUI.onPreviewFocusChanged(previewFocused); + forceFlashOff(!previewFocused); } private final class JpegPictureCallback implements CameraPictureCallback { diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java index 88a7b5863..204195f44 100644 --- a/src/com/android/camera/VideoUI.java +++ b/src/com/android/camera/VideoUI.java @@ -612,20 +612,20 @@ public class VideoUI implements PieRenderer.PieListener, } } - public void onSwitchMode(boolean toCamera) { - if (toCamera) { + public void onPreviewFocusChanged(boolean previewFocused) { + if (previewFocused) { showUI(); } else { hideUI(); } 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); } - setShowMenu(toCamera); + setShowMenu(previewFocused); } public void initializePopup(PreferenceGroup pref) { @@ -672,6 +672,7 @@ public class VideoUI implements PieRenderer.PieListener, return mTextureView.getVisibility() == View.VISIBLE; } + @Override public void onDisplayChanged() { mCameraControls.checkLayoutFlip(); mController.updateCameraOrientation(); diff --git a/src/com/android/camera/WideAnglePanoramaModule.java b/src/com/android/camera/WideAnglePanoramaModule.java index 053e99df7..abdb24825 100644 --- a/src/com/android/camera/WideAnglePanoramaModule.java +++ b/src/com/android/camera/WideAnglePanoramaModule.java @@ -308,8 +308,8 @@ public class WideAnglePanoramaModule } @Override - public void onSwitchMode(boolean toCamera) { - if (toCamera) { + public void onPreviewFocusChanged(boolean previewFocused) { + if (previewFocused) { mUI.showUI(); } else { mUI.hideUI(); @@ -1058,10 +1058,6 @@ public class WideAnglePanoramaModule return false; } - @Override - public void updateCameraAppView() { - } - @Override public void onShowSwitcherPopup() { } diff --git a/src/com/android/camera/ui/FilmStripView.java b/src/com/android/camera/ui/FilmStripView.java index 4cf8e9461..571462177 100644 --- a/src/com/android/camera/ui/FilmStripView.java +++ b/src/com/android/camera/ui/FilmStripView.java @@ -328,14 +328,6 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { */ public void onDataFullScreenChange(int dataID, boolean fullScreen); - /** - * Callback when entering/leaving camera mode. - * - * @param toCamera {@code true} if entering camera mode. Otherwise, - * {@code false} - */ - public void onSwitchMode(boolean toCamera); - /** * The callback when the item is centered/off-centered. * @@ -1984,7 +1976,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { } if (mListener != null) { - mListener.onSwitchMode(false); + mListener.onDataFullScreenChange(mViewItem[mCurrentItem].getId(), false); mBottomControls.setVisibility(View.VISIBLE); } } @@ -2005,11 +1997,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { private void enterFullScreen() { if (mListener != null) { - // TODO: After full size images snapping to fill the screen at - // the end of a scroll/fling is implemented, we should only make - // this call when the view on the center of the screen is - // camera preview - mListener.onSwitchMode(true); + mListener.onDataFullScreenChange(mViewItem[mCurrentItem].getId(), true); mBottomControls.setVisibility(View.GONE); } } @@ -2028,7 +2016,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { private void leaveFullScreen() { if (mListener != null) { - mListener.onSwitchMode(false); + mListener.onDataFullScreenChange(mViewItem[mCurrentItem].getId(), false); mBottomControls.setVisibility(View.VISIBLE); } } -- cgit v1.2.3