Java Code Examples for android.widget.SectionIndexer

The following are top voted examples for showing how to use android.widget.SectionIndexer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: PinnedSectionListView.java   Source Code and License 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 2
Project: AndroidMuseumBleManager   File: MergeAdapter.java   Source Code and License 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 3
Project: AndroidMuseumBleManager   File: MergeAdapter.java   Source Code and License 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 4
Project: boohee_v5.6   File: PinnedSectionListView.java   Source Code and License 6 votes vote down vote up
private int findCurrentSectionPosition(int fromPosition) {
    PinnedSectionListAdapter adapter = (PinnedSectionListAdapter) getAdapter();
    if (adapter instanceof SectionIndexer) {
        SectionIndexer indexer = (SectionIndexer) adapter;
        int itemPosition = indexer.getPositionForSection(indexer.getSectionForPosition
                (fromPosition));
        if (adapter.isItemViewTypePinned(adapter.getItemViewType(itemPosition))) {
            return itemPosition;
        }
    }
    for (int position = fromPosition; position >= 0; position--) {
        if (adapter.isItemViewTypePinned(adapter.getItemViewType(position))) {
            return position;
        }
    }
    return -1;
}
 
Example 5
Project: Idea-ChainSelector   File: PinnedSectionListView.java   Source Code and License 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 6
Project: CitySelct   File: PinnedSectionListView.java   Source Code and License 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 7
Project: EsperantoRadio   File: PinnedSectionListView.java   Source Code and 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 8
Project: MediaManager   File: MergeAdapter.java   Source Code and License 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 9
Project: MediaManager   File: MergeAdapter.java   Source Code and License 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.size() == 0) {
        return (null);
    }

    return (sections.toArray(new Object[sections.size()]));
}
 
Example 10
Project: BLE   File: MergeAdapter.java   Source Code and License 6 votes vote down vote up
public int getPositionForSection(int section) {
    int position = 0;

    ListAdapter piece;
    for (Iterator i$ = this.getPieces().iterator(); i$.hasNext(); position += piece.getCount()) {
        piece = (ListAdapter) i$.next();
        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);
            }

            if (sections != null) {
                section -= numSections;
            }
        }
    }

    return 0;
}
 
Example 11
Project: BLE   File: MergeAdapter.java   Source Code and License 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 12
Project: BLE   File: MergeAdapter.java   Source Code and License 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 13
Project: SecretBrand   File: PinnedSectionListView.java   Source Code and 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=Math.min(fromPosition,adapter.getCount()-1); position>=0; position--) {
		int viewType = adapter.getItemViewType(position);
		if (isItemViewTypePinned(adapter, viewType)) return position;
	}
	return -1; // no candidate found
}
 
Example 14
Project: AndroidWeekly   File: PinnedSectionListView.java   Source Code and License 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 15
Project: BigApp_Discuz_Android   File: PinnedSectionListView.java   Source Code and 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 16
Project: android-open-project-demo-master   File: PinnedSectionListView.java   Source Code and 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 17
Project: AndroidBleManager   File: MergeAdapter.java   Source Code and License 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 18
Project: AndroidBleManager   File: MergeAdapter.java   Source Code and License 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 19
Project: SelectCity-master   File: PinnedSectionListView.java   Source Code and License 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 20
Project: eshow-android   File: AbLetterFilterListView.java   Source Code and License 6 votes vote down vote up
@Override
protected void onFinishInflate() {
	super.onFinishInflate();
	int count = getChildCount();
	if (count < 1) {
		throw new IllegalArgumentException("this layout must contain 1 child views,and AdapterView  must in the first position!");
	}
	View view = this.getChildAt(0);
	AdapterView<?> adapterView = null;
	if (view instanceof AdapterView<?>) {
		adapterView = (AdapterView<?>) view;
		listView = (ListView)adapterView;
		sectionIndexter = (SectionIndexer) listView.getAdapter();
		letterView = new LetterView(context);
		letterView.setListView(listView);
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(60, ViewGroup.LayoutParams.WRAP_CONTENT);
		layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,RelativeLayout.TRUE);
		layoutParams.topMargin=10;
		layoutParams.rightMargin=10;
		layoutParams.bottomMargin=10;
		this.addView(letterView,layoutParams);
	}
	if (adapterView == null) {
		throw new IllegalArgumentException("must contain a AdapterView in this layout!");
	}
}
 
