Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish show animation before close #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class LoadToast {
private boolean mToastCanceled = false;
private boolean mInflated = false;
private boolean mVisible = false;
private boolean mShowAnimationActive = false;
private boolean mSlideUpPending = false;


public LoadToast(Context context){
Expand Down Expand Up @@ -87,9 +89,34 @@ public LoadToast show(){
ViewHelper.setAlpha(mView, 0f);
ViewHelper.setTranslationY(mView, -mView.getHeight() + mTranslationY);
//mView.setVisibility(View.VISIBLE);
ViewPropertyAnimator.animate(mView).alpha(1f).translationY(25 + mTranslationY)
ViewPropertyAnimator showAnimator = ViewPropertyAnimator.animate(mView).alpha(1f).translationY(25 + mTranslationY)
.setInterpolator(new DecelerateInterpolator())
.setDuration(300).setStartDelay(0).start();
.setDuration(300).setStartDelay(0);
showAnimator.setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
mShowAnimationActive = true;
}

@Override
public void onAnimationEnd(Animator animation) {
mShowAnimationActive = false;
if (mSlideUpPending) {
slideUp();
}
}

@Override
public void onAnimationCancel(Animator animation) {

}

@Override
public void onAnimationRepeat(Animator animation) {

}
});
showAnimator.start();

mVisible = true;
checkZPosition();
Expand Down Expand Up @@ -130,6 +157,11 @@ private void checkZPosition(){
}

private void slideUp(){
if (mShowAnimationActive) {
mSlideUpPending = true;
return;
}
mSlideUpPending = false;
ViewPropertyAnimator.animate(mView).setStartDelay(1000).alpha(0f)
.translationY(-mView.getHeight() + mTranslationY)
.setInterpolator(new AccelerateInterpolator())
Expand Down