Merge "Wait until the remote transtions are received before trying to quickscrub animations" into ub-launcher3-edmonton
diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml
index ad5f767..ed18bf5 100644
--- a/quickstep/res/values/dimens.xml
+++ b/quickstep/res/values/dimens.xml
@@ -21,6 +21,7 @@
     <dimen name="task_menu_background_radius">12dp</dimen>
     <dimen name="task_corner_radius">2dp</dimen>
     <dimen name="recents_page_spacing">10dp</dimen>
+    <dimen name="quickscrub_adjacent_visible_width">20dp</dimen>
 
     <!-- The speed in dp/s at which the user needs to be scrolling in recents such that we start
              loading full resolution screenshots. -->
diff --git a/quickstep/src/com/android/launcher3/uioverrides/FastOverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/FastOverviewState.java
index da85990..43d9822 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/FastOverviewState.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/FastOverviewState.java
@@ -15,8 +15,13 @@
  */
 package com.android.launcher3.uioverrides;
 
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Rect;
+
 import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.Launcher;
+import com.android.launcher3.R;
 import com.android.quickstep.QuickScrubController;
 import com.android.quickstep.views.RecentsView;
 
@@ -25,6 +30,12 @@
  */
 public class FastOverviewState extends OverviewState {
 
+    private static final float MAX_PREVIEW_SCALE_UP = 1.3f;
+    /**
+     * Vertical transition of the task previews relative to the full container.
+     */
+    public static final float OVERVIEW_TRANSLATION_FACTOR = 0.5f;
+
     private static final int STATE_FLAGS = FLAG_DISABLE_RESTORE | FLAG_DISABLE_INTERACTION
             | FLAG_OVERVIEW_UI | FLAG_HIDE_BACK_BUTTON | FLAG_DISABLE_ACCESSIBILITY;
 
@@ -46,15 +57,23 @@
 
     @Override
     public float[] getOverviewScaleAndTranslationYFactor(Launcher launcher) {
-        return new float[] {getOverviewScale(launcher.getDeviceProfile()), 0.5f};
+        RecentsView recentsView = launcher.getOverviewPanel();
+        recentsView.getTaskSize(sTempRect);
+
+        return new float[] {getOverviewScale(launcher.getDeviceProfile(), sTempRect, launcher),
+                OVERVIEW_TRANSLATION_FACTOR};
     }
 
-    public static float getOverviewScale(DeviceProfile dp) {
-        if (dp.isMultiWindowMode || dp.isVerticalBarLayout()) {
+    public static float getOverviewScale(DeviceProfile dp, Rect taskRect, Context context) {
+        if (dp.isVerticalBarLayout()) {
             return 1f;
         }
 
-        // TODO: Calculate it dynamically based on available space
-        return 1.3f;
+        Resources res = context.getResources();
+        float usedHeight = taskRect.height() + res.getDimension(R.dimen.task_thumbnail_top_margin);
+        float usedWidth = taskRect.width() + 2 * (res.getDimension(R.dimen.recents_page_spacing)
+                + res.getDimension(R.dimen.quickscrub_adjacent_visible_width));
+        return Math.min(Math.min(dp.availableHeightPx / usedHeight,
+                dp.availableWidthPx / usedWidth), MAX_PREVIEW_SCALE_UP);
     }
 }
diff --git a/quickstep/src/com/android/quickstep/ActivityControlHelper.java b/quickstep/src/com/android/quickstep/ActivityControlHelper.java
index d47fec5..e202c57 100644
--- a/quickstep/src/com/android/quickstep/ActivityControlHelper.java
+++ b/quickstep/src/com/android/quickstep/ActivityControlHelper.java
@@ -153,8 +153,8 @@
         @Override
         public float getTranslationYForQuickScrub(Launcher activity) {
             LauncherRecentsView recentsView = activity.getOverviewPanel();
-            float transYFactor = FAST_OVERVIEW.getOverviewScaleAndTranslationYFactor(activity)[1];
-            return recentsView.computeTranslationYForFactor(transYFactor);
+            return recentsView.computeTranslationYForFactor(
+                    FastOverviewState.OVERVIEW_TRANSLATION_FACTOR);
         }
 
         @Override
@@ -167,7 +167,7 @@
                 @InteractionType int interactionType, TransformedRect outRect) {
             LayoutUtils.calculateLauncherTaskSize(context, dp, outRect.rect);
             if (interactionType == INTERACTION_QUICK_SCRUB) {
-                outRect.scale = FastOverviewState.getOverviewScale(dp);
+                outRect.scale = FastOverviewState.getOverviewScale(dp, outRect.rect, context);
             }
             if (dp.isVerticalBarLayout()) {
                 Rect targetInsets = dp.getInsets();
diff --git a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
index a2aa4b9..9ba3328 100644
--- a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
+++ b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java
@@ -265,12 +265,10 @@
 
         if (Looper.myLooper() != Looper.getMainLooper()) {
             startActivity.run();
-            if (!mIsDeferredDownTarget) {
-                try {
-                    drawWaitLock.await(LAUNCHER_DRAW_TIMEOUT_MS, TimeUnit.MILLISECONDS);
-                } catch (Exception e) {
-                    // We have waited long enough for launcher to draw
-                }
+            try {
+                drawWaitLock.await(LAUNCHER_DRAW_TIMEOUT_MS, TimeUnit.MILLISECONDS);
+            } catch (Exception e) {
+                // We have waited long enough for launcher to draw
             }
         } else {
             // We should almost always get touch-town on background thread. This is an edge case
diff --git a/quickstep/src/com/android/quickstep/QuickScrubController.java b/quickstep/src/com/android/quickstep/QuickScrubController.java
index abb479d..8e1a3d5 100644
--- a/quickstep/src/com/android/quickstep/QuickScrubController.java
+++ b/quickstep/src/com/android/quickstep/QuickScrubController.java
@@ -49,7 +49,7 @@
      * Snap to a new page when crossing these thresholds. The first and last auto-advance.
      */
     private static final float[] QUICK_SCRUB_THRESHOLDS = new float[] {
-            0.04f, 0.27f, 0.50f, 0.73f, 0.96f
+            0.05f, 0.20f, 0.35f, 0.50f, 0.65f, 0.80f, 0.95f
     };
 
     private static final String TAG = "QuickScrubController";
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 4f169fb..2f6ce8a 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1315,8 +1315,9 @@
         super.onInitializeAccessibilityEvent(event);
 
         if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
-            event.setFromIndex(getCurrentPage());
-            event.setToIndex(getCurrentPage());
+            final int visiblePageNumber = getChildCount() - getCurrentPage() - 1;
+            event.setFromIndex(visiblePageNumber);
+            event.setToIndex(visiblePageNumber);
             event.setItemCount(getChildCount());
         }
     }
diff --git a/quickstep/src/com/android/quickstep/views/TaskView.java b/quickstep/src/com/android/quickstep/views/TaskView.java
index 213d9cb..5413a13 100644
--- a/quickstep/src/com/android/quickstep/views/TaskView.java
+++ b/quickstep/src/com/android/quickstep/views/TaskView.java
@@ -325,7 +325,8 @@
 
         final AccessibilityNodeInfo.CollectionItemInfo itemInfo =
                 AccessibilityNodeInfo.CollectionItemInfo.obtain(
-                        0, 1, recentsView.indexOfChild(this), 1, false);
+                        0, 1, recentsView.getChildCount() - recentsView.indexOfChild(this) - 1, 1,
+                        false);
         info.setCollectionItemInfo(itemInfo);
     }
 
diff --git a/src/com/android/launcher3/AbstractFloatingView.java b/src/com/android/launcher3/AbstractFloatingView.java
index c75509e..daf2032 100644
--- a/src/com/android/launcher3/AbstractFloatingView.java
+++ b/src/com/android/launcher3/AbstractFloatingView.java
@@ -51,6 +51,7 @@
             TYPE_WIDGET_RESIZE_FRAME,
             TYPE_WIDGETS_FULL_SHEET,
             TYPE_ON_BOARD_POPUP,
+            TYPE_DISCOVERY_BOUNCE,
 
             TYPE_QUICKSTEP_PREVIEW,
             TYPE_TASK_MENU,
@@ -64,6 +65,7 @@
     public static final int TYPE_WIDGET_RESIZE_FRAME = 1 << 3;
     public static final int TYPE_WIDGETS_FULL_SHEET = 1 << 4;
     public static final int TYPE_ON_BOARD_POPUP = 1 << 5;
+    public static final int TYPE_DISCOVERY_BOUNCE = 1 << 6;
 
     // Popups related to quickstep UI
     public static final int TYPE_QUICKSTEP_PREVIEW = 1 << 6;
@@ -72,14 +74,17 @@
 
     public static final int TYPE_ALL = TYPE_FOLDER | TYPE_ACTION_POPUP
             | TYPE_WIDGETS_BOTTOM_SHEET | TYPE_WIDGET_RESIZE_FRAME | TYPE_WIDGETS_FULL_SHEET
-            | TYPE_QUICKSTEP_PREVIEW | TYPE_ON_BOARD_POPUP | TYPE_TASK_MENU | TYPE_OPTIONS_POPUP;
+            | TYPE_QUICKSTEP_PREVIEW | TYPE_ON_BOARD_POPUP | TYPE_DISCOVERY_BOUNCE | TYPE_TASK_MENU
+            | TYPE_OPTIONS_POPUP;
 
     // Type of popups which should be kept open during launcher rebind
     public static final int TYPE_REBIND_SAFE = TYPE_WIDGETS_FULL_SHEET
-            | TYPE_QUICKSTEP_PREVIEW | TYPE_ON_BOARD_POPUP;
+            | TYPE_QUICKSTEP_PREVIEW | TYPE_ON_BOARD_POPUP | TYPE_DISCOVERY_BOUNCE;
 
     // Usually we show the back button when a floating view is open. Instead, hide for these types.
-    public static final int TYPE_HIDE_BACK_BUTTON = TYPE_ON_BOARD_POPUP;
+    public static final int TYPE_HIDE_BACK_BUTTON = TYPE_ON_BOARD_POPUP | TYPE_DISCOVERY_BOUNCE;
+
+    public static final int TYPE_ACCESSIBLE = TYPE_ALL & ~TYPE_DISCOVERY_BOUNCE;
 
     protected boolean mIsOpen;
 
diff --git a/src/com/android/launcher3/allapps/DiscoveryBounce.java b/src/com/android/launcher3/allapps/DiscoveryBounce.java
index a0a79c8..3c3c406 100644
--- a/src/com/android/launcher3/allapps/DiscoveryBounce.java
+++ b/src/com/android/launcher3/allapps/DiscoveryBounce.java
@@ -110,7 +110,7 @@
 
     @Override
     protected boolean isOfType(int type) {
-        return (type & TYPE_ON_BOARD_POPUP) != 0;
+        return (type & TYPE_DISCOVERY_BOUNCE) != 0;
     }
 
     private void show(int containerType) {
diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java
index 53e9e2d..6d2d3cb 100644
--- a/src/com/android/launcher3/dragndrop/DragLayer.java
+++ b/src/com/android/launcher3/dragndrop/DragLayer.java
@@ -218,7 +218,8 @@
 
     @Override
     public void addChildrenForAccessibility(ArrayList<View> childrenForAccessibility) {
-        View topView = AbstractFloatingView.getTopOpenView(mActivity);
+        View topView = AbstractFloatingView.getTopOpenViewWithType(mActivity,
+                AbstractFloatingView.TYPE_ACCESSIBLE);
         if (topView != null) {
             addAccessibleChildToList(topView, childrenForAccessibility);
             if (isInAccessibleDrag()) {
diff --git a/src/com/android/launcher3/views/BaseDragLayer.java b/src/com/android/launcher3/views/BaseDragLayer.java
index 2f142ac..8457b2b 100644
--- a/src/com/android/launcher3/views/BaseDragLayer.java
+++ b/src/com/android/launcher3/views/BaseDragLayer.java
@@ -16,6 +16,8 @@
 
 package com.android.launcher3.views;
 
+import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
+
 import android.content.Context;
 import android.graphics.Rect;
 import android.util.AttributeSet;
@@ -36,8 +38,6 @@
 
 import java.util.ArrayList;
 
-import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
-
 /**
  * A viewgroup with utility methods for drag-n-drop and touch interception
  */
@@ -100,7 +100,8 @@
     @Override
     public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
         // Shortcuts can appear above folder
-        View topView = AbstractFloatingView.getTopOpenView(mActivity);
+        View topView = AbstractFloatingView.getTopOpenViewWithType(mActivity,
+                AbstractFloatingView.TYPE_ACCESSIBLE);
         if (topView != null) {
             if (child == topView) {
                 return super.onRequestSendAccessibilityEvent(child, event);
@@ -114,7 +115,8 @@
 
     @Override
     public void addChildrenForAccessibility(ArrayList<View> childrenForAccessibility) {
-        View topView = AbstractFloatingView.getTopOpenView(mActivity);
+        View topView = AbstractFloatingView.getTopOpenViewWithType(mActivity,
+                AbstractFloatingView.TYPE_ACCESSIBLE);
         if (topView != null) {
             // Only add the top view as a child for accessibility when it is open
             addAccessibleChildToList(topView, childrenForAccessibility);