Browse Source

0.0.49.beta3
- 修复 ActivityScreenShotImageView 可能引发的“Software rendering doesn’t support hardware bitmaps” 异常;
- 修复 BottomDialog/FullScreenDialog 的滑动事件在内部存在 ScrollController 时,若触摸位置处于 ScrollController 布局外无法滑动对话框的问题;

0.0.49.beta2
- InputInfo新增方法:`getInputFilters()`、`setInputFilters(InputFilter[] inputFilters)`、`addInputFilter(InputFilter inputFilter)` 和 `removeInputFilter(InputFilter inputFilter)`(issues:332);
- 尝试性修复 DialogFragment 模式实现下的 WaitDialog 内存泄漏问题(issues:334);
- 修复关于DialogFragmentImpl引发的空指针问题此问题(issues:335);

0.0.49.beta1
- 修复 BlurRelativeLayout 和 BlurLinearLayout 在 iOS 主题下使用 DialogFragment 模式时存在的渲染宽度和高度 <=0 导致的异常(issues:324);
- 修复 IOS 主题下可能存在的 `RSInvalidStateException: Calling RS with no Context active` 异常问题(issues:327);
- 修复可能存在的高频启关对话框过程中,因UI未完成构建被关闭引发的空指针异常(issues:331);

Kongzue 1 year ago
parent
commit
6837bdc283

+ 6 - 0
DialogX/src/main/java/com/kongzue/dialogx/interfaces/BaseDialog.java

@@ -808,6 +808,9 @@ public abstract class BaseDialog implements LifecycleOwner {
                     for (BaseDialog baseDialog : copyOnWriteList) {
                         if (baseDialog.getOwnActivity() == activity && baseDialog.dialogView != null) {
                             WindowUtil.dismiss(baseDialog.dialogView.get());
+                            if (baseDialog instanceof WaitDialog){
+                                ((WaitDialog) baseDialog).cleanInstance();
+                            }
                             runningDialogList.remove(baseDialog);
                         }
                     }
@@ -837,6 +840,9 @@ public abstract class BaseDialog implements LifecycleOwner {
                         if (baseDialog.getOwnActivity() == activity) {
                             baseDialog.cleanActivityContext();
                             runningDialogList.remove(baseDialog);
+                            if (baseDialog instanceof WaitDialog){
+                                ((WaitDialog) baseDialog).cleanInstance();
+                            }
                         }
                     }
                 }

+ 29 - 7
DialogX/src/main/java/com/kongzue/dialogx/util/BottomDialogTouchEventInterceptor.java

@@ -2,6 +2,7 @@ package com.kongzue.dialogx.util;
 
 import android.animation.ObjectAnimator;
 import android.content.res.Resources;
+import android.graphics.RectF;
 import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