Example 21
Project: MediaManager   File: MergeAdapter.java   Source Code and License 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 22
Project: MediaManager   File: MergeAdapter.java   Source Code and License 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.size() == 0) {
        return (null);
    }

    return (sections.toArray(new Object[sections.size()]));
}
 
Example 23
Project: FMTech   File: dxb.java   Source Code and License 6 votes vote down vote up
final void d()
{
  ListAdapter localListAdapter = (ListAdapter)this.f.getAdapter();
  this.C = null;
  if ((localListAdapter instanceof HeaderViewListAdapter))
  {
    this.w = ((HeaderViewListAdapter)localListAdapter).getHeadersCount();
    localListAdapter = ((HeaderViewListAdapter)localListAdapter).getWrappedAdapter();
  }
  this.B = localListAdapter;
  if ((localListAdapter instanceof SectionIndexer))
  {
    this.C = ((SectionIndexer)localListAdapter);
    this.z = this.C.getSections();
    return;
  }
  this.z = new String[] { " " };
}
 
Example 24
Project: love   File: PinnedSectionListView.java   Source Code and 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 25
Project: shikimori   File: PinnedSectionGridView.java   Source Code and License 6 votes vote down vote up
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;
	}
	return -1; // no candidate found
}
 
Example 26
Project: shikimori   File: PinnedSectionListView.java   Source Code and License 6 votes vote down vote up
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;
	}
	return -1; // no candidate found
}
 
Example 27
Project: Infodota   File: PinnedSectionListView.java   Source Code and 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=Math.min(fromPosition,adapter.getCount()-1); position>=0; position--) {
		int viewType = adapter.getItemViewType(position);
		if (isItemViewTypePinned(adapter, viewType)) return position;
	}
	return -1; // no candidate found
}
 
Example 28
Project: androidsummary   File: AbLetterFilterListView.java   Source Code and License 6 votes vote down vote up
@Override
protected void onFinishInflate() {
	super.onFinishInflate();
	int count = getChildCount();
	if (count < 1) {
		throw new IllegalArgumentException("this layout must contain 1 child views,and AdapterView  must in the first position!");
	}
	View view = this.getChildAt(0);
	AdapterView<?> adapterView = null;
	if (view instanceof AdapterView<?>) {
		adapterView = (AdapterView<?>) view;
		listView = (ListView)adapterView;
		sectionIndexter = (SectionIndexer) listView.getAdapter();
		letterView = new LetterView(context);
		letterView.setListView(listView);
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(60, ViewGroup.LayoutParams.WRAP_CONTENT);
		layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,RelativeLayout.TRUE);
		layoutParams.topMargin=10;
		layoutParams.rightMargin=10;
		layoutParams.bottomMargin=10;
		this.addView(letterView,layoutParams);
	}
	if (adapterView == null) {
		throw new IllegalArgumentException("must contain a AdapterView in this layout!");
	}
}
 
Example 29
Project: like_googleplus_layout   File: StickyListHeadersListView.java   Source Code and License 6 votes vote down vote up
private AdapterWrapper wrapAdapter(ListAdapter adapter)
{
	AdapterWrapper wrapper;
	if (adapter instanceof SectionIndexer)
	{
		wrapper = new SectionIndexerAdapterWrapper(getContext(), (StickyHeadersAdapter) adapter);
	}
	else
	{
		wrapper = new AdapterWrapper(getContext(), (StickyHeadersAdapter) adapter);
	}
	wrapper.setDivider(mDivider);
	wrapper.setDividerHeight(mDividerHeight);
	wrapper.registerDataSetObserver(mDataSetChangedObserver);
	wrapper.setOnHeaderClickListener(mAdapterHeaderClickListener);
	return wrapper;
}
 
Example 30
Project: PullToRefresh-PinnedSection-ListView   File: PinnedSectionListView.java   Source Code and 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 31
Project: mimicry   File: MergeAdapter.java   Source Code and License 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 32
Project: mimicry   File: MergeAdapter.java   Source Code and License 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 33
Project: android-woodenbox   File: PinnedSectionListView.java   Source Code and 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 34
Project: android-open-project-demo   File: PinnedSectionListView.java   Source Code and 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 35
Project: GameRecorder   File: PinnedSectionListView.java   Source Code and 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--) {
		if(position >= adapter.getCount())break;//fix by bitjjj
		int viewType = adapter.getItemViewType(position);
		if (isItemViewTypePinned(adapter, viewType)) return position;
	}
	return -1; // no candidate found
}
 
