Code example for LinkedList

Methods: addFirst, addLast, get, removeFirst, removeLast, size

0
            mCurrentBufferIndex--;
            View recycleView = null;
 
            // Remove view outside buffer range 
            if (mAdapter.getCount() - 1 - mCurrentAdapterIndex > mSideBuffer) {
                recycleView = mLoadedViews.removeLast();
                detachViewFromParent(recycleView);
            } 
 
            // Add new view to buffer 
            int newBufferIndex = mCurrentAdapterIndex - mSideBuffer;
            if (newBufferIndex > -1) {
                mLoadedViews.addFirst(makeAndAddView(newBufferIndex, false, recycleView));
                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 = child.getLayoutParams();
        if (p == null) {
            p = new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_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, View convertView) {
        View view = mAdapter.getView(position, convertView, this);
        return setupChild(view, addToEnd, convertView != null);
    } 
 
    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("FlowView", "Size of mLoadedViews: " + mLoadedViews.size() + ", X: " + mScroller.getCurrX() + ", Y: " + mScroller.getCurrY());
        Log.d("FlowView", "IndexInAdapter: " + mCurrentAdapterIndex + ", IndexInBuffer: " + mCurrentBufferIndex);
    } 
 
    /** */ 
    private OnScrollListener onScrollListener;