From 2233950e703e2532b01f9f2893d9f7d8f5845cb1 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Thu, 14 Jan 2016 11:36:38 +0100 Subject: CameraActivity: Don't hide navigation bar * Make it transparent instead. Change-Id: I08b06ac72d88aaf62ae7f52a3dde9ba865bc3542 --- src/com/android/camera/ui/CameraControls.java | 24 ++++-- src/com/android/camera/ui/CameraRootView.java | 108 +++----------------------- src/com/android/camera/ui/RenderOverlay.java | 26 ++++++- 3 files changed, 53 insertions(+), 105 deletions(-) (limited to 'src/com/android/camera/ui') diff --git a/src/com/android/camera/ui/CameraControls.java b/src/com/android/camera/ui/CameraControls.java index b6e31ada2..15836353e 100644 --- a/src/com/android/camera/ui/CameraControls.java +++ b/src/com/android/camera/ui/CameraControls.java @@ -23,9 +23,8 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.drawable.AnimationDrawable; import android.graphics.Paint; -import android.graphics.Rect; -import android.graphics.Paint; import android.graphics.Path; +import android.graphics.Rect; import android.util.AttributeSet; import android.util.Log; import android.view.Gravity; @@ -82,6 +81,7 @@ public class CameraControls extends RotatableLayout { private LinearLayout mRemainingPhotos; private TextView mRemainingPhotosText; private int mOrientation; + private final Rect mInsets = new Rect(); private int mPreviewRatio; private static int mTopMargin = 0; @@ -239,6 +239,12 @@ public class CameraControls extends RotatableLayout { mRemainingPhotosText = (TextView) findViewById(R.id.remaining_photos_text); } + @Override + protected boolean fitSystemWindows(Rect insets) { + mInsets.set(insets); + return false; + } + @Override public void onLayout(boolean changed, int l, int t, int r, int b) { int orientation = getResources().getConfiguration().orientation; @@ -247,18 +253,24 @@ public class CameraControls extends RotatableLayout { adjustBackground(); // As l,t,r,b are positions relative to parents, we need to convert them // to child's coordinates - r = r - l; - b = b - t; + r = r - l - mInsets.right; + b = b - t - mInsets.bottom; l = 0; t = 0; for (int i = 0; i < getChildCount(); i++) { View v = getChildAt(i); - v.layout(l, t, r, b); + if (v == mBackgroundView) { + v.layout(l, t, r + mInsets.right, b + mInsets.bottom); + } else { + v.layout(l, t, r, b); + } } + Rect shutter = new Rect(); center(mShutter, l, t, r, b, orientation, rotation, shutter, SHUTTER_INDEX); mSize = (int) (Math.max(shutter.right - shutter.left, shutter.bottom - shutter.top) * 1.2f); - center(mBackgroundView, l, t, r, b, orientation, rotation, new Rect(), -1); + center(mBackgroundView, l, t, r + mInsets.right, b + mInsets.bottom, + orientation, rotation, new Rect(), -1); mBackgroundView.setVisibility(View.GONE); setLocation(r - l, b - t); diff --git a/src/com/android/camera/ui/CameraRootView.java b/src/com/android/camera/ui/CameraRootView.java index 42eebaa98..cd30e8e4f 100644 --- a/src/com/android/camera/ui/CameraRootView.java +++ b/src/com/android/camera/ui/CameraRootView.java @@ -17,9 +17,7 @@ package com.android.camera.ui; import android.annotation.SuppressLint; -import android.app.Activity; import android.content.Context; -import android.content.res.Configuration; import android.graphics.Rect; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager.DisplayListener; @@ -28,7 +26,6 @@ import android.view.View; import android.widget.FrameLayout; import com.android.camera.util.ApiHelper; -import com.android.camera.util.CameraUtil; @SuppressLint("NewApi") public class CameraRootView extends FrameLayout { @@ -37,10 +34,9 @@ public class CameraRootView extends FrameLayout { private int mBottomMargin = 0; private int mLeftMargin = 0; private int mRightMargin = 0; - private final Rect mCurrentInsets = new Rect(0, 0, 0, 0); - private int mOffset = 0; private Object mDisplayListener; private MyDisplayListener mListener; + private Rect mLastInsets = new Rect(); public interface MyDisplayListener { public void onDisplayChanged(); @@ -51,26 +47,18 @@ public class CameraRootView extends FrameLayout { initDisplayListener(); } - @Override - protected boolean fitSystemWindows(Rect insets) { - // insets include status bar, navigation bar, etc - // In this case, we are only concerned with the size of nav bar - if (mCurrentInsets.equals(insets)) { - // Local copy of the insets is up to date. No need to do anything. - return false; + public void redoFitSystemWindows() { + if (mLastInsets.left != 0 || mLastInsets.right != 0 + || mLastInsets.top != 0 || mLastInsets.bottom != 0) { + Rect insets = new Rect(mLastInsets); + fitSystemWindows(insets); } + } - if (mOffset == 0) { - if (insets.bottom > 0) { - mOffset = insets.bottom; - } else if (insets.right > 0) { - mOffset = insets.right; - } - } - mCurrentInsets.set(insets); - // Make sure onMeasure will be called to adapt to the new insets. - requestLayout(); - return false; + @Override + protected boolean fitSystemWindows(Rect insets) { + mLastInsets.set(insets); + return super.fitSystemWindows(insets); } public void initDisplayListener() { @@ -118,78 +106,4 @@ public class CameraRootView extends FrameLayout { .unregisterDisplayListener((DisplayListener) mDisplayListener); } } -/* - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int rotation = CameraUtil.getDisplayRotation((Activity) getContext()); - // all the layout code assumes camera device orientation to be portrait - // adjust rotation for landscape - int orientation = getResources().getConfiguration().orientation; - int camOrientation = (rotation % 180 == 0) ? Configuration.ORIENTATION_PORTRAIT - : Configuration.ORIENTATION_LANDSCAPE; - if (camOrientation != orientation) { - rotation = (rotation + 90) % 360; - } - // calculate margins - mLeftMargin = 0; - mRightMargin = 0; - mBottomMargin = 0; - mTopMargin = 0; - switch (rotation) { - case 0: - mBottomMargin += mOffset; - break; - case 90: - mRightMargin += mOffset; - break; - case 180: - mTopMargin += mOffset; - break; - case 270: - mLeftMargin += mOffset; - break; - } - if (mCurrentInsets != null) { - if (mCurrentInsets.right > 0) { - // navigation bar on the right - mRightMargin = mRightMargin > 0 ? mRightMargin : mCurrentInsets.right; - } else { - // navigation bar on the bottom - mBottomMargin = mBottomMargin > 0 ? mBottomMargin : mCurrentInsets.bottom; - } - } - // make sure all the children are resized - super.onMeasure(widthMeasureSpec - mLeftMargin - mRightMargin, - heightMeasureSpec - mTopMargin - mBottomMargin); - setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); - } - - @Override - public void onLayout(boolean changed, int l, int t, int r, int b) { - r -= l; - b -= t; - l = 0; - t = 0; - int orientation = getResources().getConfiguration().orientation; - // Lay out children - for (int i = 0; i < getChildCount(); i++) { - View v = getChildAt(i); - if (v instanceof CameraControls) { - // Lay out camera controls to center on the short side of the screen - // so that they stay in place during rotation - int width = v.getMeasuredWidth(); - int height = v.getMeasuredHeight(); - if (orientation == Configuration.ORIENTATION_PORTRAIT) { - int left = (l + r - width) / 2; - v.layout(left, t + mTopMargin, left + width, b - mBottomMargin); - } else { - int top = (t + b - height) / 2; - v.layout(l + mLeftMargin, top, r - mRightMargin, top + height); - } - } else { - v.layout(l + mLeftMargin, t + mTopMargin, r - mRightMargin, b - mBottomMargin); - } - } - } -*/ } diff --git a/src/com/android/camera/ui/RenderOverlay.java b/src/com/android/camera/ui/RenderOverlay.java index d82ce18b6..75e616441 100644 --- a/src/com/android/camera/ui/RenderOverlay.java +++ b/src/com/android/camera/ui/RenderOverlay.java @@ -18,6 +18,7 @@ package com.android.camera.ui; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Rect; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; @@ -48,6 +49,7 @@ public class RenderOverlay extends FrameLayout { // reverse list of touch clients private List mTouchClients; private int[] mPosition = new int[2]; + private final Rect mInsets = new Rect(); public RenderOverlay(Context context, AttributeSet attrs) { super(context, attrs); @@ -69,13 +71,15 @@ public class RenderOverlay extends FrameLayout { if (renderer.handlesTouch()) { mTouchClients.add(0, renderer); } - renderer.layout(getLeft(), getTop(), getRight(), getBottom()); + renderer.layout(mRenderView.getLeft(), mRenderView.getTop(), + mRenderView.getRight(), mRenderView.getBottom()); } public void addRenderer(int pos, Renderer renderer) { mClients.add(pos, renderer); renderer.setOverlay(this); - renderer.layout(getLeft(), getTop(), getRight(), getBottom()); + renderer.layout(mRenderView.getLeft(), mRenderView.getTop(), + mRenderView.getRight(), mRenderView.getBottom()); } public void remove(Renderer renderer) { @@ -87,6 +91,24 @@ public class RenderOverlay extends FrameLayout { return mClients.size(); } + @Override + protected boolean fitSystemWindows(Rect insets) { + if (!mInsets.equals(insets)) { + mInsets.set(insets); + // Make sure onMeasure will be called to adapt to the new insets. + requestLayout(); + } + return false; + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + // make sure all the children are resized - insets include status bar, + // navigation bar, etc, but in this case, we are only concerned with the size of nav bar + super.onMeasure(widthMeasureSpec - mInsets.right, heightMeasureSpec - mInsets.bottom); + setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); + } + @Override public boolean dispatchTouchEvent(MotionEvent m) { if (mGestures != null) { -- cgit v1.2.3