Просмотр исходного кода

0.0.49.beta16
- 修复<=API29的部分设备上存在的非安全区不回调的问题;

0.0.49.beta14 ready
- 修复 PopNotification 存在的显示位置错误问题;
- 修复 InputDialog 点击背景无法关闭的问题;
- 修复 FullScreenDialog 滑动错位问题;
- 修复 OnBindView 回调 view 不为 customView 的问题;

0.0.49.beta13
- FullScreenDialog 增加 maskColor 设置;
- 修复 IOS 主题下 MessageDialog 使用 build() 构建模式时无法设置背景颜色的问题;
- 修复 CustomDialog 设置 FullScreen 属性无效的问题;

0.0.49.beta12 ready
- 尝试修正 padding属性设置错误的bug(via @Matcha-xiaobin #356);
- 修复了 PopTip 在频繁弹出时某些已经显示的 PopTip 可能存在的导致异常显示在屏幕顶部的问题;
- BottomDialog 增加 setScrollableWhenContentLargeThanVisibleRange(boolean) 允许将自定义布局添加到对话框本身存在的 ScrollView 外,请注意此方法将会使自定义布局添加到 Title Text、Content(Message Text)之间;

0.0.49.beta11
- 修复部分已知问题;

0.0.49.beta10
- 完善 OnBindView 内部逻辑,当dialog和view相同时不重复执行onBind事件;
- WaitDialog新增onShow(DialogXRunnable)和onDismiss(DialogXRunnable);
- 尝试修复可能存在的问题;

0.0.49.beta9
- 菜单布局结构优化;

0.0.49.beta8
- 对话框内的 dialogView 引用进行了处理,以及 PopTip 的 baseView,减少在低版本安卓系统上出现内存泄漏的可能性
- FullScreenDialog 新增了方法 hideActivityContentView(boolean) 用于设置是否在显示 FullScreenDialog 时不对 activity 的界面内容进行渲染,这将提升一定的性能,此方法只可以在使用 build 方法构建且在执行show方法之前使用,但这将引发一些问题,例如输入法弹出时 FullScreenDialog 无法上浮等;
- 其他问题修复;

0.0.49.beta6
- 对 BottomMenu 的 setOkButton、setCancelButton、setOtherButton 提供了单独的 OnBottomMenuButtonClickListener 参数接口,可直接提供 BottomMenu 参数的 onClick 回调事件;
- BottomDialog/BottomMenu 新增 set/get OkTextInfo 和 OtherTextInfo 方法;
- 修复 DialogXBaseRelativeLayout 可能存在的嵌套循环调用 requestFocus() 方法的问题;
- 修复关于 WaitDialog 设置背景颜色不生效的问题;

0.0.49.beta5 ready
- ActivityScreenShotImageView 增加静态方法 useHardwareRenderingMode,开启可使用硬件加速渲染模式;
- 修复部分系统下 ActivityScreenShotImageView 在执行回收时触发的“Software rendering doesn't support hardware bitmaps.”异常;
- 其他问题修复;

0.0.49.beta4 ready
- 修复部分系统下 BlurRelativeLayout 或 BlurRelativeLayout 在执行回收时触发的“Calling RS with no Context active.”异常;
- ActivityScreenShotImageView 截图方案更新;

0.0.49.beta4 ready
- 修复在部分设备上由 DialogXBaseRelativeLayout 引发的 StackOverflowError,此问题猜测跟特定版本系统固件存在问题有关;

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 год назад
Родитель
Сommit
ad7821a18d

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

@@ -439,7 +439,7 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
                 bkg.setY(thisVal);
 
                 makeEnterY();
-                float newBkgEnterAimY = getEnterY();
+                float newBkgEnterAimY = boxRoot.getSafeHeight() - enterY - boxRoot.getUnsafePlace().bottom - boxRoot.getUnsafePlace().top;
                 if (newBkgEnterAimY < 0) newBkgEnterAimY = 0;
                 if (newBkgEnterAimY != bkgEnterAimY) {
                     bkgEnterAimY = newBkgEnterAimY;

+ 4 - 4
DialogX/src/main/java/com/kongzue/dialogx/interfaces/OnBindView.java

@@ -178,7 +178,7 @@ public abstract class OnBindView<D> {
         }
         parentView.addView(getCustomView(), lp);
         onBind((D) dialog, getCustomView());
-        callSetEvent((D) dialog, (ViewGroup) getCustomView());
+        callSetEvent((D) dialog,  getCustomView());
         if (fragment != null || supportFragment != null) {
             if (dialog.getDialogImplMode() != DialogX.IMPL_MODE.VIEW) {
                 BaseDialog.error(dialog.dialogKey() + "非 VIEW 实现模式不支持 fragment 作为子布局显示。\n" +
@@ -209,10 +209,10 @@ public abstract class OnBindView<D> {
 
     private int dialogHash, parentViewHash;
 
-    private void callSetEvent(D dialog, ViewGroup parentView) {
-        if (dialog.hashCode() != dialogHash || parentView.hashCode() != parentViewHash) {
+    private void callSetEvent(D dialog, View view) {
+        if (dialog.hashCode() != dialogHash || view.hashCode() != parentViewHash) {
             dialogHash = dialog.hashCode();
-            parentViewHash = parentView.hashCode();
+            parentViewHash = view.hashCode();
             setEvent(dialog, getCustomView());
         }
     }

+ 60 - 78
DialogX/src/main/java/com/kongzue/dialogx/util/views/DialogXBaseRelativeLayout.java

@@ -12,6 +12,7 @@ import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.RelativeLayout;
 
@@ -40,10 +41,10 @@ import java.util.Map;
  */
 public class DialogXBaseRelativeLayout extends RelativeLayout {
 
-    public static boolean debugMode = true;
+    public static boolean debugMode = false;
 
     private OnSafeInsetsChangeListener onSafeInsetsChangeListener;
-    private BaseDialog parentDialog;
+    private WeakReference<BaseDialog> parentDialog;
     private boolean autoUnsafePlacePadding = true;
     private boolean focusable = true;
     private boolean interceptBack = true;
@@ -97,74 +98,64 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
             }
             setClipChildren(false);
             setClipToPadding(false);
-        }
-        //新增的 设置监听 OnApplyWindowInsetsListener
-        fitSystemBarUtils = FitSystemBarUtils.attachView(this, new FitSystemBarUtils.CallBack() {
-            @Override
-            public boolean isEnable(FitSystemBarUtils.Orientation orientation) {
-                return true;
-            }
 
-            @Override
-            public void unsafeRect(int start, int top, int end, int bottom) {
-                if (unsafePlace == null) {
-                    unsafePlace = new Rect();
+            //新增的 设置监听 OnApplyWindowInsetsListener
+            log("KONGZUE DEBUG DIALOGX: create fitSystemBarUtils");
+            fitSystemBarUtils = FitSystemBarUtils.attachView(this, new FitSystemBarUtils.CallBack() {
+                @Override
+                public boolean isEnable(FitSystemBarUtils.Orientation orientation) {
+                    return true;
                 }
-                unsafePlace.left = start;
-                unsafePlace.top = top;
-                unsafePlace.right = end;
-                unsafePlace.bottom = bottom;
 
-                if (onSafeInsetsChangeListener != null) {
-                    onSafeInsetsChangeListener.onChange(unsafePlace);
-                }
+                @Override
+                public void unsafeRect(int start, int top, int end, int bottom) {
+                    log("KONGZUE DEBUG DIALOGX: unsafeRect t=" + top + " b=" + bottom);
+                    if (unsafePlace == null) {
+                        unsafePlace = new Rect();
+                    }
+                    unsafePlace.left = start;
+                    unsafePlace.top = top;
+                    unsafePlace.right = end;
+                    unsafePlace.bottom = bottom;
 
-                //做下判断,如果是底部对话框,则把paddingBottom设为0,改为推起子控件
-                MaxRelativeLayout bkgView = findViewById(R.id.bkg);
-                if (bkgView != null && bkgView.getLayoutParams() instanceof LayoutParams) {
-                    LayoutParams bkgLp = (LayoutParams) bkgView.getLayoutParams();
-                    if (bkgLp.getRules()[ALIGN_PARENT_BOTTOM] == RelativeLayout.TRUE && isAutoUnsafePlacePadding()) {
-                        setPadding(extraPadding[0] + unsafePlace.left,
-                                extraPadding[1] + unsafePlace.top,
-                                extraPadding[2] + unsafePlace.right,
-                                extraPadding[3]
-                        );
-                        bkgView.setNavBarHeight(bottom);
-                        if (getParentDialog() instanceof DialogXBaseBottomDialog) {
-                            if (((DialogXBaseBottomDialog) getParentDialog()).isBottomNonSafetyAreaBySelf()) {
-                                bkgView.setPadding(0, 0, 0, 0);
-                                return;
-                            }
-                        }
-                        bkgView.setPadding(0, 0, 0, bottom);
+                    if (onSafeInsetsChangeListener != null) {
+                        onSafeInsetsChangeListener.onChange(unsafePlace);
                     }
+
+                    setUnsafePadding(start, top, end, bottom);
                 }
-            }
 
-            @Override
-            public int initialPadding(FitSystemBarUtils.Orientation orientation) {
-                switch (orientation) {
-                    case Start:
-                        return extraPadding[0];
-                    case Top:
-                        return extraPadding[1];
-                    case End:
-                        return extraPadding[2];
-                    case Bottom:
-                        return extraPadding[3];
+                @Override
+                public int initialPadding(FitSystemBarUtils.Orientation orientation) {
+                    switch (orientation) {
+                        case Start:
+                            return extraPadding[0];
+                        case Top:
+                            return extraPadding[1];
+                        case End:
+                            return extraPadding[2];
+                        case Bottom:
+                            return extraPadding[3];
+                    }
+                    return 0;
                 }
-                return 0;
-            }
-        });
+            });
+        }
     }
 
     public void setUnsafePadding(@Px int start, @Px int top, @Px int end, @Px int bottom) {
-        if (!isAutoUnsafePlacePadding()) {
-            return;
+        log("KONGZUE DEBUG DIALOGX: getParentDialog()=" + getParentDialog()+" t=" + top + " b=" + bottom);
+        if (getParentDialog() instanceof DialogXBaseBottomDialog) {
+            log("  KONGZUE DEBUG DIALOGX: isDialogXBaseBottomDialog");
+            ViewGroup bkgView = findViewById(R.id.bkg);
+            if (!((DialogXBaseBottomDialog) getParentDialog()).isBottomNonSafetyAreaBySelf() && bkgView != null) {
+                log("    KONGZUE DEBUG DIALOGX: bkgView.setPadding b=" + bottom);
+                bkgView.setPadding(0, 0, 0, bottom);
+            }
+            bottom = 0;
         }
-        if (Build.VERSION.SDK_INT >= 17) {
-            setPaddingRelative(start, top, end, bottom);
-        } else {
+        if (isAutoUnsafePlacePadding()) {
+            log("  KONGZUE DEBUG DIALOGX: root.setPadding t=" + top + " b=" + bottom);
             setPadding(start, top, end, bottom);
         }
     }
@@ -192,8 +183,8 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
                 touchDownY = event.getY();
                 break;
             case MotionEvent.ACTION_UP:
-                if (touch && findFocus() != this) {
-                    float deltaTouchOffset = parentDialog.dip2px(5);
+                if (touch && findFocus() != this && getParentDialog() != null) {
+                    float deltaTouchOffset = getParentDialog().dip2px(5);
                     if (Math.abs(event.getX() - touchDownX) <= deltaTouchOffset && Math.abs(event.getY() - touchDownY) <= deltaTouchOffset) {
                         callOnClick();
                     }
@@ -223,27 +214,12 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
         }
     }
 
-    static Map<String, List<DynamicWindowInsetsAnimationListener>> dynamicWindowInsetsAnimationListenerListMap = new HashMap<>();
-    DynamicWindowInsetsAnimationListener dynamicWindowInsetsAnimationListener;
-    String parentKey;
-
-    public List<DynamicWindowInsetsAnimationListener> getDynamicWindowInsetsAnimationListener(String key) {
-        List<DynamicWindowInsetsAnimationListener> list = dynamicWindowInsetsAnimationListenerListMap.get(key);
-        if (list == null) {
-            list = new ArrayList<>();
-            dynamicWindowInsetsAnimationListenerListMap.put(key, list);
-        }
-        return list;
-    }
-
     @Override
     protected void onDetachedFromWindow() {
         if (onLifecycleCallBack != null) {
             onLifecycleCallBack.onDismiss();
         }
-        getDynamicWindowInsetsAnimationListener(parentKey).remove(dynamicWindowInsetsAnimationListener);
         onSafeInsetsChangeListener = null;
-        parentDialog = null;
         super.onDetachedFromWindow();
     }
 
@@ -338,14 +314,20 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     }
 
     public BaseDialog getParentDialog() {
-        return parentDialog;
+        return parentDialog == null ? null : parentDialog.get();
     }
 
     public DialogXBaseRelativeLayout setParentDialog(BaseDialog parentDialog) {
-        this.parentDialog = parentDialog;
+        this.parentDialog = new WeakReference<>(parentDialog);
         if (parentDialog != null && parentDialog.getDialogImplMode() != DialogX.IMPL_MODE.VIEW) {
             setFitsSystemWindows(true);
         }
+        if (unsafePlace != null) {
+            log("KONGZUE DEBUG DIALOGX: setParentDialog()=" + getParentDialog());
+            setUnsafePadding(unsafePlace.left, unsafePlace.top, unsafePlace.right, unsafePlace.bottom);
+        } else {
+            log("KONGZUE DEBUG DIALOGX: setParentDialog() unsafePlace is null");
+        }
         return this;
     }
 
@@ -438,7 +420,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     }
 
     protected void log(String s) {
-        if (debugMode) {
+        if (debugMode && DialogX.DEBUGMODE) {
             Log.e(">>>", s);
         }
     }

+ 30 - 9
DialogX/src/main/java/com/kongzue/dialogx/util/views/FitSystemBarUtils.java

@@ -4,6 +4,7 @@ package com.kongzue.dialogx.util.views;
 import static androidx.core.view.WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE;
 
 import android.os.Build;
+import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.WindowInsets;
@@ -15,6 +16,8 @@ import androidx.core.view.ViewCompat;
 import androidx.core.view.WindowInsetsAnimationCompat;
 import androidx.core.view.WindowInsetsCompat;
 
+import com.kongzue.dialogx.DialogX;
+
 import java.util.List;
 
 public class FitSystemBarUtils {
@@ -172,21 +175,27 @@ public class FitSystemBarUtils {
         }
 
         if (ViewCompat.isAttachedToWindow(contentView)) {
+            log("KONGZUE DEBUG DIALOGX: AttachedToWindow ok");
             ViewCompat.requestApplyInsets(contentView);
         } else {
+            log("KONGZUE DEBUG DIALOGX: wait AttachedToWindow");
             contentView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
                 @Override
                 public void onViewAttachedToWindow(View view) {
                     view.removeOnAttachStateChangeListener(this);
 
+                    log("KONGZUE DEBUG DIALOGX: onViewAttachedToWindow");
                     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
-                        //别问为啥,问就是在解决API-29的设备上不稳定的问题
-                        ((ViewGroup)view.getParent()).setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
-                            @Override
-                            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
-                                return insets;
+                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
+                            //修复<=API29的部分设备上存在的非安全区不回调的问题
+                            WindowInsets windowInsets = ((ViewGroup) view.getParent()).getRootView().getRootWindowInsets();
+                            if (windowInsets != null) {
+                                log("KONGZUE DEBUG DIALOGX: RootView get Insets");
+                                formatInsets(WindowInsetsCompat.toWindowInsetsCompat(windowInsets), new RelativePadding(initialPadding));
+                            } else {
+                                log("KONGZUE DEBUG DIALOGX: RootView not get Insets");
                             }
-                        });
+                        }
                     }
 
                     ViewCompat.requestApplyInsets(view);
@@ -196,7 +205,6 @@ public class FitSystemBarUtils {
                 public void onViewDetachedFromWindow(View view) {
 
                 }
-
             });
         }
     }
@@ -241,13 +249,16 @@ public class FitSystemBarUtils {
             naviBar = (suv & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
         }
         if (naviBar && (insetsCompat.isVisible(WindowInsetsCompat.Type.ime())
-                        || insetsCompat.isVisible(WindowInsetsCompat.Type.navigationBars()))
+                || insetsCompat.isVisible(WindowInsetsCompat.Type.navigationBars()))
         ) {
             systemWindowInsetBottom = systemBars.bottom;
         }
         if (statusBar && insetsCompat.isVisible(WindowInsetsCompat.Type.statusBars())) {
             systemWindowInsetTop = systemBars.top;
         }
+        if (isWrongInsets(systemBars)) {
+            return;
+        }
 
         if (callBack.isEnable(Orientation.Top)) {
             initialPadding.top += Math.max(systemWindowInsetTop, cutoutPaddingTop);
@@ -289,6 +300,10 @@ public class FitSystemBarUtils {
 
     }
 
+    private boolean isWrongInsets(Insets systemBars) {
+        return systemBars.top == 0 && systemBars.bottom == 0 && systemBars.left == 0 && systemBars.right == 0;
+    }
+
     public interface CallBack {
 
         //是否启用指定边的insets
@@ -326,7 +341,7 @@ public class FitSystemBarUtils {
          */
         public void applyToView(View view) {
             if (view instanceof DialogXBaseRelativeLayout) {
-                ((DialogXBaseRelativeLayout) view).setUnsafePadding(start, top, end, bottom);
+                //((DialogXBaseRelativeLayout) view).setUnsafePadding(start, top, end, bottom);
             } else {
                 ViewCompat.setPaddingRelative(view, start, top, end, bottom);
             }
@@ -336,4 +351,10 @@ public class FitSystemBarUtils {
     enum Orientation {
         Start, Top, End, Bottom
     }
+
+    protected void log(String s) {
+        if (DialogXBaseRelativeLayout.debugMode && DialogX.DEBUGMODE) {
+            Log.e(">>>", s);
+        }
+    }
 }

+ 1 - 1
app/src/main/java/com/kongzue/dialogxdemo/activity/MainActivity.java

@@ -1043,7 +1043,7 @@ public class MainActivity extends BaseActivity {
 
                         webView.loadUrl("https://github.com/kongzue/DialogX");
                     }
-                }).setBottomNonSafetyAreaBySelf(true);
+                }).setBottomNonSafetyAreaBySelf(false);
             }
         });