summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/ui/CameraRootView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/camera/ui/CameraRootView.java')
-rw-r--r--src/com/android/camera/ui/CameraRootView.java143
1 files changed, 46 insertions, 97 deletions
diff --git a/src/com/android/camera/ui/CameraRootView.java b/src/com/android/camera/ui/CameraRootView.java
index 42eebaa98..92ac21e34 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,10 @@ 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();
+ private Rect mTmpRect = new Rect();
public interface MyDisplayListener {
public void onDisplayChanged();
@@ -51,26 +48,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() {
@@ -101,6 +90,40 @@ public class CameraRootView extends FrameLayout {
mListener = listener;
}
+ public Rect getInsetsForOrientation(int orientation) {
+ switch (orientation) {
+ case 90:
+ mTmpRect.set(mLastInsets.top, mLastInsets.right,
+ mLastInsets.bottom, mLastInsets.left);
+ break;
+ case 180:
+ mTmpRect.set(mLastInsets.right, mLastInsets.bottom,
+ mLastInsets.left, mLastInsets.top);
+ break;
+ case 270:
+ mTmpRect.set(mLastInsets.bottom, mLastInsets.left,
+ mLastInsets.top, mLastInsets.right);
+ break;
+ default:
+ mTmpRect.set(mLastInsets);
+ break;
+ }
+
+ return mTmpRect;
+ }
+
+ public Rect getClientRectForOrientation(int orientation) {
+ Rect result = getInsetsForOrientation(orientation);
+ if (orientation == 90 || orientation == 270) {
+ result.right = getHeight() - result.right;
+ result.bottom = getWidth() - result.bottom;
+ } else {
+ result.right = getWidth() - result.right;
+ result.bottom = getHeight() - result.bottom;
+ }
+ return result;
+ }
+
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
@@ -118,78 +141,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);
- }
- }
- }
-*/
}