From e9fd8b79f2c3cdbb973cd54fd244ff9588331635 Mon Sep 17 00:00:00 2001 From: Pierfrancesco Soffritti Date: Sat, 2 Jul 2016 10:02:14 +0200 Subject: [PATCH] slide duration can now be changed --- .../slidingdrawer/SlidingDrawer.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/slidingdrawer/src/main/java/com/pierfrancescosoffritti/slidingdrawer/SlidingDrawer.java b/slidingdrawer/src/main/java/com/pierfrancescosoffritti/slidingdrawer/SlidingDrawer.java index a2961ef..acbf8ca 100644 --- a/slidingdrawer/src/main/java/com/pierfrancescosoffritti/slidingdrawer/SlidingDrawer.java +++ b/slidingdrawer/src/main/java/com/pierfrancescosoffritti/slidingdrawer/SlidingDrawer.java @@ -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 {} @@ -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; @@ -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 @@ -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); }