Example 36
Project: transdroid   File: MergeAdapter.java   Source Code and License 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 37
Project: transdroid   File: MergeAdapter.java   Source Code and License 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 38
Project: SimpleExplorer   File: MergeAdapter.java   Source Code and License 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 39
Project: SimpleExplorer   File: MergeAdapter.java   Source Code and License 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 40
Project: ZalartAndroid   File: MergeAdapter.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 41
Project: ZalartAndroid   File: MergeAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public 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(new String[0]);
  }

  return(sections.toArray(new Object[0]));
}
 
Example 42
Project: ZalartAndroid   File: BaseSectionListAdapter.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 43
Project: ZalartAndroid   File: BaseSectionListAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public 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 (new String[0]);
	}

	return (sections.toArray(new Object[0]));
}
 
Example 44
Project: Kernel-Tuner   File: PinnedSectionListView.java   Source Code and 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 45
Project: Joszolgalat_Android_App   File: BaseSectionListAdapter.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 46
Project: Joszolgalat_Android_App   File: BaseSectionListAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public 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 (new String[0]);
	}

	return (sections.toArray(new Object[0]));
}
 
Example 47
Project: Joszolgalat_Android_App   File: MergeAdapter.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 48
Project: Joszolgalat_Android_App   File: MergeAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public 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(new String[0]);
  }

  return(sections.toArray(new Object[0]));
}
 
Example 49
Project: pinned-section-listview   File: PinnedSectionListView.java   Source Code and License 6 votes vote down vote up
private int findCurrentSectionPosition(int fromPosition) {
	PinnedSectionListAdapter adapter = (PinnedSectionListAdapter) 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 (adapter.isItemViewTypePinned(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 (adapter.isItemViewTypePinned(viewType)) return position;
	}
	return -1; // no candidate found
}
 
Example 50
Project: Swface   File: StickyListHeadersListView.java   Source Code and License 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 51
Project: AlphabetIndex-Fast-Scroll-RecyclerView   File: IndexFastScrollRecyclerSection.java   Source Code and License 5 votes vote down vote up
public void setAdapter(RecyclerView.Adapter adapter) {
    if (adapter instanceof SectionIndexer) {
        adapter.registerAdapterDataObserver(this);
        mIndexer = (SectionIndexer) adapter;
        mSections = (String[]) mIndexer.getSections();
    }
}
 
Example 52
Project: Hotspot-master-devp   File: StickyListHeadersListView.java   Source Code and License 5 votes vote down vote up
public void setAdapter(StickyListHeadersAdapter adapter) {
    if (adapter == 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 53
Project: AndroidMuseumBleManager   File: MergeAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public int getSectionForPosition(int position) {
    int section = 0;

    for (ListAdapter piece : getPieces()) {
        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 54
Project: MediaManager   File: MergeAdapter.java   Source Code and License 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 55
Project: ListViewAnimations   File: BaseAdapterDecorator.java   Source Code and License 5 votes vote down vote up
@Override
public int getPositionForSection(final int sectionIndex) {
    int result = 0;
    if (mDecoratedBaseAdapter instanceof SectionIndexer) {
        result = ((SectionIndexer) mDecoratedBaseAdapter).getPositionForSection(sectionIndex);
    }
    return result;
}
 
Example 56
Project: ListViewAnimations   File: BaseAdapterDecorator.java   Source Code and License 5 votes vote down vote up
@Override
public int getSectionForPosition(final int position) {
    int result = 0;
    if (mDecoratedBaseAdapter instanceof SectionIndexer) {
        result = ((SectionIndexer) mDecoratedBaseAdapter).getSectionForPosition(position);
    }
    return result;
}
 
Example 57
Project: ListViewAnimations   File: BaseAdapterDecorator.java   Source Code and License 5 votes vote down vote up
@Override
@NonNull
public Object[] getSections() {
    Object[] result = new Object[0];
    if (mDecoratedBaseAdapter instanceof SectionIndexer) {
        result = ((SectionIndexer) mDecoratedBaseAdapter).getSections();
    }
    return result;
}
 
Example 58
Project: StickyListHeadersWithRefreshAndLoadMore   File: StickyListHeadersListView.java   Source Code and License 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 59
Project: HPlayer   File: BaseAdapterDecorator.java   Source Code and License 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 60
Project: HPlayer   File: BaseAdapterDecorator.java   Source Code and License 5 votes vote down vote up
@Override
public int getSectionForPosition(final int position) {
    if (mDecoratedBaseAdapter instanceof SectionIndexer) {
        return ((SectionIndexer) mDecoratedBaseAdapter).getSectionForPosition(position);
    }
    return 0;
}