소스 검색

Merge remote-tracking branch 'origin/master'

Kongzue 1 년 전
부모
커밋
9f977e5c66

+ 103 - 21
DialogX/src/main/java/com/kongzue/dialogx/dialogs/FullScreenDialog.java

@@ -82,9 +82,9 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
     }
 
     public static FullScreenDialog show(OnBindView<FullScreenDialog> onBindView) {
-        FullScreenDialog fullScreenDialog = new FullScreenDialog(onBindView);
-        fullScreenDialog.show();
-        return fullScreenDialog;
+        FullScreenDialog FullScreenDialog = new FullScreenDialog(onBindView);
+        FullScreenDialog.show();
+        return FullScreenDialog;
     }
 
     public FullScreenDialog show() {
@@ -166,6 +166,8 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
         public float bkgEnterAimY = -1;
         protected int enterY;
 
+        private Rect mUnsafeRect = new Rect(0,0,0,0);
+
         public float getEnterY() {
             return boxRoot.getSafeHeight() - enterY > 0 ? boxRoot.getSafeHeight() - enterY : 0;
         }
@@ -229,6 +231,7 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
             boxRoot.setOnSafeInsetsChangeListener(new OnSafeInsetsChangeListener() {
                 @Override
                 public void onChange(Rect unsafeRect) {
+                    mUnsafeRect.set(unsafeRect);
                     makeEnterY();
                     if (!enterAnimRunning) {
                         bkg.setY(getEnterY());
@@ -249,6 +252,36 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
                 }
             });
 
+            /**
+             * 给自定义布局增加监听,如果布局高度发生改变,则重新计算位置,位置发生变化,则再次使用动画移动布局到指定位置
+             * 目的是给自定义布局高度为wrap_content的用于纠正布局的Y轴位置
+             */
+            boxCustom.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
+                @Override
+                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
+                    int oldHeight = oldBottom - oldTop;
+                    int newHeight = bottom - top;
+                    if (oldHeight != newHeight) {
+                        /**
+                         * 高度发生改变
+                         * 这里判断是否在两种动画途中
+                         */
+                        if (!enterAnimRunning && !boxRoot.getFitSystemBarUtils().isInSmoothingPadding()) {
+                            makeEnterY();
+                            float newBkgEnterAimY = boxRoot.getSafeHeight() - mUnsafeRect.bottom - enterY - boxRoot.getUnsafePlace().top;
+                            if (newBkgEnterAimY < 0) newBkgEnterAimY = 0;
+                            if (newBkgEnterAimY != bkgEnterAimY && bkg.getY() != newBkgEnterAimY) {
+                                float oldVal = bkgEnterAimY;
+                                bkgEnterAimY = newBkgEnterAimY;
+                                //需要重新定义终点
+                                doShowAnimRepeat((int) oldVal, (int) newBkgEnterAimY, true);
+                            } else if (bkg.getY() != newBkgEnterAimY) {
+                                bkg.setY(newBkgEnterAimY);
+                            }
+                        }
+                    }
+                }
+            });
             onDialogInit();
         }
 
@@ -387,32 +420,81 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
 
         private boolean enterAnimRunning = true;
 
