summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/PreviewFrameLayout.java
diff options
context:
space:
mode:
authorWu-cheng Li <wuchengli@google.com>2011-05-12 17:45:00 +0800
committerWu-cheng Li <wuchengli@google.com>2011-05-12 18:10:48 +0800
commit940b813c57c6c6eb66f55d968c9cb2b28e79b24b (patch)
treeb9922c7b87b77de8de98bd758e78becb08a9a298 /src/com/android/camera/PreviewFrameLayout.java
parentd4594cafc86f8400012146abd48534aa9d68d92d (diff)
downloadLegacyCamera-940b813c57c6c6eb66f55d968c9cb2b28e79b24b.zip
LegacyCamera-940b813c57c6c6eb66f55d968c9cb2b28e79b24b.tar.gz
LegacyCamera-940b813c57c6c6eb66f55d968c9cb2b28e79b24b.tar.bz2
Refactor preview frame layout.
Change-Id: Ief0acb3841078a36974e315054110bd9070a1f3f
Diffstat (limited to 'src/com/android/camera/PreviewFrameLayout.java')
-rw-r--r--src/com/android/camera/PreviewFrameLayout.java36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/com/android/camera/PreviewFrameLayout.java b/src/com/android/camera/PreviewFrameLayout.java
index 4583d5d..8fee82d 100644
--- a/src/com/android/camera/PreviewFrameLayout.java
+++ b/src/com/android/camera/PreviewFrameLayout.java
@@ -29,8 +29,6 @@ import android.widget.RelativeLayout;
* A layout which handles the preview aspect ratio.
*/
public class PreviewFrameLayout extends RelativeLayout {
- private static final int MIN_HORIZONTAL_MARGIN = 10; // 10dp
-
/** A callback to be invoked when the preview frame's size changes. */
public interface OnSizeChangedListener {
public void onSizeChanged();
@@ -56,18 +54,7 @@ public class PreviewFrameLayout extends RelativeLayout {
protected void onFinishInflate() {
super.onFinishInflate();
mFrame = (View) findViewById(R.id.frame);
- if (mFrame == null) {
- throw new IllegalStateException(
- "must provide child with id as \"frame\"");
- }
-
- View preview = (View) findViewById(R.id.camera_preview);
- ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)
- preview.getLayoutParams();
mBorderView = (View) findViewById(R.id.preview_border);
- View f = mBorderView;
- params.setMargins(f.getPaddingLeft(), f.getPaddingTop(), f.getPaddingRight(), f.getPaddingBottom());
- preview.setLayoutParams(params);
}
public void setAspectRatio(double ratio) {
@@ -81,31 +68,38 @@ public class PreviewFrameLayout extends RelativeLayout {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
+ // Calculate the width and the height of preview frame.
int frameWidth = getWidth();
int frameHeight = getHeight();
-
View f = mBorderView;
int horizontalPadding = f.getPaddingLeft() + f.getPaddingRight();
int verticalPadding = f.getPaddingBottom() + f.getPaddingTop();
int previewHeight = frameHeight - verticalPadding;
int previewWidth = frameWidth - horizontalPadding;
-
- // resize frame and preview for aspect ratio
if (previewWidth > previewHeight * mAspectRatio) {
previewWidth = (int) (previewHeight * mAspectRatio + .5);
} else {
previewHeight = (int) (previewWidth / mAspectRatio + .5);
}
+ // Measure and layout preview frame.
+ int hSpace = ((r - l) - previewWidth) / 2;
+ int vSpace = ((b - t) - previewHeight) / 2;
+ mFrame.measure(
+ MeasureSpec.makeMeasureSpec(previewWidth, MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(previewHeight, MeasureSpec.EXACTLY));
+ mFrame.layout(hSpace, vSpace, frameWidth + hSpace, frameHeight + vSpace);
+
+ // Measure and layout the border of preview frame.
frameWidth = previewWidth + horizontalPadding;
frameHeight = previewHeight + verticalPadding;
-
- int hSpace = ((r - l) - frameWidth) / 2;
- int vSpace = ((b - t) - frameHeight) / 2;
- mFrame.measure(
+ hSpace = ((r - l) - frameWidth) / 2;
+ vSpace = ((b - t) - frameHeight) / 2;
+ mBorderView.measure(
MeasureSpec.makeMeasureSpec(frameWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(frameHeight, MeasureSpec.EXACTLY));
- mFrame.layout(hSpace, vSpace, frameWidth + hSpace, frameHeight + vSpace);
+ mBorderView.layout(hSpace, vSpace, frameWidth + hSpace, frameHeight + vSpace);
+
if (mSizeListener != null) {
mSizeListener.onSizeChanged();
}