Bläddra i källkod

0.0.44.beta19

kongzue 3 år sedan
förälder
incheckning
3f5ae224bc

+ 18 - 89
DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java

@@ -290,18 +290,16 @@ public class BottomDialog extends BaseDialog {
             if (btnCancel != null) btnCancel.getPaint().setFakeBoldText(true);
             if (btnSelectPositive != null) btnSelectPositive.getPaint().setFakeBoldText(true);
             if (btnSelectOther != null) btnSelectOther.getPaint().setFakeBoldText(true);
-            
+    
+            boxBkg.setY(getRootFrameLayout().getMeasuredHeight());
             bkg.setMaxWidth(getMaxWidth());
             boxRoot.setParentDialog(me);
             boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
                 @Override
                 public void onShow() {
-                    bkg.setY(getRootFrameLayout().getMeasuredHeight());
                     
                     isShow = true;
                     
-                    boxContent.getViewTreeObserver().addOnGlobalLayoutListener(onContentViewLayoutChangeListener);
-                    
                     getDialogLifecycleCallback().onShow(me);
                     
                     onDialogInit(dialogImpl);
@@ -411,31 +409,26 @@ public class BottomDialog extends BaseDialog {
                     return false;
                 }
             });
-            
-            boxRoot.post(new Runnable() {
+    
+            boxBkg.post(new Runnable() {
                 @Override
                 public void run() {
                     long enterAnimDurationTemp = 300;
-                    /**
-                     * 对于非支持滑动展开的对话框,直接使用从下往上的资源动画实现
-                     * 其他情况不适用,请参考 onContentViewLayoutChangeListener 的代码实现。
-                     */
-                    if (style.overrideBottomDialogRes() == null || !style.overrideBottomDialogRes().touchSlide()) {
-                        Animation enterAnim = AnimationUtils.loadAnimation(getContext(), R.anim.anim_dialogx_bottom_enter);
-                        enterAnimDurationTemp = enterAnim.getDuration();
-                        if (overrideEnterDuration >= 0) {
-                            enterAnimDurationTemp = overrideEnterDuration;
-                        }
-                        if (enterAnimDuration >= 0) {
-                            enterAnimDurationTemp = enterAnimDuration;
-                        }
-                        enterAnim.setDuration(enterAnimDurationTemp);
-                        enterAnim.setInterpolator(new DecelerateInterpolator(2f));
-                        
-                        bkg.setY(bkgEnterAimY);
-                        bkg.startAnimation(enterAnim);
-                    }
                     
+                    //上移动画
+                    ObjectAnimator enterAnim = ObjectAnimator.ofFloat(boxBkg, "y", boxBkg.getY(), boxRoot.getUnsafePlace().top);
+                    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() {
@@ -453,67 +446,6 @@ public class BottomDialog extends BaseDialog {
             });
         }
         
-        private boolean isEnterAnimFinished = false;
-        
-        private ViewTreeObserver.OnGlobalLayoutListener onContentViewLayoutChangeListener = new ViewTreeObserver.OnGlobalLayoutListener() {
-            @Override
-            public void onGlobalLayout() {
-                if (boxContent != null) {
-                    if (style.overrideBottomDialogRes() != null && style.overrideBottomDialogRes().touchSlide()) {
-                        //若内容布已经超出屏幕可用范围,且预设的对话框最大高度已知
-                        if (scrollView.isCanScroll() && bottomDialogMaxHeight != 0) {
-                            //先将内容布局放置到屏幕底部以外区域,然后执行上移动画
-                            if (!isEnterAnimFinished)
-                                bkg.setY(getRootFrameLayout().getMeasuredHeight());
-                            //执行上移动画
-                            if (bottomDialogMaxHeight <= 1) {
-                                //bottomDialogMaxHeight 值若为小于 1 的小数,视为比例
-                                bkgEnterAimY = boxBkg.getHeight() - bkg.getHeight() * bottomDialogMaxHeight;
-                            } else {
-                                bkgEnterAimY = boxBkg.getHeight() - bottomDialogMaxHeight;
-                            }
-                            long enterAnimDurationTemp = 300;
-                            if (overrideEnterDuration >= 0) {
-                                enterAnimDurationTemp = overrideEnterDuration;
-                            }
-                            if (enterAnimDuration >= 0) {
-                                enterAnimDurationTemp = enterAnimDuration;
-                            }
-                            ObjectAnimator keepBottomAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), bkgEnterAimY);
-                            keepBottomAnim.setDuration(enterAnimDurationTemp);
-                            keepBottomAnim.setAutoCancel(true);
-                            keepBottomAnim.setInterpolator(new DecelerateInterpolator(2f));
-                            keepBottomAnim.start();
-                            boxContent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
-                        } else {
-                            bkgEnterAimY = boxBkg.getHeight() - bkg.getHeight();
-                            if (!isEnterAnimFinished) bkg.setY(boxRoot.getHeight());
-                            bkg.post(new Runnable() {
-                                @Override
-                                public void run() {
-                                    ObjectAnimator enterAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), bkgEnterAimY);
-                                    long enterAnimDurationTemp = 300;
-                                    if (overrideEnterDuration >= 0) {
-                                        enterAnimDurationTemp = overrideEnterDuration;
-                                    }
-                                    if (enterAnimDuration >= 0) {
-                                        enterAnimDurationTemp = enterAnimDuration;
-                                    }
-                                    enterAnim.setDuration(enterAnimDurationTemp);
-                                    enterAnim.setAutoCancel(true);
-                                    enterAnim.setInterpolator(new DecelerateInterpolator(2f));
-                                    enterAnim.start();
-                                }
-                            });
-                        }
-                    } else {
-                        bkgEnterAimY = boxBkg.getHeight() - bkg.getHeight();
-                    }
-                }
-                isEnterAnimFinished = true;
-            }
-        };
-        
         @Override
         public void refreshView() {
             if (boxRoot == null || getContext() == null) {
@@ -615,9 +547,6 @@ public class BottomDialog extends BaseDialog {
             
             if (!dismissAnimFlag) {
                 dismissAnimFlag = true;
-                if (boxContent != null) {
-                    boxContent.getViewTreeObserver().removeOnGlobalLayoutListener(onContentViewLayoutChangeListener);
-                }
                 
                 long exitAnimDurationTemp = 300;
                 if (overrideExitDuration >= 0) {

+ 12 - 20
DialogX/src/main/java/com/kongzue/dialogx/util/BottomDialogTouchEventInterceptor.java

@@ -66,18 +66,18 @@ public class BottomDialogTouchEventInterceptor {
                         case MotionEvent.ACTION_DOWN:
                             bkgTouchDownY = event.getY();
                             isBkgTouched = true;
-                            bkgOldY = impl.bkg.getY();
+                            bkgOldY = impl.boxBkg.getY();
                             break;
                         case MotionEvent.ACTION_MOVE:
                             if (isBkgTouched) {
-                                float aimY = impl.bkg.getY() + event.getY() - bkgTouchDownY;
+                                float aimY = impl.boxBkg.getY() + event.getY() - bkgTouchDownY;
                                 if (impl.scrollView.isCanScroll()) {
-                                    if (aimY > 0) {
+                                    if (aimY > impl.boxRoot.getUnsafePlace().top) {
                                         if (impl.scrollView.getScrollDistance() == 0) {
                                             if (impl.scrollView instanceof ScrollController) {
                                                 ((ScrollController) impl.scrollView).lockScroll(true);
                                             }
-                                            impl.bkg.setY(aimY);
+                                            impl.boxBkg.setY(aimY);
                                         } else {
                                             bkgTouchDownY = event.getY();
                                         }
@@ -85,14 +85,14 @@ public class BottomDialogTouchEventInterceptor {
                                         if (impl.scrollView instanceof ScrollController) {
                                             ((ScrollController) impl.scrollView).lockScroll(false);
                                         }
-                                        impl.bkg.setY(0);
+                                        impl.boxBkg.setY(impl.boxRoot.getUnsafePlace().top);
                                     }
                                 } else {
-                                    if (aimY > impl.bkgEnterAimY) {
-                                        impl.bkg.setY(aimY);
+                                    if (aimY > impl.boxRoot.getUnsafePlace().top) {
+                                        impl.boxBkg.setY(aimY);
                                         return true;
                                     } else {
-                                        impl.bkg.setY(impl.bkgEnterAimY);
+                                        impl.boxBkg.setY(impl.boxRoot.getUnsafePlace().top);
                                     }
                                 }
                             }
@@ -102,26 +102,18 @@ public class BottomDialogTouchEventInterceptor {
                             scrolledY = impl.scrollView.getScrollDistance();
                             isBkgTouched = false;
                             if (bkgOldY == 0) {
-                                if (impl.bkg.getY() < dip2px(35)) {
-                                    ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.bkg, "y", impl.bkg.getY(), 0);
-                                    enterAnim.setDuration(300);
-                                    enterAnim.start();
-                                } else if (impl.bkg.getY() > impl.bkgEnterAimY + dip2px(35)) {
+                                if (impl.boxBkg.getY() > impl.bkgEnterAimY + dip2px(35)) {
                                     impl.preDismiss();
                                 } else {
-                                    ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.bkg, "y", impl.bkg.getY(), impl.bkgEnterAimY);
+                                    ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.boxBkg, "y", impl.boxBkg.getY(), impl.boxRoot.getUnsafePlace().top);
                                     enterAnim.setDuration(300);
                                     enterAnim.start();
                                 }
                             } else {
-                                if (impl.bkg.getY() < bkgOldY - dip2px(35)) {
-                                    ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.bkg, "y", impl.bkg.getY(), 0);
-                                    enterAnim.setDuration(300);
-                                    enterAnim.start();
-                                } else if (impl.bkg.getY() > bkgOldY + dip2px(35)) {
+                                if (impl.boxBkg.getY() > bkgOldY + dip2px(35)) {
                                     impl.preDismiss();
                                 } else {
-                                    ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.bkg, "y", impl.bkg.getY(), impl.bkgEnterAimY);
+                                    ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.boxBkg, "y", impl.boxBkg.getY(), impl.boxRoot.getUnsafePlace().top);
                                     enterAnim.setDuration(300);
                                     enterAnim.start();
                                 }

+ 1 - 1
gradle.properties

@@ -19,5 +19,5 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.44.beta18
+BUILD_VERSION=0.0.44.beta19
 BUILD_VERSION_INT=43