From 6906885aca5f6513a8fffaaf7d8e0da7a0ca5229 Mon Sep 17 00:00:00 2001 From: Mai Cervantes Date: Thu, 14 Jan 2021 16:04:41 +0800 Subject: [PATCH 1/2] Add customization of starting point of animation within an individual progress bar --- .../storiesprogressview/PausableProgressBar.java | 14 +++++++++++--- .../storiesprogressview/StoriesProgressView.java | 14 +++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) 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..9cdb6a1 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); + Log.d("PausableProgressBar", "fromX = " + fromX); + 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); } /** From 5b55feaf106af12b7e4e0629d28a24191c1bad30 Mon Sep 17 00:00:00 2001 From: Mai Cervantes Date: Thu, 14 Jan 2021 16:05:23 +0800 Subject: [PATCH 2/2] remove log --- .../shts/android/storiesprogressview/PausableProgressBar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9cdb6a1..d975b7c 100644 --- a/library/src/main/java/jp/shts/android/storiesprogressview/PausableProgressBar.java +++ b/library/src/main/java/jp/shts/android/storiesprogressview/PausableProgressBar.java @@ -104,7 +104,7 @@ public void startProgress(long startTime) { throw new IllegalArgumentException("Start time is greater than story duration"); } float fromX = 1.0f - ((float)remainingTime/(float)duration); - Log.d("PausableProgressBar", "fromX = " + fromX); + animation = new PausableScaleAnimation(fromX, 1, 1, 1, Animation.ABSOLUTE, 0, Animation.RELATIVE_TO_SELF, 0); animation.setDuration(remainingTime);