Skip to content

Commit bd9bc0a

Browse files
committed
add setDuration method
1 parent 620da9a commit bd9bc0a

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

demo/src/main/java/com/daimajia/slider/demo/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
6161
mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Accordion);
6262
mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
6363
mDemoSlider.setCustomAnimation(new DescriptionAnimation());
64+
mDemoSlider.setDuration(3400);
6465
ListView l = (ListView)findViewById(R.id.transformers);
6566
l.setAdapter(new TransformerAdapter(this));
6667
l.setOnItemClickListener(new AdapterView.OnItemClickListener() {

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
# org.gradle.parallel=true
1919

2020

21-
VERSION_NAME=1.0.1
22-
VERSION_CODE=2
21+
VERSION_NAME=1.0.2
22+
VERSION_CODE=3
2323
GROUP=com.daimajia.slider
2424

2525
POM_DESCRIPTION=An amazing and convenient Android image slider.

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 8
99
targetSdkVersion 19
10-
versionCode 2
11-
versionName "1.0.1"
10+
versionCode 3
11+
versionName "1.0.2"
1212
}
1313
buildTypes {
1414
release {

library/src/main/java/com/daimajia/slider/library/SliderLayout.java

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public class SliderLayout extends RelativeLayout{
123123
/**
124124
* If auto recover after user touch the {@link com.daimajia.slider.library.Tricks.ViewPagerEx}
125125
*/
126-
private boolean mAutoRecover;
126+
private boolean mAutoRecover = true;
127127

128128

129129
private int mTransformerId;
@@ -135,6 +135,11 @@ public class SliderLayout extends RelativeLayout{
135135

136136
private boolean mAutoCycle;
137137

138+
/**
139+
* the duration between animation.
140+
*/
141+
private long mSliderDuration = 3400;
142+
138143
/**
139144
* Visibility of {@link com.daimajia.slider.library.Indicators.PagerIndicator}
140145
*/
@@ -223,17 +228,28 @@ public <T extends BaseSliderView> void addSlider(T imageContent){
223228
mSliderAdapter.addSlider(imageContent);
224229
}
225230

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+
226239
public void startAutoCycle(){
227-
startAutoCycle(1000, 3400, true);
240+
startAutoCycle(1000, mSliderDuration, mAutoRecover);
228241
}
229242

230243
/**
231244
* start auto cycle.
232245
* @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.
235248
*/
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;
237253
mCycleTimer = new Timer();
238254
mAutoRecover = autoRecover;
239255
mCycleTask = new TimerTask() {
@@ -242,7 +258,7 @@ public void run() {
242258
mh.sendEmptyMessage(0);
243259
}
244260
};
245-
mCycleTimer.schedule(mCycleTask,delay,period);
261+
mCycleTimer.schedule(mCycleTask,delay,mSliderDuration);
246262
mCycling = true;
247263
}
248264

@@ -261,6 +277,17 @@ private void pauseAutoCycle(){
261277
}
262278
}
263279

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+
264291
/**
265292
* stop the auto circle
266293
*/
@@ -283,7 +310,6 @@ public void stopAutoCycle(){
283310
* when paused cycle, this method can weak it up.
284311
*/
285312
private void recoverCycle(){
286-
287313
if(!mAutoRecover){
288314
return;
289315
}
@@ -304,13 +330,7 @@ public void run() {
304330
}
305331
}
306332

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+
314334

315335
@Override
316336
public boolean onInterceptTouchEvent(MotionEvent ev) {

0 commit comments

Comments
 (0)