Skip to content

Commit d1f9eb9

Browse files
committed
overlay fade out when dialog dismissing
1 parent 1a8c2a8 commit d1f9eb9

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed
File renamed without changes.

res/anim/dialog_scale_out.xml res/anim/modal_out.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
android:duration="150"/>
1414
<alpha
1515
android:fromAlpha="1"
16-
android:toAlpha="0.1"
16+
android:toAlpha="0"
1717
android:duration="150"/>
1818
</set>

src/cn/pedant/SweetAlert/widget/SweetAlertDialog.java

+18-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.view.animation.AlphaAnimation;
1111
import android.view.animation.Animation;
1212
import android.view.animation.AnimationSet;
13+
import android.view.animation.Transformation;
1314
import android.widget.Button;
1415
import android.widget.FrameLayout;
1516
import android.widget.ImageView;
@@ -20,8 +21,9 @@
2021

2122
public class SweetAlertDialog extends Dialog implements View.OnClickListener {
2223
private View mDialogView;
23-
private AnimationSet mScaleInAnim;
24-
private AnimationSet mScaleOutAnim;
24+
private AnimationSet mModalInAnim;
25+
private AnimationSet mModalOutAnim;
26+
private Animation mOverlayOutAnim;
2527
private Animation mErrorInAnim;
2628
private AnimationSet mErrorXInAnim;
2729
private AnimationSet mSuccessLayoutAnimSet;
@@ -85,9 +87,9 @@ public SweetAlertDialog(Context context, int alertType) {
8587
}
8688
mSuccessBowAnim = OptAnimationLoader.loadAnimation(getContext(), R.anim.success_bow_roate);
8789
mSuccessLayoutAnimSet = (AnimationSet)OptAnimationLoader.loadAnimation(getContext(), R.anim.success_mask_layout);
88-
mScaleInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.dialog_scale_in);
89-
mScaleOutAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.dialog_scale_out);
90-
mScaleOutAnim.setAnimationListener(new Animation.AnimationListener() {
90+
mModalInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_in);
91+
mModalOutAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_out);
92+
mModalOutAnim.setAnimationListener(new Animation.AnimationListener() {
9193
@Override
9294
public void onAnimationStart(Animation animation) {
9395

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

110112
}
111113
});
114+
// dialog overlay fade out
115+
mOverlayOutAnim = new Animation() {
116+
@Override
117+
protected void applyTransformation(float interpolatedTime, Transformation t) {
118+
getWindow().getDecorView().getBackground().setAlpha((int)((1 - interpolatedTime) * 255));
119+
}
120+
};
121+
mOverlayOutAnim.setDuration(150);
112122
}
113123

114124
protected void onCreate(Bundle savedInstanceState) {
@@ -289,12 +299,13 @@ public SweetAlertDialog setConfirmClickListener (OnSweetClickListener listener)
289299
}
290300

291301
protected void onStart() {
292-
mDialogView.startAnimation(mScaleInAnim);
302+
mDialogView.startAnimation(mModalInAnim);
293303
playAnimation();
294304
}
295305

296306
public void dismiss() {
297-
mDialogView.startAnimation(mScaleOutAnim);
307+
mConfirmButton.startAnimation(mOverlayOutAnim);
308+
mDialogView.startAnimation(mModalOutAnim);
298309
}
299310

300311
@Override

0 commit comments

Comments
 (0)