@@ -78,20 +79,16 @@ public class BottomDialogTouchEventInterceptor {
                         case MotionEvent.ACTION_MOVE:
                             if (isBkgTouched) {
                                 float aimY = impl.boxBkg.getY() + event.getY() - bkgTouchDownY;
-                                if (impl.scrollView.isCanScroll()) {
+                                if (impl.scrollView.isCanScroll() && touchInScrollView(impl.bkg, impl.scrollView, event)) {
                                     if (aimY > impl.boxRoot.getUnsafePlace().top) {
                                         if (impl.scrollView.getScrollDistance() == 0) {
-                                            if (impl.scrollView instanceof ScrollController) {
-                                                ((ScrollController) impl.scrollView).lockScroll(true);
-                                            }
+                                            impl.scrollView.lockScroll(true);
                                             impl.boxBkg.setY(aimY);
                                         } else {
                                             bkgTouchDownY = event.getY();
                                         }
                                     } else {
-                                        if (impl.scrollView instanceof ScrollController) {
-                                            ((ScrollController) impl.scrollView).lockScroll(false);
-                                        }
+                                        impl.scrollView.lockScroll(false);
                                         impl.boxBkg.setY(impl.boxRoot.getUnsafePlace().top);
                                     }
                                 } else {
@@ -139,6 +136,31 @@ public class BottomDialogTouchEventInterceptor {
         }
     }
 
+    /**
+     * 检查 MotionEvent 触摸点是否在 scrollView 相对于对话框移动布局 slideView 范围内
+     *
+     * @param slideView  对话框移动布局
+     * @param scrollView 内部滚动布局
+     * @param event      触摸事件
+     * @return 是否在范围内
+     */
+    private boolean touchInScrollView(View slideView, ScrollController scrollView, MotionEvent event) {
+        View scrollViewImpl = (View) scrollView;
+        RectF scrollViewLocation = new RectF();
+        int[] scrollViewScreenLoc = new int[2];
+        int[] rootViewScreenLoc = new int[2];
+        scrollViewImpl.getLocationOnScreen(scrollViewScreenLoc);
+        slideView.getLocationOnScreen(rootViewScreenLoc);
+
+        scrollViewLocation.left = scrollViewScreenLoc[0] - rootViewScreenLoc[0];
+        scrollViewLocation.top = scrollViewScreenLoc[1] - rootViewScreenLoc[1];
+        scrollViewLocation.right = scrollViewLocation.left + scrollViewImpl.getWidth();
+        scrollViewLocation.bottom = scrollViewLocation.top + scrollViewImpl.getHeight();
+
+        return event.getX() >= scrollViewLocation.left && event.getX() <= scrollViewLocation.right &&
+                event.getY() >= scrollViewLocation.top && event.getY() <= scrollViewLocation.bottom;
+    }
+
     private int dip2px(float dpValue) {
         final float scale = Resources.getSystem().getDisplayMetrics().density;
         return (int) (dpValue * scale + 0.5f);

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

@@ -2,6 +2,8 @@ package com.kongzue.dialogx.util;
 
 import android.animation.ObjectAnimator;
 import android.content.res.Resources;
+import android.graphics.Rect;
+import android.graphics.RectF;
 import android.view.MotionEvent;
 import android.view.View;
 
@@ -17,7 +19,7 @@ import com.kongzue.dialogx.interfaces.ScrollController;
  * @createTime: 2020/10/19 13:54
  */
 public class FullScreenDialogTouchEventInterceptor {
-    
+
     /**
      * 下边三个值用于判断触控过程,
      * isBkgTouched:标记是否已按下
@@ -28,11 +30,11 @@ public class FullScreenDialogTouchEventInterceptor {
     private boolean isBkgTouched = false;
     private float bkgTouchDownY;
     private float bkgOldY;
-    
+
     public FullScreenDialogTouchEventInterceptor(FullScreenDialog me, FullScreenDialog.DialogImpl impl) {
         refresh(me, impl);
     }
-    
+
     public void refresh(final FullScreenDialog me, final FullScreenDialog.DialogImpl impl) {
         if (me == null || impl == null || impl.bkg == null) {
             return;
@@ -54,7 +56,7 @@ public class FullScreenDialogTouchEventInterceptor {
                         case MotionEvent.ACTION_MOVE:
                             if (isBkgTouched) {
                                 float aimY = impl.bkg.getY() + event.getY() - bkgTouchDownY;
-                                if (impl.scrollView != null && impl.scrollView.isCanScroll()) {
+                                if (impl.scrollView != null && impl.scrollView.isCanScroll() && touchInScrollView(v, impl.scrollView, event)) {
                                     if (aimY > me.getDialogImpl().getEnterY()) {
                                         if (impl.scrollView.getScrollDistance() == 0) {
                                             if (impl.scrollView instanceof ScrollController) {
@@ -122,7 +124,32 @@ public class FullScreenDialogTouchEventInterceptor {
             touchView.setOnTouchListener(null);
         }
     }
-    
+
+    /**
+     * 检查 MotionEvent 触摸点是否在 scrollView 相对于对话框移动布局 slideView 范围内
+     *
+     * @param slideView  对话框移动布局
+     * @param scrollView 内部滚动布局
+     * @param event      触摸事件
+     * @return 是否在范围内
+     */
+    private boolean touchInScrollView(View slideView, ScrollController scrollView, MotionEvent event) {
+        View scrollViewImpl = (View) scrollView;
+        RectF scrollViewLocation = new RectF();
+        int[] scrollViewScreenLoc = new int[2];
+        int[] rootViewScreenLoc = new int[2];
+        scrollViewImpl.getLocationOnScreen(scrollViewScreenLoc);
+        slideView.getLocationOnScreen(rootViewScreenLoc);
+
+        scrollViewLocation.left = scrollViewScreenLoc[0] - rootViewScreenLoc[0];
+        scrollViewLocation.top = scrollViewScreenLoc[1] - rootViewScreenLoc[1];
+        scrollViewLocation.right = scrollViewLocation.left + scrollViewImpl.getWidth();
+        scrollViewLocation.bottom = scrollViewLocation.top + scrollViewImpl.getHeight();
+
+        return event.getX() >= scrollViewLocation.left && event.getX() <= scrollViewLocation.right &&
+                event.getY() >= scrollViewLocation.top && event.getY() <= scrollViewLocation.bottom;
+    }
+
     private int dip2px(float dpValue) {
         final float scale = Resources.getSystem().getDisplayMetrics().density;
         return (int) (dpValue * scale + 0.5f);

+ 14 - 7
DialogX/src/main/java/com/kongzue/dialogx/util/views/ActivityScreenShotImageView.java

@@ -152,14 +152,21 @@ public class ActivityScreenShotImageView extends ImageView {
         if (view.getWidth() == 0 || view.getHeight() == 0) return;
         dialog.getDialogView().setVisibility(GONE);
         setContentViewVisibility(true);
-        view.buildDrawingCache();
-        Rect rect = new Rect();
-        view.getWindowVisibleDisplayFrame(rect);
-        view.setDrawingCacheEnabled(true);
-        setImageBitmap(Bitmap.createBitmap(view.getDrawingCache(), 0, 0, view.getWidth(), view.getHeight()));
-        view.destroyDrawingCache();
+        try {
+            view.buildDrawingCache();
+        }catch (Exception ignored){
+        }
+        try {
+            Rect rect = new Rect();
+            view.getWindowVisibleDisplayFrame(rect);
+            view.setDrawingCacheEnabled(true);
+            setImageBitmap(Bitmap.createBitmap(view.getDrawingCache(), 0, 0, view.getWidth(), view.getHeight()));
+            view.destroyDrawingCache();
+            isScreenshotSuccess = true;
+        }catch (Exception e){
+            isScreenshotSuccess = false;
+        }
         setContentViewVisibility(false);
-        isScreenshotSuccess = true;
         dialog.getDialogView().setVisibility(VISIBLE);
         dialog.getDialogView().requestFocus();
     }

+ 1 - 1
gradle.properties

@@ -19,7 +19,7 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.49.beta2
+BUILD_VERSION=0.0.49.beta3
 BUILD_VERSION_INT=48
 DIALOGX_STYLE_VERSION=5
 android.nonTransitiveRClass=true