@@ -123,7 +123,7 @@ public class SliderLayout extends RelativeLayout{
123
123
/**
124
124
* If auto recover after user touch the {@link com.daimajia.slider.library.Tricks.ViewPagerEx}
125
125
*/
126
- private boolean mAutoRecover ;
126
+ private boolean mAutoRecover = true ;
127
127
128
128
129
129
private int mTransformerId ;
@@ -135,6 +135,11 @@ public class SliderLayout extends RelativeLayout{
135
135
136
136
private boolean mAutoCycle ;
137
137
138
+ /**
139
+ * the duration between animation.
140
+ */
141
+ private long mSliderDuration = 3400 ;
142
+
138
143
/**
139
144
* Visibility of {@link com.daimajia.slider.library.Indicators.PagerIndicator}
140
145
*/
@@ -223,17 +228,28 @@ public <T extends BaseSliderView> void addSlider(T imageContent){
223
228
mSliderAdapter .addSlider (imageContent );
224
229
}
225
230
231
+ private android .os .Handler mh = new android .os .Handler (){
232
+ @ Override
233
+ public void handleMessage (Message msg ) {
234
+ super .handleMessage (msg );
235
+ mViewPager .nextItem ();
236
+ }
237
+ };
238
+
226
239
public void startAutoCycle (){
227
- startAutoCycle (1000 , 3400 , true );
240
+ startAutoCycle (1000 , mSliderDuration , mAutoRecover );
228
241
}
229
242
230
243
/**
231
244
* start auto cycle.
232
245
* @param delay delay time
233
- * @param period period time.
234
- * @param autoRecover
246
+ * @param duration animation duration time.
247
+ * @param autoRecover if recover after user touches the slider.
235
248
*/
236
- public void startAutoCycle (long delay ,long period ,boolean autoRecover ){
249
+ public void startAutoCycle (long delay ,long duration ,boolean autoRecover ){
250
+ if (mCycleTimer != null ) mCycleTimer .cancel ();
251
+ if (mCycleTask != null ) mCycleTask .cancel ();
252
+ mSliderDuration = duration ;
237
253
mCycleTimer = new Timer ();
238
254
mAutoRecover = autoRecover ;
239
255
mCycleTask = new TimerTask () {
@@ -242,7 +258,7 @@ public void run() {
242
258
mh .sendEmptyMessage (0 );
243
259
}
244
260
};
245
- mCycleTimer .schedule (mCycleTask ,delay ,period );
261
+ mCycleTimer .schedule (mCycleTask ,delay ,mSliderDuration );
246
262
mCycling = true ;
247
263
}
248
264
@@ -261,6 +277,17 @@ private void pauseAutoCycle(){
261
277
}
262
278
}
263
279
280
+ /**
281
+ * set the duration between two slider changes. the duration value must >= 500
282
+ * @param duration
283
+ */
284
+ public void setDuration (long duration ){
285
+ if (duration >= 500 ){
286
+ mSliderDuration = duration ;
287
+ startAutoCycle ();
288
+ }
289
+ }
290
+
264
291
/**
265
292
* stop the auto circle
266
293
*/
@@ -283,7 +310,6 @@ public void stopAutoCycle(){
283
310
* when paused cycle, this method can weak it up.
284
311
*/
285
312
private void recoverCycle (){
286
-
287
313
if (!mAutoRecover ){
288
314
return ;
289
315
}
@@ -304,13 +330,7 @@ public void run() {
304
330
}
305
331
}
306
332
307
- private android .os .Handler mh = new android .os .Handler (){
308
- @ Override
309
- public void handleMessage (Message msg ) {
310
- super .handleMessage (msg );
311
- mViewPager .nextItem ();
312
- }
313
- };
333
+
314
334
315
335
@ Override
316
336
public boolean onInterceptTouchEvent (MotionEvent ev ) {
0 commit comments