Merge "Use getScaledTouchSlop instead of MIN_LENGTH_FOR_FLING" into ub-launcher3-master
diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
index 8f498d2..0fe29e3 100644
--- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
+++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
@@ -21,6 +21,7 @@
 import static com.android.systemui.shared.recents.utilities.Utilities.getNextFrameNumber;
 import static com.android.systemui.shared.recents.utilities.Utilities.getSurface;
 import static com.android.systemui.shared.recents.utilities.Utilities.postAtFrontOfQueueAsynchronously;
+import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_CLOSING;
 import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_OPENING;
 
 import android.animation.Animator;
@@ -427,17 +428,19 @@
      */
     private LauncherTransitionAnimator composeAppLaunchAnimator(View v,
             RemoteAnimationTargetCompat[] targets) {
-        return new LauncherTransitionAnimator(getLauncherAnimators(v),
+        return new LauncherTransitionAnimator(getLauncherAnimators(v, targets),
                 getWindowAnimators(v, targets));
     }
 
     /**
      * @return Animators that control the movements of the Launcher and icon of the opening target.
      */
-    private AnimatorSet getLauncherAnimators(View v) {
+    private AnimatorSet getLauncherAnimators(View v, RemoteAnimationTargetCompat[] targets) {
         AnimatorSet launcherAnimators = new AnimatorSet();
-        launcherAnimators.play(getLauncherContentAnimator(false /* show */));
         launcherAnimators.play(getIconAnimator(v));
+        if (launcherIsATargetWithMode(targets, MODE_CLOSING)) {
+            launcherAnimators.play(getLauncherContentAnimator(false /* show */));
+        }
         return launcherAnimators;
     }
 
@@ -498,8 +501,10 @@
         mFloatingView = new View(mLauncher);
         if (isBubbleTextView && v.getTag() instanceof ItemInfoWithIcon ) {
             // Create a copy of the app icon
-            mFloatingView.setBackground(
-                    DrawableFactory.get(mLauncher).newIcon((ItemInfoWithIcon) v.getTag()));
+            ItemInfoWithIcon info = (ItemInfoWithIcon) v.getTag();
+            FastBitmapDrawable d = DrawableFactory.get(mLauncher).newIcon(info);
+            d.setIsDisabled(info.isDisabled());
+            mFloatingView.setBackground(d);
         }
 
         // Position the floating view exactly on top of the original
@@ -685,10 +690,10 @@
         }
     }
 
-    private boolean isLauncherInSetOfOpeningTargets(RemoteAnimationTargetCompat[] targets) {
+    private boolean launcherIsATargetWithMode(RemoteAnimationTargetCompat[] targets, int mode) {
         int launcherTaskId = mLauncher.getTaskId();
         for (RemoteAnimationTargetCompat target : targets) {
-            if (target.mode == MODE_OPENING && target.taskId == launcherTaskId) {
+            if (target.mode == mode && target.taskId == launcherTaskId) {
                 return true;
             }
         }
@@ -709,7 +714,7 @@
                     if ((Utilities.getPrefs(mLauncher)
                             .getBoolean("pref_use_screenshot_for_swipe_up", false)
                             && mLauncher.isInState(LauncherState.OVERVIEW))
-                            || !isLauncherInSetOfOpeningTargets(targets)) {
+                            || !launcherIsATargetWithMode(targets, MODE_OPENING)) {
                         // We use a separate transition for Overview mode. And we can skip the
                         // animation in cases where Launcher is not in the set of opening targets.
                         // This can happen when Launcher is already visible. ie. Closing a dialog.
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2318e9e..381830c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -334,7 +334,7 @@
     <!-- Title of an overlay in All Apps. This overlay is letting a user know about their work profile, which is managed by their employer. "Work apps" are apps in a user's work profile.-->
     <string name="bottom_work_tab_user_education_title">Find work apps here</string>
     <!-- Text in an overlay in All Apps. This overlay is letting a user know about their work profile, which is managed by their employer.-->
-    <string name="bottom_work_tab_user_education_body">Each work app has an orange badge and is kept secure by your organization. Move apps to your Home screen for easier access.</string>
+    <string name="bottom_work_tab_user_education_body">Each work app has a badge and is kept secure by your organization. Move apps to your Home screen for easier access.</string>
     <!-- This string is in the work profile tab when a user has All Apps open on their phone. It describes the label of a toggle, "Work profile," as being managed by the user's employer.
     "Organization" is used to represent a variety of businesses, non-profits, and educational institutions).-->
     <string name="work_mode_on_label">Managed by your organization</string>
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 78ff985..d6e5d18 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -1887,6 +1887,14 @@
                 getNextPage() + 1, getChildCount());
     }
 
+    protected float getDownMotionX() {
+        return mDownMotionX;
+    }
+
+    protected float getDownMotionY() {
+        return mDownMotionY;
+    }
+
     @Override
     public boolean onHoverEvent(android.view.MotionEvent event) {
         return true;
diff --git a/src/com/android/launcher3/allapps/AllAppsPagedView.java b/src/com/android/launcher3/allapps/AllAppsPagedView.java
index 86186fd..3b4450b 100644
--- a/src/com/android/launcher3/allapps/AllAppsPagedView.java
+++ b/src/com/android/launcher3/allapps/AllAppsPagedView.java
@@ -18,12 +18,17 @@
 import android.content.Context;
 import android.util.AttributeSet;
 
+import android.view.MotionEvent;
 import com.android.launcher3.PagedView;
 import com.android.launcher3.R;
 
 public class AllAppsPagedView extends PagedView<PersonalWorkSlidingTabStrip> {
 
-    public AllAppsPagedView(Context context) {
+  final static float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6;
+  final static float MAX_SWIPE_ANGLE = (float) Math.PI / 3;
+  final static float TOUCH_SLOP_DAMPING_FACTOR = 4;
+
+  public AllAppsPagedView(Context context) {
         this(context, null);
     }
 
@@ -46,4 +51,30 @@
         super.onScrollChanged(l, t, oldl, oldt);
         mPageIndicator.setScroll(l, mMaxScrollX);
     }
+
+    @Override
+    protected void determineScrollingStart(MotionEvent ev) {
+        float absDeltaX = Math.abs(ev.getX() - getDownMotionX());
+        float absDeltaY = Math.abs(ev.getY() - getDownMotionY());
+
+        if (Float.compare(absDeltaX, 0f) == 0) return;
+
+        float slope = absDeltaY / absDeltaX;
+        float theta = (float) Math.atan(slope);
+
+        if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) {
+            cancelCurrentPageLongPress();
+        }
+
+        if (theta > MAX_SWIPE_ANGLE) {
+            return;
+        } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) {
+            theta -= START_DAMPING_TOUCH_SLOP_ANGLE;
+            float extraRatio = (float)
+                    Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE)));
+            super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio);
+        } else {
+            super.determineScrollingStart(ev);
+        }
+    }
 }