summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/ui/RotatableLayout.java
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2013-10-13 14:46:57 -0700
committerDoris Liu <tianliu@google.com>2013-10-13 14:55:16 -0700
commit3068c52499b43b679d2af8018d7f1ab0b1a7e863 (patch)
treefd5cc4f6f321dbaf16a10282c613357ca07c053a /src/com/android/camera/ui/RotatableLayout.java
parentf1582c9c075e9cd5790b4bbe1101c94a45ac15d2 (diff)
downloadandroid_packages_apps_Snap-3068c52499b43b679d2af8018d7f1ab0b1a7e863.tar.gz
android_packages_apps_Snap-3068c52499b43b679d2af8018d7f1ab0b1a7e863.tar.bz2
android_packages_apps_Snap-3068c52499b43b679d2af8018d7f1ab0b1a7e863.zip
Fix for mis-placed camera controls
Bug: 11205682 Change-Id: Ie74e906a059158db825977af898445b2b2ba5a48
Diffstat (limited to 'src/com/android/camera/ui/RotatableLayout.java')
-rw-r--r--src/com/android/camera/ui/RotatableLayout.java32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/com/android/camera/ui/RotatableLayout.java b/src/com/android/camera/ui/RotatableLayout.java
index 0997d26ad..04c36331d 100644
--- a/src/com/android/camera/ui/RotatableLayout.java
+++ b/src/com/android/camera/ui/RotatableLayout.java
@@ -19,14 +19,16 @@ package com.android.camera.ui;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
+import android.graphics.Point;
import android.util.AttributeSet;
+import android.view.Display;
import android.view.Gravity;
+import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.android.camera.util.CameraUtil;
-import com.android.camera2.R;
/* RotatableLayout rotates itself as well as all its children when orientation
* changes. Specifically, when going from portrait to landscape, camera
@@ -43,7 +45,7 @@ public class RotatableLayout extends FrameLayout {
// Initial orientation of the layout (ORIENTATION_PORTRAIT, or ORIENTATION_LANDSCAPE)
private int mInitialOrientation;
private int mPrevRotation = UNKOWN_ORIENTATION;
- private boolean mIsTablet = false;
+ private boolean mIsDefaultToPortrait = false;
public RotatableLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
@@ -62,7 +64,6 @@ public class RotatableLayout extends FrameLayout {
private void init() {
mInitialOrientation = getResources().getConfiguration().orientation;
- mIsTablet = getResources().getBoolean(R.bool.is_tablet);
}
@Override
@@ -72,12 +73,13 @@ public class RotatableLayout extends FrameLayout {
// we need to rotate the view if necessary. After that, onConfigurationChanged
// call will track all the subsequent device rotation.
if (mPrevRotation == UNKOWN_ORIENTATION) {
- if (mIsTablet) {
+ calculateDefaultOrientation();
+ if (mIsDefaultToPortrait) {
// Natural orientation for tablet is landscape
- mPrevRotation = mInitialOrientation == Configuration.ORIENTATION_LANDSCAPE ?
+ mPrevRotation = mInitialOrientation == Configuration.ORIENTATION_PORTRAIT ?
0 : 90;
} else {
- mPrevRotation = mInitialOrientation == Configuration.ORIENTATION_PORTRAIT ?
+ mPrevRotation = mInitialOrientation == Configuration.ORIENTATION_LANDSCAPE ?
0 : 90;
}
@@ -86,6 +88,22 @@ public class RotatableLayout extends FrameLayout {
}
}
+ private void calculateDefaultOrientation() {
+ Display currentDisplay = getDisplay();
+ Point displaySize = new Point();
+ currentDisplay.getSize(displaySize);
+ int orientation = currentDisplay.getRotation();
+ int naturalWidth, naturalHeight;
+ if (orientation == Surface.ROTATION_0 || orientation == Surface.ROTATION_180) {
+ naturalWidth = displaySize.x;
+ naturalHeight = displaySize.y;
+ } else {
+ naturalWidth = displaySize.y;
+ naturalHeight = displaySize.x;
+ }
+ mIsDefaultToPortrait = naturalWidth < naturalHeight;
+ }
+
private void rotateIfNeeded() {
if (mPrevRotation == UNKOWN_ORIENTATION) {
return;
@@ -111,7 +129,7 @@ public class RotatableLayout extends FrameLayout {
// all the layout code assumes camera device orientation to be portrait
// adjust rotation for landscape
int rotation = CameraUtil.getDisplayRotation((Activity) getContext());
- if (mIsTablet) {
+ if (!mIsDefaultToPortrait) {
return (rotation + 90) % 360;
}
return rotation;