OSDN Git Service

Fix bug 5073637 - Market apps crashing FastScroller
authorAdam Powell <adamp@google.com>
Thu, 4 Aug 2011 05:38:48 +0000 (22:38 -0700)
committerAdam Powell <adamp@google.com>
Thu, 4 Aug 2011 17:36:37 +0000 (10:36 -0700)
It seems that some popular Market apps do not properly implement
SectionIndexer#getSectionForPosition and the framework did not
previously call it. Revert to more simplistic scrollbar behavior for
apps targeting sdk < Honeycomb.

Change-Id: If0b1f2b4db540de4bb8ba45798e498c09cddb42f

core/java/android/widget/FastScroller.java

index 00ebe0d..7ad5d6c 100644 (file)
@@ -116,6 +116,8 @@ class FastScroller {
 
     private int mOverlayPosition;
 
+    private boolean mMatchDragPosition;
+
     private static final int FADE_TIMEOUT = 1500;
 
     private final Rect mTmpRect = new Rect();
@@ -262,6 +264,9 @@ class FastScroller {
 
         ta.recycle();
 
+        mMatchDragPosition = context.getApplicationInfo().targetSdkVersion >=
+                android.os.Build.VERSION_CODES.HONEYCOMB;
+
         setScrollbarPosition(mList.getVerticalScrollbarPosition());
     }
     
@@ -417,7 +422,7 @@ class FastScroller {
             }
             return;
         }
-        if (totalItemCount - visibleItemCount > 0 && mState != STATE_DRAGGING ) {
+        if (totalItemCount - visibleItemCount > 0 && mState != STATE_DRAGGING) {
             mThumbY = getThumbPositionForListPosition(firstVisibleItem, visibleItemCount,
                     totalItemCount);
             if (mChangedBounds) {
@@ -595,7 +600,7 @@ class FastScroller {
         if (mSectionIndexer == null) {
             getSectionsFromIndexer();
         }
-        if (mSectionIndexer == null) {
+        if (mSectionIndexer == null || !mMatchDragPosition) {
             return ((mList.getHeight() - mThumbH) * firstVisibleItem)
                     / (totalItemCount - visibleItemCount);
         }