Adjustments to expanded view size and position

* Previously on large screens the expanded view was centered on the
  screen now it will be anchored to whichever edge it was expanded on
  ONLY when in landscape on a large large screen. In portrait, and on
  "small tablets" it will continue to be centered.
* Updates the width of the expanded view on portrait and on landscape
  for large screens.
* Adds the notion of small tablet

Test: manual - Open a bubble in various configurations:
      1) on phone:
        * landscape => bubbles show vertically on the side they were
          expanded on and expanded view is centered horizontally
        * portrait => bubbles show on top, expanded view centered
          horizontally
      2) on tablet that isn't small:
        * landscape => bubbles show vertically on the side they were
          expanded on and the expanded view is anchored to that edge
          with some padding
        * portrait => bubbles show vertically on the side they were
          expanded on and expanded view is centered horizontally
      3) on small tablet:
        * portrait & landscape => bubbles show vertically on the side
          they were expanded on and the expanded view is centered
          horizontally and takes up more space %-wise compared to a
          large tablet
Bug: 217211205
Change-Id: I7259e03aab35e0039c9b7bd855c12afe38373ace
diff --git a/libs/WindowManager/Shell/res/values/dimen.xml b/libs/WindowManager/Shell/res/values/dimen.xml
index 8a8231d..3852c69 100644
--- a/libs/WindowManager/Shell/res/values/dimen.xml
+++ b/libs/WindowManager/Shell/res/values/dimen.xml
@@ -129,6 +129,9 @@
     <dimen name="bubble_dismiss_encircle_size">52dp</dimen>
     <!-- Padding around the view displayed when the bubble is expanded -->
     <dimen name="bubble_expanded_view_padding">16dp</dimen>
+    <!-- Padding for the edge of the expanded view that is closest to the edge of the screen used
+         when displaying in landscape on a large screen. -->
+    <dimen name="bubble_expanded_view_largescreen_landscape_padding">128dp</dimen>
     <!-- This should be at least the size of bubble_expanded_view_padding; it is used to include
          a slight touch slop around the expanded view. -->
     <dimen name="bubble_expanded_view_slop">8dp</dimen>
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java
index 75b19fb..bc0db36 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java
@@ -67,7 +67,11 @@
     /** The max percent of screen width to use for the flyout on phone. */
     public static final float FLYOUT_MAX_WIDTH_PERCENT = 0.6f;
     /** The percent of screen width that should be used for the expanded view on a large screen. **/
-    public static final float EXPANDED_VIEW_LARGE_SCREEN_WIDTH_PERCENT = 0.72f;
+    private static final float EXPANDED_VIEW_LARGE_SCREEN_LANDSCAPE_WIDTH_PERCENT = 0.48f;
+    /** The percent of screen width that should be used for the expanded view on a large screen. **/
+    private static final float EXPANDED_VIEW_LARGE_SCREEN_PORTRAIT_WIDTH_PERCENT = 0.70f;
+    /** The percent of screen width that should be used for the expanded view on a small tablet. **/
+    private static final float EXPANDED_VIEW_SMALL_TABLET_WIDTH_PERCENT = 0.72f;
 
     private Context mContext;
     private WindowManager mWindowManager;
@@ -77,6 +81,7 @@
     private boolean mImeVisible;
     private int mImeHeight;
     private boolean mIsLargeScreen;
+    private boolean mIsSmallTablet;
 
     private Rect mPositionRect;
     private int mDefaultMaxBubbles;
@@ -86,7 +91,8 @@
 
     private int mExpandedViewMinHeight;
     private int mExpandedViewLargeScreenWidth;
-    private int mExpandedViewLargeScreenInset;
+    private int mExpandedViewLargeScreenInsetClosestEdge;
+    private int mExpandedViewLargeScreenInsetFurthestEdge;
 
     private int mOverflowWidth;
     private int mExpandedViewPadding;
@@ -127,17 +133,26 @@
                 | WindowInsets.Type.statusBars()
                 | WindowInsets.Type.displayCutout());
 
-        mIsLargeScreen = mContext.getResources().getConfiguration().smallestScreenWidthDp >= 600;
+        final Rect bounds = windowMetrics.getBounds();
+        Configuration config = mContext.getResources().getConfiguration();
+        mIsLargeScreen = config.smallestScreenWidthDp >= 600;
+        if (mIsLargeScreen) {
+            float largestEdgeDp = Math.max(config.screenWidthDp, config.screenHeightDp);
+            mIsSmallTablet = largestEdgeDp < 960;
+        } else {
+            mIsSmallTablet = false;
+        }
 
         if (BubbleDebugConfig.DEBUG_POSITIONER) {
             Log.w(TAG, "update positioner:"
                     + " rotation: " + mRotation
                     + " insets: " + insets
                     + " isLargeScreen: " + mIsLargeScreen
-                    + " bounds: " + windowMetrics.getBounds()
+                    + " isSmallTablet: " + mIsSmallTablet
+                    + " bounds: " + bounds
                     + " showingInTaskbar: " + mShowingInTaskbar);
         }
