Fix assorted FastScroller regressions

Fixes the following bugs:
- Don't show preview if text is empty, e.g. whitespace
- Avoid transitioning decor from DRAGGING to DRAGGING
- Restore original font size
- Restore thumb position adjustment for last row

BUG: 11207575
Change-Id: I72fc031d1fd22a41d81e7f52ca0856cf82d1be27
diff --git a/core/java/android/widget/FastScroller.java b/core/java/android/widget/FastScroller.java
index 4614c53..01ac8fd 100644
--- a/core/java/android/widget/FastScroller.java
+++ b/core/java/android/widget/FastScroller.java
@@ -29,6 +29,7 @@
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.os.Build;
+import android.text.TextUtils;
 import android.text.TextUtils.TruncateAt;
 import android.util.IntProperty;
 import android.util.MathUtils;
@@ -176,6 +177,9 @@
      */
     private int mState;
 
+    /** Whether the preview image is visible. */
+    private boolean mShowingPreview;
+
     private BaseAdapter mListAdapter;
     private SectionIndexer mSectionIndexer;
 
@@ -769,6 +773,8 @@
         mDecorAnimation = new AnimatorSet();
         mDecorAnimation.playTogether(fadeOut, slideOut);
         mDecorAnimation.start();
+
+        mShowingPreview = false;
     }
 
     /**
@@ -790,6 +796,8 @@
         mDecorAnimation = new AnimatorSet();
         mDecorAnimation.playTogether(fadeIn, fadeOut, slideIn);
         mDecorAnimation.start();
+
+        mShowingPreview = false;
     }
 
     /**
@@ -809,6 +817,8 @@
         mDecorAnimation = new AnimatorSet();
         mDecorAnimation.playTogether(fadeIn, slideIn);
         mDecorAnimation.start();
+
+        mShowingPreview = true;
     }
 
     private void postAutoHide() {
@@ -982,9 +992,10 @@
         if (mCurrentSection != sectionIndex) {
             mCurrentSection = sectionIndex;
 
-            if (transitionPreviewLayout(sectionIndex)) {
+            final boolean hasPreview = transitionPreviewLayout(sectionIndex);
+            if (!mShowingPreview && hasPreview) {
                 transitionToDragging();
-            } else {
+            } else if (mShowingPreview && !hasPreview) {
                 transitionToVisible();
             }
         }
@@ -1072,7 +1083,7 @@
 
         mPreviewAnimation.start();
 
-        return (text != null && text.length() > 0);
+        return !TextUtils.isEmpty(text);
     }
 
     /**
@@ -1184,7 +1195,19 @@
                     / positionsInSection;
         }
 
-        return (section + posWithinSection) / sectionCount;
+        float result = (section + posWithinSection) / sectionCount;
+
+        // Fake out the scroll bar for the last item. Since the section indexer
+        // won't ever actually move the list in this end space, make scrolling
+        // across the last item account for whatever space is remaining.
+        if (firstVisibleItem > 0 && firstVisibleItem + visibleItemCount == totalItemCount) {
+            final View lastChild = mList.getChildAt(visibleItemCount - 1);
+            final float lastItemVisible = (float) (mList.getHeight() - mList.getPaddingBottom()
+                    - lastChild.getTop()) / lastChild.getHeight();
+            result += (1 - result) * lastItemVisible;
+        }
+
+        return result;
     }
 
     /**
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index aad6252..f96195c 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -53,7 +53,7 @@
     <!-- Minimum size of the fastscroll overlay -->
     <dimen name="fastscroll_overlay_size">104dp</dimen>
     <!-- Text size of the fastscroll overlay -->
-    <dimen name="fastscroll_overlay_text_size">24sp</dimen>
+    <dimen name="fastscroll_overlay_text_size">52sp</dimen>
     <!-- Padding of the fastscroll overlay -->
     <dimen name="fastscroll_overlay_padding">16dp</dimen>
     <!-- Width of the fastscroll thumb -->