summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/ui/RotatableLayout.java
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2013-06-07 18:04:57 -0700
committerDoris Liu <tianliu@google.com>2013-06-13 10:42:27 -0700
commit44ab147ed213bf6a1aa6c62e08c20d7fca03503d (patch)
tree73ebb4d025896d3f4a60351960ba4607dc28ca97 /src/com/android/camera/ui/RotatableLayout.java
parentd483ca1f81704f7a1c6a310bd2ba289aef2ffb65 (diff)
downloadandroid_packages_apps_Snap-44ab147ed213bf6a1aa6c62e08c20d7fca03503d.tar.gz
android_packages_apps_Snap-44ab147ed213bf6a1aa6c62e08c20d7fca03503d.tar.bz2
android_packages_apps_Snap-44ab147ed213bf6a1aa6c62e08c20d7fca03503d.zip
Update camera orientation when device is flipped
Bug: 8963053 Change-Id: I909793a7da3903a080a19cd7e271b3720df4ec0a
Diffstat (limited to 'src/com/android/camera/ui/RotatableLayout.java')
-rw-r--r--src/com/android/camera/ui/RotatableLayout.java52
1 files changed, 48 insertions, 4 deletions
diff --git a/src/com/android/camera/ui/RotatableLayout.java b/src/com/android/camera/ui/RotatableLayout.java
index 8355c8826..965d62a90 100644
--- a/src/com/android/camera/ui/RotatableLayout.java
+++ b/src/com/android/camera/ui/RotatableLayout.java
@@ -65,9 +65,11 @@ public class RotatableLayout extends FrameLayout {
mPrevRotation = Util.getDisplayRotation((Activity) getContext());
// check if there is any rotation before the view is attached to window
int currentOrientation = getResources().getConfiguration().orientation;
- if (mInitialOrientation == currentOrientation) {
+ int orientation = getUnifiedRotation();
+ if (mInitialOrientation == currentOrientation && orientation < 180) {
return;
}
+
if (mInitialOrientation == Configuration.ORIENTATION_LANDSCAPE
&& currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
rotateLayout(true);
@@ -75,19 +77,62 @@ public class RotatableLayout extends FrameLayout {
&& currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
rotateLayout(false);
}
+ // In reverse landscape and reverse portrait, camera controls will be laid out
+ // on the wrong side of the screen. We need to make adjustment to move the controls
+ // to the USB side
+ if (orientation >= 180) {
+ flipChildren();
+ }
+ }
+
+ protected int getUnifiedRotation() {
+ // all the layout code assumes camera device orientation to be portrait
+ // adjust rotation for landscape
+ int orientation = getResources().getConfiguration().orientation;
+ int rotation = Util.getDisplayRotation((Activity) getContext());
+ int camOrientation = (rotation % 180 == 0) ? Configuration.ORIENTATION_PORTRAIT
+ : Configuration.ORIENTATION_LANDSCAPE;
+ if (camOrientation != orientation) {
+ return (rotation + 90) % 360;
+ }
+ return rotation;
+ }
+
+ public void checkLayoutFlip() {
+ int currentRotation = Util.getDisplayRotation((Activity) getContext());
+ if ((currentRotation - mPrevRotation + 360) % 360 == 180) {
+ mPrevRotation = currentRotation;
+ flipChildren();
+ getParent().requestLayout();
+ }
+ }
+
+ @Override
+ public void onWindowVisibilityChanged(int visibility) {
+ if (visibility == View.VISIBLE) {
+ // Make sure when coming back from onPause, the layout is rotated correctly
+ checkLayoutFlip();
+ }
}
@Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
int rotation = Util.getDisplayRotation((Activity) getContext());
- if ((rotation - mPrevRotation + 360) % 180 == 0) {
+ int diff = (rotation - mPrevRotation + 360) % 360;
+ if ( diff == 0) {
+ // No rotation
+ return;
+ } else if (diff == 180) {
+ // 180-degree rotation
mPrevRotation = rotation;
+ flipChildren();
return;
}
+ // 90 or 270-degree rotation
boolean clockwise = isClockWiseRotation(mPrevRotation, rotation);
- rotateLayout(clockwise);
mPrevRotation = rotation;
+ rotateLayout(clockwise);
}
protected void rotateLayout(boolean clockwise) {
@@ -113,7 +158,6 @@ public class RotatableLayout extends FrameLayout {
}
protected void flipChildren() {
- mPrevRotation = Util.getDisplayRotation((Activity) getContext());
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);