-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from shts/feature/add-pause-resume
pause and resume impl
- Loading branch information
Showing
23 changed files
with
313 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
app/src/androidTest/java/jp/shts/android/storyprogressbar/ExampleInstrumentedTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
app/src/test/java/jp/shts/android/storyprogressbar/ExampleUnitTest.java
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
173 changes: 173 additions & 0 deletions
173
library/src/main/java/jp/shts/android/storiesprogressview/PausableProgressBar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package jp.shts.android.storiesprogressview; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.AttrRes; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.util.AttributeSet; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.animation.Animation; | ||
import android.view.animation.LinearInterpolator; | ||
import android.view.animation.ScaleAnimation; | ||
import android.view.animation.Transformation; | ||
import android.widget.FrameLayout; | ||
|
||
final class PausableProgressBar extends FrameLayout { | ||
|
||
/*** | ||
* progress満了タイマーのデフォルト時間 | ||
*/ | ||
private static final int DEFAULT_PROGRESS_DURATION = 2000; | ||
|
||
private View frontProgressView; | ||
private View maxProgressView; | ||
|
||
private PausableScaleAnimation animation; | ||
private long duration = DEFAULT_PROGRESS_DURATION; | ||
private Callback callback; | ||
|
||
interface Callback { | ||
void onStartProgress(); | ||
void onFinishProgress(); | ||
} | ||
|
||
public PausableProgressBar(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public PausableProgressBar(@NonNull Context context, @Nullable AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public PausableProgressBar(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
LayoutInflater.from(context).inflate(R.layout.pausable_progress, this); | ||
frontProgressView = findViewById(R.id.front_progress); | ||
maxProgressView = findViewById(R.id.max_progress); // work around | ||
} | ||
|
||
public void setDuration(long duration) { | ||
this.duration = duration; | ||
} | ||
|
||
public void setCallback(@NonNull Callback callback) { | ||
this.callback = callback; | ||
} | ||
|
||
void setMax() { | ||
finishProgress(true); | ||
} | ||
|
||
void setMin() { | ||
finishProgress(false); | ||
} | ||
|
||
void setMinWithoutCallback() { | ||
maxProgressView.setBackgroundResource(R.color.progress_secondary); | ||
|
||
maxProgressView.setVisibility(VISIBLE); | ||
if (animation != null) { | ||
animation.setAnimationListener(null); | ||
animation.cancel(); | ||
} | ||
} | ||
|
||
private void finishProgress(boolean isMax) { | ||
if (isMax) maxProgressView.setBackgroundResource(R.color.progress_max_active); | ||
maxProgressView.setVisibility(isMax ? VISIBLE : GONE); | ||
if (animation != null) { | ||
animation.setAnimationListener(null); | ||
animation.cancel(); | ||
if (callback != null) { | ||
callback.onFinishProgress(); | ||
} | ||
} | ||
} | ||
|
||
public void startProgress() { | ||
maxProgressView.setVisibility(GONE); | ||
|
||
animation = new PausableScaleAnimation(0, 1, 1, 1, Animation.ABSOLUTE, 0, Animation.RELATIVE_TO_SELF, 0); | ||
animation.setDuration(duration); | ||
animation.setInterpolator(new LinearInterpolator()); | ||
animation.setAnimationListener(new Animation.AnimationListener() { | ||
@Override | ||
public void onAnimationStart(Animation animation) { | ||
frontProgressView.setVisibility(View.VISIBLE); | ||
if (callback != null) callback.onStartProgress(); | ||
} | ||
|
||
@Override | ||
public void onAnimationRepeat(Animation animation) { | ||
} | ||
|
||
@Override | ||
public void onAnimationEnd(Animation animation) { | ||
if (callback != null) callback.onFinishProgress(); | ||
} | ||
}); | ||
animation.setFillAfter(true); | ||
frontProgressView.startAnimation(animation); | ||
} | ||
|
||
public void pauseProgress() { | ||
if (animation != null) { | ||
animation.pause(); | ||
} | ||
} | ||
|
||
public void resumeProgress() { | ||
if (animation != null) { | ||
animation.resume(); | ||
} | ||
} | ||
|
||
void clear() { | ||
if (animation != null) { | ||
animation.setAnimationListener(null); | ||
animation.cancel(); | ||
animation = null; | ||
} | ||
} | ||
|
||
private class PausableScaleAnimation extends ScaleAnimation { | ||
|
||
private long mElapsedAtPause = 0; | ||
private boolean mPaused = false; | ||
|
||
PausableScaleAnimation(float fromX, float toX, float fromY, | ||
float toY, int pivotXType, float pivotXValue, int pivotYType, | ||
float pivotYValue) { | ||
super(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, | ||
pivotYValue); | ||
} | ||
|
||
@Override | ||
public boolean getTransformation(long currentTime, Transformation outTransformation, float scale) { | ||
if (mPaused && mElapsedAtPause == 0) { | ||
mElapsedAtPause = currentTime - getStartTime(); | ||
} | ||
if (mPaused) { | ||
setStartTime(currentTime - mElapsedAtPause); | ||
} | ||
return super.getTransformation(currentTime, outTransformation, scale); | ||
} | ||
|
||
/*** | ||
* pause animation | ||
*/ | ||
void pause() { | ||
if (mPaused) return; | ||
mElapsedAtPause = 0; | ||
mPaused = true; | ||
} | ||
|
||
/*** | ||
* resume animation | ||
*/ | ||
void resume() { | ||
mPaused = false; | ||
} | ||
} | ||
} |
Oops, something went wrong.
e73a02b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello is it possible to add .mp4 format ? If yes then how to achieve this please help me for the same.
e73a02b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any success with .mp4?
e73a02b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e73a02b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MayankSoni Can you help with the code or push your changes?
e73a02b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AnirudhLoya I have done few changes but sorry its not free.
e73a02b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AnirudhLoya I have added video and image support it has some issues but it works and yes its open source https://github.com/gulzar1996/InstaStories
e73a02b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gulzar1996 Really appreciate your work & contribution. Its fun people use open source code from github do some changes & and then don't want to contribute back to the community.