From fa458f0a64a6b4412912c9177ec0fbeed084a28f Mon Sep 17 00:00:00 2001 From: Byunghun Jeon Date: Tue, 16 Jun 2015 20:17:22 -0700 Subject: SnapdragonCamera: remove nav bar to enable full screen preview Remove the navigation bar in order to take advantage of full screen. Change-Id: I25f42af825c4f3b7ad6521c2ee6d62fa4219044a CRs-Fixed: 865254 --- src/com/android/camera/CameraActivity.java | 15 ++- src/com/android/camera/PhotoUI.java | 136 ++++++++++++----------- src/com/android/camera/VideoUI.java | 168 ++++++++++++----------------- 3 files changed, 152 insertions(+), 167 deletions(-) (limited to 'src') diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java index 71e0db051..c900d1bf4 100644 --- a/src/com/android/camera/CameraActivity.java +++ b/src/com/android/camera/CameraActivity.java @@ -223,7 +223,8 @@ public class CameraActivity extends Activity private LocalMediaObserver mLocalImagesObserver; private LocalMediaObserver mLocalVideosObserver; - private final int DEFAULT_SYSTEM_UI_VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + private final int DEFAULT_SYSTEM_UI_VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; private boolean mPendingDeletion = false; @@ -621,12 +622,16 @@ public class CameraActivity extends Activity private void setSystemBarsVisibility(boolean visible, boolean hideLater) { mMainHandler.removeMessages(HIDE_ACTION_BAR); - int currentSystemUIVisibility = mAboveFilmstripControlLayout.getSystemUiVisibility(); + View decorView = getWindow().getDecorView(); + int currentSystemUIVisibility = decorView.getSystemUiVisibility(); int newSystemUIVisibility = DEFAULT_SYSTEM_UI_VISIBILITY - | (visible ? View.SYSTEM_UI_FLAG_VISIBLE : View.SYSTEM_UI_FLAG_LOW_PROFILE - | View.SYSTEM_UI_FLAG_FULLSCREEN); + | (visible ? View.SYSTEM_UI_FLAG_VISIBLE : + View.SYSTEM_UI_FLAG_LOW_PROFILE + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); if (newSystemUIVisibility != currentSystemUIVisibility) { - mAboveFilmstripControlLayout.setSystemUiVisibility(newSystemUIVisibility); + decorView.setSystemUiVisibility(newSystemUIVisibility); } boolean currentActionBarVisibility = mActionBar.isShowing(); diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java index d2e2345e6..ea85aa36b 100644 --- a/src/com/android/camera/PhotoUI.java +++ b/src/com/android/camera/PhotoUI.java @@ -19,31 +19,32 @@ package com.android.camera; import java.util.List; +import org.codeaurora.snapcam.R; + import android.app.AlertDialog; import android.content.DialogInterface; +import android.content.DialogInterface.OnDismissListener; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Matrix; -import android.graphics.RectF; import android.graphics.Point; +import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.ColorDrawable; import android.hardware.Camera; import android.hardware.Camera.Face; import android.os.AsyncTask; -import android.os.Handler; +import android.preference.PreferenceManager; import android.util.Log; import android.view.Gravity; -import android.view.Surface; -import android.view.SurfaceView; -import android.view.SurfaceHolder; -import android.view.SurfaceHolder.Callback; import android.view.MotionEvent; +import android.view.SurfaceHolder; +import android.view.SurfaceView; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLayoutChangeListener; import android.view.ViewGroup; -import android.view.ViewPropertyAnimator; import android.view.ViewStub; import android.widget.FrameLayout; import android.widget.FrameLayout.LayoutParams; @@ -52,7 +53,6 @@ import android.widget.LinearLayout; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.Toast; -import android.graphics.drawable.AnimationDrawable; import com.android.camera.CameraPreference.OnPreferenceChangedListener; import com.android.camera.FocusOverlayManager.FocusUI; @@ -73,7 +73,6 @@ import com.android.camera.ui.RotateLayout; import com.android.camera.ui.RotateTextToast; import com.android.camera.ui.ZoomRenderer; import com.android.camera.util.CameraUtil; -import org.codeaurora.snapcam.R; public class PhotoUI implements PieListener, PreviewGestures.SingleTapListener, @@ -121,10 +120,8 @@ public class PhotoUI implements PieListener, private int mZoomMax; private List mZoomRatios; - private int mPreviewWidth = 0; - private int mPreviewHeight = 0; - private int mOriginalPreviewWidth = 0; - private int mOriginalPreviewHeight = 0; + private int mMaxPreviewWidth = 0; + private int mMaxPreviewHeight = 0; public boolean mMenuInitialized = false; private float mSurfaceTextureUncroppedWidth; @@ -135,7 +132,6 @@ public class PhotoUI implements PieListener, private SurfaceTextureSizeChangedListener mSurfaceTextureSizeListener; private SurfaceView mSurfaceView = null; - private Matrix mMatrix = null; private float mAspectRatio = 4f / 3f; private boolean mAspectRatioResize; @@ -163,38 +159,6 @@ public class PhotoUI implements PieListener, @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - int width = right - left; - int height = bottom - top; - - int orientation = mActivity.getResources().getConfiguration().orientation; - if ((orientation == Configuration.ORIENTATION_PORTRAIT && width > height) - || (orientation == Configuration.ORIENTATION_LANDSCAPE && width < height)) { - // The screen has rotated; swap SurfaceView width & height - // to ensure correct preview - int oldWidth = width; - width = height; - height = oldWidth; - Log.d(TAG, "Swapping SurfaceView width & height dimensions"); - if (mOriginalPreviewWidth != 0 && mOriginalPreviewHeight != 0) { - int temp = mOriginalPreviewWidth; - mOriginalPreviewWidth = mOriginalPreviewHeight; - mOriginalPreviewHeight = temp; - } - } - - if (mPreviewWidth != width || mPreviewHeight != height - || (mOrientationResize != mPrevOrientationResize) - || mAspectRatioResize) { - if (mOriginalPreviewWidth == 0) mOriginalPreviewWidth = width; - if (mOriginalPreviewHeight == 0) mOriginalPreviewHeight = height; - mPreviewWidth = width; - mPreviewHeight = height; - setTransformMatrix(mPreviewWidth, mPreviewHeight); - mController.onScreenSizeChanged((int) mSurfaceTextureUncroppedWidth, - (int) mSurfaceTextureUncroppedHeight); - mAspectRatioResize = false; - } - if (mMenu != null) mMenu.tryToCloseSubList(); } @@ -265,6 +229,43 @@ public class PhotoUI implements PieListener, 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 + public void onLayoutChange(View v, int left, int top, int right, + int bottom, int oldLeft, int oldTop, int oldRight, + int oldBottom) { + int width = right - left; + int height = bottom - top; + + if (mMaxPreviewWidth == 0 && mMaxPreviewHeight == 0) { + mMaxPreviewWidth = width; + mMaxPreviewHeight = height; + } + + int orientation = mActivity.getResources().getConfiguration().orientation; + if ((orientation == Configuration.ORIENTATION_PORTRAIT && width > height) + || (orientation == Configuration.ORIENTATION_LANDSCAPE && width < height)) { + // The screen has rotated; swap SurfaceView width & height + // to ensure correct preview + int oldWidth = width; + width = height; + height = oldWidth; + Log.d(TAG, "Swapping SurfaceView width & height dimensions"); + if (mMaxPreviewWidth != 0 && mMaxPreviewHeight != 0) { + int temp = mMaxPreviewWidth; + mMaxPreviewWidth = mMaxPreviewHeight; + mMaxPreviewHeight = temp; + } + } + if (mOrientationResize != mPrevOrientationResize + || mAspectRatioResize) { + layoutPreview(mAspectRatio); + mAspectRatioResize = false; + } + } + }); + mRenderOverlay = (RenderOverlay) mRootView.findViewById(R.id.render_overlay); mFlashOverlay = mRootView.findViewById(R.id.flash_overlay); mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button); @@ -370,7 +371,7 @@ public class PhotoUI implements PieListener, break; } } else { - float width = mOriginalPreviewWidth, height = mOriginalPreviewHeight; + float width = mMaxPreviewWidth, height = mMaxPreviewHeight; if (width == 0 || height == 0) return; if (mOrientationResize) { @@ -383,18 +384,27 @@ public class PhotoUI implements PieListener, } } else { if (width > height) { - scaledTextureWidth = Math.max(width, height * mAspectRatio); - scaledTextureHeight = Math.max(height, width / mAspectRatio); + if(Math.max(width, height * mAspectRatio) > width) { + scaledTextureWidth = width; + scaledTextureHeight = width / mAspectRatio; + } else { + scaledTextureWidth = height * mAspectRatio; + scaledTextureHeight = height; + } } else { - scaledTextureWidth = Math.max(width, height / mAspectRatio); - scaledTextureHeight = Math.max(height, width * mAspectRatio); + if(Math.max(height, width * mAspectRatio) > height) { + scaledTextureWidth = height / mAspectRatio; + scaledTextureHeight = height; + } else { + scaledTextureWidth = width; + scaledTextureHeight = width * mAspectRatio; + } } } Log.v(TAG, "setTransformMatrix: scaledTextureWidth = " + scaledTextureWidth + ", scaledTextureHeight = " + scaledTextureHeight); - int orientation = mActivity.getResources().getConfiguration().orientation; if (((rotation == 0 || rotation == 180) && scaledTextureWidth > scaledTextureHeight) || ((rotation == 90 || rotation == 270) && scaledTextureWidth < scaledTextureHeight)) { @@ -423,21 +433,15 @@ public class PhotoUI implements PieListener, if (mFaceView != null) { mFaceView.setLayoutParams(lp); } + + mController.onScreenSizeChanged((int) mSurfaceTextureUncroppedWidth, + (int) mSurfaceTextureUncroppedHeight); } public void setSurfaceTextureSizeChangedListener(SurfaceTextureSizeChangedListener listener) { mSurfaceTextureSizeListener = listener; } - private void setTransformMatrix(int width, int height) { - mMatrix = mSurfaceView.getMatrix(); - - // Calculate the new preview rectangle. - RectF previewRect = new RectF(0, 0, width, height); - mMatrix.mapRect(previewRect); - mController.onPreviewRectChanged(CameraUtil.rectFToRect(previewRect)); - } - // SurfaceHolder callbacks @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { @@ -449,10 +453,6 @@ public class PhotoUI implements PieListener, Log.v(TAG, "surfaceCreated"); mSurfaceHolder = holder; mController.onPreviewUIReady(); - if (mPreviewWidth != 0 && mPreviewHeight != 0) { - // Re-apply transform matrix for new surface texture - setTransformMatrix(mPreviewWidth, mPreviewHeight); - } mActivity.updateThumbnail(mThumbnail); } @@ -667,6 +667,12 @@ public class PhotoUI implements PieListener, mLocationDialog = null; } }) + .setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + mActivity.setSystemBarsVisibility(false); + } + }) .show(); } diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java index 8fbae5ee6..a2475354d 100644 --- a/src/com/android/camera/VideoUI.java +++ b/src/com/android/camera/VideoUI.java @@ -18,26 +18,23 @@ package com.android.camera; import java.util.List; +import org.codeaurora.snapcam.R; + import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Color; -import android.graphics.Matrix; import android.graphics.Point; import android.graphics.drawable.ColorDrawable; import android.hardware.Camera.Parameters; -import android.os.Handler; -import android.os.Message; import android.util.Log; import android.view.Gravity; +import android.view.MotionEvent; import android.view.SurfaceHolder; -import android.view.SurfaceHolder.Callback; import android.view.SurfaceView; -import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLayoutChangeListener; import android.view.ViewGroup; -import android.view.ViewPropertyAnimator; import android.widget.FrameLayout; import android.widget.FrameLayout.LayoutParams; import android.widget.ImageView; @@ -58,7 +55,6 @@ import com.android.camera.ui.RotateLayout; import com.android.camera.ui.RotateTextToast; import com.android.camera.ui.ZoomRenderer; import com.android.camera.util.CameraUtil; -import org.codeaurora.snapcam.R; public class VideoUI implements PieRenderer.PieListener, PreviewGestures.SingleTapListener, @@ -66,7 +62,6 @@ public class VideoUI implements PieRenderer.PieListener, SurfaceHolder.Callback, PauseButton.OnPauseButtonListener { private static final String TAG = "CAM_VideoUI"; - private static final int UPDATE_TRANSFORM_MATRIX = 1; // module fields private CameraActivity mActivity; private View mRootView; @@ -108,13 +103,10 @@ public class VideoUI implements PieRenderer.PieListener, private View mPreviewCover; private SurfaceView mSurfaceView = null; - private int mPreviewWidth = 0; - private int mPreviewHeight = 0; - private int mOriginalPreviewWidth = 0; - private int mOriginalPreviewHeight = 0; + private int mMaxPreviewWidth = 0; + private int mMaxPreviewHeight = 0; private float mAspectRatio = 4f / 3f; private boolean mAspectRatioResize; - private Matrix mMatrix = null; private final AnimationManager mAnimationManager; private boolean mUIhidden = false; private int mPreviewOrientation = -1; @@ -124,43 +116,13 @@ public class VideoUI implements PieRenderer.PieListener, private int mTopMargin = 0; private int mBottomMargin = 0; - // temporary variables for updating SurfaceView - private int mTempWidth; - private int mTempHeight; - 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) { - int width = right - left; - int height = bottom - top; - - int orientation = mActivity.getResources().getConfiguration().orientation; - if ((orientation == Configuration.ORIENTATION_PORTRAIT && width > height) - || (orientation == Configuration.ORIENTATION_LANDSCAPE && width < height)) { - // The screen has rotated; swap SurfaceView width & height - // to ensure correct preview - int oldWidth = width; - width = height; - height = oldWidth; - Log.d(TAG, "Swapping SurfaceView width & height dimensions"); - if (mOriginalPreviewWidth != 0 && mOriginalPreviewHeight != 0) { - int temp = mOriginalPreviewWidth; - mOriginalPreviewWidth = mOriginalPreviewHeight; - mOriginalPreviewHeight = temp; - } + if(mVideoMenu != null) { + mVideoMenu.tryToCloseSubList(); } - if (mPreviewWidth != width || mPreviewHeight != height - || (mOrientationResize != mPrevOrientationResize) - || mAspectRatioResize) { - if (mOriginalPreviewWidth == 0) mOriginalPreviewWidth = width; - if (mOriginalPreviewHeight == 0) mOriginalPreviewHeight = height; - mPreviewWidth = width; - mPreviewHeight = height; - setTransformMatrix(mPreviewWidth, mPreviewHeight); - mAspectRatioResize = false; - } - mVideoMenu.tryToCloseSubList(); } }; @@ -206,12 +168,49 @@ public class VideoUI implements PieRenderer.PieListener, mPreviewCover = mRootView.findViewById(R.id.preview_cover); // display the view mSurfaceView = (SurfaceView) mRootView.findViewById(R.id.mdp_preview_content); - mSurfaceView.setVisibility(View.VISIBLE); - 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)"); + mSurfaceView.setVisibility(View.VISIBLE); + 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 + public void onLayoutChange(View v, int left, int top, int right, + int bottom, int oldLeft, int oldTop, int oldRight, + int oldBottom) { + int width = right - left; + int height = bottom - top; + + if (mMaxPreviewWidth == 0 && mMaxPreviewHeight == 0) { + mMaxPreviewWidth = width; + mMaxPreviewHeight = height; + } + + int orientation = mActivity.getResources().getConfiguration().orientation; + if ((orientation == Configuration.ORIENTATION_PORTRAIT && width > height) + || (orientation == Configuration.ORIENTATION_LANDSCAPE && width < height)) { + // The screen has rotated; swap SurfaceView width & height + // to ensure correct preview + int oldWidth = width; + width = height; + height = oldWidth; + Log.d(TAG, "Swapping SurfaceView width & height dimensions"); + if (mMaxPreviewWidth != 0 && mMaxPreviewHeight != 0) { + int temp = mMaxPreviewWidth; + mMaxPreviewWidth = mMaxPreviewHeight; + mMaxPreviewHeight = temp; + } + } + if (mOrientationResize != mPrevOrientationResize + || mAspectRatioResize) { + layoutPreview(mAspectRatio); + mAspectRatioResize = false; + } + } + }); mFlashOverlay = mRootView.findViewById(R.id.flash_overlay); mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button); @@ -245,9 +244,6 @@ public class VideoUI implements PieRenderer.PieListener, mBottomMargin = l / 4 - mTopMargin; } mCameraControls.setMargins(mTopMargin, mBottomMargin); - - mOriginalPreviewWidth = size.x; - mOriginalPreviewHeight = size.y; } public void cameraOrientationPreviewResize(boolean orientation){ @@ -335,16 +331,8 @@ public class VideoUI implements PieRenderer.PieListener, layoutPreview((float)ratio); } - public int getPreviewWidth() { - return mPreviewWidth; - } - - public int getPreviewHeight() { - return mPreviewHeight; - } - private void layoutPreview(float ratio) { - FrameLayout.LayoutParams lp; + FrameLayout.LayoutParams lp = null; float scaledTextureWidth, scaledTextureHeight; int rotation = CameraUtil.getDisplayRotation(mActivity); @@ -378,8 +366,8 @@ public class VideoUI implements PieRenderer.PieListener, scaledTextureHeight = l * 3 / 4; break; } - } else { - float width = mOriginalPreviewWidth, height = mOriginalPreviewHeight; + } else if (mMaxPreviewWidth != 0 && mMaxPreviewHeight != 0) { + float width = mMaxPreviewWidth, height = mMaxPreviewHeight; if (mOrientationResize) { scaledTextureWidth = height * mAspectRatio; if (scaledTextureWidth > width) { @@ -390,18 +378,27 @@ public class VideoUI implements PieRenderer.PieListener, } } else { if (width > height) { - scaledTextureWidth = Math.max(width, height * mAspectRatio); - scaledTextureHeight = Math.max(height, width / mAspectRatio); + if(Math.max(width, height * mAspectRatio) > width) { + scaledTextureWidth = width; + scaledTextureHeight = width / mAspectRatio; + } else { + scaledTextureWidth = height * mAspectRatio; + scaledTextureHeight = height; + } } else { - scaledTextureWidth = Math.max(width, height / mAspectRatio); - scaledTextureHeight = Math.max(height, width * mAspectRatio); + if(Math.max(height, width * mAspectRatio) > height) { + scaledTextureWidth = height / mAspectRatio; + scaledTextureHeight = height; + } else { + scaledTextureWidth = width; + scaledTextureHeight = width * mAspectRatio; + } } } Log.v(TAG, "setTransformMatrix: scaledTextureWidth = " + scaledTextureWidth + ", scaledTextureHeight = " + scaledTextureHeight); - int orientation = mActivity.getResources().getConfiguration().orientation; if (((rotation == 0 || rotation == 180) && scaledTextureWidth > scaledTextureHeight) || ((rotation == 90 || rotation == 270) && scaledTextureWidth < scaledTextureHeight)) { @@ -412,20 +409,11 @@ public class VideoUI implements PieRenderer.PieListener, (int) scaledTextureHeight, Gravity.CENTER); } } - mSurfaceView.setLayoutParams(lp); - } - private void setTransformMatrix(int width, int height) { - if (width == 0 || height == 0) return; - mMatrix = mSurfaceView.getMatrix(); - - mTempWidth = (int) width; - mTempHeight = (int) height; - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mSurfaceView - .getLayoutParams(); - params.width = mTempWidth; - params.height = mTempHeight; - mSurfaceView.setLayoutParams(params); + if(lp != null) { + mSurfaceView.setLayoutParams(lp); + mSurfaceView.requestLayout(); + } } /** @@ -563,14 +551,10 @@ public class VideoUI implements PieRenderer.PieListener, public void hideSurfaceView() { mSurfaceView.setVisibility(View.GONE); - - setTransformMatrix(mPreviewWidth, mPreviewHeight); } public void showSurfaceView() { mSurfaceView.setVisibility(View.VISIBLE); - - setTransformMatrix(mPreviewWidth, mPreviewHeight); } private void initializeOverlay() { @@ -665,12 +649,6 @@ public class VideoUI implements PieRenderer.PieListener, mIsTimeLapse = enable; } - private void openMenu() { - if (mPieRenderer != null) { - mPieRenderer.showInCenter(); - } - } - public void dismissPopup(boolean topLevelOnly) { // In review mode, we do not want to bring up the camera UI if (mController.isInReviewMode()) return; @@ -1059,10 +1037,6 @@ public class VideoUI implements PieRenderer.PieListener, Log.v(TAG, "surfaceCreated"); mSurfaceHolder = holder; mController.onPreviewUIReady(); - if (mPreviewWidth != 0 && mPreviewHeight != 0) { - // Re-apply transform matrix for new surface texture - setTransformMatrix(mPreviewWidth, mPreviewHeight); - } mActivity.updateThumbnail(mThumbnail); } -- cgit v1.2.3