diff options
author | Likai Ding <likaid@codeaurora.org> | 2014-12-18 23:25:22 +0800 |
---|---|---|
committer | Likai Ding <likaid@codeaurora.org> | 2015-01-08 17:58:23 +0800 |
commit | 37c3c7cc832adbd8b78fa0a3e1f8d074111638d9 (patch) | |
tree | 3600024572e813303d01bdcec417ed271762cb76 /src/com/android/camera/ui/CameraControls.java | |
parent | cc56779da62644898eb319d4b296f69d6d820013 (diff) | |
download | android_packages_apps_Snap-37c3c7cc832adbd8b78fa0a3e1f8d074111638d9.tar.gz android_packages_apps_Snap-37c3c7cc832adbd8b78fa0a3e1f8d074111638d9.tar.bz2 android_packages_apps_Snap-37c3c7cc832adbd8b78fa0a3e1f8d074111638d9.zip |
SnapdragonCamera: support 4:3 preview on 16:9 screen
When preview is set to 4:3 on a 16:9 screen, resize SurfaceView to 4:3
and cover other parts of the screen. Otherwise camera controls have
a semi-transparent background.
Change-Id: Icfbe6318b6a9de9a988468078b474e842f6ddd8c
Diffstat (limited to 'src/com/android/camera/ui/CameraControls.java')
-rw-r--r-- | src/com/android/camera/ui/CameraControls.java | 74 |
1 files changed, 71 insertions, 3 deletions
diff --git a/src/com/android/camera/ui/CameraControls.java b/src/com/android/camera/ui/CameraControls.java index 181bd991e..c2c33e785 100644 --- a/src/com/android/camera/ui/CameraControls.java +++ b/src/com/android/camera/ui/CameraControls.java @@ -21,6 +21,8 @@ import android.animation.Animator.AnimatorListener; import android.content.Context; import android.util.Log; import android.graphics.drawable.AnimationDrawable; +import android.graphics.Canvas; +import android.graphics.Paint; import android.graphics.Rect; import android.util.AttributeSet; import android.view.View; @@ -32,6 +34,7 @@ import java.util.ArrayList; import org.codeaurora.snapcam.R; import com.android.camera.ui.ModuleSwitcher; import com.android.camera.ShutterButton; +import com.android.camera.util.CameraUtil; public class CameraControls extends RotatableLayout { @@ -69,6 +72,12 @@ public class CameraControls extends RotatableLayout { private TextView mRemainingPhotos; + private int mPreviewRatio; + private static int mTopMargin = 0; + private static int mBottomMargin = 0; + + private Paint mPaint; + AnimatorListener outlistener = new AnimatorListener() { @Override public void onAnimationStart(Animator animation) { @@ -143,12 +152,12 @@ public class CameraControls extends RotatableLayout { public CameraControls(Context context, AttributeSet attrs) { super(context, attrs); - setMeasureAllChildren(true); + mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + setWillNotDraw(false); } public CameraControls(Context context) { - super(context); - setMeasureAllChildren(true); + this(context, null); } public static boolean isAnimating() { @@ -246,6 +255,32 @@ public class CameraControls extends RotatableLayout { layoutRemaingPhotos(); } + @Override + protected void onDraw(Canvas canvas) { + if (mTopMargin != 0) { + int rotation = getUnifiedRotation(); + int w = canvas.getWidth(), h = canvas.getHeight(); + switch (rotation) { + case 90: + canvas.drawRect(0, 0, mTopMargin, h, mPaint); + canvas.drawRect(w - mBottomMargin, 0, w, h, mPaint); + break; + case 180: + canvas.drawRect(0, 0, w, mBottomMargin, mPaint); + canvas.drawRect(0, h - mTopMargin, w, h, mPaint); + break; + case 270: + canvas.drawRect(0, 0, mBottomMargin, h, mPaint); + canvas.drawRect(w - mTopMargin, 0, w, h, mPaint); + break; + default: + canvas.drawRect(0, 0, w, mTopMargin, mPaint); + canvas.drawRect(0, h - mBottomMargin, w, h, mPaint); + break; + } + } + } + private void setLocation(int w, int h) { int rotation = getUnifiedRotation(); toIndex(mSwitcher, w, h, rotation, 4, 6, SWITCHER_INDEX); @@ -544,6 +579,23 @@ public class CameraControls extends RotatableLayout { int cx = (2 * windex + 1) * boxw / 2; int cy = (2 * hindex + 1) * boxh / 2; + if (index2 == 0 && mTopMargin != 0) { + switch (rotation) { + case 90: + cx = mTopMargin / 2; + break; + case 180: + cy = h - mTopMargin / 2; + break; + case 270: + cx = w - mTopMargin / 2; + break; + default: + cy = mTopMargin / 2; + break; + } + } + l = cx - tw / 2; r = cx + tw / 2; t = cy - th / 2; @@ -697,4 +749,20 @@ public class CameraControls extends RotatableLayout { getResources().getString(R.string.remaining_photos_format), remaining)); } } + + public void setMargins(int top, int bottom) { + mTopMargin = top; + mBottomMargin = bottom; + } + + public void setPreviewRatio(float ratio) { + int r = CameraUtil.determineRatio(ratio); + mPreviewRatio = r; + if (mPreviewRatio == CameraUtil.RATIO_4_3 && mTopMargin != 0) { + mPaint.setColor(getResources().getColor(R.color.camera_control_bg_opaque)); + } else { + mPaint.setColor(getResources().getColor(R.color.camera_control_bg_transparent)); + } + invalidate(); + } } |