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 | |
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')
-rw-r--r-- | src/com/android/camera/ui/CameraSwitcher.java | 23 | ||||
-rw-r--r-- | src/com/android/camera/ui/RotatableLayout.java | 32 |
2 files changed, 49 insertions, 6 deletions
diff --git a/src/com/android/camera/ui/CameraSwitcher.java b/src/com/android/camera/ui/CameraSwitcher.java index 3fa4a01d5..897729b46 100644 --- a/src/com/android/camera/ui/CameraSwitcher.java +++ b/src/com/android/camera/ui/CameraSwitcher.java @@ -19,11 +19,13 @@ package com.android.camera.ui; import android.animation.Animator; import android.animation.Animator.AnimatorListener; import android.animation.AnimatorListenerAdapter; +import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.util.AttributeSet; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -33,6 +35,7 @@ import android.view.ViewGroup; import android.widget.FrameLayout.LayoutParams; import android.widget.LinearLayout; +import com.android.camera.Util; import com.android.gallery3d.R; import com.android.gallery3d.common.ApiHelper; @@ -120,6 +123,13 @@ public class CameraSwitcher extends RotateImageView (ViewGroup) getParent()); LinearLayout content = (LinearLayout) mParent.findViewById(R.id.content); mPopup = content; + // Set the gravity of the popup, so that it shows up at the right position + // on screen + LayoutParams lp = ((LayoutParams) mPopup.getLayoutParams()); + lp.gravity = ((LayoutParams) mParent.findViewById(R.id.camera_switcher) + .getLayoutParams()).gravity; + mPopup.setLayoutParams(lp); + mPopup.setVisibility(View.INVISIBLE); mNeedsAnimationSetup = true; for (int i = mDrawIds.length - 1; i >= 0; i--) { @@ -224,15 +234,22 @@ public class CameraSwitcher extends RotateImageView } private void updateInitialTranslations() { - if (getResources().getConfiguration().orientation - == Configuration.ORIENTATION_PORTRAIT) { + int orientation = Util.getDisplayRotation((Activity) getContext()); + if (orientation == 0) { mTranslationX = -getWidth() / 2; mTranslationY = getHeight(); - } else { + } else if (orientation == 90) { mTranslationX = getWidth(); mTranslationY = getHeight() / 2; + } else if (orientation == 180) { + mTranslationX = getWidth(); + mTranslationY = -getHeight() / 2; + } else { + mTranslationX = -getWidth(); + mTranslationY = -getHeight() / 2; } } + private void popupAnimationSetup() { if (!ApiHelper.HAS_VIEW_PROPERTY_ANIMATOR) { return; 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); |