Merge "Fix for camera switcher hard to hit" into gb-ub-photos-bryce
diff --git a/src/com/android/camera/ui/RotatableLayout.java b/src/com/android/camera/ui/RotatableLayout.java
index 6836b39..bf80605 100644
--- a/src/com/android/camera/ui/RotatableLayout.java
+++ b/src/com/android/camera/ui/RotatableLayout.java
@@ -38,6 +38,8 @@
 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 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 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 @@
         setLayoutParams(lp);
 
         // rotate all the children
-        mPrevRotation = rotation;
         rotateChildren(clockwise);
     }
 
diff --git a/src/com/android/gallery3d/app/AbstractGalleryActivity.java b/src/com/android/gallery3d/app/AbstractGalleryActivity.java
index bd7e654..ac39aa5 100644
--- a/src/com/android/gallery3d/app/AbstractGalleryActivity.java
+++ b/src/com/android/gallery3d/app/AbstractGalleryActivity.java
@@ -40,12 +40,11 @@
 import com.android.gallery3d.common.ApiHelper;
 import com.android.gallery3d.data.DataManager;
 import com.android.gallery3d.data.MediaItem;
-import com.android.photos.data.GalleryBitmapPool;
 import com.android.gallery3d.ui.GLRoot;
 import com.android.gallery3d.ui.GLRootView;
 import com.android.gallery3d.util.LightCycleHelper.PanoramaViewHelper;
 import com.android.gallery3d.util.ThreadPool;
-import com.android.gallery3d.util.UsageStatistics;
+import com.android.photos.data.GalleryBitmapPool;
 
 public class AbstractGalleryActivity extends Activity implements GalleryContext {
     @SuppressWarnings("unused")
@@ -76,7 +75,6 @@
         mPanoramaViewHelper = new PanoramaViewHelper(this);
         mPanoramaViewHelper.onCreate();
         doBindBatchService();
-        UsageStatistics.showOptInDialogIfNeeded(this);
     }
 
     @Override
diff --git a/src_pd/com/android/gallery3d/util/UsageStatistics.java b/src_pd/com/android/gallery3d/util/UsageStatistics.java
index 9549b8f..acc0be4 100644
--- a/src_pd/com/android/gallery3d/util/UsageStatistics.java
+++ b/src_pd/com/android/gallery3d/util/UsageStatistics.java
@@ -16,7 +16,6 @@
 
 package com.android.gallery3d.util;
 
-import android.app.Activity;
 import android.content.Context;
 
 public class UsageStatistics {
@@ -42,7 +41,6 @@
     public static final String ACTION_SHARE = "Share";
 
     public static void initialize(Context context) {}
-    public static void showOptInDialogIfNeeded(Activity activity) {}
     public static void setPendingTransitionCause(String cause) {}
     public static void onContentViewChanged(String screenComponent, String screenName) {}
     public static void onEvent(String category, String action, String label) {};