mFastScroller.setEnabled(true);
}
- recomputePadding();
+ resolvePadding();
if (mFastScroller != null) {
mFastScroller.updateLayout();
* @see #setFastScrollAlwaysVisible(boolean)
*/
public boolean isFastScrollAlwaysVisible() {
- return mFastScrollEnabled && mFastScrollAlwaysVisible;
+ if (mFastScroller == null) {
+ return mFastScrollEnabled && mFastScrollAlwaysVisible;
+ } else {
+ return mFastScroller.isEnabled() && mFastScroller.isAlwaysShowEnabled();
+ }
}
@Override
*/
@ViewDebug.ExportedProperty
public boolean isFastScrollEnabled() {
- return mFastScrollEnabled;
+ if (mFastScroller == null) {
+ return mFastScrollEnabled;
+ } else {
+ return mFastScroller.isEnabled();
+ }
}
@Override
*/
@Override
protected boolean isVerticalScrollBarHidden() {
- return mFastScrollEnabled;
+ return isFastScrollEnabled();
}
/**
/** The number of headers at the top of the view. */
private int mHeaderCount;
- /** The number of items in the list. */
- private int mItemCount = -1;
-
/** The index of the current section. */
private int mCurrentSection = -1;
getSectionsFromIndexer();
refreshDrawablePressedState();
+ updateLongList(listView.getChildCount(), listView.getCount());
setScrollbarPosition(mList.getVerticalScrollbarPosition());
postAutoHide();
}
* @param enabled Whether the fast scroll thumb is enabled.
*/
public void setEnabled(boolean enabled) {
- mEnabled = enabled;
+ if (mEnabled != enabled) {
+ mEnabled = enabled;
- if (enabled) {
- if (mAlwaysShow) {
- setState(STATE_VISIBLE);
- }
- } else {
- stop();
+ onStateDependencyChanged();
}
}
* @return Whether the fast scroll thumb is enabled.
*/
public boolean isEnabled() {
- return mEnabled;
+ return mEnabled && (mLongList || mAlwaysShow);
}
/**
* @param alwaysShow Whether the fast scroll thumb should always be shown
*/
public void setAlwaysShow(boolean alwaysShow) {
- mAlwaysShow = alwaysShow;
+ if (mAlwaysShow != alwaysShow) {
+ mAlwaysShow = alwaysShow;
- if (alwaysShow) {
- setState(STATE_VISIBLE);
- } else if (mState == STATE_VISIBLE) {
- postAutoHide();
+ onStateDependencyChanged();
}
}
return mAlwaysShow;
}
+ /**
+ * Called when one of the variables affecting enabled state changes.
+ */
+ private void onStateDependencyChanged() {
+ if (isEnabled()) {
+ if (isAlwaysShowEnabled()) {
+ setState(STATE_VISIBLE);
+ } else if (mState == STATE_VISIBLE) {
+ postAutoHide();
+ }
+ } else {
+ stop();
+ }
+
+ mList.resolvePadding();
+ }
+
public void setScrollBarStyle(int style) {
if (mScrollBarStyle != style) {
mScrollBarStyle = style;
final int firstVisibleItem = mList.getFirstVisiblePosition();
setThumbPos(getPosFromItemCount(firstVisibleItem, visibleItemCount, totalItemCount));
}
+
+ updateLongList(visibleItemCount, totalItemCount);
+ }
+
+ private void updateLongList(int visibleItemCount, int totalItemCount) {
+ final boolean longList = visibleItemCount > 0
+ && totalItemCount / visibleItemCount >= MIN_PAGES;
+ if (mLongList != longList) {
+ mLongList = longList;
+
+ onStateDependencyChanged();
+ }
}
/**
mList.postDelayed(mDeferHide, FADE_TIMEOUT);
}
- private boolean isLongList(int visibleItemCount, int totalItemCount) {
- // Are there enough pages to require fast scroll? Recompute only if
- // total count changes.
- if (mItemCount != totalItemCount && visibleItemCount > 0) {
- mItemCount = totalItemCount;
- mLongList = mItemCount / visibleItemCount >= MIN_PAGES;
- }
-
- return mLongList;
- }
-
public void onScroll(int firstVisibleItem, int visibleItemCount, int totalItemCount) {
- if (!mEnabled || !mAlwaysShow && !isLongList(visibleItemCount, totalItemCount)) {
+ if (!isEnabled()) {
setState(STATE_NONE);
return;
}
}
public boolean onInterceptTouchEvent(MotionEvent ev) {
- if (!mEnabled) {
+ if (!isEnabled()) {
return false;
}
// need to allow the parent time to decide whether it wants
// to intercept events. If it does, we will receive a CANCEL
// event.
- if (mList.isInScrollingContainer()) {
- mInitialTouchY = ev.getY();
- startPendingDrag();
- return false;
+ if (!mList.isInScrollingContainer()) {
+ beginDrag();
+ return true;
}
- beginDrag();
- return true;
+ mInitialTouchY = ev.getY();
+ startPendingDrag();
+ }
+ break;
+ case MotionEvent.ACTION_MOVE:
+ if (!isPointInside(ev.getX(), ev.getY())) {
+ cancelPendingDrag();
}
break;
case MotionEvent.ACTION_UP:
}
public boolean onInterceptHoverEvent(MotionEvent ev) {
- if (!mEnabled) {
+ if (!isEnabled()) {
return false;
}
}
public boolean onTouchEvent(MotionEvent me) {
- if (!mEnabled) {
+ if (!isEnabled()) {
return false;
}
switch (me.getActionMasked()) {
- case MotionEvent.ACTION_DOWN: {
- if (isPointInside(me.getX(), me.getY())) {
- beginDrag();
- return true;
- }
- } break;
-
case MotionEvent.ACTION_UP: {
if (mHasPendingDrag) {
// Allow a tap to scroll.