android.widget.SectionIndexer Java Examples

The following examples show how to use android.widget.SectionIndexer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PinnedSectionListView.java    From PullToRefresh-PinnedSection-ListView with MIT License 6 votes vote down vote up
int findCurrentSectionPosition(int fromPosition) {
	ListAdapter adapter = getAdapter();

	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;
	}
	return -1; // no candidate found
}
 
Example #2
Source File: MergeAdapter.java    From SimpleExplorer with GNU General Public License v3.0 6 votes vote down vote up
public Object[] getSections() {
    ArrayList<Object> sections = new ArrayList<>();

    for (ListAdapter piece : pieces) {
        if (piece instanceof SectionIndexer) {
            Object[] curSections = ((SectionIndexer) piece).getSections();

            if (curSections != null) {
                Collections.addAll(sections, curSections);
            }
        }
    }

    if (sections.isEmpty()) {
        return null;
    }

    return sections.toArray(new Object[sections.size()]);
}
 
Example #3
Source File: MergeAdapter.java    From SimpleExplorer with GNU General Public License v3.0 6 votes vote down vote up
public int getPositionForSection(int section) {
    int position = 0;

    for (ListAdapter piece : pieces) {
        if (piece instanceof SectionIndexer) {
            Object[] sections = ((SectionIndexer) piece).getSections();
            int numSections = 0;

            if (sections != null) {
                numSections = sections.length;
            }

            if (section < numSections) {
                return (position + ((SectionIndexer) piece)
                        .getPositionForSection(section));
            } else if (sections != null) {
                section -= numSections;
            }
        }

        position += piece.getCount();
    }

    return 0;
}
 
Example #4
Source File: MergeAdapter.java    From BLE with Apache License 2.0 6 votes vote down vote up
public Object[] getSections() {
    ArrayList sections = new ArrayList();
    Iterator i$ = this.getPieces().iterator();

    while (i$.hasNext()) {
        ListAdapter piece = (ListAdapter) i$.next();
        if (piece instanceof SectionIndexer) {
            Object[] curSections = ((SectionIndexer) piece).getSections();
            if (curSections != null) {
                Collections.addAll(sections, curSections);
            }
        }
    }

    if (sections.size() == 0) {
        return new String[0];
    } else {
        return sections.toArray(new Object[sections.size()]);
    }
}
 
Example #5
Source File: MergeAdapter.java    From BLE with Apache License 2.0 6 votes vote down vote up
public int getSectionForPosition(int position) {
    int section = 0;

    int size;
    for (Iterator i$ = this.getPieces().iterator(); i$.hasNext(); position -= size) {
        ListAdapter piece = (ListAdapter) i$.next();
        size = piece.getCount();
        if (position < size) {
            if (piece instanceof SectionIndexer) {
                return section + ((SectionIndexer) piece).getSectionForPosition(position);
            }

            return 0;
        }

        if (piece instanceof SectionIndexer) {
            Object[] sections = ((SectionIndexer) piece).getSections();
            if (sections != null) {
                section += sections.length;
            }
        }
    }

    return 0;
}
 
Example #6
Source File: PinnedSectionListView.java    From Kernel-Tuner with GNU General Public License v3.0 6 votes vote down vote up
int findCurrentSectionPosition(int fromPosition) {
	ListAdapter adapter = getAdapter();

	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;
	}
	return -1; // no candidate found
}
 
Example #7
Source File: PinnedSectionListView.java    From AndroidWeekly with Apache License 2.0 6 votes vote down vote up
int findCurrentSectionPosition(int fromPosition) {
    ListAdapter adapter = getAdapter();

    if (fromPosition >= adapter.getCount()) return -1; // dataset has changed, no candidate

    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;
    }
    return -1; // no candidate found
}
 
Example #8
Source File: PinnedSectionListView.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
int findCurrentSectionPosition(int fromPosition) {
    ListAdapter adapter = getAdapter();

    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;
    }
    return -1; // no candidate found
}
 
Example #9
Source File: PinnedSectionListView.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
int findCurrentSectionPosition(int fromPosition) {
    ListAdapter adapter = getAdapter();

    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;
    }
    return -1; // no candidate found
}
 
Example #10
Source File: MergeAdapter.java    From AndroidBleManager with Apache License 2.0 6 votes vote down vote up
@Override
public int getPositionForSection(int section) {
    int position=0;

    for (ListAdapter piece : getPieces()) {
        if (piece instanceof SectionIndexer) {
            Object[] sections=((SectionIndexer)piece).getSections();
            int numSections=0;

            if (sections != null) {
                numSections=sections.length;
            }

            if (section < numSections) {
                return(position + ((SectionIndexer)piece).getPositionForSection(section));
            }
            else if (sections != null) {
                section-=numSections;
            }
        }

        position+=piece.getCount();
    }

    return(0);
}
 
