Code example for LinkedList

Methods: get, removeFirst, removeLast, size

0
			mLazyInit.add(LazyInit.LEFT);
			mLazyInit.remove(LazyInit.RIGHT);
 
			// Recycle view outside buffer range 
			if (mAdapter.getCount() - 1 - mCurrentAdapterIndex > mSideBuffer) {
				recycleView(mLoadedViews.removeLast());
			} 
 
			// Add new view to buffer 
			int newBufferIndex = mCurrentAdapterIndex - mSideBuffer;
			if (newBufferIndex > -1) {
				mLoadedViews.addFirst(makeAndAddView(newBufferIndex, false));
				mCurrentBufferIndex++;
			} 
 
		} 
 
		requestLayout();
		setVisibleView(mCurrentBufferIndex, true);
		if (mIndicator != null) {
			mIndicator.onSwitched(mLoadedViews.get(mCurrentBufferIndex),
					mCurrentAdapterIndex);
		} 
		if (mViewSwitchListener != null) {
			mViewSwitchListener
					.onSwitched(mLoadedViews.get(mCurrentBufferIndex),
							mCurrentAdapterIndex);
		} 
		logBuffer(); 
	} 
 
	private View setupChild(View child, boolean addToEnd, boolean recycle) {
		ViewGroup.LayoutParams p = (ViewGroup.LayoutParams) child
				.getLayoutParams();
		if (p == null) {
			p = new AbsListView.LayoutParams(
					ViewGroup.LayoutParams.MATCH_PARENT,
					ViewGroup.LayoutParams.WRAP_CONTENT, 0);
		} 
		if (recycle)
			attachViewToParent(child, (addToEnd ? -1 : 0), p);
		else 
			addViewInLayout(child, (addToEnd ? -1 : 0), p, true);
		return child;
	} 
 
	private View makeAndAddView(int position, boolean addToEnd) {
		return makeAndAddView(position, addToEnd, getRecycledView());
	} 
 
	private View makeAndAddView(int position, boolean addToEnd, View convertView) {
		View view = mAdapter.getView(position, convertView, this);
		if(view != convertView && convertView != null)
			mRecycledViews.add(convertView);
		return setupChild(view, addToEnd, view == convertView);
	} 
 
	class AdapterDataSetObserver extends DataSetObserver {
 
		@Override 
		public void onChanged() { 
			View v = getChildAt(mCurrentBufferIndex);
			if (v != null) {
				for (int index = 0; index < mAdapter.getCount(); index++) {
					if (v.equals(mAdapter.getItem(index))) {
						mCurrentAdapterIndex = index;
						break; 
					} 
				} 
			} 
			resetFocus(); 
		} 
 
		@Override 
		public void onInvalidated() { 
			// Not yet implemented! 
		} 
 
	} 
 
	private void logBuffer() { 
 
		Log.d("viewflow", "Size of mLoadedViews: " + mLoadedViews.size() +
				", Size of mRecycledViews: " + mRecycledViews.size() +
				", X: " + mScroller.getCurrX() + ", Y: " + mScroller.getCurrY());
		Log.d("viewflow", "IndexInAdapter: " + mCurrentAdapterIndex
				+ ", IndexInBuffer: " + mCurrentBufferIndex);
	}