package com.android.camera;
+import android.content.res.Resources;
import android.graphics.Color;
import android.os.SystemClock;
+import android.util.Log;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
+import com.android.gallery3d.R;
import com.android.gallery3d.glrenderer.GLCanvas;
import com.android.gallery3d.glrenderer.RawTexture;
private final Interpolator mSlideInterpolator = new DecelerateInterpolator();
- private int mAnimOrientation; // Could be 0, 90, 180 or 270 degrees.
+ private volatile int mAnimOrientation; // Could be 0, 90, 180 or 270 degrees.
private long mAnimStartTime; // milliseconds.
private float mX; // The center of the whole view including preview and review.
private float mY;
private int mHoldW;
private int mHoldH;
- private int mOffset = 80;
+ private int mOffset;
+
+ private int mMarginRight;
+ private int mMarginTop;
+ private int mSize;
+ private Resources mResources;
/* preview: camera preview view.
* review: view of picture just taken.
}
+ public void setResources(Resources res) {
+ mResources = res;
+ }
+
public void setOrientation(int displayRotation) {
mAnimOrientation = (360 - displayRotation) % 360;
}
// x, y, w and h: the rectangle area where the animation takes place.
public void startAnimation(int x, int y, int w, int h) {
mAnimStartTime = SystemClock.uptimeMillis();
+ setAnimationGeometry(x, y, w, h);
+ }
+
+ private void setAnimationGeometry(int x, int y, int w, int h) {
+ mMarginRight = mResources.getDimensionPixelSize(R.dimen.capture_margin_right);
+ mMarginTop = mResources.getDimensionPixelSize(R.dimen.capture_margin_top);
+ mSize = mResources.getDimensionPixelSize(R.dimen.capture_size);
+ mOffset = mMarginRight + mSize;
// Set the views to the initial positions.
mDrawWidth = w;
mDrawHeight = h;
mX = x;
mY = y;
- mHoldW = (int) (mDrawWidth * 0.7f);
- mHoldH = (int) (mDrawHeight * 0.7f);
+ mHoldW = mSize;
+ mHoldH = mSize;
switch (mAnimOrientation) {
case 0: // Preview is on the left.
- mHoldX = x + w - mOffset;
- mHoldY = y + (mDrawHeight - mHoldH) / 2;
+ mHoldX = x + w - mMarginRight - mSize;
+ mHoldY = y + mMarginTop;
break;
case 90: // Preview is below.
- mHoldX = x + (mDrawWidth - mHoldW + 1) / 2;
- mHoldY = y + mOffset- mHoldH;
+ mHoldX = x + mMarginTop;
+ mHoldY = y + mMarginRight + mSize;
break;
case 180: // Preview on the right.
- mHoldX = x - w + mOffset;
- mHoldY = y + (mDrawHeight - mHoldH) / 2;
+ mHoldX = x + mMarginRight;
+ mHoldY = y + h - mMarginTop - mSize;
break;
case 270: // Preview is above.
- mHoldX = x + (mDrawWidth - mHoldW + 1) / 2;
- mHoldY = y + h - mOffset;
+ mHoldX = x + w - mMarginTop - mSize;
+ mHoldY = y + h - mMarginRight - mSize;
break;
}
}
// Returns true if the animation has been drawn.
public boolean drawAnimation(GLCanvas canvas, CameraScreenNail preview,
- RawTexture review) {
+ RawTexture review, int lx, int ly, int lw, int lh) {
+ setAnimationGeometry(lx, ly, lw, lh);
long timeDiff = SystemClock.uptimeMillis() - mAnimStartTime;
// Check if the animation is over
if (mAnimType == ANIM_SLIDE && timeDiff > TIME_SLIDE2 - TIME_HOLD) return false;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
+import android.graphics.Rect;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.Gravity;
import android.view.View;
-import android.widget.FrameLayout.LayoutParams;
+import android.widget.FrameLayout;
import com.android.camera.Util;
import com.android.gallery3d.R;
-public class CameraControls extends RotatableLayout
-{
+public class CameraControls extends RotatableLayout {
+
+ private static final String TAG = "CAM_Controls";
+
private View mBackgroundView;
+ private View mShutter;
+ private View mSwitcher;
+ private View mMenu;
+ private View mIndicators;
+
public CameraControls(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void onFinishInflate() {
super.onFinishInflate();
mBackgroundView = findViewById(R.id.blocker);
+ mSwitcher = findViewById(R.id.camera_switcher);
+ mShutter = findViewById(R.id.shutter_button);
+ mMenu = findViewById(R.id.menu);
+ mIndicators = findViewById(R.id.on_screen_indicators);
+ }
+
+ @Override
+ public void onLayout(boolean changed, int l, int t, int r, int b) {
+ int orientation = getResources().getConfiguration().orientation;
+ int rotation = Util.getDisplayRotation((Activity) getContext());
+ rotation = correctRotation(rotation, orientation);
+ super.onLayout(changed, l, t, r, b);
+ Rect shutter = new Rect();
+ center(mShutter, l, t, r, b, orientation, rotation, shutter);
+ center(mBackgroundView, l, t, r, b, orientation, rotation, new Rect());
+ toLeft(mSwitcher, l, t, r, b, orientation, rotation, shutter);
+ toRight(mMenu, l, t, r, b, orientation, rotation, shutter);
+ toRight(mIndicators, l, t, r, b, orientation, rotation, shutter);
+ }
+
+ private int correctRotation(int rotation, int orientation) {
+ // all the layout code assumes camera device orientation to be portrait
+ // adjust rotation for landscape
+ int camOrientation = (rotation % 180 == 0) ? Configuration.ORIENTATION_PORTRAIT
+ : Configuration.ORIENTATION_LANDSCAPE;
+ if (camOrientation != orientation) {
+ return (rotation + 90) % 360;
+ }
+ return rotation;
+ }
+ private void center(View v, int l, int t, int r, int b, int orientation, int rotation, Rect result) {
+ FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) v.getLayoutParams();
+ int tw = lp.leftMargin + v.getMeasuredWidth() + lp.rightMargin;
+ int th = lp.topMargin + v.getMeasuredHeight() + lp.bottomMargin;
+ switch (rotation) {
+ case 0:
+ // phone portrait; controls bottom
+ result.left = (r - l) / 2 - tw / 2 + lp.leftMargin;
+ result.right = (r - l) / 2 + tw / 2 - lp.rightMargin;
+ result.bottom = b - lp.bottomMargin;
+ result.top = b - th + lp.topMargin;
+ break;
+ case 90:
+ // phone landscape: controls right
+ result.right = r - lp.rightMargin;
+ result.left = r - tw + lp.leftMargin;
+ result.top = (b - t) / 2 - th / 2 + lp.topMargin;
+ result.bottom = (b - t) / 2 + th / 2 - lp.bottomMargin;
+ break;
+ case 180:
+ // phone upside down: controls top
+ result.left = (r - l) / 2 - tw / 2 + lp.leftMargin;
+ result.right = (r - l) / 2 + tw / 2 - lp.rightMargin;
+ result.top = t + lp.topMargin;
+ result.bottom = t + th - lp.bottomMargin;
+ break;
+ case 270:
+ // reverse landscape: controls left
+ result.left = l + lp.leftMargin;
+ result.right = l + tw - lp.rightMargin;
+ result.top = (b - t) / 2 - th / 2 + lp.topMargin;
+ result.bottom = (b - t) / 2 + th / 2 - lp.bottomMargin;
+ break;
+ }
+ v.layout(result.left, result.top, result.right, result.bottom);
+ }
+
+ private void toLeft(View v, int l, int t, int r, int b, int orientation, int rotation, Rect anchor) {
+ FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) v.getLayoutParams();
+ int tw = lp.leftMargin + v.getMeasuredWidth() + lp.rightMargin;
+ int th = lp.topMargin + v.getMeasuredHeight() + lp.bottomMargin;
+ Rect result = new Rect();
+ switch (rotation) {
+ case 0:
+ // portrait, to left of anchor at bottom
+ result.right = anchor.left - lp.rightMargin;
+ result.left = anchor.left - tw + lp.leftMargin;
+ result.bottom = b - lp.bottomMargin;
+ result.top = b - th + lp.topMargin;
+ break;
+ case 90:
+ // phone landscape: below anchor on right
+ result.right = r - lp.rightMargin;
+ result.left = r - tw + lp.leftMargin;
+ result.top = anchor.bottom + lp.topMargin;
+ result.bottom = anchor.bottom + th - lp.bottomMargin;
+ break;
+ case 180:
+ // phone upside down: right of anchor at top
+ result.left = anchor.right + lp.leftMargin;
+ result.right = anchor.right + tw - lp.rightMargin;
+ result.top = t + lp.topMargin;
+ result.bottom = t + th - lp.bottomMargin;
+ break;
+ case 270:
+ // reverse landscape: above anchor on left
+ result.left = l + lp.leftMargin;
+ result.right = l + tw - lp.rightMargin;
+ result.bottom = anchor.top - lp.bottomMargin;
+ result.top = anchor.top - th + lp.topMargin;
+ break;
+ }
+ v.layout(result.left, result.top, result.right, result.bottom);
+ }
+
+ private void toRight(View v, int l, int t, int r, int b, int orientation, int rotation, Rect anchor) {
+ FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) v.getLayoutParams();
+ int tw = lp.leftMargin + v.getMeasuredWidth() + lp.rightMargin;
+ int th = lp.topMargin + v.getMeasuredHeight() + lp.bottomMargin;
+ Rect result = new Rect();
+ switch (rotation) {
+ case 0:
+ // portrait, right of anchor at bottom
+ result.left = anchor.right + lp.leftMargin;
+ result.right = anchor.right + tw - lp.rightMargin;
+ result.bottom = b - lp.bottomMargin;
+ result.top = b - th + lp.topMargin;
+ break;
+ case 90:
+ // phone landscape: above anchor on right
+ result.right = r - lp.rightMargin;
+ result.left = result.right - tw + lp.leftMargin;
+ result.bottom = anchor.top - lp.bottomMargin;
+ result.top = anchor.top - th + lp.topMargin;
+ break;
+ case 180:
+ // phone upside down: left of anchor at top
+ result.right = anchor.left - lp.rightMargin;
+ result.left = anchor.left - tw + lp.leftMargin;
+ result.top = t + lp.topMargin;
+ result.bottom = t + th - lp.bottomMargin;
+ break;
+ case 270:
+ // reverse landscape: below anchor on left
+ result.left = l + lp.leftMargin;
+ result.right = l + tw - lp.rightMargin;
+ result.top = anchor.bottom + lp.topMargin;
+ result.bottom = anchor.bottom + th - lp.bottomMargin;
+ break;
+ }
+ v.layout(result.left, result.top, result.right, result.bottom);
}
// In reverse landscape and reverse portrait, camera controls will be laid out
}
mBackgroundView.setBackgroundResource(R.drawable.switcher_bg);
}
+
}