diff --git a/library/src/main/java/jp/shts/android/storiesprogressview/PausableProgressBar.java b/library/src/main/java/jp/shts/android/storiesprogressview/PausableProgressBar.java index af7e472..d975b7c 100644 --- a/library/src/main/java/jp/shts/android/storiesprogressview/PausableProgressBar.java +++ b/library/src/main/java/jp/shts/android/storiesprogressview/PausableProgressBar.java @@ -5,6 +5,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import android.util.AttributeSet; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.animation.Animation; @@ -95,11 +96,18 @@ private void finishProgress(boolean isMax) { } } - public void startProgress() { + public void startProgress(long startTime) { maxProgressView.setVisibility(GONE); - animation = new PausableScaleAnimation(0, 1, 1, 1, Animation.ABSOLUTE, 0, Animation.RELATIVE_TO_SELF, 0); - animation.setDuration(duration); + long remainingTime = duration - startTime; + if(remainingTime < 0) { + throw new IllegalArgumentException("Start time is greater than story duration"); + } + float fromX = 1.0f - ((float)remainingTime/(float)duration); + + animation = new PausableScaleAnimation(fromX, 1, 1, 1, Animation.ABSOLUTE, 0, Animation.RELATIVE_TO_SELF, 0); + animation.setDuration(remainingTime); + animation.setInterpolator(new LinearInterpolator()); animation.setAnimationListener(new Animation.AnimationListener() { @Override diff --git a/library/src/main/java/jp/shts/android/storiesprogressview/StoriesProgressView.java b/library/src/main/java/jp/shts/android/storiesprogressview/StoriesProgressView.java index ec8c22e..b7cfb53 100644 --- a/library/src/main/java/jp/shts/android/storiesprogressview/StoriesProgressView.java +++ b/library/src/main/java/jp/shts/android/storiesprogressview/StoriesProgressView.java @@ -178,9 +178,9 @@ public void onFinishProgress() { if (0 <= (current - 1)) { PausableProgressBar p = progressBars.get(current - 1); p.setMinWithoutCallback(); - progressBars.get(--current).startProgress(); + progressBars.get(--current).startProgress(0); } else { - progressBars.get(current).startProgress(); + progressBars.get(current).startProgress(0); } isReverseStart = false; return; @@ -188,7 +188,7 @@ public void onFinishProgress() { int next = current + 1; if (next <= (progressBars.size() - 1)) { if (storiesListener != null) storiesListener.onNext(); - progressBars.get(next).startProgress(); + progressBars.get(next).startProgress(0); } else { isComplete = true; if (storiesListener != null) storiesListener.onComplete(); @@ -202,17 +202,21 @@ public void onFinishProgress() { * Start progress animation */ public void startStories() { - progressBars.get(0).startProgress(); + progressBars.get(0).startProgress(0); } /** * Start progress animation from specific progress */ public void startStories(int from) { + startStories(from, 0); + } + + public void startStories(int from, long startTime) { for (int i = 0; i < from; i++) { progressBars.get(i).setMaxWithoutCallback(); } - progressBars.get(from).startProgress(); + progressBars.get(from).startProgress(startTime); } /**