1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.widget;
18
19/**
20 * Interface that should be implemented on Adapters to enable fast scrolling
21 * in an {@link AbsListView} between sections of the list. A section is a group of list items
22 * to jump to that have something in common. For example, they may begin with the
23 * same letter or they may be songs from the same artist.
24 */
25public interface SectionIndexer {
26    /**
27     * This provides the list view with an array of section objects. In the simplest
28     * case these are Strings, each containing one letter of the alphabet.
29     * They could be more complex objects that indicate the grouping for the adapter's
30     * consumption. The list view will call toString() on the objects to get the
31     * preview letter to display while scrolling.
32     * @return the array of objects that indicate the different sections of the list.
33     */
34    Object[] getSections();
35
36    /**
37     * Provides the starting index in the list for a given section.
38     * @param section the index of the section to jump to.
39     * @return the starting position of that section. If the section is out of bounds, the
40     * position must be clipped to fall within the size of the list.
41     */
42    int getPositionForSection(int section);
43
44    /**
45     * This is a reverse mapping to fetch the section index for a given position
46     * in the list.
47     * @param position the position for which to return the section
48     * @return the section index. If the position is out of bounds, the section index
49     * must be clipped to fall within the size of the section array.
50     */
51    int getSectionForPosition(int position);
52}
53