use of android.widget.SectionIndexer in project philm by chrisbanes.
the class PinnedSectionListView method findCurrentSectionPosition.
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;
}
}
// no candidate found
return -1;
}
use of android.widget.SectionIndexer in project KeepScore by nolanlawson.
the class CustomFastScrollView 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;
}
}
use of android.widget.SectionIndexer in project AStickyHeader by DWorkS.
the class PinnedSectionListView method findCurrentSectionPosition.
int findCurrentSectionPosition(int fromPosition) {
PinnedSectionListAdapter adapter = getPinnedAdapter();
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, itemPosition)) {
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, position))
return position;
}
// no candidate found
return -1;
}
use of android.widget.SectionIndexer in project AStickyHeader by DWorkS.
the class PinnedSectionGridView method findCurrentSectionPosition.
int findCurrentSectionPosition(int fromPosition) {
PinnedSectionGridAdapter adapter = getPinnedAdapter();
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, itemPosition)) {
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, position))
return position;
}
// no candidate found
return -1;
}
use of android.widget.SectionIndexer in project Ushahidi_Android by ushahidi.
the class BaseSectionListAdapter method getPositionForSection.
@Override
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);
}
Aggregations