Browse Source

0.0.49.beta7
- 对话框内的 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 year ago
parent
commit
6519d806fe

+ 14 - 11
DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java

@@ -110,8 +110,6 @@ public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog
         return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
     }
 
-    private View dialogView;
-
     public static BottomDialog build() {
         return new BottomDialog();
     }
@@ -219,11 +217,13 @@ public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog
                 layoutId = style.overrideBottomDialogRes().overrideDialogLayout(isLightTheme());
             }
 
-            dialogView = createView(layoutId);
+            View dialogView = createView(layoutId);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(dialogView);
+        } else {
+            show(getDialogView());
         }
-        show(dialogView);
         return this;
     }
 
@@ -235,11 +235,13 @@ public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog
                 layoutId = style.overrideBottomDialogRes().overrideDialogLayout(isLightTheme());
             }
 
-            dialogView = createView(layoutId);
+            View dialogView = createView(layoutId);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(activity, dialogView);
+        } else {
+            show(activity, getDialogView());
         }
-        show(activity, dialogView);
     }
 
     protected DialogImpl dialogImpl;
@@ -272,6 +274,7 @@ public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog
 
         public DialogImpl(View convertView) {
             if (convertView == null) return;
+            setDialogView(convertView);
             boxRoot = convertView.findViewById(R.id.box_root);
             boxBkg = convertView.findViewById(R.id.box_bkg);
             bkg = convertView.findViewById(R.id.bkg);
@@ -293,7 +296,7 @@ public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog
             splitSelectPositive = convertView.findViewWithTag("imgPositiveButtonSplit");
             splitSelectOther = convertView.findViewWithTag("imgOtherButtonSplit");
 
-            blurViews = findAllBlurView(dialogView);
+            blurViews = findAllBlurView(convertView);
 
             init();
             dialogImpl = this;
@@ -650,7 +653,7 @@ public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog
                         if (boxRoot != null) {
                             boxRoot.setVisibility(View.GONE);
                         }
-                        dismiss(dialogView);
+                        dismiss(getDialogView());
                     }
                 }, getExitAnimationDuration());
             }
