summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/values-sw600dp/booleans.xml18
-rw-r--r--res/values/bool.xml1
-rw-r--r--src/com/android/camera/ui/RotatableLayout.java86
3 files changed, 61 insertions, 44 deletions
diff --git a/res/values-sw600dp/booleans.xml b/res/values-sw600dp/booleans.xml
new file mode 100644
index 000000000..c7522cfa9
--- /dev/null
+++ b/res/values-sw600dp/booleans.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <bool name="is_tablet">true</bool>
+</resources> \ No newline at end of file
diff --git a/res/values/bool.xml b/res/values/bool.xml
index 464842ab4..067e3d9a9 100644
--- a/res/values/bool.xml
+++ b/res/values/bool.xml
@@ -15,4 +15,5 @@
-->
<resources>
<bool name="show_action_bar_title">false</bool>
+ <bool name="is_tablet">false</bool>
</resources> \ No newline at end of file
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) {