Selaa lähdekoodia

0.0.46.beta10 ready
- MessageDialog、InputDialog、BottomDialog、BottomMenu、CustomDialog、FullScreenDialog 增加了 `.hideWithExitAnim();` 方法,使用它可以模拟关闭对话框的动画隐藏对话框,此方法只是隐藏对话框,不会真正关闭对话框,重新使用 `.show()` 命令即可恢复对话框的显示。
- 修复了 MessageDialog、InputDialog、BottomDialog、BottomMenu、CustomDialog、FullScreenDialog、PopNotification、PopTip 的 `.hide()` 方法隐藏对话框后,使用 `.show()`显示时无法恢复之前的显示状态问题;
- 现在要使用 MaterialYou 主题需要 android.material 框架,MaterialYou 主题内的组件将逐步替换为 android.material 的官方组件和相关样式;
- 尝试性提供了 FLOATING_ACTIVITY 模式在后台 Service 中启动的可能;

kongzue 2 vuotta sitten
vanhempi
commit
93ee8e3190

+ 108 - 50
DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java

@@ -35,6 +35,7 @@ import com.kongzue.dialogx.interfaces.OnBindView;
 import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
 import com.kongzue.dialogx.interfaces.ScrollController;
 import com.kongzue.dialogx.util.BottomDialogTouchEventInterceptor;
+import com.kongzue.dialogx.util.ObjectRunnable;
 import com.kongzue.dialogx.util.TextInfo;
 import com.kongzue.dialogx.util.views.BlurView;
 import com.kongzue.dialogx.util.views.BottomDialogScrollView;
