Search in sources :

Example 1 with SectionIndexer

use of android.widget.SectionIndexer in project HoloEverywhere by Prototik.

the class FastScroller method getSectionsFromIndexer.

void getSectionsFromIndexer() {
    ListAdapter adapter = mList.getAdapter();
    mSectionIndexer = null;
    if (adapter instanceof HeaderViewListAdapter) {
        mListOffset = ((HeaderViewListAdapter) adapter).getHeadersCount();
    }
    if (adapter instanceof ListAdapterWrapper) {
        adapter = ((ListAdapterWrapper) adapter).getWrappedAdapter();
    }
    if (adapter instanceof WrapperListAdapter) {
        adapter = ((WrapperListAdapter) adapter).getWrappedAdapter();
    }
    if (adapter instanceof ExpandableListConnector) {
        ExpandableListAdapter expAdapter = ((ExpandableListConnector) adapter).getAdapter();
        if (expAdapter instanceof SectionIndexer) {
            mSectionIndexer = (SectionIndexer) expAdapter;
            mListAdapter = adapter;
            mSections = mSectionIndexer.getSections();
        }
    } else {
        if (adapter instanceof SectionIndexer) {
            mSectionIndexer = (SectionIndexer) adapter;
            mSections = mSectionIndexer.getSections();
            if (mSections == null) {
                mSections = new String[] { " " };
            }
        } else {
            mSections = new String[] { " " };
        }
    }
    mListAdapter = adapter;
}
Also used : ExpandableListAdapter(android.widget.ExpandableListAdapter) SectionIndexer(android.widget.SectionIndexer) ExpandableListAdapter(android.widget.ExpandableListAdapter) ListAdapter(android.widget.ListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter)

Example 2 with SectionIndexer

use of android.widget.SectionIndexer in project KeepScore by nolanlawson.

the class CustomFastScrollView method getSections.

private void getSections() {
    Adapter adapter = mList.getAdapter();
    if (adapter instanceof HeaderViewListAdapter) {
        mListOffset = ((HeaderViewListAdapter) adapter).getHeadersCount();
        adapter = ((HeaderViewListAdapter) adapter).getWrappedAdapter();
    }
    if (adapter instanceof SectionIndexer) {
        mListAdapter = (BaseAdapter) adapter;
        mSections = ((SectionIndexer) mListAdapter).getSections();
    }
}
Also used : HeaderViewListAdapter(android.widget.HeaderViewListAdapter) Adapter(android.widget.Adapter) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) BaseAdapter(android.widget.BaseAdapter) SectionIndexer(android.widget.SectionIndexer)

Example 3 with SectionIndexer

use of android.widget.SectionIndexer in project SuperSaiyanScrollView by nolanlawson.

the class SuperSaiyanScrollView method scrollTo.

private void scrollTo(float position) {
    int count = mList.getCount();
    mScrollCompleted = false;
    final Object[] sections = mSections;
    int sectionIndex;
    if (sections != null && sections.length > 1) {
        final int nSections = sections.length;
        int section = (int) (position * nSections);
        if (section >= nSections) {
            section = nSections - 1;
        }
        sectionIndex = section;
        final SectionIndexer baseAdapter = (SectionIndexer) mListAdapter;
        int index = baseAdapter.getPositionForSection(section);
        // Given the expected section and index, the following code will
        // try to account for missing sections (no names starting with..)
        // It will compute the scroll space of surrounding empty sections
        // and interpolate the currently visible letter's range across the
        // available space, so that there is always some list movement while
        // the user moves the thumb.
        int nextIndex = count;
        int prevIndex = index;
        int prevSection = section;
        int nextSection = section + 1;
        // Assume the next section is unique
        if (section < nSections - 1) {
            nextIndex = baseAdapter.getPositionForSection(section + 1);
        }
        // Find the previous index if we're slicing the previous section
        if (nextIndex == index) {
            // Non-existent letter
            while (section > 0) {
                section--;
                prevIndex = baseAdapter.getPositionForSection(section);
                if (prevIndex != index) {
                    prevSection = section;
                    sectionIndex = section;
                    break;
                }
            }
        }
        // Find the next index, in case the assumed next index is not
        // unique. For instance, if there is no P, then request for P's 
        // position actually returns Q's. So we need to look ahead to make
        // sure that there is really a Q at Q's position. If not, move 
        // further down...
        int nextNextSection = nextSection + 1;
        while (nextNextSection < nSections && baseAdapter.getPositionForSection(nextNextSection) == nextIndex) {
            nextNextSection++;
            nextSection++;
        }
        // Compute the beginning and ending scroll range percentage of the
        // currently visible letter. This could be equal to or greater than
        // (1 / nSections). 
        float fPrev = (float) prevSection / nSections;
        float fNext = (float) nextSection / nSections;
        index = prevIndex + (int) ((nextIndex - prevIndex) * (position - fPrev) / (fNext - fPrev));
        // Don't overflow
        if (index > count - 1)
            index = count - 1;
        mList.setSelectionFromTop(index + mListOffset, 0);
    } else {
        int index = (int) (position * count);
        mList.setSelectionFromTop(index + mListOffset, 0);
        sectionIndex = -1;
    }
    if (sectionIndex >= 0) {
        String text = mSectionText = sections[sectionIndex].toString();
        mDrawOverlay = (text.length() != 1 || text.charAt(0) != ' ') && sectionIndex < sections.length;
    } else {
        mDrawOverlay = false;
    }
}
Also used : SectionIndexer(android.widget.SectionIndexer) Paint(android.graphics.Paint)