@@ -1105,8 +1108,8 @@ public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog
 
     @Override
     public void restartDialog() {
-        if (dialogView != null) {
-            dismiss(dialogView);
+        if (getDialogView() != null) {
+            dismiss(getDialogView());
             isShow = false;
         }
         if (getDialogImpl().boxCustom != null) {
@@ -1121,7 +1124,7 @@ public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog
         }
 
         enterAnimDuration = 0;
-        dialogView = createView(layoutId);
+        View dialogView = createView(layoutId);
         dialogImpl = new DialogImpl(dialogView);
         if (dialogView != null) dialogView.setTag(me);
         show(dialogView);

+ 51 - 31
DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java

@@ -31,6 +31,8 @@ import com.kongzue.dialogx.util.ObjectRunnable;
 import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
 import com.kongzue.dialogx.util.views.MaxRelativeLayout;
 
+import java.lang.ref.WeakReference;
+
 /**
  * @author: Kongzue
  * @github: https://github.com/kongzue/
@@ -54,14 +56,13 @@ public class CustomDialog extends BaseDialog {
     protected int exitAnimResId = R.anim.anim_dialogx_default_exit;
     protected ALIGN align = ALIGN.CENTER;
     protected boolean autoUnsafePlacePadding = true;
-    private View dialogView;
     protected int maskColor = Color.TRANSPARENT;
     protected BOOLEAN privateCancelable;
     protected boolean bkgInterceptTouch = true;
     protected OnBackgroundMaskClickListener<CustomDialog> onBackgroundMaskClickListener;
     protected DialogXAnimInterface<CustomDialog> dialogXAnimImpl;
 
-    protected View baseView;
+    protected WeakReference<View> baseViewWeakReference;
     protected int alignViewGravity = -1;                                    //指定菜单相对 baseView 的位置
     protected int width = -1;                                               //指定菜单宽度
     protected int height = -1;                                              //指定菜单高度
@@ -131,22 +132,26 @@ public class CustomDialog extends BaseDialog {
         }
         super.beforeShow();
         if (getDialogView() == null) {
-            dialogView = createView(R.layout.layout_dialogx_custom);
+            View dialogView = createView(R.layout.layout_dialogx_custom);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(dialogView);
+        } else {
+            show(getDialogView());
         }
-        show(dialogView);
         return this;
     }
 
     public CustomDialog show(Activity activity) {
         super.beforeShow();
         if (getDialogView() == null) {
-            dialogView = createView(R.layout.layout_dialogx_custom);
+            View dialogView = createView(R.layout.layout_dialogx_custom);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(activity, dialogView);
+        } else {
+            show(activity, getDialogView());
         }
-        show(activity, dialogView);
         return this;
     }
 
@@ -160,6 +165,7 @@ public class CustomDialog extends BaseDialog {
 
         public DialogImpl(View convertView) {
             if (convertView == null) return;
+            setDialogView(convertView);
             boxRoot = convertView.findViewById(R.id.box_root);
             boxCustom = convertView.findViewById(R.id.box_custom);
 
@@ -170,11 +176,11 @@ public class CustomDialog extends BaseDialog {
 
         @Override
         public void init() {
-            if (baseViewLoc == null && baseView != null) {
+            if (baseViewLoc == null && baseView() != null) {
                 baseViewLoc = new int[4];
-                baseView.getLocationOnScreen(baseViewLoc);
-                baseViewLoc[2] = baseView.getWidth();
-                baseViewLoc[3] = baseView.getHeight();
+                baseView().getLocationOnScreen(baseViewLoc);
+                baseViewLoc[2] = baseView().getWidth();
+                baseViewLoc[3] = baseView().getHeight();
             }
             boxRoot.setParentDialog(me);
             boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
@@ -244,7 +250,7 @@ public class CustomDialog extends BaseDialog {
                 return;
             }
             boxRoot.setRootPadding(screenPaddings[0], screenPaddings[1], screenPaddings[2], screenPaddings[3]);
-            if (baseView != null) {
+            if (baseView() != null) {
                 if (!initSetCustomViewLayoutListener) {
                     if (boxCustom != null) {
                         RelativeLayout.LayoutParams rlp;
@@ -260,14 +266,14 @@ public class CustomDialog extends BaseDialog {
                             int calX = 0, calY = 0;
                             if (alignViewGravity != -1) {
                                 if (isAlignBaseViewGravity(Gravity.CENTER_VERTICAL)) {
-                                    calY = (baseViewTop + baseView.getMeasuredHeight() / 2 - boxCustom.getHeight() / 2);
+                                    calY = (baseViewTop + baseView().getMeasuredHeight() / 2 - boxCustom.getHeight() / 2);
                                 }
                                 if (isAlignBaseViewGravity(Gravity.CENTER_HORIZONTAL)) {
-                                    calX = (baseViewLeft + baseView.getMeasuredWidth() / 2 - boxCustom.getWidth() / 2);
+                                    calX = (baseViewLeft + baseView().getMeasuredWidth() / 2 - boxCustom.getWidth() / 2);
                                 }
                                 if (isAlignBaseViewGravity(Gravity.CENTER)) {
-                                    calX = (baseViewLeft + baseView.getMeasuredWidth() / 2 - boxCustom.getWidth() / 2);
-                                    calY = (baseViewTop + baseView.getMeasuredHeight() / 2 - boxCustom.getHeight() / 2);
+                                    calX = (baseViewLeft + baseView().getMeasuredWidth() / 2 - boxCustom.getWidth() / 2);
+                                    calY = (baseViewTop + baseView().getMeasuredHeight() / 2 - boxCustom.getHeight() / 2);
                                 }
 
                                 if (isAlignBaseViewGravity(Gravity.TOP)) {
@@ -277,13 +283,13 @@ public class CustomDialog extends BaseDialog {
                                     calX = baseViewLeft - boxCustom.getWidth() - marginRelativeBaseView[2];
                                 }
                                 if (isAlignBaseViewGravity(Gravity.RIGHT)) {
-                                    calX = baseViewLeft + baseView.getWidth() + marginRelativeBaseView[0];
+                                    calX = baseViewLeft + baseView().getWidth() + marginRelativeBaseView[0];
                                 }
                                 if (isAlignBaseViewGravity(Gravity.BOTTOM)) {
-                                    calY = baseViewTop + baseView.getHeight() + marginRelativeBaseView[1];
+                                    calY = baseViewTop + baseView().getHeight() + marginRelativeBaseView[1];
                                 }
-                                int widthCache = width == 0 ? baseView.getWidth() : width;
-                                int heightCache = height == 0 ? baseView.getHeight() : height;
+                                int widthCache = width == 0 ? baseView().getWidth() : width;
+                                int heightCache = height == 0 ? baseView().getHeight() : height;
                                 baseViewLoc[2] = widthCache > 0 ? widthCache : baseViewLoc[2];
                                 baseViewLoc[3] = heightCache > 0 ? heightCache : baseViewLoc[3];
 
@@ -300,8 +306,8 @@ public class CustomDialog extends BaseDialog {
                         @Override
                         public void onDraw() {
                             int[] baseViewLocCache = new int[2];
-                            if (baseView != null) {
-                                baseView.getLocationOnScreen(baseViewLocCache);
+                            if (baseView() != null) {
+                                baseView().getLocationOnScreen(baseViewLocCache);
                                 if (getDialogImpl() != null && isShow) {
                                     baseViewLoc[0] = baseViewLocCache[0];
                                     baseViewLoc[1] = baseViewLocCache[1];
@@ -445,7 +451,7 @@ public class CustomDialog extends BaseDialog {
                                     baseViewDrawListener = null;
                                     viewTreeObserver = null;
                                 }
-                                dismiss(dialogView);
+                                dismiss(getDialogView());
                             }
                         }, getExitAnimationDuration(null));
                     }
@@ -563,7 +569,7 @@ public class CustomDialog extends BaseDialog {
         Animation enterAnim;
         if (enterAnimResId == R.anim.anim_dialogx_default_enter &&
                 exitAnimResId == R.anim.anim_dialogx_default_exit &&
-                baseView == null) {
+                baseView() == null) {
             switch (align) {
                 case TOP:
                 case TOP_CENTER:
@@ -793,7 +799,7 @@ public class CustomDialog extends BaseDialog {
 
     @Override
     public void restartDialog() {
-        if (dialogView != null) {
+        if (getDialogView() != null) {
             if (getDialogImpl() != null && getDialogImpl().boxCustom != null) {
                 if (baseViewDrawListener != null) {
                     if (viewTreeObserver != null) {
@@ -807,7 +813,7 @@ public class CustomDialog extends BaseDialog {
                     viewTreeObserver = null;
                 }
             }
-            dismiss(dialogView);
+            dismiss(getDialogView());
             isShow = false;
         }
         if (getDialogImpl() != null && getDialogImpl().boxCustom != null) {
@@ -815,7 +821,7 @@ public class CustomDialog extends BaseDialog {
         }
 
         enterAnimDuration = 0;
-        dialogView = createView(R.layout.layout_dialogx_custom);
+        View dialogView = createView(R.layout.layout_dialogx_custom);
         dialogImpl = new DialogImpl(dialogView);
         if (dialogView != null) dialogView.setTag(me);
         show(dialogView);
@@ -885,7 +891,7 @@ public class CustomDialog extends BaseDialog {
     }
 
     public CustomDialog setAlignBaseViewGravity(View baseView, int alignGravity) {
-        this.baseView = baseView;
+        this.baseView(baseView);
         this.alignViewGravity = alignGravity;
         baseViewLoc = new int[4];
         baseView.getLocationOnScreen(baseViewLoc);
@@ -894,7 +900,7 @@ public class CustomDialog extends BaseDialog {
     }
 
     public CustomDialog setAlignBaseView(View baseView) {
-        this.baseView = baseView;
+        this.baseView(baseView);
         baseViewLoc = new int[4];
         baseView.getLocationOnScreen(baseViewLoc);
         setFullScreen(true);
@@ -903,9 +909,9 @@ public class CustomDialog extends BaseDialog {
 
     public CustomDialog setAlignBaseViewGravity(int alignGravity) {
         this.alignViewGravity = alignGravity;
-        if (baseView != null) {
+        if (baseView() != null) {
             baseViewLoc = new int[4];
-            baseView.getLocationOnScreen(baseViewLoc);
+            baseView().getLocationOnScreen(baseViewLoc);
         }
         setFullScreen(true);
         return this;
@@ -976,7 +982,7 @@ public class CustomDialog extends BaseDialog {
     }
 
     public View getBaseView() {
-        return baseView;
+        return baseView();
     }
 
     public int getWidth() {
@@ -1079,4 +1085,18 @@ public class CustomDialog extends BaseDialog {
     public void onDismiss(CustomDialog dialog) {
 
     }
+
+    protected CustomDialog baseView(View view) {
+        if (view == null && baseViewWeakReference != null) {
+            baseViewWeakReference.clear();
+            baseViewWeakReference = null;
+        } else {
+            baseViewWeakReference = new WeakReference<>(view);
+        }
+        return this;
+    }
+
+    protected View baseView() {
+        return baseViewWeakReference == null ? null : baseViewWeakReference.get();
+    }
 }

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

@@ -62,6 +62,7 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
     protected boolean allowInterceptTouch = true;
     protected DialogXAnimInterface<FullScreenDialog> dialogXAnimImpl;
     protected boolean bottomNonSafetyAreaBySelf = false;
+    protected boolean hideActivityContentView;
 
     protected DialogLifecycleCallback<FullScreenDialog> dialogLifecycleCallback;
     protected OnBackgroundMaskClickListener<FullScreenDialog> onBackgroundMaskClickListener;
@@ -72,8 +73,6 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
         super();
     }
 
-    private View dialogView;
-
     public static FullScreenDialog build() {
         return new FullScreenDialog();
     }
@@ -104,22 +103,26 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
         }
         super.beforeShow();
         if (getDialogView() == null) {
-            dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
+            View dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(dialogView);
+        } else {
+            show(getDialogView());
         }
-        show(dialogView);
         return this;
     }
 
     public void show(Activity activity) {
         super.beforeShow();
         if (getDialogView() == null) {
-            dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
+            View dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(activity, dialogView);
+        } else {
+            show(activity, getDialogView());
         }
-        show(activity, dialogView);
     }
 
     protected DialogImpl dialogImpl;
@@ -142,19 +145,21 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
 
         public DialogImpl(View convertView) {
             if (convertView == null) return;
+            setDialogView(convertView);
             imgZoomActivity = convertView.findViewById(R.id.img_zoom_activity);
             boxRoot = convertView.findViewById(R.id.box_root);
             boxBkg = convertView.findViewById(R.id.box_bkg);
             bkg = convertView.findViewById(R.id.bkg);
             boxCustom = convertView.findViewById(R.id.box_custom);
+            imgZoomActivity.hideActivityContentView = hideActivityContentView;
 
             imgZoomActivity.bindDialog(FullScreenDialog.this);
 
             if (hideZoomBackground) {
-                dialogView.setBackgroundResource(R.color.black20);
+                convertView.setBackgroundResource(R.color.black20);
                 imgZoomActivity.setVisibility(View.GONE);
             } else {
-                dialogView.setBackgroundResource(R.color.black);
+                convertView.setBackgroundResource(R.color.black);
                 imgZoomActivity.setVisibility(View.VISIBLE);
             }
             init();
@@ -330,10 +335,10 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
             }
 
             if (hideZoomBackground) {
-                dialogView.setBackgroundResource(R.color.black20);
+                getDialogView().setBackgroundResource(R.color.black20);
                 imgZoomActivity.setVisibility(View.GONE);
             } else {
-                dialogView.setBackgroundResource(R.color.black);
+                getDialogView().setBackgroundResource(R.color.black);
                 imgZoomActivity.setVisibility(View.VISIBLE);
             }
 
@@ -357,7 +362,7 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
                         if (boxRoot != null) {
                             boxRoot.setVisibility(View.GONE);
                         }
-                        dismiss(dialogView);
+                        dismiss(getDialogView());
                     }
                 }, getExitAnimationDuration());
             }
@@ -598,15 +603,15 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
 
     @Override
     public void restartDialog() {
-        if (dialogView != null) {
-            dismiss(dialogView);
+        if (getDialogView() != null) {
+            dismiss(getDialogView());
             isShow = false;
         }
         if (getDialogImpl().boxCustom != null) {
             getDialogImpl().boxCustom.removeAllViews();
         }
         enterAnimDuration = 0;
-        dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
+        View dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
         dialogImpl = new DialogImpl(dialogView);
         if (dialogView != null) dialogView.setTag(me);
         show(dialogView);
@@ -771,4 +776,17 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
         this.bottomNonSafetyAreaBySelf = bottomNonSafetyAreaBySelf;
         return this;
     }
+
+    /**
+     * 是否在显示 FullScreenDialog 时不对 activity 的界面内容进行渲染,这将提升一定的性能
+     * 只可以在使用 build 方法构建且在执行show方法之前使用
+     * 但这将引发一些问题,例如输入法弹出时 FullScreenDialog 无法上浮等
+     *
+     * @param hideActivityContentView 是否显示 activity 的界面内容
+     * @return this
+     */
+    public FullScreenDialog hideActivityContentView(boolean hideActivityContentView) {
+        this.hideActivityContentView = hideActivityContentView;
+        return this;
+    }
 }

+ 3 - 3
DialogX/src/main/java/com/kongzue/dialogx/dialogs/InputDialog.java

@@ -545,8 +545,8 @@ public class InputDialog extends MessageDialog {
     
     @Override
     public void restartDialog() {
-        if (dialogView != null) {
-            dismiss(dialogView);
+        if (getDialogView() != null) {
+            dismiss(getDialogView());
             isShow = false;
         }
         if (getDialogImpl().boxCustom != null) {
@@ -557,7 +557,7 @@ public class InputDialog extends MessageDialog {
         
         String inputText = getInputText();
         enterAnimDuration = 0;
-        dialogView = createView(layoutId);
+        View dialogView = createView(layoutId);
         dialogImpl = new DialogImpl(dialogView);
         if (dialogView != null) dialogView.setTag(me);
         show(dialogView);

+ 14 - 12
DialogX/src/main/java/com/kongzue/dialogx/dialogs/MessageDialog.java

@@ -91,8 +91,6 @@ public class MessageDialog extends BaseDialog {
         super();
     }
 
-    protected View dialogView;
-
     protected CharSequence title;
     protected CharSequence message;
     protected CharSequence okText;
@@ -246,11 +244,13 @@ public class MessageDialog extends BaseDialog {
             int layoutId = style.layout(isLightTheme());
             layoutId = layoutId == 0 ? (isLightTheme() ? R.layout.layout_dialogx_material : R.layout.layout_dialogx_material_dark) : layoutId;
 
-            dialogView = createView(layoutId);
+            View dialogView = createView(layoutId);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(dialogView);
+        }else{
+            show(getDialogView());
         }
-        show(dialogView);
         return this;
     }
 
@@ -260,11 +260,13 @@ public class MessageDialog extends BaseDialog {
             int layoutId = style.layout(isLightTheme());
             layoutId = layoutId == 0 ? (isLightTheme() ? R.layout.layout_dialogx_material : R.layout.layout_dialogx_material_dark) : layoutId;
 
-            dialogView = createView(layoutId);
+            View dialogView = createView(layoutId);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(activity, dialogView);
+        }else{
+            show(activity, getDialogView());
         }
-        show(activity, dialogView);
     }
 
     public void refreshUI() {
@@ -296,6 +298,7 @@ public class MessageDialog extends BaseDialog {
 
         public DialogImpl(View convertView) {
             if (convertView == null) return;
+            setDialogView(convertView);
             boxRoot = convertView.findViewById(R.id.box_root);
             bkg = convertView.findViewById(R.id.bkg);
             txtDialogTitle = convertView.findViewById(R.id.txt_dialog_title);
@@ -309,7 +312,7 @@ public class MessageDialog extends BaseDialog {
             btnSelectNegative = convertView.findViewById(R.id.btn_selectNegative);
             btnSelectPositive = convertView.findViewById(R.id.btn_selectPositive);
 
-            blurViews = findAllBlurView(dialogView);
+            blurViews = findAllBlurView(convertView);
 
             init();
 
@@ -402,7 +405,6 @@ public class MessageDialog extends BaseDialog {
                     isShow = false;
                     getDialogLifecycleCallback().onDismiss(me);
                     MessageDialog.this.onDismiss(me);
-                    dialogView = null;
                     dialogLifecycleCallback = null;
 
                     setLifecycleState(Lifecycle.State.DESTROYED);
@@ -819,7 +821,7 @@ public class MessageDialog extends BaseDialog {
                         if (boxRoot != null) {
                             boxRoot.setVisibility(View.GONE);
                         }
-                        dismiss(dialogView);
+                        dismiss(getDialogView());
                     }
                 }, getExitAnimationDuration(null));
             }
@@ -1269,8 +1271,8 @@ public class MessageDialog extends BaseDialog {
 
     @Override
     public void restartDialog() {
-        if (dialogView != null) {
-            dismiss(dialogView);
+        if (getDialogView() != null) {
+            dismiss(getDialogView());
             isShow = false;
         }
         if (getDialogImpl().boxCustom != null) {
@@ -1280,7 +1282,7 @@ public class MessageDialog extends BaseDialog {
         layoutId = layoutId == 0 ? (isLightTheme() ? R.layout.layout_dialogx_material : R.layout.layout_dialogx_material_dark) : layoutId;
 
         enterAnimDuration = 0;
-        dialogView = createView(layoutId);
+        View dialogView = createView(layoutId);
         dialogImpl = new DialogImpl(dialogView);
         if (dialogView != null) dialogView.setTag(me);
         show(dialogView);

+ 67 - 57
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopMenu.java

@@ -47,6 +47,7 @@ import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
 import com.kongzue.dialogx.util.views.MaxRelativeLayout;
 import com.kongzue.dialogx.util.views.PopMenuListView;
 
+import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -68,10 +69,9 @@ public class PopMenu extends BaseDialog {
     protected OnBindView<PopMenu> onBindView;                               //自定义布局
     protected DialogLifecycleCallback<PopMenu> dialogLifecycleCallback;     //对话框生命周期
     protected OnBackgroundMaskClickListener<PopMenu> onBackgroundMaskClickListener;
-    protected View dialogView;
     protected List<CharSequence> menuList;
     protected DialogImpl dialogImpl;
-    protected View baseView;
+    protected WeakReference<View> baseViewWeakReference;
     protected boolean overlayBaseView = true;                               //允许菜单覆盖在 baseView 上
     protected OnMenuItemClickListener<PopMenu> onMenuItemClickListener;
     protected OnIconChangeCallBack<PopMenu> onIconChangeCallBack;           //设置图标
@@ -98,13 +98,13 @@ public class PopMenu extends BaseDialog {
     public PopMenu(View baseView, List<CharSequence> menuList) {
         this.menuList = new ArrayList<>();
         this.menuList.addAll(menuList);
-        this.baseView = baseView;
+        this.baseView(baseView);
     }
 
     public PopMenu(View baseView, CharSequence[] menuList) {
         this.menuList = new ArrayList<>();
         this.menuList.addAll(Arrays.asList(menuList));
-        this.baseView = baseView;
+        this.baseView(baseView);
     }
 
     public PopMenu(List<CharSequence> menuList) {
@@ -122,19 +122,19 @@ public class PopMenu extends BaseDialog {
     }
 
     public PopMenu(View baseView, OnBindView<PopMenu> onBindView) {
-        this.baseView = baseView;
+        this.baseView(baseView);
         this.onBindView = onBindView;
     }
 
     public PopMenu(View baseView, List<CharSequence> menuList, OnBindView<PopMenu> onBindView) {
-        this.baseView = baseView;
+        this.baseView(baseView);
         this.menuList = new ArrayList<>();
         this.menuList.addAll(menuList);
         this.onBindView = onBindView;
     }
 
     public PopMenu(View baseView, CharSequence[] menuList, OnBindView<PopMenu> onBindView) {
-        this.baseView = baseView;
+        this.baseView(baseView);
         this.menuList = new ArrayList<>();
         this.menuList.addAll(Arrays.asList(menuList));
         this.onBindView = onBindView;
@@ -233,21 +233,23 @@ public class PopMenu extends BaseDialog {
                 }
             }
 
-            dialogView = createView(layoutId);
+            View dialogView = createView(layoutId);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) {
                 dialogView.setTag(me);
             }
+            show(dialogView);
+        } else {
+            show(getDialogView());
         }
-        show(dialogView);
-        if (baseView != null) {
-            viewTreeObserver = baseView.getViewTreeObserver();
+        if (baseView() != null) {
+            viewTreeObserver = baseView().getViewTreeObserver();
             viewTreeObserver.addOnDrawListener(baseViewDrawListener = new ViewTreeObserver.OnDrawListener() {
                 @Override
                 public void onDraw() {
                     int[] baseViewLocCache = new int[2];
-                    if (baseView != null) {
-                        baseView.getLocationOnScreen(baseViewLocCache);
+                    if (baseView() != null) {
+                        baseView().getLocationOnScreen(baseViewLocCache);
                         if (getDialogImpl() != null && !baseViewLoc.isSameLoc(baseViewLocCache)) {
                             baseViewLoc.set(baseViewLocCache);
                             refreshMenuLoc();
@@ -300,46 +302,46 @@ public class PopMenu extends BaseDialog {
         int calX = 0, calY = 0;
         if (alignGravity != -1) {
             if (isAlignGravity(Gravity.CENTER_VERTICAL)) {
-                calY = (Math.max(0, baseViewTop + baseView.getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
+                calY = (Math.max(0, baseViewTop + baseView().getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
             }
             if (isAlignGravity(Gravity.CENTER_HORIZONTAL)) {
                 calX = (Math.max(0, baseViewLeft + (
-                        getWidth() > 0 ? baseView.getMeasuredWidth() / 2 - getWidth() / 2 : 0
+                        getWidth() > 0 ? baseView().getMeasuredWidth() / 2 - getWidth() / 2 : 0
                 )));
             }
             if (isAlignGravity(Gravity.CENTER)) {
                 calX = (Math.max(0, baseViewLeft + (
-                        getWidth() > 0 ? (baseView.getMeasuredWidth() / 2 - getWidth() / 2) : 0
+                        getWidth() > 0 ? (baseView().getMeasuredWidth() / 2 - getWidth() / 2) : 0
                 )));
-                calY = (Math.max(0, baseViewTop + baseView.getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
+                calY = (Math.max(0, baseViewTop + baseView().getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
             }
             if (overlayBaseView) {
                 //菜单覆盖在 baseView 上时
                 if (isAlignGravity(Gravity.TOP)) {
-                    calY = (baseViewTop + baseView.getMeasuredHeight() - boxBody.getHeight());
+                    calY = (baseViewTop + baseView().getMeasuredHeight() - boxBody.getHeight());
                     if (calX == 0) {
                         calX = (Math.max(0, baseViewLeft + (
-                                getWidth() > 0 ? baseView.getMeasuredWidth() / 2 - getWidth() / 2 : 0
+                                getWidth() > 0 ? baseView().getMeasuredWidth() / 2 - getWidth() / 2 : 0
                         )));
                     }
                 }
                 if (isAlignGravity(Gravity.LEFT)) {
-                    calX = Math.max(0, (baseViewLeft + baseView.getMeasuredWidth() - boxBody.getWidth()));
+                    calX = Math.max(0, (baseViewLeft + baseView().getMeasuredWidth() - boxBody.getWidth()));
                     if (calY == 0) {
-                        calY = (Math.max(0, baseViewTop + baseView.getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
+                        calY = (Math.max(0, baseViewTop + baseView().getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
                     }
                 }
                 if (isAlignGravity(Gravity.RIGHT)) {
                     calX = baseViewLeft;
                     if (calY == 0) {
-                        calY = (Math.max(0, baseViewTop + baseView.getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
+                        calY = (Math.max(0, baseViewTop + baseView().getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
                     }
                 }
                 if (isAlignGravity(Gravity.BOTTOM)) {
                     calY = baseViewTop;
                     if (calX == 0) {
                         calX = (Math.max(0, baseViewLeft + (
-                                getWidth() > 0 ? baseView.getMeasuredWidth() / 2 - getWidth() / 2 : 0
+                                getWidth() > 0 ? baseView().getMeasuredWidth() / 2 - getWidth() / 2 : 0
                         )));
                     }
                 }
@@ -348,27 +350,27 @@ public class PopMenu extends BaseDialog {
                     calY = (Math.max(0, baseViewTop - boxBody.getHeight()));
                     if (calX == 0) {
                         calX = (Math.max(0, baseViewLeft + (
-                                getWidth() > 0 ? baseView.getMeasuredWidth() / 2 - getWidth() / 2 : 0
+                                getWidth() > 0 ? baseView().getMeasuredWidth() / 2 - getWidth() / 2 : 0
                         )));
                     }
                 }
                 if (isAlignGravity(Gravity.LEFT)) {
                     calX = Math.max(0, (baseViewLeft - boxBody.getWidth()));
                     if (calY == 0) {
-                        calY = (Math.max(0, baseViewTop + baseView.getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
+                        calY = (Math.max(0, baseViewTop + baseView().getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
                     }
                 }
                 if (isAlignGravity(Gravity.RIGHT)) {
-                    calX = (Math.max(0, baseViewLeft + baseView.getWidth()));
+                    calX = (Math.max(0, baseViewLeft + baseView().getWidth()));
                     if (calY == 0) {
-                        calY = (Math.max(0, baseViewTop + baseView.getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
+                        calY = (Math.max(0, baseViewTop + baseView().getMeasuredHeight() / 2 - boxBody.getHeight() / 2));
                     }
                 }
                 if (isAlignGravity(Gravity.BOTTOM)) {
-                    calY = (Math.max(0, baseViewTop + baseView.getHeight()));
+                    calY = (Math.max(0, baseViewTop + baseView().getHeight()));
                     if (calX == 0) {
                         calX = (Math.max(0, baseViewLeft + (
-                                getWidth() > 0 ? baseView.getMeasuredWidth() / 2 - getWidth() / 2 : 0
+                                getWidth() > 0 ? baseView().getMeasuredWidth() / 2 - getWidth() / 2 : 0
                         )));
                     }
                 }
@@ -389,7 +391,7 @@ public class PopMenu extends BaseDialog {
             }
             result.setX(calX).setY(calY);
         } else {
-            int mHeight = PopMenu.this.height == -1 ? baseView.getHeight() : PopMenu.this.height;
+            int mHeight = PopMenu.this.height == -1 ? baseView().getHeight() : PopMenu.this.height;
             int left = (int) baseViewLoc.getX();
             int top = (int) (baseViewLoc.getY() + (overlayBaseView ? 0 : mHeight) + selectItemYDeviation);
 
@@ -410,8 +412,8 @@ public class PopMenu extends BaseDialog {
             result.setX(left).setY(top);
         }
 
-        int mWidth = PopMenu.this.width == -1 ? baseView.getWidth() : PopMenu.this.width;
-        int mHeight = PopMenu.this.height == -1 ? baseView.getHeight() : PopMenu.this.height;
+        int mWidth = PopMenu.this.width == -1 ? baseView().getWidth() : PopMenu.this.width;
+        int mHeight = PopMenu.this.height == -1 ? baseView().getHeight() : PopMenu.this.height;
         result.setW(mWidth).setH(mHeight);
         return result;
     }
@@ -430,13 +432,15 @@ public class PopMenu extends BaseDialog {
         public PopMenuListView listMenu;
 
         public DialogImpl(View convertView) {
+            if (convertView == null) return;
+            setDialogView(convertView);
             boxRoot = convertView.findViewById(R.id.box_root);
             boxBody = convertView.findViewById(R.id.box_body);
             boxCustom = convertView.findViewById(R.id.box_custom);
             listMenu = convertView.findViewById(R.id.listMenu);
             boxBody.setVisibility(View.INVISIBLE);
 
-            blurViews = findAllBlurView(dialogView);
+            blurViews = findAllBlurView(convertView);
 
             //先设置为 -1 表示未初始化位置
             boxBody.setX(-1);
@@ -471,7 +475,7 @@ public class PopMenu extends BaseDialog {
                     PopMenu.this.onDismiss(me);
                     menuListAdapter = null;
                     dialogImpl = null;
-                    baseView = null;
+                    baseView(null);
                     dialogLifecycleCallback = null;
                     setLifecycleState(Lifecycle.State.DESTROYED);
                     System.gc();
@@ -652,14 +656,14 @@ public class PopMenu extends BaseDialog {
                                     if (viewTreeObserver != null) {
                                         removeDrawListener(viewTreeObserver, baseViewDrawListener);
                                     } else {
-                                        if (baseView != null) {
-                                            removeDrawListener(baseView.getViewTreeObserver(), baseViewDrawListener);
+                                        if (baseView() != null) {
+                                            removeDrawListener(baseView().getViewTreeObserver(), baseViewDrawListener);
                                         }
                                     }
                                     baseViewDrawListener = null;
                                     viewTreeObserver = null;
                                 }
-                                dismiss(dialogView);
+                                dismiss(getDialogView());
                             }
                         }, getExitAnimationDuration(null));
                     }
@@ -677,14 +681,14 @@ public class PopMenu extends BaseDialog {
                     public void doShowAnim(PopMenu dialog, ViewGroup dialogBodyView) {
                         long enterAnimDurationTemp = getEnterAnimationDuration(null);
 
-                        if (baseView != null) {
+                        if (baseView() != null) {
                             //有绑定按钮的情况下
                             int targetHeight = getBodyRealHeight();
                             boxBody.getLayoutParams().height = 1;
 
                             if (overlayBaseView && !listMenu.isCanScroll()) {
-                                if (baseView instanceof TextView) {
-                                    String baseText = ((TextView) baseView).getText().toString();
+                                if (baseView() instanceof TextView) {
+                                    String baseText = ((TextView) baseView()).getText().toString();
                                     for (CharSequence c : menuList) {
                                         if (TextUtils.equals(c.toString(), baseText)) {
                                             selectMenuIndex = menuList.indexOf(c);
@@ -698,7 +702,7 @@ public class PopMenu extends BaseDialog {
                                     if (listMenu.getChildAt(selectMenuIndex) != null) {
                                         int itemHeight = listMenu.getChildAt(selectMenuIndex).getMeasuredHeight();
                                         listMenu.getChildAt(selectMenuIndex).getLocationOnScreen(viewLoc);
-                                        selectItemYDeviation = (int) ((baseView.getMeasuredHeight() / 2f) - (viewLoc[1] - boxBody.getY()) - (itemHeight / 2f));
+                                        selectItemYDeviation = (int) ((baseView().getMeasuredHeight() / 2f) - (viewLoc[1] - boxBody.getY()) - (itemHeight / 2f));
                                     }
                                 }
                             }
@@ -720,7 +724,7 @@ public class PopMenu extends BaseDialog {
 
                                     int aimHeight = animatedValue == 1f ? ViewGroup.LayoutParams.WRAP_CONTENT : (int) (targetHeight * animatedValue);
                                     boxBody.getLayoutParams().height = aimHeight;
-                                    boxBody.getLayoutParams().width = getWidth() == -1 ? baseView.getWidth() : getWidth();
+                                    boxBody.getLayoutParams().width = getWidth() == -1 ? baseView().getWidth() : getWidth();
                                     if ((boxBody.getY() + aimHeight) > boxRoot.getSafeHeight()) {
                                         boxBody.setY(boxRoot.getSafeHeight() - aimHeight);
                                     }
@@ -801,7 +805,7 @@ public class PopMenu extends BaseDialog {
                         bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                             @Override
                             public void onAnimationUpdate(ValueAnimator animation) {
-                                if (boxRoot != null && baseView == null) {
+                                if (boxRoot != null && baseView() == null) {
                                     boxRoot.setBkgAlpha((Float) animation.getAnimatedValue());
                                 }
                             }
@@ -885,18 +889,18 @@ public class PopMenu extends BaseDialog {
 
     @Override
     public void restartDialog() {
-        if (dialogView != null) {
+        if (getDialogView() != null) {
             if (baseViewDrawListener != null) {
                 if (viewTreeObserver != null) {
                     removeDrawListener(viewTreeObserver, baseViewDrawListener);
                 } else {
-                    if (baseView != null) {
-                        removeDrawListener(baseView.getViewTreeObserver(), baseViewDrawListener);
+                    if (baseView() != null) {
+                        removeDrawListener(baseView().getViewTreeObserver(), baseViewDrawListener);
                     }
                 }
                 baseViewDrawListener = null;
             }
-            dismiss(dialogView);
+            dismiss(getDialogView());
             isShow = false;
         }
         if (getDialogImpl().boxCustom != null) {
@@ -910,14 +914,6 @@ public class PopMenu extends BaseDialog {
 
     }
 
-    @Override
-    public View getDialogView() {
-        if (dialogView == null) {
-            return null;
-        }
-        return dialogView;
-    }
-
     public List<CharSequence> getMenuList() {
         return menuList;
     }
@@ -1207,11 +1203,11 @@ public class PopMenu extends BaseDialog {
     }
 
     public View getBaseView() {
-        return baseView;
+        return baseView();
     }
 
     public PopMenu setBaseView(View baseView) {
-        this.baseView = baseView;
+        baseView(baseView);
         refreshUI();
         return this;
     }
@@ -1295,4 +1291,18 @@ public class PopMenu extends BaseDialog {
         this.menuMenuItemLayoutRefreshCallback = menuMenuItemLayoutRefreshCallback;
         return this;
     }
+
+    protected PopMenu baseView(View view) {
+        if (view == null && baseViewWeakReference != null) {
+            baseViewWeakReference.clear();
+            baseViewWeakReference = null;
+        } else {
+            baseViewWeakReference = new WeakReference<>(view);
+        }
+        return this;
+    }
+
+    protected View baseView() {
+        return baseViewWeakReference == null ? null : baseViewWeakReference.get();
+    }
 }

+ 15 - 11
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopNotification.java

@@ -72,7 +72,6 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
     protected DialogImpl dialogImpl;
     protected int enterAnimResId = 0;
     protected int exitAnimResId = 0;
-    private View dialogView;
     protected DialogXStyle.PopNotificationSettings.ALIGN align;
     protected OnDialogButtonClickListener<PopNotification> onButtonClickListener;
     protected OnDialogButtonClickListener<PopNotification> onPopNotificationClickListener;
@@ -381,17 +380,19 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
                         overrideExitDuration
                 ) : exitAnimDuration;
             }
-            dialogView = createView(layoutResId);
+            View dialogView = createView(layoutResId);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(dialogView);
+        } else {
+            show(getDialogView());
         }
-        show(dialogView);
         return this;
     }
 
     public PopNotification show(Activity activity) {
         super.beforeShow();
-        if (dialogView != null) {
+        if (getDialogView() != null) {
             if (DialogX.onlyOnePopNotification) {
                 PopNotification oldInstance = null;
                 if (popNotificationList != null && !popNotificationList.isEmpty()) {
@@ -425,11 +426,13 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
                         overrideExitDuration
                 ) : exitAnimDuration;
             }
-            dialogView = createView(layoutResId);
+            View dialogView = createView(layoutResId);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(activity, dialogView);
+        } else {
+            show(activity, getDialogView());
         }
-        show(activity, dialogView);
         return this;
     }
 
@@ -506,6 +509,7 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
 
         public DialogImpl(View convertView) {
             if (convertView == null) return;
+            setDialogView(convertView);
             boxRoot = convertView.findViewById(R.id.box_root);
             boxBody = convertView.findViewById(R.id.box_body);
             imgDialogxPopIcon = convertView.findViewById(R.id.img_dialogx_pop_icon);
@@ -514,7 +518,7 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
             txtDialogxButton = convertView.findViewById(R.id.txt_dialogx_button);
             boxCustom = convertView.findViewById(R.id.box_custom);
 
-            blurViews = findAllBlurView(dialogView);
+            blurViews = findAllBlurView(convertView);
 
             init();
             dialogImpl = this;
@@ -928,7 +932,7 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
                 }
             }
             for (PopNotification popNotification : new CopyOnWriteArrayList<>(popNotificationList)) {
-                dismiss(popNotification.dialogView);
+                dismiss(popNotification.getDialogView());
             }
         }
     }
@@ -1217,8 +1221,8 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
 
     @Override
     public void restartDialog() {
-        if (dialogView != null) {
-            dismiss(dialogView);
+        if (getDialogView() != null) {
+            dismiss(getDialogView());
             isShow = false;
         }
         if (getDialogImpl().boxCustom != null) {
@@ -1260,7 +1264,7 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
             ) : exitAnimDuration;
         }
         enterAnimDuration = 0;
-        dialogView = createView(layoutResId);
+        View dialogView = createView(layoutResId);
         dialogImpl = new DialogImpl(dialogView);
         if (dialogView != null) dialogView.setTag(me);
         show(dialogView);

+ 15 - 11
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopTip.java

@@ -71,7 +71,6 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
     protected DialogImpl dialogImpl;
     protected int enterAnimResId = 0;
     protected int exitAnimResId = 0;
-    private View dialogView;
     protected DialogXStyle.PopTipSettings.ALIGN align;
     protected OnDialogButtonClickListener<PopTip> onButtonClickListener;
     protected OnDialogButtonClickListener<PopTip> onPopTipClickListener;
@@ -349,17 +348,19 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
                         overrideExitDuration
                 ) : exitAnimDuration;
             }
-            dialogView = createView(layoutResId);
+           View dialogView = createView(layoutResId);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(dialogView);
+        }else{
+            show(getDialogView());
         }
-        show(dialogView);
         return this;
     }
 
     public PopTip show(Activity activity) {
         super.beforeShow();
-        if (dialogView != null) {
+        if (getDialogView() != null) {
             if (DialogX.onlyOnePopTip) {
                 PopTip oldInstance = null;
                 if (popTipList != null && !popTipList.isEmpty()) {
@@ -406,11 +407,13 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
                         overrideExitDuration
                 ) : exitAnimDuration;
             }
-            dialogView = createView(layoutResId);
+           View dialogView = createView(layoutResId);
             dialogImpl = new DialogImpl(dialogView);
             if (dialogView != null) dialogView.setTag(me);
+            show(activity, dialogView);
+        }else{
+            show(activity, getDialogView());
         }
-        show(activity, dialogView);
         return this;
     }
 
@@ -480,6 +483,7 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
 
         public DialogImpl(View convertView) {
             if (convertView == null) return;
+            setDialogView(convertView);
             boxRoot = convertView.findViewById(R.id.box_root);
             boxBody = convertView.findViewById(R.id.box_body);
             imgDialogxPopIcon = convertView.findViewById(R.id.img_dialogx_pop_icon);
@@ -487,7 +491,7 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
             boxCustom = convertView.findViewById(R.id.box_custom);
             txtDialogxButton = convertView.findViewById(R.id.txt_dialogx_button);
 
-            blurViews = findAllBlurView(dialogView);
+            blurViews = findAllBlurView(convertView);
 
             init();
             dialogImpl = this;
@@ -788,7 +792,7 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
                 }
             }
             for (PopTip popTip : new CopyOnWriteArrayList<>(popTipList)) {
-                dismiss(popTip.dialogView);
+                dismiss(popTip.getDialogView());
             }
         }
     }
@@ -1061,8 +1065,8 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
 
     @Override
     public void restartDialog() {
-        if (dialogView != null) {
-            dismiss(dialogView);
+        if (getDialogView() != null) {
+            dismiss(getDialogView());
             isShow = false;
         }
         if (getDialogImpl().boxCustom != null) {
@@ -1116,7 +1120,7 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
             ) : exitAnimDuration;
         }
         enterAnimDuration = 0;
-        dialogView = createView(layoutResId);
+        View dialogView = createView(layoutResId);
         dialogImpl = new DialogImpl(dialogView);
         if (dialogView != null) dialogView.setTag(me);
         show(dialogView);

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

@@ -311,6 +311,7 @@ public class WaitDialog extends BaseDialog {
 
         public DialogImpl(View convertView) {
             if (convertView == null) return;
+            setDialogView(convertView);
             boxRoot = convertView.findViewById(R.id.box_root);
             bkg = convertView.findViewById(R.id.bkg);
             boxProgress = convertView.findViewById(R.id.box_progress);

+ 37 - 23
DialogX/src/main/java/com/kongzue/dialogx/impl/ActivityLifecycleImpl.java

@@ -30,15 +30,15 @@ import static com.kongzue.dialogx.DialogX.error;
  * @createTime: 2020/9/22 11:31
  */
 public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallbacks {
-    
+
     private onActivityResumeCallBack onActivityResumeCallBack;
     private static ActivityLifecycleImpl activityLifecycle;
     private static Application application;
-    
+
     public ActivityLifecycleImpl(ActivityLifecycleImpl.onActivityResumeCallBack onActivityResumeCallBack) {
         this.onActivityResumeCallBack = onActivityResumeCallBack;
     }
-    
+
     public static void init(Context context, ActivityLifecycleImpl.onActivityResumeCallBack onActivityResumeCallBack) {
         if (context != null) {
             Application application = getApplicationContext(context);
@@ -46,7 +46,7 @@ public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallb
                 error("DialogX 未初始化(E1)。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
                 return;
             }
-            
+
             ActivityLifecycleImpl.application = application;
             if (activityLifecycle != null) {
                 application.unregisterActivityLifecycleCallbacks(activityLifecycle);
@@ -58,7 +58,7 @@ public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallb
             }
         }
     }
-    
+
     public static Application getApplicationContext(Context context) {
         if (context != null) {
             return (Application) context.getApplicationContext();
@@ -84,7 +84,7 @@ public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallb
         error("DialogX.init: 初始化异常,请确保init方法内传入的Context是有效的。");
         return null;
     }
-    
+
     public static Application getApplicationContext() {
         if (application != null) {
             return application;
@@ -109,7 +109,7 @@ public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallb
         }
         return null;
     }
-    
+
     public static Activity getTopActivity() {
         try {
             Class activityThreadClass = Class.forName("android.app.ActivityThread");
@@ -141,7 +141,7 @@ public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallb
         }
         return null;
     }
-    
+
     @Override
     public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
         if (onActivityResumeCallBack != null) {
@@ -151,7 +151,7 @@ public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallb
             onActivityResumeCallBack.getActivity(activity);
         }
     }
-    
+
     @Override
     public void onActivityStarted(@NonNull Activity activity) {
         if (application == null) {
@@ -162,11 +162,8 @@ public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallb
     @Override
     public void onActivityPreResumed(@NonNull Activity activity) {
         Application.ActivityLifecycleCallbacks.super.onActivityPreResumed(activity);
-        if (activity.isDestroyed() || activity.isFinishing() || activity instanceof DialogXFloatingWindowActivity) {
-            return;
-        }
-        if (onActivityResumeCallBack != null) {
-            onActivityResumeCallBack.getActivity(activity);
+        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+            callOnResume(activity);
         }
     }
 
@@ -175,38 +172,55 @@ public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallb
         if (activity.isDestroyed() || activity.isFinishing() || activity instanceof DialogXFloatingWindowActivity) {
             return;
         }
+        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
+            callOnResume(activity);
+        }
         BaseDialog.onActivityResume(activity);
     }
-    
+
+    private void callOnResume(Activity activity) {
+        if (activity.isDestroyed() || activity.isFinishing() || activity instanceof DialogXFloatingWindowActivity) {
+            return;
+        }
+        if (onActivityResumeCallBack != null) {
+            onActivityResumeCallBack.getActivity(activity);
+        }
+    }
+
     @Override
     public void onActivityPaused(@NonNull Activity activity) {
     }
-    
+
     @Override
     public void onActivityStopped(@NonNull Activity activity) {
     }
-    
+
     @Override
     public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
-    
+
     }
-    
+
     @Override
     public void onActivityDestroyed(@NonNull Activity activity) {
         if (BaseDialog.getTopActivity() == activity) {
             BaseDialog.cleanContext();
         }
+        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
+            BaseDialog.recycleDialog(activity);
+        }
     }
-    
+
     @Override
     public void onActivityPreDestroyed(@NonNull final Activity activity) {
-        BaseDialog.recycleDialog(activity);
+        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+            BaseDialog.recycleDialog(activity);
+        }
     }
-    
+
     public interface onActivityResumeCallBack {
         void getActivity(Activity activity);
     }
-    
+
     public static boolean isExemptActivities(Activity activity) {
         if (activity == null) return true;
         for (String packageName : DialogX.unsupportedActivitiesPackageNames) {

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

@@ -787,6 +787,7 @@ public abstract class BaseDialog implements LifecycleOwner {
         if (ownActivity != null) {
             ownActivity.clear();
         }
+        dialogView=null;
         ownActivity = null;
     }
 
@@ -1035,4 +1036,8 @@ public abstract class BaseDialog implements LifecycleOwner {
         log("return styleValue=" + styleValue);
         return styleValue;
     }
+
+    protected void setDialogView(View view){
+        dialogView = new WeakReference<>(view);
+    }
 }

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

@@ -33,8 +33,9 @@ import java.util.Objects;
 @SuppressLint("AppCompatCustomView")
 public class ActivityScreenShotImageView extends ImageView {
 
+    public boolean hideActivityContentView;
     float width, height, mRadius;
-    public static boolean useHardwareRenderingMode = false;
+    public static boolean useHardwareRenderingMode = true;
 
     public ActivityScreenShotImageView(Context context) {
         super(context);
@@ -52,6 +53,10 @@ public class ActivityScreenShotImageView extends ImageView {
     }
 
     private void init(AttributeSet attrs) {
+        requestLayoutType();
+    }
+
+    private void requestLayoutType() {
         setLayerType(useHardwareRenderingMode ? LAYER_TYPE_HARDWARE : LAYER_TYPE_SOFTWARE, null);
     }
 
@@ -94,11 +99,8 @@ public class ActivityScreenShotImageView extends ImageView {
 
             canvas.clipPath(path);
         }
-        try {
-            canvas.drawColor(Color.WHITE);
-            super.onDraw(canvas);
-        } catch (Exception e) {
-        }
+        canvas.drawColor(Color.WHITE);
+        super.onDraw(canvas);
     }
 
     @Override
@@ -164,6 +166,11 @@ public class ActivityScreenShotImageView extends ImageView {
             view.draw(canvas);
         } catch (Exception e) {
             if (DialogX.DEBUGMODE) e.printStackTrace();
+            if (useHardwareRenderingMode) {
+                useHardwareRenderingMode = false;
+                requestLayoutType();
+                drawViewImage(view);
+            }
         }
         setImageBitmap(Bitmap.createBitmap(bitmap, 0, 0, view.getWidth(), view.getHeight()));
         isScreenshotSuccess = true;
@@ -173,7 +180,7 @@ public class ActivityScreenShotImageView extends ImageView {
     }
 
     protected void setContentViewVisibility(boolean show) {
-        if (hideContentView) {
+        if (hideContentView || hideActivityContentView) {
             if (show) {
                 if (contentView != null && contentView.get() != null) {
                     contentView.get().setVisibility(VISIBLE);

+ 1 - 1
app/release/output-metadata.json

@@ -12,7 +12,7 @@
       "filters": [],
       "attributes": [],
       "versionCode": 48,
-      "versionName": "0.0.49.beta4",
+      "versionName": "0.0.49.beta6",
       "outputFile": "app-release.apk"
     }
   ],

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -12,6 +12,7 @@
         android:label="@string/app_name"
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
+        android:hardwareAccelerated="true"
         android:theme="@style/AppTheme">
 
         <activity

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

@@ -81,6 +81,7 @@ import com.kongzue.dialogx.style.MIUIStyle;
 import com.kongzue.dialogx.style.MaterialStyle;
 import com.kongzue.dialogx.util.InputInfo;
 import com.kongzue.dialogx.util.TextInfo;
+import com.kongzue.dialogx.util.views.ActivityScreenShotImageView;
 import com.kongzue.dialogxdemo.BuildConfig;
 import com.kongzue.dialogxdemo.R;
 import com.kongzue.dialogxdemo.custom.recycleview.CustomRecycleViewAdapter;
@@ -492,12 +493,14 @@ public class MainActivity extends BaseActivity {
                                 btnFullScreenDialogFragment.callOnClick();
                             }
                         });
-                FullScreenDialog.show(new OnBindView<FullScreenDialog>(customFragment) {
-                    @Override
-                    public void onBind(FullScreenDialog dialog, View v) {
+                FullScreenDialog.build(new OnBindView<FullScreenDialog>(customFragment) {
+                            @Override
+                            public void onBind(FullScreenDialog dialog, View v) {
 
-                    }
-                });
+                            }
+                        })
+                        .hideActivityContentView(true)
+                        .show();
             }
         });
 
@@ -548,7 +551,6 @@ public class MainActivity extends BaseActivity {
             @Override
             public void onClick(View v) {
                 WaitDialog.show("Please Wait!")
-                        .setBackgroundColor(Color.GRAY)
                         .setOnBackPressedListener(new OnBackPressedListener<WaitDialog>() {
                             @Override
                             public boolean onBackPressed(WaitDialog dialog) {
@@ -1216,7 +1218,7 @@ public class MainActivity extends BaseActivity {
                                 selectMenuIndex = index;
                             }
                         })
-                        .setCancelButton("确定",new OnBottomMenuButtonClickListener<BottomMenu>() {
+                        .setCancelButton("确定", new OnBottomMenuButtonClickListener<BottomMenu>() {
                             @Override
                             public boolean onClick(BottomMenu baseDialog, View v) {
                                 PopTip.show("已选择:" + singleSelectMenuText[selectMenuIndex]);
@@ -1243,7 +1245,7 @@ public class MainActivity extends BaseActivity {
                                 selectMenuIndexArray = index;
                             }
                         })
-                        .setOkButton("确定",new OnBottomMenuButtonClickListener<BottomMenu>() {
+                        .setOkButton("确定", new OnBottomMenuButtonClickListener<BottomMenu>() {
                             @Override
                             public boolean onClick(BottomMenu dialog, View v) {
                                 PopTip.show("已选择:" + multiSelectMenuResultCache);