@@ -189,6 +190,21 @@ public class BottomDialog extends BaseDialog {
     }
     
     public BottomDialog show() {
+        if (isHide && getDialogView() != null && isShow) {
+            if (hideWithExitAnim && getDialogImpl()!=null) {
+                getDialogView().setVisibility(View.VISIBLE);
+                getDialogImpl().doShowAnim(new ObjectRunnable<ValueAnimator>() {
+                    @Override
+                    public void run(ValueAnimator valueAnimator) {
+                        float value = (float) valueAnimator.getAnimatedValue();
+                        getDialogImpl().boxRoot.setBkgAlpha(value);
+                    }
+                });
+            } else {
+                getDialogView().setVisibility(View.VISIBLE);
+            }
+            return this;
+        }
         super.beforeShow();
         if (getDialogView() == null) {
             int layoutId = isLightTheme() ? R.layout.layout_dialogx_bottom_material : R.layout.layout_dialogx_bottom_material_dark;
@@ -427,44 +443,16 @@ public class BottomDialog extends BaseDialog {
             boxBkg.post(new Runnable() {
                 @Override
                 public void run() {
-                    long enterAnimDurationTemp = 300;
-                    
-                    float customDialogTop = 0;
-                    if (bottomDialogMaxHeight > 0 && bottomDialogMaxHeight <= 1) {
-                        customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight * boxBkg.getHeight();
-                    } else if (bottomDialogMaxHeight > 1) {
-                        customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight;
-                    }
-                    
-                    //上移动画
-                    ObjectAnimator enterAnim = ObjectAnimator.ofFloat(boxBkg, "y", boxBkg.getY(),
-                            bkgEnterAimY = boxRoot.getUnsafePlace().top + customDialogTop
-                    );
-                    if (overrideEnterDuration >= 0) {
-                        enterAnimDurationTemp = overrideEnterDuration;
-                    }
-                    if (enterAnimDuration >= 0) {
-                        enterAnimDurationTemp = enterAnimDuration;
-                    }
-                    enterAnim.setDuration(enterAnimDurationTemp);
-                    enterAnim.setAutoCancel(true);
-                    enterAnim.setInterpolator(new DecelerateInterpolator(2f));
-                    enterAnim.start();
-                    
-                    //遮罩层动画
-                    ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
-                    bkgAlpha.setDuration(enterAnimDurationTemp);
-                    bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                    doShowAnim(new ObjectRunnable<ValueAnimator>() {
                         @Override
-                        public void onAnimationUpdate(ValueAnimator animation) {
-                            float value = (float) animation.getAnimatedValue();
+                        public void run(ValueAnimator valueAnimator) {
+                            float value = (float) valueAnimator.getAnimatedValue();
                             boxRoot.setBkgAlpha(value);
                             if (value == 1f) {
                                 bottomDialogTouchEventInterceptor = new BottomDialogTouchEventInterceptor(me, dialogImpl);
                             }
                         }
                     });
-                    bkgAlpha.start();
                 }
             });
             
@@ -605,33 +593,18 @@ public class BottomDialog extends BaseDialog {
             if (!dismissAnimFlag) {
                 dismissAnimFlag = true;
                 
-                long exitAnimDurationTemp = 300;
-                if (overrideExitDuration >= 0) {
-                    exitAnimDurationTemp = overrideExitDuration;
-                }
-                if (exitAnimDuration >= 0) {
-                    exitAnimDurationTemp = exitAnimDuration;
-                }
-                
-                ObjectAnimator exitAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), boxBkg.getHeight());
-                exitAnim.setDuration(exitAnimDurationTemp);
-                exitAnim.start();
-                
-                ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
-                bkgAlpha.setDuration(exitAnimDurationTemp);
-                bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                doExitAnim(new ObjectRunnable<ValueAnimator>() {
                     @Override
-                    public void onAnimationUpdate(ValueAnimator animation) {
+                    public void run(ValueAnimator valueAnimator) {
                         if (boxRoot != null) {
-                            float value = (float) animation.getAnimatedValue();
+                            float value = (float) valueAnimator.getAnimatedValue();
                             boxRoot.setBkgAlpha(value);
                             if (value == 0) boxRoot.setVisibility(View.GONE);
                         }
                     }
                 });
-                bkgAlpha.start();
                 
-                new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
+                runOnMainDelay(new Runnable() {
                     @Override
                     public void run() {
                         dismiss(dialogView);
@@ -640,6 +613,68 @@ public class BottomDialog extends BaseDialog {
             }
         }
         
+        long exitAnimDurationTemp = 300;
+    
+        protected void doExitAnim(ObjectRunnable<ValueAnimator> objectRunnable) {
+            if (overrideExitDuration >= 0) {
+                exitAnimDurationTemp = overrideExitDuration;
+            }
+            if (exitAnimDuration >= 0) {
+                exitAnimDurationTemp = exitAnimDuration;
+            }
+            
+            ObjectAnimator exitAnim = ObjectAnimator.ofFloat(boxBkg, "y", boxBkg.getY(), boxBkg.getHeight());
+            exitAnim.setDuration(exitAnimDurationTemp);
+            exitAnim.start();
+            
+            ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
+            bkgAlpha.setDuration(exitAnimDurationTemp);
+            bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                @Override
+                public void onAnimationUpdate(ValueAnimator animation) {
+                    objectRunnable.run(animation);
+                }
+            });
+            bkgAlpha.start();
+        }
+    
+        protected void doShowAnim(ObjectRunnable<ValueAnimator> objectRunnable){
+            long enterAnimDurationTemp = 300;
+    
+            float customDialogTop = 0;
+            if (bottomDialogMaxHeight > 0 && bottomDialogMaxHeight <= 1) {
+                customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight * boxBkg.getHeight();
+            } else if (bottomDialogMaxHeight > 1) {
+                customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight;
+            }
+    
+            //上移动画
+            ObjectAnimator enterAnim = ObjectAnimator.ofFloat(boxBkg, "y", boxBkg.getY(),
+                    bkgEnterAimY = boxRoot.getUnsafePlace().top + customDialogTop
+            );
+            if (overrideEnterDuration >= 0) {
+                enterAnimDurationTemp = overrideEnterDuration;
+            }
+            if (enterAnimDuration >= 0) {
+                enterAnimDurationTemp = enterAnimDuration;
+            }
+            enterAnim.setDuration(enterAnimDurationTemp);
+            enterAnim.setAutoCancel(true);
+            enterAnim.setInterpolator(new DecelerateInterpolator(2f));
+            enterAnim.start();
+    
+            //遮罩层动画
+            ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
+            bkgAlpha.setDuration(enterAnimDurationTemp);
+            bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                @Override
+                public void onAnimationUpdate(ValueAnimator animation) {
+                    objectRunnable.run(animation);
+                }
+            });
+            bkgAlpha.start();
+        }
+        
         public void preDismiss() {
             if (isCancelable()) {
                 doDismiss(boxRoot);
@@ -1000,12 +1035,35 @@ public class BottomDialog extends BaseDialog {
         show(dialogView);
     }
     
+    protected boolean isHide;
+    
     public void hide() {
+        isHide = true;
+        hideWithExitAnim = false;
         if (getDialogView() != null) {
             getDialogView().setVisibility(View.GONE);
         }
     }
     
+    protected boolean hideWithExitAnim;
+    
+    public void hideWithExitAnim() {
+        hideWithExitAnim = true;
+        isHide = true;
+        if (getDialogImpl() != null) {
+            getDialogImpl().doExitAnim(new ObjectRunnable<ValueAnimator>() {
+                @Override
+                public void run(ValueAnimator valueAnimator) {
+                    float value = (float) valueAnimator.getAnimatedValue();
+                    getDialogImpl().boxRoot.setBkgAlpha(value);
+                    if (value == 0 && getDialogView() != null) {
+                        getDialogView().setVisibility(View.GONE);
+                    }
+                }
+            });
+        }
+    }
+    
     @Override
     protected void shutdown() {
         dismiss();

+ 170 - 120
DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java

@@ -1,5 +1,6 @@
 package com.kongzue.dialogx.dialogs;
 
+import android.animation.ObjectAnimator;
 import android.animation.ValueAnimator;
 import android.app.Activity;
 import android.graphics.Color;
@@ -23,6 +24,7 @@ import com.kongzue.dialogx.interfaces.DialogXStyle;
 import com.kongzue.dialogx.interfaces.OnBackPressedListener;
 import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
 import com.kongzue.dialogx.interfaces.OnBindView;
+import com.kongzue.dialogx.util.ObjectRunnable;
 import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
 import com.kongzue.dialogx.util.views.MaxRelativeLayout;
 
@@ -113,6 +115,21 @@ public class CustomDialog extends BaseDialog {
     }
     
     public CustomDialog show() {
+        if (isHide && getDialogView() != null && isShow) {
+            if (hideWithExitAnim && getDialogImpl()!=null) {
+                getDialogView().setVisibility(View.VISIBLE);
+                getDialogImpl().doShowAnim(new ObjectRunnable<ValueAnimator>() {
+                    @Override
+                    public void run(ValueAnimator valueAnimator) {
+                        float value = (float) valueAnimator.getAnimatedValue();
+                        getDialogImpl().boxRoot.setBkgAlpha(value);
+                    }
+                });
+            } else {
+                getDialogView().setVisibility(View.VISIBLE);
+            }
+            return this;
+        }
         super.beforeShow();
         if (getDialogView() == null) {
             dialogView = createView(R.layout.layout_dialogx_custom);
@@ -197,81 +214,13 @@ public class CustomDialog extends BaseDialog {
             boxRoot.post(new Runnable() {
                 @Override
                 public void run() {
-                    Animation enterAnim;
-                    if (enterAnimResId == R.anim.anim_dialogx_default_enter &&
-                            exitAnimResId == R.anim.anim_dialogx_default_exit &&
-                            baseView == null) {
-                        switch (align) {
-                            case TOP:
-                            case TOP_CENTER:
-                            case TOP_LEFT:
-                            case TOP_RIGHT:
-                                enterAnimResId = R.anim.anim_dialogx_top_enter;
-                                exitAnimResId = R.anim.anim_dialogx_top_exit;
-                                break;
-                            case BOTTOM:
-                            case BOTTOM_CENTER:
-                            case BOTTOM_LEFT:
-                            case BOTTOM_RIGHT:
-                                enterAnimResId = R.anim.anim_dialogx_bottom_enter;
-                                exitAnimResId = R.anim.anim_dialogx_bottom_exit;
-                                break;
-                            case LEFT:
-                            case LEFT_CENTER:
-                            case LEFT_TOP:
-                            case LEFT_BOTTOM:
-                                enterAnimResId = R.anim.anim_dialogx_left_enter;
-                                exitAnimResId = R.anim.anim_dialogx_left_exit;
-                                break;
-                            case RIGHT:
-                            case RIGHT_CENTER:
-                            case RIGHT_TOP:
-                            case RIGHT_BOTTOM:
-                                enterAnimResId = R.anim.anim_dialogx_right_enter;
-                                exitAnimResId = R.anim.anim_dialogx_right_exit;
-                                break;
-                        }
-                        enterAnim = AnimationUtils.loadAnimation(getTopActivity(), enterAnimResId);
-                        enterAnim.setInterpolator(new DecelerateInterpolator(2f));
-                    } else {
-                        int enterAnimResIdTemp = R.anim.anim_dialogx_default_enter;
-                        if (overrideEnterAnimRes != 0) {
-                            enterAnimResIdTemp = overrideEnterAnimRes;
-                        }
-                        if (enterAnimResId != 0) {
-                            enterAnimResIdTemp = enterAnimResId;
-                        }
-                        enterAnim = AnimationUtils.loadAnimation(getTopActivity(), enterAnimResIdTemp);
-                    }
-                    long enterAnimDurationTemp = enterAnim.getDuration();
-                    if (overrideEnterDuration >= 0) {
-                        enterAnimDurationTemp = overrideEnterDuration;
-                    }
-                    if (enterAnimDuration >= 0) {
-                        enterAnimDurationTemp = enterAnimDuration;
-                    }
-                    enterAnim.setDuration(enterAnimDurationTemp);
-                    boxCustom.setVisibility(View.VISIBLE);
-                    boxCustom.startAnimation(enterAnim);
-                    
-                    boxRoot.setBackgroundColor(maskColor);
-                    if (overrideMaskEnterAnimRes != 0) {
-                        Animation maskEnterAnim = AnimationUtils.loadAnimation(getTopActivity(), overrideMaskEnterAnimRes);
-                        maskEnterAnim.setInterpolator(new DecelerateInterpolator(2f));
-                        maskEnterAnim.setDuration(enterAnimDurationTemp);
-                        boxRoot.startAnimation(maskEnterAnim);
-                    }
-                    
-                    ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
-                    bkgAlpha.setDuration(enterAnimDurationTemp);
-                    bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                    doShowAnim(new ObjectRunnable<ValueAnimator>() {
                         @Override
-                        public void onAnimationUpdate(ValueAnimator animation) {
-                            float value = (float) animation.getAnimatedValue();
+                        public void run(ValueAnimator valueAnimator) {
+                            float value = (float) valueAnimator.getAnimatedValue();
                             boxRoot.setBkgAlpha(value);
                         }
                     });
-                    bkgAlpha.start();
                 }
             });
             
@@ -448,66 +397,144 @@ public class CustomDialog extends BaseDialog {
                 boxCustom.post(new Runnable() {
                     @Override
                     public void run() {
-                        int exitAnimResIdTemp = R.anim.anim_dialogx_default_exit;
-                        if (overrideExitAnimRes != 0) {
-                            exitAnimResIdTemp = overrideExitAnimRes;
-                        }
-                        if (exitAnimResId != 0) {
-                            exitAnimResIdTemp = exitAnimResId;
-                        }
-                        
-                        Animation exitAnim = AnimationUtils.loadAnimation(getTopActivity() == null ? boxCustom.getContext() : getTopActivity(), exitAnimResIdTemp);
-                        
-                        long exitAnimDurationTemp = exitAnim.getDuration();
-                        if (overrideExitDuration >= 0) {
-                            exitAnimDurationTemp = overrideExitDuration;
-                        }
-                        if (exitAnimDuration >= 0) {
-                            exitAnimDurationTemp = exitAnimDuration;
-                        }
-                        exitAnim.setDuration(exitAnimDurationTemp);
-                        exitAnim.setAnimationListener(new Animation.AnimationListener() {
-                            @Override
-                            public void onAnimationStart(Animation animation) {
-                            
-                            }
-                            
+                        doExitAnim(new ObjectRunnable<ValueAnimator>() {
                             @Override
-                            public void onAnimationEnd(Animation animation) {
-                                dismiss(dialogView);
-                            }
-                            
-                            @Override
-                            public void onAnimationRepeat(Animation animation) {
-                            
-                            }
-                        });
-                        boxCustom.startAnimation(exitAnim);
-                        
-                        if (overrideMaskExitAnimRes != 0) {
-                            Animation maskExitAnim = AnimationUtils.loadAnimation(getTopActivity(), overrideMaskExitAnimRes);
-                            maskExitAnim.setDuration(exitAnimDurationTemp);
-                            maskExitAnim.setInterpolator(new DecelerateInterpolator(2f));
-                            boxRoot.startAnimation(maskExitAnim);
-                        }
-                        
-                        ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
-                        bkgAlpha.setDuration(exitAnimDurationTemp);
-                        bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
-                            @Override
-                            public void onAnimationUpdate(ValueAnimator animation) {
+                            public void run(ValueAnimator valueAnimator) {
                                 if (boxRoot != null) {
-                                    float value = (float) animation.getAnimatedValue();
+                                    float value = (float) valueAnimator.getAnimatedValue();
                                     boxRoot.setBkgAlpha(value);
                                     if (value == 0) boxRoot.setVisibility(View.GONE);
                                 }
                             }
                         });
-                        bkgAlpha.start();
+    
+                        runOnMainDelay(new Runnable() {
+                            @Override
+                            public void run() {
+                                dismiss(dialogView);
+                            }
+                        },exitAnimDurationTemp);
                     }
                 });
             }
         }
+    
+        long exitAnimDurationTemp;
+    
+        protected void doExitAnim(ObjectRunnable<ValueAnimator> objectRunnable) {
+            int exitAnimResIdTemp = R.anim.anim_dialogx_default_exit;
+            if (overrideExitAnimRes != 0) {
+                exitAnimResIdTemp = overrideExitAnimRes;
+            }
+            if (exitAnimResId != 0) {
+                exitAnimResIdTemp = exitAnimResId;
+            }
+    
+            Animation exitAnim = AnimationUtils.loadAnimation(getTopActivity() == null ? boxCustom.getContext() : getTopActivity(), exitAnimResIdTemp);
+            exitAnimDurationTemp = exitAnim.getDuration();
+            if (overrideExitDuration >= 0) {
+                exitAnimDurationTemp = overrideExitDuration;
+            }
+            if (exitAnimDuration >= 0) {
+                exitAnimDurationTemp = exitAnimDuration;
+            }
+            exitAnim.setDuration(exitAnimDurationTemp);
+            boxCustom.startAnimation(exitAnim);
+    
+            if (overrideMaskExitAnimRes != 0) {
+                Animation maskExitAnim = AnimationUtils.loadAnimation(getTopActivity(), overrideMaskExitAnimRes);
+                maskExitAnim.setDuration(exitAnimDurationTemp);
+                maskExitAnim.setInterpolator(new DecelerateInterpolator(2f));
+                boxRoot.startAnimation(maskExitAnim);
+            }
+    
+            ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
+            bkgAlpha.setDuration(exitAnimDurationTemp);
+            bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                @Override
+                public void onAnimationUpdate(ValueAnimator animation) {
+                    objectRunnable.run(animation);
+                }
+            });
+            bkgAlpha.start();
+        }
+    
+        protected void doShowAnim(ObjectRunnable<ValueAnimator> objectRunnable){
+            Animation enterAnim;
+            if (enterAnimResId == R.anim.anim_dialogx_default_enter &&
+                    exitAnimResId == R.anim.anim_dialogx_default_exit &&
+                    baseView == null) {
+                switch (align) {
+                    case TOP:
+                    case TOP_CENTER:
+                    case TOP_LEFT:
+                    case TOP_RIGHT:
+                        enterAnimResId = R.anim.anim_dialogx_top_enter;
+                        exitAnimResId = R.anim.anim_dialogx_top_exit;
+                        break;
+                    case BOTTOM:
+                    case BOTTOM_CENTER:
+                    case BOTTOM_LEFT:
+                    case BOTTOM_RIGHT:
+                        enterAnimResId = R.anim.anim_dialogx_bottom_enter;
+                        exitAnimResId = R.anim.anim_dialogx_bottom_exit;
+                        break;
+                    case LEFT:
+                    case LEFT_CENTER:
+                    case LEFT_TOP:
+                    case LEFT_BOTTOM:
+                        enterAnimResId = R.anim.anim_dialogx_left_enter;
+                        exitAnimResId = R.anim.anim_dialogx_left_exit;
+                        break;
+                    case RIGHT:
+                    case RIGHT_CENTER:
+                    case RIGHT_TOP:
+                    case RIGHT_BOTTOM:
+                        enterAnimResId = R.anim.anim_dialogx_right_enter;
+                        exitAnimResId = R.anim.anim_dialogx_right_exit;
+                        break;
+                }
+                enterAnim = AnimationUtils.loadAnimation(getTopActivity(), enterAnimResId);
+                enterAnim.setInterpolator(new DecelerateInterpolator(2f));
+            } else {
+                int enterAnimResIdTemp = R.anim.anim_dialogx_default_enter;
+                if (overrideEnterAnimRes != 0) {
+                    enterAnimResIdTemp = overrideEnterAnimRes;
+                }
+                if (enterAnimResId != 0) {
+                    enterAnimResIdTemp = enterAnimResId;
+                }
+                enterAnim = AnimationUtils.loadAnimation(getTopActivity(), enterAnimResIdTemp);
+            }
+            long enterAnimDurationTemp = enterAnim.getDuration();
+            if (overrideEnterDuration >= 0) {
+                enterAnimDurationTemp = overrideEnterDuration;
+            }
+            if (enterAnimDuration >= 0) {
+                enterAnimDurationTemp = enterAnimDuration;
+            }
+            enterAnim.setDuration(enterAnimDurationTemp);
+            boxCustom.setVisibility(View.VISIBLE);
+            boxCustom.startAnimation(enterAnim);
+    
+            boxRoot.setBackgroundColor(maskColor);
+            if (overrideMaskEnterAnimRes != 0) {
+                Animation maskEnterAnim = AnimationUtils.loadAnimation(getTopActivity(), overrideMaskEnterAnimRes);
+                maskEnterAnim.setInterpolator(new DecelerateInterpolator(2f));
+                maskEnterAnim.setDuration(enterAnimDurationTemp);
+                boxRoot.startAnimation(maskEnterAnim);
+            }
+    
+            ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
+            bkgAlpha.setDuration(enterAnimDurationTemp);
+            bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                @Override
+                public void onAnimationUpdate(ValueAnimator animation) {
+                    objectRunnable.run(animation);
+                }
+            });
+            bkgAlpha.start();
+        }
     }
     
     protected void onGetBaseViewLoc(int[] baseViewLoc) {
@@ -696,12 +723,35 @@ public class CustomDialog extends BaseDialog {
         show(dialogView);
     }
     
+    private boolean isHide;
+    
     public void hide() {
+        isHide = true;
+        hideWithExitAnim = false;
         if (getDialogView() != null) {
             getDialogView().setVisibility(View.GONE);
         }
     }
     
+    protected boolean hideWithExitAnim;
+    
+    public void hideWithExitAnim() {
+        hideWithExitAnim = true;
+        isHide = true;
+        if (getDialogImpl() != null) {
+            getDialogImpl().doExitAnim(new ObjectRunnable<ValueAnimator>() {
+                @Override
+                public void run(ValueAnimator valueAnimator) {
+                    float value = (float) valueAnimator.getAnimatedValue();
+                    getDialogImpl().boxRoot.setBkgAlpha(value);
+                    if (value == 0 && getDialogView() != null) {
+                        getDialogView().setVisibility(View.GONE);
+                    }
+                }
+            });
+        }
+    }
+    
     @Override
     protected void shutdown() {
         dismiss();

+ 75 - 27
DialogX/src/main/java/com/kongzue/dialogx/dialogs/FullScreenDialog.java

@@ -28,6 +28,7 @@ import com.kongzue.dialogx.interfaces.OnBindView;
 import com.kongzue.dialogx.interfaces.OnSafeInsetsChangeListener;
 import com.kongzue.dialogx.interfaces.ScrollController;
 import com.kongzue.dialogx.util.FullScreenDialogTouchEventInterceptor;
+import com.kongzue.dialogx.util.ObjectRunnable;
 import com.kongzue.dialogx.util.views.ActivityScreenShotImageView;
 import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
 import com.kongzue.dialogx.util.views.MaxRelativeLayout;
@@ -81,6 +82,15 @@ public class FullScreenDialog extends BaseDialog {
     }
     
     public FullScreenDialog show() {
+        if (isHide && getDialogView() != null && isShow) {
+            if (hideWithExitAnim && getDialogImpl()!=null) {
+                getDialogView().setVisibility(View.VISIBLE);
+                getDialogImpl().doShowAnim();
+            } else {
+                getDialogView().setVisibility(View.VISIBLE);
+            }
+            return this;
+        }
         super.beforeShow();
         if (getDialogView() == null) {
             dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
@@ -198,14 +208,7 @@ public class FullScreenDialog extends BaseDialog {
             boxRoot.post(new Runnable() {
                 @Override
                 public void run() {
-                    int customViewHeight = boxCustom.getHeight();
-                    if (customViewHeight == 0) {
-                        //实测在 Android 10 中,离屏情况下 View可能无法得到正确高度(恒 0),此时直接按照全屏高度处理
-                        //其他版本 Android 未发现此问题
-                        showEnterAnim((int) boxRoot.getSafeHeight());
-                    } else {
-                        showEnterAnim(customViewHeight);
-                    }
+                    doShowAnim();
                 }
             });
             
@@ -330,32 +333,17 @@ public class FullScreenDialog extends BaseDialog {
             
             if (!dismissAnimFlag) {
                 dismissAnimFlag = true;
-                long exitAnimDurationTemp = 300;
-                if (overrideExitDuration >= 0) {
-                    exitAnimDurationTemp = overrideExitDuration;
-                }
-                if (exitAnimDuration >= 0) {
-                    exitAnimDurationTemp = exitAnimDuration;
-                }
-                
-                ObjectAnimator exitAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), boxBkg.getHeight());
-                exitAnim.setDuration(exitAnimDurationTemp);
-                exitAnim.start();
-                
-                ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
-                bkgAlpha.setDuration(exitAnimDurationTemp);
-                bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                doExitAnim(new ObjectRunnable<ValueAnimator>() {
                     @Override
-                    public void onAnimationUpdate(ValueAnimator animation) {
+                    public void run(ValueAnimator valueAnimator) {
                         if (boxRoot != null) {
-                            float value = (float) animation.getAnimatedValue();
+                            float value = (float) valueAnimator.getAnimatedValue();
                             boxRoot.setBkgAlpha(value);
                             if (value == 0) boxRoot.setVisibility(View.GONE);
                         }
                     }
                 });
-                bkgAlpha.start();
-                
+    
                 new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
                     @Override
                     public void run() {
@@ -382,6 +370,43 @@ public class FullScreenDialog extends BaseDialog {
                 exitAnim.start();
             }
         }
+        
+        protected void doShowAnim() {
+            int customViewHeight = boxCustom.getHeight();
+            if (customViewHeight == 0) {
+                //实测在 Android 10 中,离屏情况下 View可能无法得到正确高度(恒 0),此时直接按照全屏高度处理
+                //其他版本 Android 未发现此问题
+                showEnterAnim((int) boxRoot.getSafeHeight());
+            } else {
+                showEnterAnim(customViewHeight);
+            }
+        }
+        
+        long exitAnimDurationTemp;
+        
+        protected void doExitAnim(ObjectRunnable<ValueAnimator> objectRunnable) {
+            exitAnimDurationTemp = 300;
+            if (overrideExitDuration >= 0) {
+                exitAnimDurationTemp = overrideExitDuration;
+            }
+            if (exitAnimDuration >= 0) {
+                exitAnimDurationTemp = exitAnimDuration;
+            }
+            
+            ObjectAnimator exitAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), boxBkg.getHeight());
+            exitAnim.setDuration(exitAnimDurationTemp);
+            exitAnim.start();
+            
+            ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
+            bkgAlpha.setDuration(exitAnimDurationTemp);
+            bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                @Override
+                public void onAnimationUpdate(ValueAnimator animation) {
+                    objectRunnable.run(animation);
+                }
+            });
+            bkgAlpha.start();
+        }
     }
     
     @Override
@@ -537,12 +562,35 @@ public class FullScreenDialog extends BaseDialog {
         show(dialogView);
     }
     
+    private boolean isHide;
+    
     public void hide() {
+        isHide = true;
+        hideWithExitAnim = false;
         if (getDialogView() != null) {
             getDialogView().setVisibility(View.GONE);
         }
     }
     
+    protected boolean hideWithExitAnim;
+    
+    public void hideWithExitAnim() {
+        hideWithExitAnim = true;
+        isHide = true;
+        if (getDialogImpl() != null) {
+            getDialogImpl().doExitAnim(new ObjectRunnable<ValueAnimator>() {
+                @Override
+                public void run(ValueAnimator valueAnimator) {
+                    float value = (float) valueAnimator.getAnimatedValue();
+                    getDialogImpl().boxRoot.setBkgAlpha(value);
+                    if (value == 0 && getDialogView() != null) {
+                        getDialogView().setVisibility(View.GONE);
+                    }
+                }
+            });
+        }
+    }
+    
     @Override
     protected void shutdown() {
         dismiss();

+ 109 - 48
DialogX/src/main/java/com/kongzue/dialogx/dialogs/MessageDialog.java

@@ -41,6 +41,7 @@ import com.kongzue.dialogx.interfaces.OnBindView;
 import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
 import com.kongzue.dialogx.interfaces.OnInputDialogButtonClickListener;
 import com.kongzue.dialogx.style.MaterialStyle;
+import com.kongzue.dialogx.util.ObjectRunnable;
 import com.kongzue.dialogx.util.views.BlurView;
 import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
 import com.kongzue.dialogx.util.InputInfo;
@@ -216,6 +217,21 @@ public class MessageDialog extends BaseDialog {
     protected DialogImpl dialogImpl;
     
     public MessageDialog show() {
+        if (isHide && getDialogView() != null && isShow) {
+            if (hideWithExitAnim && getDialogImpl() != null) {
+                getDialogView().setVisibility(View.VISIBLE);
+                getDialogImpl().doShowAnim(new ObjectRunnable<ValueAnimator>() {
+                    @Override
+                    public void run(ValueAnimator valueAnimator) {
+                        float value = (float) valueAnimator.getAnimatedValue();
+                        getDialogImpl().boxRoot.setBkgAlpha(value);
+                    }
+                });
+            } else {
+                getDialogView().setVisibility(View.VISIBLE);
+            }
+            return this;
+        }
         super.beforeShow();
         if (getDialogView() == null) {
             int layoutId = style.layout(isLightTheme());
@@ -312,35 +328,14 @@ public class MessageDialog extends BaseDialog {
                 public void onShow() {
                     isShow = true;
                     preShow = false;
-                    int enterAnimResId = style.enterAnimResId() == 0 ? R.anim.anim_dialogx_default_enter : style.enterAnimResId();
-                    if (overrideEnterAnimRes != 0) {
-                        enterAnimResId = overrideEnterAnimRes;
-                    }
-                    if (customEnterAnimResId != 0) {
-                        enterAnimResId = customEnterAnimResId;
-                    }
-                    Animation enterAnim = AnimationUtils.loadAnimation(getTopActivity(), enterAnimResId);
-                    long enterAnimDurationTemp = enterAnim.getDuration();
-                    if (overrideEnterDuration >= 0) {
-                        enterAnimDurationTemp = overrideEnterDuration;
-                    }
-                    if (enterAnimDuration >= 0) {
-                        enterAnimDurationTemp = enterAnimDuration;
-                    }
-                    enterAnim.setDuration(enterAnimDurationTemp);
-                    enterAnim.setInterpolator(new DecelerateInterpolator());
-                    bkg.startAnimation(enterAnim);
                     
-                    ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
-                    bkgAlpha.setDuration(enterAnimDurationTemp);
-                    bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                    doShowAnim(new ObjectRunnable<ValueAnimator>() {
                         @Override
-                        public void onAnimationUpdate(ValueAnimator animation) {
-                            float value = (float) animation.getAnimatedValue();
+                        public void run(ValueAnimator valueAnimator) {
+                            float value = (float) valueAnimator.getAnimatedValue();
                             boxRoot.setBkgAlpha(value);
                         }
                     });
-                    bkgAlpha.start();
                     
                     onDialogShow();
                     getDialogLifecycleCallback().onShow(me);
@@ -722,38 +717,17 @@ public class MessageDialog extends BaseDialog {
             
             if (!dismissAnimFlag) {
                 dismissAnimFlag = true;
-                int exitAnimResId = style.exitAnimResId() == 0 ? R.anim.anim_dialogx_default_exit : style.exitAnimResId();
-                if (overrideExitAnimRes != 0) {
-                    exitAnimResId = overrideExitAnimRes;
-                }
-                if (customExitAnimResId != 0) {
-                    exitAnimResId = customExitAnimResId;
-                }
-                Animation exitAnim = AnimationUtils.loadAnimation(getTopActivity(), exitAnimResId);
-                long exitAnimDurationTemp = exitAnim.getDuration();
-                exitAnim.setInterpolator(new AccelerateInterpolator());
-                if (overrideExitDuration >= 0) {
-                    exitAnimDurationTemp = overrideExitDuration;
-                }
-                if (exitAnimDuration >= 0) {
-                    exitAnimDurationTemp = exitAnimDuration;
-                }
-                exitAnim.setDuration(exitAnimDurationTemp);
-                bkg.startAnimation(exitAnim);
                 
-                ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
-                bkgAlpha.setDuration(exitAnimDurationTemp);
-                bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                doExitAnim(new ObjectRunnable<ValueAnimator>() {
                     @Override
-                    public void onAnimationUpdate(ValueAnimator animation) {
+                    public void run(ValueAnimator valueAnimator) {
                         if (boxRoot != null) {
-                            float value = (float) animation.getAnimatedValue();
+                            float value = (float) valueAnimator.getAnimatedValue();
                             boxRoot.setBkgAlpha(value);
                             if (value == 0) boxRoot.setVisibility(View.GONE);
                         }
                     }
                 });
-                bkgAlpha.start();
                 
                 new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
                     @Override
@@ -763,6 +737,70 @@ public class MessageDialog extends BaseDialog {
                 }, exitAnimDurationTemp);
             }
         }
+        
+        protected void doShowAnim(ObjectRunnable<ValueAnimator> objectRunnable) {
+            int enterAnimResId = style.enterAnimResId() == 0 ? R.anim.anim_dialogx_default_enter : style.enterAnimResId();
+            if (overrideEnterAnimRes != 0) {
+                enterAnimResId = overrideEnterAnimRes;
+            }
+            if (customEnterAnimResId != 0) {
+                enterAnimResId = customEnterAnimResId;
+            }
+            Animation enterAnim = AnimationUtils.loadAnimation(getTopActivity(), enterAnimResId);
+            long enterAnimDurationTemp = enterAnim.getDuration();
+            if (overrideEnterDuration >= 0) {
+                enterAnimDurationTemp = overrideEnterDuration;
+            }
+            if (enterAnimDuration >= 0) {
+                enterAnimDurationTemp = enterAnimDuration;
+            }
+            enterAnim.setDuration(enterAnimDurationTemp);
+            enterAnim.setInterpolator(new DecelerateInterpolator());
+            bkg.startAnimation(enterAnim);
+            
+            ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
+            bkgAlpha.setDuration(enterAnimDurationTemp);
+            bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                @Override
+                public void onAnimationUpdate(ValueAnimator animation) {
+                    objectRunnable.run(animation);
+                }
+            });
+            bkgAlpha.start();
+        }
+        
+        long exitAnimDurationTemp;
+        
+        protected void doExitAnim(ObjectRunnable<ValueAnimator> objectRunnable) {
+            int exitAnimResId = style.exitAnimResId() == 0 ? R.anim.anim_dialogx_default_exit : style.exitAnimResId();
+            if (overrideExitAnimRes != 0) {
+                exitAnimResId = overrideExitAnimRes;
+            }
+            if (customExitAnimResId != 0) {
+                exitAnimResId = customExitAnimResId;
+            }
+            Animation exitAnim = AnimationUtils.loadAnimation(getTopActivity(), exitAnimResId);
+            exitAnimDurationTemp = exitAnim.getDuration();
+            exitAnim.setInterpolator(new AccelerateInterpolator());
+            if (overrideExitDuration >= 0) {
+                exitAnimDurationTemp = overrideExitDuration;
+            }
+            if (exitAnimDuration >= 0) {
+                exitAnimDurationTemp = exitAnimDuration;
+            }
+            exitAnim.setDuration(exitAnimDurationTemp);
+            bkg.startAnimation(exitAnim);
+            
+            ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
+            bkgAlpha.setDuration(exitAnimDurationTemp);
+            bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                @Override
+                public void onAnimationUpdate(ValueAnimator animation) {
+                    objectRunnable.run(animation);
+                }
+            });
+            bkgAlpha.start();
+        }
     }
     
     @Override
@@ -1138,12 +1176,35 @@ public class MessageDialog extends BaseDialog {
         show(dialogView);
     }
     
+    private boolean isHide;
+    
     public void hide() {
+        isHide = true;
+        hideWithExitAnim = false;
         if (getDialogView() != null) {
             getDialogView().setVisibility(View.GONE);
         }
     }
     
+    protected boolean hideWithExitAnim;
+    
+    public void hideWithExitAnim() {
+        hideWithExitAnim = true;
+        isHide = true;
+        if (getDialogImpl() != null) {
+            getDialogImpl().doExitAnim(new ObjectRunnable<ValueAnimator>() {
+                @Override
+                public void run(ValueAnimator valueAnimator) {
+                    float value = (float) valueAnimator.getAnimatedValue();
+                    getDialogImpl().boxRoot.setBkgAlpha(value);
+                    if (value == 0 && getDialogView() != null) {
+                        getDialogView().setVisibility(View.GONE);
+                    }
+                }
+            });
+        }
+    }
+    
     public MessageDialog setAnimResId(int enterResId, int exitResId) {
         customEnterAnimResId = enterResId;
         customExitAnimResId = exitResId;

+ 7 - 0
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopNotification.java

@@ -338,6 +338,10 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
     }
     
     public PopNotification show() {
+        if (isHide && getDialogView() != null){
+            getDialogView().setVisibility(View.VISIBLE);
+            return this;
+        }
         super.beforeShow();
         if (getDialogView() == null) {
             if (DialogX.onlyOnePopNotification) {
@@ -1120,7 +1124,10 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
         show(dialogView);
     }
     
+    private boolean isHide;
+    
     public void hide() {
+        isHide = true;
         if (getDialogView() != null) {
             getDialogView().setVisibility(View.GONE);
         }

+ 7 - 0
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopTip.java

@@ -267,6 +267,10 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
     }
     
     public PopTip show() {
+        if (isHide && getDialogView() != null){
+            getDialogView().setVisibility(View.VISIBLE);
+            return this;
+        }
         super.beforeShow();
         if (getDialogView() == null) {
             if (DialogX.onlyOnePopTip) {
@@ -995,7 +999,10 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
         show(dialogView);
     }
     
+    private boolean isHide;
+    
     public void hide() {
+        isHide = true;
         if (getDialogView() != null) {
             getDialogView().setVisibility(View.GONE);
         }

+ 12 - 0
DialogX/src/main/java/com/kongzue/dialogx/util/ObjectRunnable.java

@@ -0,0 +1,12 @@
+package com.kongzue.dialogx.util;
+
+/**
+ * @author: Kongzue
+ * @github: https://github.com/kongzue/
+ * @homepage: http://kongzue.com/
+ * @mail: myzcxhh@live.cn
+ * @createTime: 2022/8/26 17:10
+ */
+public interface ObjectRunnable<D> {
+    public abstract void run(D d);
+}