summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2013-05-06 18:30:30 -0700
committerDoris Liu <tianliu@google.com>2013-05-06 18:39:39 -0700
commitbcd73db9b9a5580167f1f54e78b798cbf9165940 (patch)
tree90db7ddbdd2cefafd51ad90dd3a1af0a157a4ea7 /src/com
parent93240535cafe2b1a7630f8350963a3d84cbb9937 (diff)
downloadandroid_packages_apps_Snap-bcd73db9b9a5580167f1f54e78b798cbf9165940.tar.gz
android_packages_apps_Snap-bcd73db9b9a5580167f1f54e78b798cbf9165940.tar.bz2
android_packages_apps_Snap-bcd73db9b9a5580167f1f54e78b798cbf9165940.zip
Resize children to avoid laying out outside parent
Bug: 8838983 Change-Id: Idc8ec7b96dd13e9c99dbc8b4710aa9d768ef198e
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/camera/ui/CameraRootView.java48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/com/android/camera/ui/CameraRootView.java b/src/com/android/camera/ui/CameraRootView.java
index e49ac59a6..76fea2cfa 100644
--- a/src/com/android/camera/ui/CameraRootView.java
+++ b/src/com/android/camera/ui/CameraRootView.java
@@ -60,7 +60,8 @@ public class CameraRootView extends RelativeLayout {
return true;
}
- public void onLayout(boolean changed, int l, int t, int r, int b) {
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int rotation = Util.getDisplayRotation((Activity) getContext());
// all the layout code assumes camera device orientation to be portrait
// adjust rotation for landscape
@@ -71,45 +72,60 @@ public class CameraRootView extends RelativeLayout {
rotation = (rotation + 90) % 360;
}
// calculate margins
- int left = 0;
- int right = 0;
- int bottom = 0;
- int top = 0;
+ mLeftMargin = 0;
+ mRightMargin = 0;
+ mBottomMargin = 0;
+ mTopMargin = 0;
switch (rotation) {
case 0:
- bottom += mOffset;
+ mBottomMargin += mOffset;
break;
case 90:
- right += mOffset;
+ mRightMargin += mOffset;
break;
case 180:
- top += mOffset;
+ mTopMargin += mOffset;
break;
case 270:
- left += mOffset;
+ mLeftMargin += mOffset;
break;
}
if (mCurrentInsets != null) {
if (mCurrentInsets.right > 0) {
// navigation bar on the right
- right = right > 0 ? right : mCurrentInsets.right;
+ mRightMargin = mRightMargin > 0 ? mRightMargin : mCurrentInsets.right;
} else {
// navigation bar on the bottom
- bottom = bottom > 0 ? bottom : mCurrentInsets.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) {
+ 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 fill the short side of the screen
+ // Lay out camera controls to center on the short side of the screen
// so that they stay in place during rotation
- if (rotation % 180 == 0) {
- v.layout(l, t + top, r, b - bottom);
+ 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 {
- v.layout(l + left, t, r - right, b);
+ int top = (t + b - height) / 2;
+ v.layout(l + mLeftMargin, top, r - mRightMargin, top + height);
}
} else {
- v.layout(l + left, t + top, r - right, b - bottom);
+ v.layout(l + mLeftMargin, t + mTopMargin, r - mRightMargin, b - mBottomMargin);
}
}
}