Merge "Update documentation for FastScroller and SectionIndexer" into klp-dev

This commit is contained in:
Alan Viverette
2013-08-16 17:56:40 +00:00
committed by Android (Google) Code Review
2 changed files with 71 additions and 38 deletions

View File

@@ -1211,13 +1211,19 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} }
/** /**
* Enables fast scrolling by letting the user quickly scroll through lists by * Specifies whether fast scrolling is enabled or disabled.
* dragging the fast scroll thumb. The adapter attached to the list may want * <p>
* to implement {@link SectionIndexer} if it wishes to display alphabet preview and * When fast scrolling is enabled, the user can quickly scroll through lists
* jump between sections of the list. * by dragging the fast scroll thumb.
* <p>
* If the adapter backing this list implements {@link SectionIndexer}, the
* fast scroller will display section header previews as the user scrolls.
* Additionally, the user will be able to quickly jump between sections by
* tapping along the length of the scroll bar.
*
* @see SectionIndexer * @see SectionIndexer
* @see #isFastScrollEnabled() * @see #isFastScrollEnabled()
* @param enabled whether or not to enable fast scrolling * @param enabled true to enable fast scrolling, false otherwise
*/ */
public void setFastScrollEnabled(final boolean enabled) { public void setFastScrollEnabled(final boolean enabled) {
if (mFastScrollEnabled != enabled) { if (mFastScrollEnabled != enabled) {
@@ -1252,13 +1258,16 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} }
/** /**
* Set whether or not the fast scroller should always be shown in place of the * Set whether or not the fast scroller should always be shown in place of
* standard scrollbars. Fast scrollers shown in this way will not fade out and will * the standard scroll bars. This will enable fast scrolling if it is not
* be a permanent fixture within the list. Best combined with an inset scroll bar style
* that will ensure enough padding. This will enable fast scrolling if it is not
* already enabled. * already enabled.
* <p>
* Fast scrollers shown in this way will not fade out and will be a
* permanent fixture within the list. This is best combined with an inset
* scroll bar style to ensure the scroll bar does not overlap content.
* *
* @param alwaysShow true if the fast scroller should always be displayed. * @param alwaysShow true if the fast scroller should always be displayed,
* false otherwise
* @see #setScrollBarStyle(int) * @see #setScrollBarStyle(int)
* @see #setFastScrollEnabled(boolean) * @see #setFastScrollEnabled(boolean)
*/ */
@@ -1297,10 +1306,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} }
/** /**
* Returns true if the fast scroller is set to always show on this view rather than * Returns true if the fast scroller is set to always show on this view.
* fade out when not in use.
* *
* @return true if the fast scroller will always show. * @return true if the fast scroller will always show
* @see #setFastScrollAlwaysVisible(boolean) * @see #setFastScrollAlwaysVisible(boolean)
*/ */
public boolean isFastScrollAlwaysVisible() { public boolean isFastScrollAlwaysVisible() {
@@ -1316,7 +1324,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} }
/** /**
* Returns the current state of the fast scroll feature. * Returns true if the fast scroller is enabled.
*
* @see #setFastScrollEnabled(boolean) * @see #setFastScrollEnabled(boolean)
* @return true if fast scroll is enabled, false otherwise * @return true if fast scroll is enabled, false otherwise
*/ */

View File

@@ -17,38 +17,62 @@
package android.widget; package android.widget;
/** /**
* Interface that should be implemented on Adapters to enable fast scrolling * Interface that may implemented on {@link Adapter}s to enable fast scrolling
* in an {@link AbsListView} between sections of the list. A section is a group of list items * between sections of an {@link AbsListView}.
* to jump to that have something in common. For example, they may begin with the * <p>
* same letter or they may be songs from the same artist. ExpandableListAdapters that * A section is a group of list items that have something in common. For
* consider groups and sections as synonymous should account for collapsed groups and return * example, they may begin with the same letter or they may be songs from the
* an appropriate section/position. * same artist.
* <p>
* {@link ExpandableListAdapter}s that consider groups and sections as
* synonymous should account for collapsed groups and return an appropriate
* section/position.
*
* @see AbsListView#setFastScrollEnabled(boolean)
*/ */
public interface SectionIndexer { public interface SectionIndexer {
/** /**
* This provides the list view with an array of section objects. In the simplest * Returns an array of objects representing sections of the list. The
* case these are Strings, each containing one letter of the alphabet. * returned array and its contents should be non-null.
* They could be more complex objects that indicate the grouping for the adapter's * <p>
* consumption. The list view will call toString() on the objects to get the * The list view will call toString() on the objects to get the preview text
* preview letter to display while scrolling. * to display while scrolling. For example, an adapter may return an array
* @return the array of objects that indicate the different sections of the list. * of Strings representing letters of the alphabet. Or, it may return an
* array of objects whose toString() methods return their section titles.
*
* @return the array of section objects
*/ */
Object[] getSections(); Object[] getSections();
/** /**
* Provides the starting index in the list for a given section. * Given the index of a section within the array of section objects, returns
* @param section the index of the section to jump to. * the starting position of that section within the adapter.
* @return the starting position of that section. If the section is out of bounds, the * <p>
* position must be clipped to fall within the size of the list. * If the section's starting position is outside of the adapter bounds, the
* position must be clipped to fall within the size of the adapter.
*
* @param sectionIndex the index of the section within the array of section
* objects
* @return the starting position of that section within the adapter,
* constrained to fall within the adapter bounds
*/ */
int getPositionForSection(int section); int getPositionForSection(int sectionIndex);
/** /**
* This is a reverse mapping to fetch the section index for a given position * Given a position within the adapter, returns the index of the
* in the list. * corresponding section within the array of section objects.
* @param position the position for which to return the section * <p>
* @return the section index. If the position is out of bounds, the section index * If the section index is outside of the section array bounds, the index
* must be clipped to fall within the size of the section array. * must be clipped to fall within the size of the section array.
* <p>
* For example, consider an indexer where the section at array index 0
* starts at adapter position 100. Calling this method with position 10,
* which is before the first section, must return index 0.
*
* @param position the position within the adapter for which to return the
* corresponding section index
* @return the index of the corresponding section within the array of
* section objects, constrained to fall within the array bounds
*/ */
int getSectionForPosition(int position); int getSectionForPosition(int position);
} }