List of usage examples for android.support.v4.util LongSparseArray clear
public void clear()
From source file:com.devbrackets.android.recyclerext.adapter.header.HeaderAdapterDataObserver.java
/** * Performs a full calculation for the header indices *///w ww . java 2 s . c om protected void calculateHeaderIndices() { List<HeaderItem> items = headerCore.getHeaderItems(); LongSparseArray<Integer> counts = headerCore.getHeaderChildCountMap(); items.clear(); counts.clear(); HeaderItem currentItem = null; for (int i = 0; i < headerApi.getChildCount(); i++) { long id = headerApi.getHeaderId(i); if (id == RecyclerView.NO_ID) { continue; } //Updates the child count for the headerId Integer childCount = counts.get(id); childCount = (childCount == null) ? 1 : childCount + 1; counts.put(id, childCount); //Adds new headers to the list when detected if (currentItem == null || currentItem.getId() != id) { int position = i + (headerCore.showHeaderAsChild ? 0 : items.size()); currentItem = new HeaderItem(id, position); items.add(currentItem); } } }
From source file:com.geecko.QuickLyric.fragment.LocalLyricsFragment.java
public void addObserver(final LongSparseArray<Integer> itemIdTopMap) { final boolean[] firstAnimation = { true }; final ViewTreeObserver observer = megaListView.getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { public boolean onPreDraw() { observer.removeOnPreDrawListener(this); firstAnimation[0] = true;//from w w w . j av a 2s .com int firstVisiblePosition = megaListView.getFirstVisiblePosition(); for (int i = 0; i < megaListView.getChildCount(); ++i) { final View child = megaListView.getChildAt(i); int position = firstVisiblePosition + i; long itemId = getListView().getAdapter().getItemId(position); Integer formerTop = itemIdTopMap.get(itemId); int newTop = child.getTop(); if (formerTop != null) { if (formerTop != newTop) { int delta = formerTop - newTop; child.setTranslationY(delta); int MOVE_DURATION = 500; child.animate().setDuration(MOVE_DURATION).translationY(0); if (firstAnimation[0]) { child.animate().setListener(new AnimatorActionListener(new Runnable() { public void run() { mSwiping = false; getListView().setEnabled(true); } }, AnimatorActionListener.ActionType.END)); firstAnimation[0] = false; } } } else { // Animate new views along with the others. The catch is that they did not // exist in the start state, so we must calculate their starting position // based on neighboring views. int childHeight = child.getHeight() + megaListView.getDividerHeight(); boolean isFurthest = true; for (int j = 0; j < itemIdTopMap.size(); j++) { Integer top = itemIdTopMap.valueAt(j); if (top - childHeight > newTop) { isFurthest = false; break; } } formerTop = newTop + (i > 0 ? childHeight : -childHeight); int delta = formerTop - newTop; int MOVE_DURATION = 500; if (isFurthest) { child.setTranslationY(delta); child.animate().setDuration(MOVE_DURATION).translationY(0); } else { int translationX = formerTop > childHeight ? child.getWidth() : 0; child.setTranslationX(translationX); if (translationX == 0) child.setTranslationY(formerTop - newTop); child.animate().setDuration(MOVE_DURATION).translationX(0).translationY(0); } if (firstAnimation[0]) { child.animate().setListener(new AnimatorActionListener(new Runnable() { public void run() { getListView().setEnabled(true); mSwiping = false; } }, AnimatorActionListener.ActionType.END)); firstAnimation[0] = false; } } } if (firstAnimation[0]) { mSwiping = false; getListView().setEnabled(true); firstAnimation[0] = false; } itemIdTopMap.clear(); return true; } }); }