From 1a18632c11d3f4593547e9afe309cad1f4ea7204 Mon Sep 17 00:00:00 2001 From: Jack Yoo Date: Mon, 22 Feb 2016 17:40:11 -0800 Subject: SnapdragonCamera: Adjusting view initialization Instead of removing and adding the entire root view, changing only core surface view on module change. Change-Id: I5c39cf23b2a58280f4e4e8484865bbed0b12e1cf CRs-Fixed: 979254 --- src/com/android/camera/CameraActivity.java | 11 +++-------- src/com/android/camera/PhotoModule.java | 6 ++++++ src/com/android/camera/PhotoUI.java | 20 ++++++++++++++++---- src/com/android/camera/VideoModule.java | 5 +++++ src/com/android/camera/VideoUI.java | 22 +++++++++++++--------- 5 files changed, 43 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java index 6a3bddbd2..bdb03bb0a 100644 --- a/src/com/android/camera/CameraActivity.java +++ b/src/com/android/camera/CameraActivity.java @@ -1944,10 +1944,7 @@ public class CameraActivity extends Activity mCameraPhotoModuleRootView.setVisibility(View.GONE); mCameraVideoModuleRootView.setVisibility(View.GONE); mCameraPanoModuleRootView.setVisibility(View.GONE); - mCameraRootFrame.removeAllViews(); mCurrentModuleIndex = moduleIndex; - - final CameraRootView rootView; switch (moduleIndex) { case ModuleSwitcher.VIDEO_MODULE_INDEX: if (mVideoModule == null) { @@ -1955,7 +1952,7 @@ public class CameraActivity extends Activity mVideoModule.init(this, mCameraVideoModuleRootView); } mCurrentModule = mVideoModule; - rootView = mCameraVideoModuleRootView; + mCameraVideoModuleRootView.setVisibility(View.VISIBLE); break; case ModuleSwitcher.WIDE_ANGLE_PANO_MODULE_INDEX: @@ -1964,7 +1961,7 @@ public class CameraActivity extends Activity mPanoModule.init(this, mCameraPanoModuleRootView); } mCurrentModule = mPanoModule; - rootView = mCameraPanoModuleRootView; + mCameraPanoModuleRootView.setVisibility(View.VISIBLE); break; case ModuleSwitcher.PHOTO_MODULE_INDEX: @@ -1976,11 +1973,9 @@ public class CameraActivity extends Activity mPhotoModule.init(this, mCameraPhotoModuleRootView); } mCurrentModule = mPhotoModule; - rootView = mCameraPhotoModuleRootView; + mCameraPhotoModuleRootView.setVisibility(View.VISIBLE); break; } - mCameraRootFrame.addView(rootView); - rootView.setVisibility(View.VISIBLE); // Re-apply the last fitSystemWindows() run. Our views rely on this, but // the framework's ActionBarOverlayLayout effectively prevents this if the diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index c867bc7a8..1d49cfbd5 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -688,6 +688,7 @@ public class PhotoModule private void switchCamera() { if (mPaused) return; + mUI.applySurfaceChange(PhotoUI.SURFACE_STATUS.HIDE); Log.v(TAG, "Start to switch camera. id=" + mPendingSwitchCameraId); mCameraId = mPendingSwitchCameraId; mPendingSwitchCameraId = -1; @@ -735,6 +736,7 @@ public class PhotoModule mFocusManager.setParameters(mInitialParams); setupPreview(); + mUI.applySurfaceChange(PhotoUI.SURFACE_STATUS.SURFACE_VIEW); // reset zoom value index mZoomValue = 0; resizeForPreviewAspectRatio(); @@ -2449,6 +2451,8 @@ public class PhotoModule mOpenCameraThread.start(); } + mUI.applySurfaceChange(PhotoUI.SURFACE_STATUS.SURFACE_VIEW); + mJpegPictureCallbackTime = 0; mZoomValue = 0; @@ -2485,6 +2489,8 @@ public class PhotoModule @Override public void onPauseBeforeSuper() { mPaused = true; + mUI.applySurfaceChange(PhotoUI.SURFACE_STATUS.HIDE); + Sensor gsensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (gsensor != null) { mSensorManager.unregisterListener(this, gsensor); diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java index a2d86313b..23ed1bad4 100644 --- a/src/com/android/camera/PhotoUI.java +++ b/src/com/android/camera/PhotoUI.java @@ -151,6 +151,11 @@ public class PhotoUI implements PieListener, private int mOrientation; private float mScreenBrightness = 0.0f; + public enum SURFACE_STATUS { + HIDE, + SURFACE_VIEW; + } + public interface SurfaceTextureSizeChangedListener { public void onSurfaceTextureSizeChanged(int uncroppedWidth, int uncroppedHeight); } @@ -220,6 +225,14 @@ public class PhotoUI implements PieListener, } } + public synchronized void applySurfaceChange(SURFACE_STATUS status) { + if(status == SURFACE_STATUS.HIDE) { + mSurfaceView.setVisibility(View.GONE); + return; + } + mSurfaceView.setVisibility(View.VISIBLE); + } + public PhotoUI(CameraActivity activity, PhotoController controller, View parent) { mActivity = activity; mController = controller; @@ -232,11 +245,8 @@ public class PhotoUI implements PieListener, mSurfaceHolder = mSurfaceView.getHolder(); mSurfaceHolder.addCallback(this); mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); - mSurfaceView.addOnLayoutChangeListener(mLayoutListener); Log.v(TAG, "Using mdp_preview_content (MDP path)"); - - View surfaceContainer = mRootView.findViewById(R.id.preview_container); - surfaceContainer.addOnLayoutChangeListener(new OnLayoutChangeListener() { + mSurfaceView.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, @@ -245,6 +255,8 @@ public class PhotoUI implements PieListener, int height = bottom - top; boolean isMaxSizeBeingValid = false; + tryToCloseSubList(); + if (mMaxPreviewWidth == 0 && mMaxPreviewHeight == 0) { mMaxPreviewWidth = width; mMaxPreviewHeight = height; diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java index 721fb957d..a9e6074ae 100644 --- a/src/com/android/camera/VideoModule.java +++ b/src/com/android/camera/VideoModule.java @@ -1154,6 +1154,8 @@ public class VideoModule implements CameraModule, mUI.enableShutter(true); } + mUI.applySurfaceChange(VideoUI.SURFACE_STATUS.SURFACE_VIEW); + mUI.initDisplayChangeListener(); // Initializing it here after the preview is started. mUI.initializeZoom(mParameters); @@ -1338,6 +1340,7 @@ public class VideoModule implements CameraModule, mUI.collapseCameraControls(); mUI.removeDisplayChangeListener(); + mUI.applySurfaceChange(VideoUI.SURFACE_STATUS.HIDE); } @Override @@ -2763,6 +2766,7 @@ public class VideoModule implements CameraModule, } Log.d(TAG, "Start to switch camera."); + mUI.applySurfaceChange(VideoUI.SURFACE_STATUS.HIDE); mCameraId = mPendingSwitchCameraId; mPendingSwitchCameraId = -1; setCameraId(mCameraId); @@ -2782,6 +2786,7 @@ public class VideoModule implements CameraModule, mFocusManager.setParameters(mParameters); readVideoPreferences(); + mUI.applySurfaceChange(VideoUI.SURFACE_STATUS.SURFACE_VIEW); startPreview(); initializeVideoSnapshot(); resizeForPreviewAspectRatio(); diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java index 4fcc20fbf..9eecd6bd6 100644 --- a/src/com/android/camera/VideoUI.java +++ b/src/com/android/camera/VideoUI.java @@ -118,13 +118,10 @@ public class VideoUI implements PieRenderer.PieListener, private int mTopMargin = 0; private int mBottomMargin = 0; - private OnLayoutChangeListener mLayoutListener = new OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, - int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - tryToCloseSubList(); - } - }; + public enum SURFACE_STATUS { + HIDE, + SURFACE_VIEW; + } public void showPreviewCover() { mPreviewCover.setVisibility(View.VISIBLE); @@ -165,6 +162,14 @@ public class VideoUI implements PieRenderer.PieListener, } } + public synchronized void applySurfaceChange(SURFACE_STATUS status) { + if(status == SURFACE_STATUS.HIDE) { + mSurfaceView.setVisibility(View.GONE); + return; + } + mSurfaceView.setVisibility(View.VISIBLE); + } + public VideoUI(CameraActivity activity, VideoController controller, View parent) { mActivity = activity; mController = controller; @@ -177,9 +182,7 @@ public class VideoUI implements PieRenderer.PieListener, mSurfaceHolder = mSurfaceView.getHolder(); mSurfaceHolder.addCallback(this); mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); - mSurfaceView.addOnLayoutChangeListener(mLayoutListener); Log.v(TAG, "Using mdp_preview_content (MDP path)"); - View surfaceContainer = mRootView.findViewById(R.id.preview_container); surfaceContainer.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override @@ -189,6 +192,7 @@ public class VideoUI implements PieRenderer.PieListener, int width = right - left; int height = bottom - top; + tryToCloseSubList(); if (mMaxPreviewWidth == 0 && mMaxPreviewHeight == 0) { mMaxPreviewWidth = width; mMaxPreviewHeight = height; -- cgit v1.2.3