Example #11
Source File: MergeAdapter.java    From AndroidBleManager with Apache License 2.0 6 votes vote down vote up
@Override
public Object[] getSections() {
    ArrayList<Object> sections=new ArrayList<Object>();

    for (ListAdapter piece : getPieces()) {
        if (piece instanceof SectionIndexer) {
            Object[] curSections=((SectionIndexer)piece).getSections();

            if (curSections != null) {
                Collections.addAll(sections, curSections);
            }
        }
    }

    if (sections.size() == 0) {
        return(new String[0]);
    }

    return(sections.toArray(new Object[0]));
}
 
Example #12
Source File: PinnedSectionListView.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
int findCurrentSectionPosition(int fromPosition) {
	ListAdapter adapter = getAdapter();

	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;
	}
	return -1; // no candidate found
}
 
Example #13
Source File: MergeAdapter.java    From mimicry with Apache License 2.0 6 votes vote down vote up
public final Object[] getSections() {
	ArrayList<Object> sections = new ArrayList<Object>();

	for (ListAdapter piece : pieces) {
		if (piece instanceof SectionIndexer) {
			Object[] curSections = ((SectionIndexer) piece).getSections();

			if (curSections != null) {
				for (Object section : curSections) {
					sections.add(section);
				}
			}
		}
	}

	if (sections.size() == 0) {
		return (null);
	}

	return (sections.toArray(new Object[0]));
}
 
Example #14
Source File: PinnedSectionListView.java    From Contacts with MIT License 6 votes vote down vote up
int findCurrentSectionPosition(int fromPosition) {
	ListAdapter adapter = getAdapter();

	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;
	}
	return -1; // no candidate found
}
 
Example #15
Source File: MergeAdapter.java    From mimicry with Apache License 2.0 6 votes vote down vote up
public final int getPositionForSection(int section) {
	int position = 0;

	for (ListAdapter piece : pieces) {
		if (piece instanceof SectionIndexer) {
			Object[] sections = ((SectionIndexer) piece).getSections();
			int numSections = 0;

			if (sections != null) {
				numSections = sections.length;
			}

			if (section < numSections) {
				return (position + ((SectionIndexer) piece).getPositionForSection(section));
			} else if (sections != null) {
				section -= numSections;
			}
		}

		position += piece.getCount();
	}

	return (0);
}
 
Example #16
Source File: IndexScroller.java    From weixin with Apache License 2.0 5 votes vote down vote up
/**
 * 设置右侧索引条数据
 * 
 * @param adapter
 */
public void setAdapter(Adapter adapter) {
	if (adapter instanceof SectionIndexer) {
		mIndexer = (SectionIndexer) adapter;
		mSections = (String[]) mIndexer.getSections();
	}
}
 
Example #17
Source File: StickyListHeadersListView.java    From Swface with Apache License 2.0 5 votes vote down vote up
public void setAdapter(StickyListHeadersAdapter adapter) {
    if (adapter == null) {
        if (mAdapter instanceof SectionIndexerAdapterWrapper) {
            ((SectionIndexerAdapterWrapper) mAdapter).mSectionIndexerDelegate = null;
        }
        if (mAdapter != null) {
            mAdapter.mDelegate = null;
        }
        mList.setAdapter(null);
        clearHeader();
        return;
    }
    if (mAdapter != null) {
        mAdapter.unregisterDataSetObserver(mDataSetObserver);
    }

    if (adapter instanceof SectionIndexer) {
        mAdapter = new SectionIndexerAdapterWrapper(getContext(), adapter);
    } else {
        mAdapter = new AdapterWrapper(getContext(), adapter);
    }
    mDataSetObserver = new AdapterWrapperDataSetObserver();
    mAdapter.registerDataSetObserver(mDataSetObserver);

    if (mOnHeaderClickListener != null) {
        mAdapter.setOnHeaderClickListener(new AdapterWrapperHeaderClickHandler());
    } else {
        mAdapter.setOnHeaderClickListener(null);
    }

    mAdapter.setDivider(mDivider, mDividerHeight);

    mList.setAdapter(mAdapter);
    clearHeader();
}
 
Example #18
Source File: StickyListHeadersListView.java    From FimiX8-RE with MIT License 5 votes vote down vote up
private AdapterWrapper wrapAdapter(ListAdapter adapter) {
    AdapterWrapper wrapper;
    if (adapter instanceof SectionIndexer) {
        wrapper = new SectionIndexerAdapterWrapper(getContext(), (StickyListHeadersAdapter) adapter);
    } else {
        wrapper = new AdapterWrapper(getContext(), (StickyListHeadersAdapter) adapter);
    }
    wrapper.setDivider(this.mDivider);
    wrapper.setDividerHeight(this.mDividerHeight);
    wrapper.registerDataSetObserver(this.mDataSetChangedObserver);
    wrapper.setOnHeaderClickListener(this.mAdapterHeaderClickListener);
    return wrapper;
}
 
