Skip to content

Commit

Permalink
slide duration can now be changed
Browse files Browse the repository at this point in the history
  • Loading branch information
PierfrancescoSoffritti committed Jul 2, 2016
1 parent bff2fd6 commit e9fd8b7
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@
// TODO A LOT of uses cases have not been taken into consideration yet.
public class SlidingDrawer extends LinearLayout {

private static final int SLIDE_DURATION = 300;

private static final byte UP = 0;
private static final byte DOWN = 1;
private static final byte NONE = 2;

@IntDef({UP, DOWN, NONE})
@Retention(RetentionPolicy.SOURCE)
private @interface SlidingDirection {}
Expand Down Expand Up @@ -75,6 +78,9 @@ public class SlidingDrawer extends LinearLayout {
private int maxSlide;
private final int minSlide = 0;

// duration of the slide in milliseconds, when executed automatically
private long slideDuration = SLIDE_DURATION;

private boolean isSliding;
private boolean canSlide = false;

Expand Down Expand Up @@ -437,7 +443,7 @@ public void slideTo(float finalYNormalized) {

ValueAnimator va = ValueAnimator.ofFloat(currentSlide, finalYNormalized);
va.setInterpolator(new DecelerateInterpolator(1.5f));
va.setDuration(300);
va.setDuration(slideDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

@Override
Expand Down Expand Up @@ -487,6 +493,18 @@ public void setState(@State int state) {
}
}

public long getSlideDuration() {
return slideDuration;
}

/**
* Set the duration of the slide, when executed automatically
* @param slideDuration duration in milliseconds
*/
public void setSlideDuration(long slideDuration) {
this.slideDuration = slideDuration;
}

public void addSlideListener(@NonNull OnSlideListener listener) {
listeners.add(listener);
}
Expand Down

0 comments on commit e9fd8b7

Please sign in to comment.