summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2013-10-11 19:01:30 -0700
committerDoris Liu <tianliu@google.com>2013-10-11 20:10:46 -0700
commit86ad8435b60a91fc97abf9d188b1e1af457e4885 (patch)
tree04f157c7a07f256c5e1ac0fd23a5037014b50f17 /src
parent87d093d6145524b1c8f5c052dfe40c18b52e5235 (diff)
downloadandroid_packages_apps_Snap-86ad8435b60a91fc97abf9d188b1e1af457e4885.tar.gz
android_packages_apps_Snap-86ad8435b60a91fc97abf9d188b1e1af457e4885.tar.bz2
android_packages_apps_Snap-86ad8435b60a91fc97abf9d188b1e1af457e4885.zip
Correct initial orientation of camera controls
Bug: 8878379 Change-Id: I3ecf190b19e91ae963e67ae2930b7388c4f92c70
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/ui/RotatableLayout.java86
1 files changed, 42 insertions, 44 deletions
diff --git a/src/com/android/camera/ui/RotatableLayout.java b/src/com/android/camera/ui/RotatableLayout.java
index ef3061a64..0997d26ad 100644
--- a/src/com/android/camera/ui/RotatableLayout.java
+++ b/src/com/android/camera/ui/RotatableLayout.java
@@ -26,6 +26,7 @@ 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
@@ -42,20 +43,26 @@ 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;
public RotatableLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- mInitialOrientation = getResources().getConfiguration().orientation;
+ init();
}
public RotatableLayout(Context context, AttributeSet attrs) {
super(context, attrs);
- mInitialOrientation = getResources().getConfiguration().orientation;
+ init();
}
public RotatableLayout(Context context) {
super(context);
+ init();
+ }
+
+ private void init() {
mInitialOrientation = getResources().getConfiguration().orientation;
+ mIsTablet = getResources().getBoolean(R.bool.is_tablet);
}
@Override
@@ -65,38 +72,46 @@ 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) {
- mPrevRotation = CameraUtil.getDisplayRotation((Activity) getContext());
- // check if there is any rotation before the view is attached to window
- int currentOrientation = getResources().getConfiguration().orientation;
- int orientation = getUnifiedRotation();
- if (mInitialOrientation == currentOrientation && orientation < 180) {
- return;
+ if (mIsTablet) {
+ // Natural orientation for tablet is landscape
+ mPrevRotation = mInitialOrientation == Configuration.ORIENTATION_LANDSCAPE ?
+ 0 : 90;
+ } else {
+ mPrevRotation = mInitialOrientation == Configuration.ORIENTATION_PORTRAIT ?
+ 0 : 90;
}
- if (mInitialOrientation == Configuration.ORIENTATION_LANDSCAPE
- && currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
- rotateLayout(true);
- } else if (mInitialOrientation == Configuration.ORIENTATION_PORTRAIT
- && 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();
- }
+ // check if there is any rotation before the view is attached to window
+ rotateIfNeeded();
+ }
+ }
+
+ private void rotateIfNeeded() {
+ if (mPrevRotation == UNKOWN_ORIENTATION) {
+ return;
+ }
+ int rotation = CameraUtil.getDisplayRotation((Activity) getContext());
+ 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);
+ mPrevRotation = rotation;
+ rotateLayout(clockwise);
}
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 = CameraUtil.getDisplayRotation((Activity) getContext());
- int camOrientation = (rotation % 180 == 0) ? Configuration.ORIENTATION_PORTRAIT
- : Configuration.ORIENTATION_LANDSCAPE;
- if (camOrientation != orientation) {
+ if (mIsTablet) {
return (rotation + 90) % 360;
}
return rotation;
@@ -107,7 +122,7 @@ public class RotatableLayout extends FrameLayout {
if ((currentRotation - mPrevRotation + 360) % 360 == 180) {
mPrevRotation = currentRotation;
flipChildren();
- getParent().requestLayout();
+ requestLayout();
}
}
@@ -122,24 +137,7 @@ public class RotatableLayout extends FrameLayout {
@Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
- if (mPrevRotation == UNKOWN_ORIENTATION) {
- return;
- }
- int rotation = CameraUtil.getDisplayRotation((Activity) getContext());
- 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);
- mPrevRotation = rotation;
- rotateLayout(clockwise);
+ rotateIfNeeded();
}
protected void rotateLayout(boolean clockwise) {