Example #19
Source File: BaseAdapterDecorator.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
@Override
public int getPositionForSection(int section) {
	if (mDecoratedBaseAdapter instanceof SectionIndexer) {
		return ((SectionIndexer) mDecoratedBaseAdapter).getPositionForSection(section);
	}
	return 0;
}
 
Example #20
Source File: BaseAdapterDecorator.java    From HPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public int getSectionForPosition(final int position) {
    if (mDecoratedBaseAdapter instanceof SectionIndexer) {
        return ((SectionIndexer) mDecoratedBaseAdapter).getSectionForPosition(position);
    }
    return 0;
}
 
Example #21
Source File: BaseAdapterDecorator.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
@Override
public int getSectionForPosition(int position) {
	if (mDecoratedBaseAdapter instanceof SectionIndexer) {
		return ((SectionIndexer) mDecoratedBaseAdapter).getSectionForPosition(position);
	}
	return 0;
}
 
Example #22
Source File: BaseAdapterDecorator.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
@Override
public Object[] getSections() {
	if (mDecoratedBaseAdapter instanceof SectionIndexer) {
		return ((SectionIndexer) mDecoratedBaseAdapter).getSections();
	}
	return null;
}
 
Example #23
Source File: MergeAdapter.java    From SimpleExplorer with GNU General Public License v3.0 5 votes vote down vote up
public int getSectionForPosition(int position) {
    int section = 0;

    for (ListAdapter piece : pieces) {
        int size = piece.getCount();

        if (position < size) {
            if (piece instanceof SectionIndexer) {
                return (section + ((SectionIndexer) piece)
                        .getSectionForPosition(position));
            }

            return 0;
        } else {
            if (piece instanceof SectionIndexer) {
                Object[] sections = ((SectionIndexer) piece).getSections();

                if (sections != null) {
                    section += sections.length;
                }
            }
        }

        position -= size;
    }

    return 0;
}
 
Example #24
Source File: MergeAdapter.java    From mimicry with Apache License 2.0 5 votes vote down vote up
public final int getSectionForPosition(int position) {
	int section = 0;

	for (ListAdapter piece : pieces) {
		int size = piece.getCount();

		if (position < size) {
			if (piece instanceof SectionIndexer) {
				return (section + ((SectionIndexer) piece).getSectionForPosition(position));
			}

			return (0);
		} else {
			if (piece instanceof SectionIndexer) {
				Object[] sections = ((SectionIndexer) piece).getSections();

				if (sections != null) {
					section += sections.length;
				}
			}
		}

		position -= size;
	}

	return (0);
}
 
Example #25
Source File: BaseAdapterDecorator.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public Object[] getSections() {
	if (mDecoratedBaseAdapter instanceof SectionIndexer) {
		return ((SectionIndexer) mDecoratedBaseAdapter).getSections();
	}
	return null;
}
 
Example #26
Source File: BaseAdapterDecorator.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public int getSectionForPosition(final int position) {
	if (mDecoratedBaseAdapter instanceof SectionIndexer) {
		return ((SectionIndexer) mDecoratedBaseAdapter).getSectionForPosition(position);
	}
	return 0;
}
 
Example #27
Source File: BaseAdapterDecorator.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public int getPositionForSection(final int section) {
	if (mDecoratedBaseAdapter instanceof SectionIndexer) {
		return ((SectionIndexer) mDecoratedBaseAdapter).getPositionForSection(section);
	}
	return 0;
}
 
Example #28
Source File: BaseAdapterDecorator.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public int getSectionForPosition(final int position) {
	if (mDecoratedBaseAdapter instanceof SectionIndexer) {
		return ((SectionIndexer) mDecoratedBaseAdapter).getSectionForPosition(position);
	}
	return 0;
}
 
Example #29
Source File: BaseAdapterDecorator.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public Object[] getSections() {
	if (mDecoratedBaseAdapter instanceof SectionIndexer) {
		return ((SectionIndexer) mDecoratedBaseAdapter).getSections();
	}
	return null;
}
 
Example #30
Source File: BaseAdapterDecorator.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public int getPositionForSection(final int section) {
	if (mDecoratedBaseAdapter instanceof SectionIndexer) {
		return ((SectionIndexer) mDecoratedBaseAdapter).getPositionForSection(section);
	}
	return 0;
}