Disable match drag position behavior in FastScroller

I'm not sure what it's supposed to accomplish, but whatever it is, it
doesn't do it very well.

This always makes sure the FastScroller remains always visible after
changing the sort order.
This commit is contained in:
Christopher Eby 2012-03-01 02:30:42 -06:00
parent 88fe955b23
commit 80ca7d955e
4 changed files with 39 additions and 8 deletions

View File

@ -27,6 +27,4 @@ THE SOFTWARE.
android:divider="@color/divider_color"
android:dividerHeight="1dip"
android:listSelector="@drawable/selectable_item_bg"
android:fastScrollEnabled="true"
android:fastScrollAlwaysVisible="true"
android:scrollbarStyle="outsideInset" />

View File

@ -87,11 +87,12 @@ public class CompatHoneycomb {
}
/**
* Call {@link ListView#setFastScrollAlwaysVisible(boolean)} on the given ListView.
* Call {@link ListView#setFastScrollAlwaysVisible(boolean)} on the given
* ListView with value true.
*/
public static void setFastScrollAlwaysVisible(ListView view, boolean visible)
public static void setFastScrollAlwaysVisible(ListView view)
{
view.setFastScrollAlwaysVisible(visible);
view.setFastScrollAlwaysVisible(true);
}
/**

View File

@ -27,6 +27,7 @@ import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
@ -147,6 +148,10 @@ public class LibraryActivity
* The adapter for the currently visible list.
*/
private LibraryAdapter mCurrentAdapter;
/**
* If true, return target GINGERBREAD from getApplicationInfo().
*/
boolean mFakeTarget;
@Override
public void onCreate(Bundle state)
@ -1013,4 +1018,14 @@ public class LibraryActivity
CompatHoneycomb.selectTab(this, mViewPager.getCurrentItem());
}
}
@Override
public ApplicationInfo getApplicationInfo()
{
ApplicationInfo info = super.getApplicationInfo();
if (mFakeTarget) {
info.targetSdkVersion = Build.VERSION_CODES.GINGERBREAD;
}
return info;
}
}

View File

@ -25,6 +25,7 @@ package org.kreed.vanilla;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.ContentObserver;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@ -214,11 +215,10 @@ public class LibraryPagerAdapter
header.setTag(position + 1);
view.addHeaderView(header);
}
view.setAdapter(adapter);
if (position != 5)
loadSortOrder((MediaAdapter)adapter);
enableFastScroll(view);
adapter.setFilter(mFilter);
mAdapters[position] = adapter;
@ -598,7 +598,7 @@ public class LibraryPagerAdapter
// are updated.
ListView view = mLists[mCurrentPage];
view.setFastScrollEnabled(false);
view.setFastScrollEnabled(true);
enableFastScroll(view);
Handler handler = mWorkerHandler;
handler.sendMessage(handler.obtainMessage(MSG_SAVE_SORT, adapter));
@ -671,4 +671,21 @@ public class LibraryPagerAdapter
Intent intent = id == -1 ? createHeaderIntent(view) : mCurrentAdapter.createData(view);
mActivity.onItemClicked(intent);
}
/**
* Enables FastScroller on the given list, ensuring it is always visible
* and suppresses the match drag position feature in newer versions of
* Android.
*
* @param list The list to enable.
*/
private void enableFastScroll(ListView list)
{
mActivity.mFakeTarget = true;
list.setFastScrollEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
CompatHoneycomb.setFastScrollAlwaysVisible(list);
}
mActivity.mFakeTarget = false;
}
}