updated = firstItem != range.getFirst() || itemsLayout.getChildCount() != range.getCount(); if (firstItem > range.getFirst() && firstItem <= range.getLast()) { for (int i = firstItem - 1; i >= range.getFirst(); i--) { if (!addViewItem(i, true)) { break; firstItem = range.getFirst(); for (int i = itemsLayout.getChildCount(); i < range.getCount(); i++) { if (!addViewItem(firstItem + i, false) && itemsLayout.getChildCount() == 0) { first++;
/** * 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(); }
/** * 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; }
updated = firstItem != range.getFirst() || itemsLayout.getChildCount() != range.getCount(); if (firstItem > range.getFirst() && firstItem <= range.getLast()) { for (int i = firstItem - 1; i >= range.getFirst(); i--) { if (!addViewItem(i, true)) { break; firstItem = range.getFirst(); for (int i = itemsLayout.getChildCount(); i < range.getCount(); i++) { if (!addViewItem(firstItem + i, false) && itemsLayout.getChildCount() == 0) { first++;
/** * 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(); }
/** * 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; }
/** * 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; } } }
/** * 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; } } }
/** * Calculates range for wheel items * @return the items range */ private ItemsRange getItemsRange() { if (getItemHeight() == 0) { return null; } int first = currentItem; int count = 1; while (count * getItemHeight() < getHeight()) { first--; count += 2; // top + bottom items } if (scrollingOffset != 0) { if (scrollingOffset > 0) { first--; } count++; // process empty items above the first or below the second int emptyItems = scrollingOffset / getItemHeight(); first -= emptyItems; count += Math.asin(emptyItems); } return new ItemsRange(first, count); }
/** * Calculates range for wheel items * * @return the items range */ private ItemsRange getItemsRange() { if (getItemHeight() == 0) { return null; } int first = currentItem; int count = 1; while (count * getItemHeight() < getHeight()) { first--; count += 2; // top + bottom items } if (scrollingOffset != 0) { if (scrollingOffset > 0) { first--; } count++; // process empty items above the first or below the second int emptyItems = scrollingOffset / getItemHeight(); first -= emptyItems; count += Math.asin(emptyItems); } return new ItemsRange(first, count); }