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

+ 10 - 1
DialogX/src/main/java/com/kongzue/dialogx/DialogX.java

@@ -1,6 +1,7 @@
 package com.kongzue.dialogx;
 
 import android.content.Context;
+import android.content.res.Resources;
 import android.graphics.Color;
 import android.util.Log;
 
@@ -112,7 +113,7 @@ public class DialogX {
     
     /**
      * 声明:若 Activity 已使用沉浸式适配请开启(已废弃)
-     *
+     * <p>
      * 请注意,若你没有使用沉浸式适配,请关闭此选项,此选项将影响对话框布局是否允许延伸至导航栏背后显示
      */
     @Deprecated
@@ -124,6 +125,9 @@ public class DialogX {
      */
     public static int bottomDialogNavbarColor = Color.TRANSPARENT;
     
+    //触摸滑动触发阈值,影响 BottomDialog、FullScreenDialog 下滑关闭触发距离,单位:像素
+    public static int touchSlideTriggerThreshold = dip2px(35);
+    
     public enum THEME {
         LIGHT, DARK, AUTO
     }
@@ -143,4 +147,9 @@ public class DialogX {
     public static void error(Object o) {
         if (DEBUGMODE) Log.e(">>>", o.toString());
     }
+    
+    private static int dip2px(float dpValue) {
+        final float scale = Resources.getSystem().getDisplayMetrics().density;
+        return (int) (dpValue * scale + 0.5f);
+    }
 }

+ 3 - 2
DialogX/src/main/java/com/kongzue/dialogx/util/BottomDialogTouchEventInterceptor.java

@@ -5,6 +5,7 @@ import android.content.res.Resources;
 import android.view.MotionEvent;
 import android.view.View;
 
+import com.kongzue.dialogx.DialogX;
 import com.kongzue.dialogx.dialogs.BottomDialog;
 import com.kongzue.dialogx.interfaces.ScrollController;
 
@@ -101,7 +102,7 @@ public class BottomDialogTouchEventInterceptor {
                             scrolledY = impl.scrollView.getScrollDistance();
                             isBkgTouched = false;
                             if (bkgOldY == impl.boxRoot.getUnsafePlace().top) {
-                                if (impl.boxBkg.getY() > impl.boxRoot.getUnsafePlace().top + impl.bkgEnterAimY + dip2px(35)) {
+                                if (impl.boxBkg.getY() > impl.boxRoot.getUnsafePlace().top + impl.bkgEnterAimY + DialogX.touchSlideTriggerThreshold) {
                                     impl.preDismiss();
                                 } else if (impl.boxBkg.getY() != bkgOldY) {
                                     ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.boxBkg, "y", impl.boxBkg.getY(),
@@ -110,7 +111,7 @@ public class BottomDialogTouchEventInterceptor {
                                     enterAnim.start();
                                 }
                             } else {
-                                if (impl.boxBkg.getY() > bkgOldY + dip2px(35)) {
+                                if (impl.boxBkg.getY() > bkgOldY + DialogX.touchSlideTriggerThreshold) {
                                     impl.preDismiss();
                                 } else if (impl.boxBkg.getY() != bkgOldY) {
                                     ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.boxBkg, "y", impl.boxBkg.getY(), impl.boxRoot.getUnsafePlace().top);

+ 5 - 4
DialogX/src/main/java/com/kongzue/dialogx/util/FullScreenDialogTouchEventInterceptor.java

@@ -5,6 +5,7 @@ import android.content.res.Resources;
 import android.view.MotionEvent;
 import android.view.View;
 
+import com.kongzue.dialogx.DialogX;
 import com.kongzue.dialogx.dialogs.FullScreenDialog;
 import com.kongzue.dialogx.interfaces.ScrollController;
 
@@ -80,11 +81,11 @@ public class FullScreenDialogTouchEventInterceptor {
                     case MotionEvent.ACTION_CANCEL:
                         isBkgTouched = false;
                         if (bkgOldY == 0) {
-                            if (impl.bkg.getY() < dip2px(35)) {
+                            if (impl.bkg.getY() < DialogX.touchSlideTriggerThreshold) {
                                 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)) {
+                            } else if (impl.bkg.getY() > impl.bkgEnterAimY + DialogX.touchSlideTriggerThreshold) {
                                 impl.preDismiss();
                             } else {
                                 ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.bkg, "y", impl.bkg.getY(), impl.bkgEnterAimY);
@@ -92,11 +93,11 @@ public class FullScreenDialogTouchEventInterceptor {
                                 enterAnim.start();
                             }
                         } else {
-                            if (impl.bkg.getY() < bkgOldY - dip2px(35)) {
+                            if (impl.bkg.getY() < bkgOldY - DialogX.touchSlideTriggerThreshold) {
                                 ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.bkg, "y", impl.bkg.getY(), 0);
                                 enterAnim.setDuration(300);
                                 enterAnim.start();
-                            } else if (impl.bkg.getY() > bkgOldY + dip2px(35)) {
+                            } else if (impl.bkg.getY() > bkgOldY + DialogX.touchSlideTriggerThreshold) {
                                 impl.preDismiss();
                             } else {
                                 ObjectAnimator enterAnim = ObjectAnimator.ofFloat(impl.bkg, "y", impl.bkg.getY(), impl.bkgEnterAimY);

+ 2 - 2
gradle.properties

@@ -19,5 +19,5 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.45.beta25
-BUILD_VERSION_INT=44
+BUILD_VERSION=0.0.45
+BUILD_VERSION_INT=45