+        /**
+         * 弹窗显示的动画
+         * 动画执行途中实时检测终点是否改变,如果改变则中断这次动画重新设置新终点的动画并执行
+         *
+         * @param start 起点位置
+         * @param end   终点位置
+         */
+        private void doShowAnimRepeat(int start, int end, boolean isRepeat) {
+            enterAnimRunning = true;
+            long enterAnimDurationTemp = getEnterAnimationDuration();
+
+            ValueAnimator enterAnimVal = ValueAnimator.ofInt(start, end);
+            enterAnimVal.setDuration(enterAnimDurationTemp);
+            enterAnimVal.setInterpolator(new DecelerateInterpolator());
+            enterAnimVal.addUpdateListener(animation -> {
+                int thisVal = (int) animation.getAnimatedValue();
+                bkg.setY(thisVal);
+
+                makeEnterY();
+                float newBkgEnterAimY = boxRoot.getSafeHeight() - enterY - boxRoot.getUnsafePlace().bottom - boxRoot.getUnsafePlace().top;
+                if (newBkgEnterAimY < 0) newBkgEnterAimY = 0;
+                if (newBkgEnterAimY != bkgEnterAimY) {
+                    bkgEnterAimY = newBkgEnterAimY;
+                    //需要重新定义终点
+                    animation.cancel();
+                    doShowAnimRepeat(thisVal, (int) newBkgEnterAimY, true);
+                } else if (thisVal >= end) {
+                    enterAnimRunning = false;
+                }
+            });
+            enterAnimVal.start();
+            bkg.setVisibility(View.VISIBLE);
+
+            if (!isRepeat) {
+                ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
+                bkgAlpha.setDuration(enterAnimDurationTemp);
+                bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+                    @Override
+                    public void onAnimationUpdate(ValueAnimator animation) {
+                        float value = (float) animation.getAnimatedValue();
+                        boxRoot.setBkgAlpha(value);
+                    }
+                });
+                bkgAlpha.start();
+            }
+        }
+
         protected DialogXAnimInterface<FullScreenDialog> getDialogXAnimImpl() {
             if (dialogXAnimImpl == null) {
                 dialogXAnimImpl = new DialogXAnimInterface<FullScreenDialog>() {
                     @Override
                     public void doShowAnim(FullScreenDialog dialog, ViewGroup dialogBodyView) {
-                        long enterAnimDurationTemp = getEnterAnimationDuration();
+//                        long enterAnimDurationTemp = getEnterAnimationDuration();
                         makeEnterY();
                         bkgEnterAimY = boxRoot.getSafeHeight() - enterY;
                         if (bkgEnterAimY < 0) bkgEnterAimY = 0;
-                        ObjectAnimator enterAnim = ObjectAnimator.ofFloat(bkg, "y", boxRoot.getHeight(), bkgEnterAimY);
-                        enterAnim.setDuration(enterAnimDurationTemp);
-                        enterAnim.setInterpolator(new DecelerateInterpolator());
-                        enterAnim.start();
-                        bkg.setVisibility(View.VISIBLE);
-
-                        ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
-                        bkgAlpha.setDuration(enterAnimDurationTemp);
-                        bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
-                            @Override
-                            public void onAnimationUpdate(ValueAnimator animation) {
-                                float value = (float) animation.getAnimatedValue();
-                                boxRoot.setBkgAlpha(value);
-                                enterAnimRunning = !(value == 1f);
-                            }
-                        });
-                        bkgAlpha.start();
+                        //启动带监控终点位置变化的动画
+                        doShowAnimRepeat(boxRoot.getHeight(), (int) bkgEnterAimY, false);
+//                        ObjectAnimator enterAnim = ObjectAnimator.ofFloat(bkg, "y", boxRoot.getHeight(), bkgEnterAimY);
+//                        enterAnim.setDuration(enterAnimDurationTemp);
+//                        enterAnim.setInterpolator(new DecelerateInterpolator());
+//                        enterAnim.start();
+//                        bkg.setVisibility(View.VISIBLE);
+//
+//                        ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
+//                        bkgAlpha.setDuration(enterAnimDurationTemp);
+//                        bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+//                            @Override
+//                            public void onAnimationUpdate(ValueAnimator animation) {
+//                                float value = (float) animation.getAnimatedValue();
+//                                boxRoot.setBkgAlpha(value);
+//                                enterAnimRunning = !(value == 1f);
+//                            }
+//                        });
+//                        bkgAlpha.start();
                     }
 
                     @Override

+ 7 - 1
DialogX/src/main/java/com/kongzue/dialogx/util/views/DialogXBaseRelativeLayout.java

@@ -60,6 +60,12 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     private OnLifecycleCallBack onLifecycleCallBack;
     private PrivateBackPressedListener onBackPressedListener;
 
+    private FitSystemBarUtils fitSystemBarUtils;
+
+    public FitSystemBarUtils getFitSystemBarUtils() {
+        return fitSystemBarUtils;
+    }
+
     public DialogXBaseRelativeLayout(Context context) {
         super(context);
         init(null);
@@ -102,7 +108,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
             setClipToPadding(false);
         }
         //新增的 设置监听 OnApplyWindowInsetsListener
-        FitSystemBarUtils.attachView(this, new FitSystemBarUtils.CallBack() {
+        fitSystemBarUtils = FitSystemBarUtils.attachView(this, new FitSystemBarUtils.CallBack() {
             @Override
             public boolean isEnable(FitSystemBarUtils.Orientation orientation) {
                 return true;