Skip to content

Commit

Permalink
overlay fade out when dialog dismissing
Browse files Browse the repository at this point in the history
  • Loading branch information
pedant committed Oct 30, 2014
1 parent 1a8c2a8 commit d1f9eb9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion res/anim/dialog_scale_out.xml → res/anim/modal_out.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
android:duration="150"/>
<alpha
android:fromAlpha="1"
android:toAlpha="0.1"
android:toAlpha="0"
android:duration="150"/>
</set>
25 changes: 18 additions & 7 deletions src/cn/pedant/SweetAlert/widget/SweetAlertDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.Transformation;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand All @@ -20,8 +21,9 @@

public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private View mDialogView;
private AnimationSet mScaleInAnim;
private AnimationSet mScaleOutAnim;
private AnimationSet mModalInAnim;
private AnimationSet mModalOutAnim;
private Animation mOverlayOutAnim;
private Animation mErrorInAnim;
private AnimationSet mErrorXInAnim;
private AnimationSet mSuccessLayoutAnimSet;
Expand Down Expand Up @@ -85,9 +87,9 @@ public SweetAlertDialog(Context context, int alertType) {
}
mSuccessBowAnim = OptAnimationLoader.loadAnimation(getContext(), R.anim.success_bow_roate);
mSuccessLayoutAnimSet = (AnimationSet)OptAnimationLoader.loadAnimation(getContext(), R.anim.success_mask_layout);
mScaleInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.dialog_scale_in);
mScaleOutAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.dialog_scale_out);
mScaleOutAnim.setAnimationListener(new Animation.AnimationListener() {
mModalInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_in);
mModalOutAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_out);
mModalOutAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

Expand All @@ -109,6 +111,14 @@ public void onAnimationRepeat(Animation animation) {

}
});
// dialog overlay fade out
mOverlayOutAnim = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
getWindow().getDecorView().getBackground().setAlpha((int)((1 - interpolatedTime) * 255));
}
};
mOverlayOutAnim.setDuration(150);
}

protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -289,12 +299,13 @@ public SweetAlertDialog setConfirmClickListener (OnSweetClickListener listener)
}

protected void onStart() {
mDialogView.startAnimation(mScaleInAnim);
mDialogView.startAnimation(mModalInAnim);
playAnimation();
}

public void dismiss() {
mDialogView.startAnimation(mScaleOutAnim);
mConfirmButton.startAnimation(mOverlayOutAnim);
mDialogView.startAnimation(mModalOutAnim);
}

@Override
Expand Down

0 comments on commit d1f9eb9

Please sign in to comment.