diff options
author | Doris Liu <tianliu@google.com> | 2013-03-04 22:19:10 -0800 |
---|---|---|
committer | Doris Liu <tianliu@google.com> | 2013-03-05 14:11:05 -0800 |
commit | 48239f4dd39040a9ab2ffc977586035a8784fd78 (patch) | |
tree | c7221012018ef477e04262befecee5ff43c9beb5 /src/com/android/camera/ui/RotatableLayout.java | |
parent | 72db7ea0c18e5cc2f465252b53d9b6d2a8dcc6a0 (diff) | |
download | android_packages_apps_Snap-48239f4dd39040a9ab2ffc977586035a8784fd78.tar.gz android_packages_apps_Snap-48239f4dd39040a9ab2ffc977586035a8784fd78.tar.bz2 android_packages_apps_Snap-48239f4dd39040a9ab2ffc977586035a8784fd78.zip |
Keep camera controls on the same physical side
Change-Id: I09c50650c77a89fadfeb376564ef43e750994f8a
Diffstat (limited to 'src/com/android/camera/ui/RotatableLayout.java')
-rw-r--r-- | src/com/android/camera/ui/RotatableLayout.java | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/com/android/camera/ui/RotatableLayout.java b/src/com/android/camera/ui/RotatableLayout.java index 9c5ebd34d..4edec5dd7 100644 --- a/src/com/android/camera/ui/RotatableLayout.java +++ b/src/com/android/camera/ui/RotatableLayout.java @@ -16,13 +16,17 @@ package com.android.camera.ui; +import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; +import android.view.ViewGroup; import android.widget.FrameLayout; +import com.android.camera.Util; + /* RotatableLayout rotates itself as well as all its children when orientation * changes. Specifically, when going from portrait to landscape, camera * controls move from the bottom of the screen to right side of the screen @@ -33,6 +37,8 @@ import android.widget.FrameLayout; public class RotatableLayout extends FrameLayout { + private static final String TAG = "RotatableLayout"; + private int mPrevRotation; public RotatableLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @@ -46,11 +52,24 @@ public class RotatableLayout extends FrameLayout { } @Override + public void onFinishInflate() { // get initial orientation + mPrevRotation = Util.getDisplayRotation((Activity) getContext()); + } + + @Override public void onConfigurationChanged(Configuration config) { super.onConfigurationChanged(config); - // rotate the layout itself and all its children - boolean clockwise = (config.orientation == Configuration.ORIENTATION_PORTRAIT); - rotate(this, clockwise); + // Change the size of the layout + ViewGroup.LayoutParams lp = getLayoutParams(); + int width = lp.width; + int height = lp.height; + lp.height = width; + lp.width = height; + setLayoutParams(lp); + // rotate all the children + int rotation = Util.getDisplayRotation((Activity) getContext()); + boolean clockwise = isClockWiseRotation(mPrevRotation, rotation); + mPrevRotation = rotation; int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); @@ -58,6 +77,13 @@ public class RotatableLayout extends FrameLayout { } } + public static boolean isClockWiseRotation(int prevRotation, int currentRotation) { + if (prevRotation == (currentRotation + 90) % 360) { + return true; + } + return false; + } + public static void rotate(View view, boolean isClockwise) { if (isClockwise) { rotateClockwise(view); |