Example 4 with SectionIndexer

use of android.widget.SectionIndexer in project SuperSaiyanScrollView by nolanlawson.

the class SuperSaiyanScrollView method getSections.

private void getSections() {
    Adapter adapter = mList.getAdapter();
    if (adapter instanceof HeaderViewListAdapter) {
        mListOffset = ((HeaderViewListAdapter) adapter).getHeadersCount();
        adapter = ((HeaderViewListAdapter) adapter).getWrappedAdapter();
    }
    if (adapter instanceof SectionIndexer) {
        mListAdapter = (BaseAdapter) adapter;
        mSections = ((SectionIndexer) mListAdapter).getSections();
    }
}
Also used : HeaderViewListAdapter(android.widget.HeaderViewListAdapter) Adapter(android.widget.Adapter) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) BaseAdapter(android.widget.BaseAdapter) SectionIndexer(android.widget.SectionIndexer)

Example 5 with SectionIndexer

use of android.widget.SectionIndexer in project routerkeygenAndroid by routerkeygen.

the class PinnedSectionListView method findCurrentSectionPosition.

private int findCurrentSectionPosition(int fromPosition) {
    ListAdapter adapter = getAdapter();
    // dataset has changed, no candidate
    if (fromPosition >= adapter.getCount())
        return -1;
    if (adapter instanceof SectionIndexer) {
        // try fast way by asking section indexer
        SectionIndexer indexer = (SectionIndexer) adapter;
        int sectionPosition = indexer.getSectionForPosition(fromPosition);
        int itemPosition = indexer.getPositionForSection(sectionPosition);
        int typeView = adapter.getItemViewType(itemPosition);
        if (isItemViewTypePinned(adapter, typeView)) {
            return itemPosition;
        }
    // else, no luck
    }
    // try slow way by looking through to the next section item above
    for (int position = fromPosition; position >= 0; position--) {
        int viewType = adapter.getItemViewType(position);
        if (isItemViewTypePinned(adapter, viewType))
            return position;
    }
    // no candidate found
    return -1;
}
Also used : SectionIndexer(android.widget.SectionIndexer) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter)

Aggregations

SectionIndexer (android.widget.SectionIndexer)17 ListAdapter (android.widget.ListAdapter)10 HeaderViewListAdapter (android.widget.HeaderViewListAdapter)7 Paint (android.graphics.Paint)3 Adapter (android.widget.Adapter)2 BaseAdapter (android.widget.BaseAdapter)2 ExpandableListAdapter (android.widget.ExpandableListAdapter)1 WrapperListAdapter (android.widget.WrapperListAdapter)1 AdapterWrapper (com.emilsjolander.components.stickylistheaders.AdapterWrapper)1 SectionIndexerAdapterWrapper (com.emilsjolander.components.stickylistheaders.SectionIndexerAdapterWrapper)1 StickyListHeadersAdapter (com.emilsjolander.components.stickylistheaders.StickyListHeadersAdapter)1