Skip to content
This repository was archived by the owner on Jul 11, 2024. It is now read-only.

Add the loop play. #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions viewflow/src/org/taptwo/android/widget/ViewFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,28 @@ public ViewFlow(Context context, AttributeSet attrs) {
mSideBuffer = styledAttrs.getInt(R.styleable.ViewFlow_sidebuffer, 3);
init();
}

/**
* DisPlay Next View,If at the last one will be the first one to slide show
*/
public void showNext() {
if (mCurrentScreen == getChildCount() - 1) {
snapToScreen(0);
} else {
snapToScreen(mCurrentScreen + 1);
}
}

/**
* DisPlay Previous View,If at the frist one will be the last one to slide show
*/
public void showPrevious() {
if (mCurrentScreen == 0) {
snapToScreen(getChildCount()-1);
} else {
snapToScreen(mCurrentScreen - 1);
}
}

private void init() {
mLoadedViews = new LinkedList<View>();
Expand Down Expand Up @@ -625,8 +647,8 @@ private void postViewSwitched(int direction) {
return;

if (direction > 0) { // to the right
mCurrentAdapterIndex++;
mCurrentBufferIndex++;
mCurrentAdapterIndex+=direction;
mCurrentBufferIndex+=direction;
mLazyInit.remove(LazyInit.LEFT);
mLazyInit.add(LazyInit.RIGHT);

Expand All @@ -642,8 +664,8 @@ private void postViewSwitched(int direction) {
mLoadedViews.addLast(makeAndAddView(newBufferIndex, true));

} else { // to the left
mCurrentAdapterIndex--;
mCurrentBufferIndex--;
mCurrentAdapterIndex+=direction;
mCurrentBufferIndex+=direction;
mLazyInit.add(LazyInit.LEFT);
mLazyInit.remove(LazyInit.RIGHT);

Expand Down