/** * Gets empty item view * @return the cached empty view */ public View getEmptyItem() { return getCachedView(emptyItems); }
/** * Invalidates wheel * @param clearCaches if true then cached views will be clear */ public void invalidateWheel(boolean clearCaches) { if (clearCaches) { recycle.clearAll(); if (itemsLayout != null) { itemsLayout.removeAllViews(); } scrollingOffset = 0; } else if (itemsLayout != null) { // cache all items recycle.recycleItems(itemsLayout, firstItem, new ItemsRange()); } invalidate(); }
/** * Returns view for specified item * @param index the item index * @return item view or empty view if index is out of bounds */ private View getItemView(int index) { if (viewAdapter == null || viewAdapter.getItemsCount() == 0) { return null; } int count = viewAdapter.getItemsCount(); if (!isValidItemIndex(index)) { return viewAdapter.getEmptyItem(recycle.getEmptyItem(), itemsLayout); } else { while (index < 0) { index = count + index; } } index %= count; return viewAdapter.getItem(index, recycle.getItem(), itemsLayout); }
/** * Builds view for measuring */ private void buildViewForMeasuring() { // clear all items if (itemsLayout != null) { recycle.recycleItems(itemsLayout, firstItem, new ItemsRange()); } else { createItemsLayout(); } // add views int addItems = visibleItems / 2; for (int i = currentItem + addItems; i >= currentItem - addItems; i--) { if (addViewItem(i, true)) { firstItem = i; } } }
/** * Adds view to cache. Determines view type (item view or empty one) by index. * @param view the view to be cached * @param index the index of view */ private void recycleView(View view, int index) { int count = wheel.getViewAdapter().getItemsCount(); if ((index < 0 || index >= count) && !wheel.isCyclic()) { // empty view emptyItems = addView(view, emptyItems); } else { while (index < 0) { index = count + index; } index %= count; items = addView(view, items); } }
/** * Recycles items from specified layout. * There are saved only items not included to specified range. * All the cached items are removed from original layout. * * @param layout the layout containing items to be cached * @param firstItem the number of first item in layout * @param range the range of current wheel items * @return the new value of first item number */ public int recycleItems(LinearLayout layout, int firstItem, ItemsRange range) { int index = firstItem; for (int i = 0; i < layout.getChildCount();) { if (!range.contains(index)) { recycleView(layout.getChildAt(i), index); layout.removeViewAt(i); if (i == 0) { // first item firstItem++; } } else { i++; // go to next item } index++; } return firstItem; }
/** * Invalidates wheel * * @param clearCaches * if true then cached views will be clear */ public void invalidateWheel(boolean clearCaches) { if (clearCaches) { recycle.clearAll(); if (itemsLayout != null) { itemsLayout.removeAllViews(); } scrollingOffset = 0; } else if (itemsLayout != null) { // cache all items recycle.recycleItems(itemsLayout, firstItem, new ItemsRange()); } invalidate(); }
/** * Returns view for specified item * * @param index * the item index * @return item view or empty view if index is out of bounds */ private View getItemView(int index) { if (viewAdapter == null || viewAdapter.getItemsCount() == 0) { return null; } int count = viewAdapter.getItemsCount(); if (!isValidItemIndex(index)) { return viewAdapter.getEmptyItem(recycle.getEmptyItem(), itemsLayout); } else { while (index < 0) { index = count + index; } } index %= count; return viewAdapter.getItem(index, recycle.getItem(), itemsLayout); }
/** * Builds view for measuring */ private void buildViewForMeasuring() { // clear all items if (itemsLayout != null) { recycle.recycleItems(itemsLayout, firstItem, new ItemsRange()); } else { createItemsLayout(); } // add views int addItems = visibleItems / 2; for (int i = currentItem + addItems; i >= currentItem - addItems; i--) { if (addViewItem(i, true)) { firstItem = i; } } }
/** * Adds view to cache. Determines view type (item view or empty one) by * index. * * @param view * the view to be cached * @param index * the index of view */ private void recycleView(View view, int index) { int count = wheel.getViewAdapter().getItemsCount(); if ((index < 0 || index >= count) && !wheel.isCyclic()) { // empty view emptyItems = addView(view, emptyItems); } else { while (index < 0) { index = count + index; } index %= count; items = addView(view, items); } }
/** * Recycles items from specified layout. There are saved only items not * included to specified range. All the cached items are removed from * original layout. * * @param layout * the layout containing items to be cached * @param firstItem * the number of first item in layout * @param range * the range of current wheel items * @return the new value of first item number */ public int recycleItems(LinearLayout layout, int firstItem, ItemsRange range) { int index = firstItem; for (int i = 0; i < layout.getChildCount();) { if (!range.contains(index)) { recycleView(layout.getChildAt(i), index); layout.removeViewAt(i); if (i == 0) { // first item firstItem++; } } else { i++; // go to next item } index++; } return firstItem; }
/** * Gets empty item view * * @return the cached empty view */ public View getEmptyItem() { return getCachedView(emptyItems); }
ItemsRange range = getItemsRange(); if (itemsLayout != null) { int first = recycle.recycleItems(itemsLayout, firstItem, range); updated = firstItem != first; firstItem = first;
/** * Gets item view * @return the cached view */ public View getItem() { return getCachedView(items); }
ItemsRange range = getItemsRange(); if (itemsLayout != null) { int first = recycle.recycleItems(itemsLayout, firstItem, range); updated = firstItem != first; firstItem = first;
/** * Gets item view * * @return the cached view */ public View getItem() { return getCachedView(items); }