Fix 4689527: Fix positioning bug with RecentHorizontalScrollView, minor tweaks.

This fixes a bug where RecentsHorizontalScrollView wasn't scrolling to the most
recent app.

Contains some minor tweaks to the layout so that it doesn't overlap the notification
bad as well as starting alpha fades while draging items sooner.

Change-Id: I94df309673f316c55b2f44aff60fd3aee746b6de
diff --git a/packages/SystemUI/res/layout-port/status_bar_recent_panel.xml b/packages/SystemUI/res/layout-port/status_bar_recent_panel.xml
index 386182d..28ef239 100644
--- a/packages/SystemUI/res/layout-port/status_bar_recent_panel.xml
+++ b/packages/SystemUI/res/layout-port/status_bar_recent_panel.xml
@@ -29,21 +29,17 @@
         android:background="@drawable/status_bar_recents_background"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_alignParentBottom="true"
-        android:paddingBottom="@*android:dimen/status_bar_height"
-        android:clipToPadding="false"
-        android:clipChildren="false">
+        android:layout_alignParentBottom="true">
 
         <LinearLayout android:id="@+id/recents_glow"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginBottom="0dp"
             android:layout_gravity="bottom"
             android:orientation="horizontal"
-            android:clipToPadding="false"
             android:clipChildren="false"
-            >
-            <com.android.systemui.recent.RecentsVerticalScrollView android:id="@+id/recents_container"
+            android:layout_marginTop="@*android:dimen/status_bar_height">
+            <com.android.systemui.recent.RecentsVerticalScrollView
+                android:id="@+id/recents_container"
                 android:layout_width="@dimen/status_bar_recents_width"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="0dp"
@@ -51,7 +47,7 @@
                 android:stackFromBottom="true"
                 android:fadingEdge="vertical"
                 android:scrollbars="none"
-                android:fadingEdgeLength="20dip"
+                android:fadingEdgeLength="@*android:dimen/status_bar_height"
                 android:listSelector="@drawable/recents_thumbnail_bg_selector"
                 android:layout_gravity="bottom|left"
                 android:clipToPadding="false"
diff --git a/packages/SystemUI/src/com/android/systemui/recent/Constants.java b/packages/SystemUI/src/com/android/systemui/recent/Constants.java
index 66f9292..8252a9f 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/Constants.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/Constants.java
@@ -18,7 +18,8 @@
 
 public class Constants {
     static final int MAX_ESCAPE_ANIMATION_DURATION = 500; // in ms
-    static final float FADE_CONSTANT = 0.5f; // unitless
     static final int SNAP_BACK_DURATION = 250; // in ms
     static final int ESCAPE_VELOCITY = 100; // speed of item required to "curate" it in dp/s
+    public static float ALPHA_FADE_START = 0.8f; // fraction of thumbnail width where fade starts
+    static final float ALPHA_FADE_END = 0.5f; // fraction of thumbnail width beyond which alpha->0
 }
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
index fb7a0a7..f984aac 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
@@ -118,12 +118,12 @@
     }
 
     private float getAlphaForOffset(View view, float thumbHeight) {
-        final float fadeHeight = Constants.FADE_CONSTANT * thumbHeight;
+        final float fadeHeight = Constants.ALPHA_FADE_END * thumbHeight;
         float result = 1.0f;
-        if (view.getY() >= thumbHeight) {
-            result = 1.0f - (view.getY() - thumbHeight) / fadeHeight;
-        } else if (view.getY() < 0.0f) {
-            result = 1.0f + (thumbHeight + view.getY()) / fadeHeight;
+        if (view.getY() >= thumbHeight * Constants.ALPHA_FADE_START) {
+            result = 1.0f - (view.getY() - thumbHeight * Constants.ALPHA_FADE_START) / fadeHeight;
+        } else if (view.getY() < thumbHeight * (1.0f - Constants.ALPHA_FADE_START)) {
+            result = 1.0f + (thumbHeight * Constants.ALPHA_FADE_START + view.getY()) / fadeHeight;
         }
         if (DEBUG) Log.v(TAG, "FADE AMOUNT: " + result);
         return result;
@@ -269,7 +269,7 @@
         // This has to happen post-layout, so run it "in the future"
         post(new Runnable() {
             public void run() {
-                scrollTo(0, mLastScrollPosition);
+                scrollTo(mLastScrollPosition, 0);
             }
         });
     }
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
index 711ffa3..27bb0b5 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
@@ -118,12 +118,12 @@
     }
 
     private float getAlphaForOffset(View view, float thumbWidth) {
-        final float fadeWidth = Constants.FADE_CONSTANT * thumbWidth;
+        final float fadeWidth = Constants.ALPHA_FADE_END * thumbWidth;
         float result = 1.0f;
-        if (view.getX() >= thumbWidth) {
-            result = 1.0f - (view.getX() - thumbWidth) / fadeWidth;
-        } else if (view.getX() < 0.0f) {
-            result = 1.0f + (thumbWidth + view.getX()) / fadeWidth;
+        if (view.getX() >= thumbWidth*Constants.ALPHA_FADE_START) {
+            result = 1.0f - (view.getX() - thumbWidth*Constants.ALPHA_FADE_START) / fadeWidth;
+        } else if (view.getX() < thumbWidth* (1.0f - Constants.ALPHA_FADE_START)) {
+            result = 1.0f + (thumbWidth*Constants.ALPHA_FADE_START + view.getX()) / fadeWidth;
         }
         if (DEBUG) Log.v(TAG, "FADE AMOUNT: " + result);
         return result;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index 5eacad7..b50fd81 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -307,7 +307,7 @@
         mDateView.setVisibility(View.INVISIBLE);
 
         // Recents Panel
-        initializeRecentsPanel();
+        updateRecentsPanel();
 
         // receive broadcasts
         IntentFilter filter = new IntentFilter();
@@ -338,7 +338,7 @@
         return lp;
     }
 
-    protected void initializeRecentsPanel() {
+    protected void updateRecentsPanel() {
         // Recents Panel
         boolean visible = false;
         if (mRecentsPanel != null) {
@@ -385,9 +385,9 @@
     // For small-screen devices (read: phones) that lack hardware navigation buttons
     private void addNavigationBar() {
         if (mNavigationBarView == null) return;
-        
+
         mNavigationBarView.reorient();
- 
+
         mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener);
 
         WindowManagerImpl.getDefault().addView(
@@ -396,7 +396,7 @@
 
     private void repositionNavigationBar() {
         if (mNavigationBarView == null) return;
-        
+
         mNavigationBarView.reorient();
 
         mNavigationBarView.getRecentsButton().setOnClickListener(mRecentsClickListener);
@@ -656,7 +656,7 @@
 
     @Override
     protected void onConfigurationChanged(Configuration newConfig) {
-        initializeRecentsPanel();
+        updateRecentsPanel();
     }