From efea9da5dab7c44520797e379fd4a3eecceed7a8 Mon Sep 17 00:00:00 2001 From: HuYunFeng Date: Fri, 24 May 2013 16:01:40 +0800 Subject: [PATCH] Add the loop play. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the loop play. Using Timer and TimerTask can automatically play. I'm sorry for my bad english, might describe the wrong, I posted the code it directly: LightTimer timer = new LightTimer() { @Override public void run(LightTimer timer) { // TODO Auto-generated method stub viewFlow.showNext(); } }; timer.startTimer(1000);//Loop play,Once per second --- .../org/taptwo/android/widget/ViewFlow.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/viewflow/src/org/taptwo/android/widget/ViewFlow.java b/viewflow/src/org/taptwo/android/widget/ViewFlow.java index 67058e6..9570476 100644 --- a/viewflow/src/org/taptwo/android/widget/ViewFlow.java +++ b/viewflow/src/org/taptwo/android/widget/ViewFlow.java @@ -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(); @@ -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); @@ -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);