-        updateInternal(mRotation, insets, windowMetrics.getBounds());
+        updateInternal(mRotation, insets, bounds);
     }
 
     /**
@@ -172,11 +187,31 @@
         mSpacingBetweenBubbles = res.getDimensionPixelSize(R.dimen.bubble_spacing);
         mDefaultMaxBubbles = res.getInteger(R.integer.bubbles_max_rendered);
         mExpandedViewPadding = res.getDimensionPixelSize(R.dimen.bubble_expanded_view_padding);
-        mExpandedViewLargeScreenWidth = (int) (bounds.width()
-                * EXPANDED_VIEW_LARGE_SCREEN_WIDTH_PERCENT);
-        mExpandedViewLargeScreenInset = mIsLargeScreen
-                ? (bounds.width() - mExpandedViewLargeScreenWidth) / 2
-                : mExpandedViewPadding;
+        if (mIsSmallTablet) {
+            mExpandedViewLargeScreenWidth = (int) (bounds.width()
+                    * EXPANDED_VIEW_SMALL_TABLET_WIDTH_PERCENT);
+        } else {
+            mExpandedViewLargeScreenWidth = isLandscape()
+                    ? (int) (bounds.width() * EXPANDED_VIEW_LARGE_SCREEN_LANDSCAPE_WIDTH_PERCENT)
+                    : (int) (bounds.width() * EXPANDED_VIEW_LARGE_SCREEN_PORTRAIT_WIDTH_PERCENT);
+        }
+        if (mIsLargeScreen) {
+            if (isLandscape() && !mIsSmallTablet) {
+                mExpandedViewLargeScreenInsetClosestEdge = res.getDimensionPixelSize(
+                        R.dimen.bubble_expanded_view_largescreen_landscape_padding);
+                mExpandedViewLargeScreenInsetFurthestEdge = bounds.width()
+                        - mExpandedViewLargeScreenInsetClosestEdge
+                        - mExpandedViewLargeScreenWidth;
+            } else {
+                final int centeredInset = (bounds.width() - mExpandedViewLargeScreenWidth) / 2;
+                mExpandedViewLargeScreenInsetClosestEdge = centeredInset;
+                mExpandedViewLargeScreenInsetFurthestEdge = centeredInset;
+            }
+        } else {
+            mExpandedViewLargeScreenInsetClosestEdge = mExpandedViewPadding;
+            mExpandedViewLargeScreenInsetFurthestEdge = mExpandedViewPadding;
+        }
+
         mOverflowWidth = mIsLargeScreen
                 ? mExpandedViewLargeScreenWidth
                 : res.getDimensionPixelSize(
@@ -328,15 +363,18 @@
     public int[] getExpandedViewContainerPadding(boolean onLeft, boolean isOverflow) {
         final int pointerTotalHeight = mPointerHeight - mPointerOverlap;
         if (mIsLargeScreen) {
+            // Note:
+            // If we're in portrait OR if we're a small tablet, then the two insets values will
+            // be equal. If we're landscape and a large tablet, the two values will be different.
             // [left, top, right, bottom]
             mPaddings[0] = onLeft
-                    ? mExpandedViewLargeScreenInset - pointerTotalHeight
-                    : mExpandedViewLargeScreenInset;
+                    ? mExpandedViewLargeScreenInsetClosestEdge - pointerTotalHeight
+                    : mExpandedViewLargeScreenInsetFurthestEdge;
             mPaddings[1] = 0;
             mPaddings[2] = onLeft
-                    ? mExpandedViewLargeScreenInset
-                    : mExpandedViewLargeScreenInset - pointerTotalHeight;
-            // Overflow doesn't show manage button / get padding from it so add padding here for it
+                    ? mExpandedViewLargeScreenInsetFurthestEdge
+                    : mExpandedViewLargeScreenInsetClosestEdge - pointerTotalHeight;
+            // Overflow doesn't show manage button / get padding from it so add padding here
             mPaddings[3] = isOverflow ? mExpandedViewPadding : 0;
             return mPaddings;
         } else {
@@ -494,12 +532,13 @@
         float x;
         float y;
         if (showBubblesVertically()) {
+            int inset = mExpandedViewLargeScreenInsetClosestEdge;
             y = rowStart + positionInRow;
             int left = mIsLargeScreen
-                    ? mExpandedViewLargeScreenInset - mExpandedViewPadding - mBubbleSize
+                    ? inset - mExpandedViewPadding - mBubbleSize
                     : mPositionRect.left;
             int right = mIsLargeScreen
-                    ? mPositionRect.right - mExpandedViewLargeScreenInset + mExpandedViewPadding
+                    ? mPositionRect.right - inset + mExpandedViewPadding
                     : mPositionRect.right - mBubbleSize;
             x = state.onLeft
                     ? left