summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/ui/RotatableLayout.java
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2013-04-20 11:30:35 -0700
committerDoris Liu <tianliu@google.com>2013-04-20 11:30:35 -0700
commitbec9cf0afe17d4fc26b4d8b6b5c7d95549bb35fe (patch)
tree77f2282cd4d0268fad6f21a7be5c6ac068db46a9 /src/com/android/camera/ui/RotatableLayout.java
parentd3f4b9350cfa2caf6fb175731b36626cf00e9dd9 (diff)
downloadandroid_packages_apps_Snap-bec9cf0afe17d4fc26b4d8b6b5c7d95549bb35fe.tar.gz
android_packages_apps_Snap-bec9cf0afe17d4fc26b4d8b6b5c7d95549bb35fe.tar.bz2
android_packages_apps_Snap-bec9cf0afe17d4fc26b4d8b6b5c7d95549bb35fe.zip
Fix camera buttons showing up at wrong position
Bug: 8607034 Change-Id: Ia796a9f5e56fd0566e2f4853ec48b9371e8134e2
Diffstat (limited to 'src/com/android/camera/ui/RotatableLayout.java')
-rw-r--r--src/com/android/camera/ui/RotatableLayout.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/com/android/camera/ui/RotatableLayout.java b/src/com/android/camera/ui/RotatableLayout.java
index 6836b39b2..bf8060528 100644
--- a/src/com/android/camera/ui/RotatableLayout.java
+++ b/src/com/android/camera/ui/RotatableLayout.java
@@ -38,6 +38,8 @@ import com.android.camera.Util;
public class RotatableLayout extends FrameLayout {
private static final String TAG = "RotatableLayout";
+ // Initial orientation of the layout (ORIENTATION_PORTRAIT, or ORIENTATION_LANDSCAPE)
+ private int mInitialOrientation;
private int mPrevRotation;
private RotationListener mListener = null;
public interface RotationListener {
@@ -45,19 +47,33 @@ public class RotatableLayout extends FrameLayout {
}
public RotatableLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
+ mInitialOrientation = getResources().getConfiguration().orientation;
}
public RotatableLayout(Context context, AttributeSet attrs) {
super(context, attrs);
+ mInitialOrientation = getResources().getConfiguration().orientation;
}
public RotatableLayout(Context context) {
super(context);
+ mInitialOrientation = getResources().getConfiguration().orientation;
}
@Override
- public void onFinishInflate() { // get initial orientation
- super.onFinishInflate();
+ public void onAttachedToWindow() {
+ // check if there is any rotation before the view is attached to window
+ int currentOrientation = getResources().getConfiguration().orientation;
+ if (mInitialOrientation == currentOrientation) {
+ return;
+ }
+ if (mInitialOrientation == Configuration.ORIENTATION_LANDSCAPE
+ && currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
+ rotateLayout(true);
+ } else if (mInitialOrientation == Configuration.ORIENTATION_PORTRAIT
+ && currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
+ rotateLayout(false);
+ }
mPrevRotation = Util.getDisplayRotation((Activity) getContext());
}
@@ -65,7 +81,16 @@ public class RotatableLayout extends FrameLayout {
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
int rotation = Util.getDisplayRotation((Activity) getContext());
+ if ((rotation - mPrevRotation + 360) % 180 == 0) {
+ flipChildren();
+ return;
+ }
boolean clockwise = isClockWiseRotation(mPrevRotation, rotation);
+ rotateLayout(clockwise);
+ mPrevRotation = rotation;
+ }
+
+ protected void rotateLayout(boolean clockwise) {
// Change the size of the layout
ViewGroup.LayoutParams lp = getLayoutParams();
int width = lp.width;
@@ -75,7 +100,6 @@ public class RotatableLayout extends FrameLayout {
setLayoutParams(lp);
// rotate all the children
- mPrevRotation = rotation;
rotateChildren(clockwise);
}