1
0
Эх сурвалжийг харах

0.0.50.beta12
- 支持使用 new 构建对话框对象并复写其 `preDismiss` 方法即可处理刚触发关闭对话框时的事件,请注意,`return true` 表示拦截关闭操作,对应的,启动事件可以使用复写 `preShow` 方法进行拦截或事物处理;

Kongzue 1 жил өмнө
parent
commit
e12a113138

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

@@ -651,6 +651,9 @@ public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog
 
         @Override
         public void doDismiss(View v) {
+            if (BottomDialog.this.preDismiss(BottomDialog.this)){
+                return;
+            }
             if (v != null) v.setEnabled(false);
             if (getOwnActivity() == null) return;
 

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

@@ -435,6 +435,9 @@ public class CustomDialog extends BaseDialog {
 
         @Override
         public void doDismiss(View v) {
+            if (CustomDialog.this.preDismiss(CustomDialog.this)){
+                return;
+            }
             if (v != null) v.setEnabled(false);
             if (!dismissAnimFlag && boxCustom != null) {
                 dismissAnimFlag = true;

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

@@ -392,6 +392,9 @@ public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDia
 
         @Override
         public void doDismiss(View v) {
+            if (FullScreenDialog.this.preDismiss(FullScreenDialog.this)){
+                return;
+            }
             if (v != null) v.setEnabled(false);
             if (getOwnActivity() == null) return;
 

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

@@ -812,6 +812,9 @@ public class MessageDialog extends BaseDialog {
         }
 
         public void doDismiss(View v) {
+            if (MessageDialog.this.preDismiss(MessageDialog.this)){
+                return;
+            }
             if (v != null) v.setEnabled(false);
             if (getOwnActivity() == null) return;
 

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

@@ -656,6 +656,9 @@ public class PopMenu extends BaseDialog {
 
         @Override
         public void doDismiss(View v) {
+            if (preDismiss(PopMenu.this)){
+                return;
+            }
             if (v != null) {
                 v.setEnabled(false);
             }

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

@@ -836,6 +836,9 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
 
         @Override
         public void doDismiss(final View v) {
+            if (PopNotification.this.preDismiss(PopNotification.this)){
+                return;
+            }
             if (v != null) v.setEnabled(false);
 
             if (!dismissAnimFlag && boxRoot != null) {

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

@@ -694,6 +694,9 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
 
         @Override
         public void doDismiss(final View v) {
+            if (PopTip.this.preDismiss(PopTip.this)){
+                return;
+            }
             if (v != null) v.setEnabled(false);
 
             if (!dismissAnimFlag && boxRoot != null) {

+ 8 - 20
DialogX/src/main/java/com/kongzue/dialogx/dialogs/WaitDialog.java

@@ -80,13 +80,7 @@ public class WaitDialog extends BaseDialog {
          * <p>
          * 要是用进度,请直接使用 WaitDialog.show(float)
          */
-        @Deprecated
-        NONE,
-        SUCCESS,
-        WARNING,
-        ERROR,
-        @Deprecated
-        PROGRESSING
+        @Deprecated NONE, SUCCESS, WARNING, ERROR, @Deprecated PROGRESSING
     }
 
     protected static WeakReference<WaitDialog> me;
@@ -342,9 +336,7 @@ public class WaitDialog extends BaseDialog {
             Float dialogXRadius = (float) dip2px(15);
             if (style.overrideWaitTipRes() != null) {
                 dialogXRadius = getFloatStyleAttr((float) style.overrideWaitTipRes().overrideRadiusPx(), dialogXRadius);
-                blurFrontColor = getColorNullable(
-                        getIntStyleAttr(style.overrideWaitTipRes().overrideBackgroundColorRes(isLightTheme()), isLightTheme() ? R.color.dialogxWaitBkgDark : R.color.dialogxWaitBkgLight),
-                        blurFrontColor);
+                blurFrontColor = getColorNullable(getIntStyleAttr(style.overrideWaitTipRes().overrideBackgroundColorRes(isLightTheme()), isLightTheme() ? R.color.dialogxWaitBkgDark : R.color.dialogxWaitBkgLight), blurFrontColor);
             }
             if (blurViews != null) {
                 for (View blurView : blurViews) {
@@ -509,6 +501,9 @@ public class WaitDialog extends BaseDialog {
         }
 
         public void doDismiss(final View v) {
+            if (WaitDialog.this.preDismiss(WaitDialog.this)) {
+                return;
+            }
             if (boxRoot == null) return;
             if (getOwnActivity() == null) return;
 
@@ -562,11 +557,7 @@ public class WaitDialog extends BaseDialog {
                         });
                         bkgAlpha.start();
 
-                        boxRoot.animate()
-                                .setDuration(enterAnimDurationTemp)
-                                .alpha(1f)
-                                .setInterpolator(new DecelerateInterpolator())
-                                .setListener(null);
+                        boxRoot.animate().setDuration(enterAnimDurationTemp).alpha(1f).setInterpolator(new DecelerateInterpolator()).setListener(null);
                     }
 
                     @Override
@@ -588,10 +579,7 @@ public class WaitDialog extends BaseDialog {
                         exitAnim.setInterpolator(new AccelerateInterpolator());
                         bkg.startAnimation(exitAnim);
 
-                        boxRoot.animate()
-                                .alpha(0f)
-                                .setInterpolator(new AccelerateInterpolator())
-                                .setDuration(exitAnimDurationTemp);
+                        boxRoot.animate().alpha(0f).setInterpolator(new AccelerateInterpolator()).setDuration(exitAnimDurationTemp);
 
                         ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
                         bkgAlpha.setDuration(exitAnimDurationTemp);
@@ -1227,7 +1215,7 @@ public class WaitDialog extends BaseDialog {
         return this;
     }
 
-    public WaitDialog appendMessage(CharSequence message){
+    public WaitDialog appendMessage(CharSequence message) {
         this.message = TextUtils.concat(this.message, message);
         refreshUI();
         return this;

+ 30 - 16
DialogX/src/main/java/com/kongzue/dialogx/interfaces/BaseDialog.java

@@ -177,6 +177,9 @@ public abstract class BaseDialog implements LifecycleOwner {
                 error(((BaseDialog) view.getTag()).dialogKey() + "已处于显示状态,请勿重复执行 show() 指令。");
                 return;
             }
+            if (dialog.preShow(dialog)) {
+                return;
+            }
             dialog.dialogView = new WeakReference<>(view);
 
             log(dialog.dialogKey() + ".show on " + dialog.getOwnActivity());
@@ -293,6 +296,9 @@ public abstract class BaseDialog implements LifecycleOwner {
                 error(((BaseDialog) view.getTag()).dialogKey() + ".show ERROR: activity is Destroyed.");
                 return;
             }
+            if (baseDialog.preShow(baseDialog)) {
+                return;
+            }
             baseDialog.dialogView = new WeakReference<>(view);
 
             log(baseDialog + ".show on " + activity);
@@ -632,23 +638,14 @@ public abstract class BaseDialog implements LifecycleOwner {
         if (activity == null) {
             activity = getTopActivity();
             if (activity == null) {
-                error("DialogX 错误:在 getRootFrameLayout() 时无法获取绑定的 activity,请确认是否正确初始化:\n" +
-                        "DialogX.init(context);\n\n" +
-                        "或者使用 .show(activity) 启动对话框\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
+                error("DialogX 错误:在 getRootFrameLayout() 时无法获取绑定的 activity,请确认是否正确初始化:\n" + "DialogX.init(context);\n\n" + "或者使用 .show(activity) 启动对话框\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
                 return null;
             }
             setOwnActivity(activity);
         }
         FrameLayout decorView = getDecorView(activity);
         if (decorView == null) {
-            error("DialogX 错误:在 getRootFrameLayout() 时无法获 activity(" + activity + ") 的 decorView,请检查该 activity 是否正常显示且可以使 DialogX 基于其显示。\n" +
-                    "若该 activity 不可用,可通过以下代码配置豁免 DialogX 对话框绑定至该 activity,例如:\n" +
-                    "DialogX.unsupportedActivitiesPackageNames = new String[]{\n" +
-                    "        \"com.bytedance.sdk.openadsdk.stub.activity\",\n" +
-                    "        \"com.mobile.auth.gatewayauth\",\n" +
-                    "        \"com.google.android.gms.ads\"\n" +
-                    "};\n\n" +
-                    "另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
+            error("DialogX 错误:在 getRootFrameLayout() 时无法获 activity(" + activity + ") 的 decorView,请检查该 activity 是否正常显示且可以使 DialogX 基于其显示。\n" + "若该 activity 不可用,可通过以下代码配置豁免 DialogX 对话框绑定至该 activity,例如:\n" + "DialogX.unsupportedActivitiesPackageNames = new String[]{\n" + "        \"com.bytedance.sdk.openadsdk.stub.activity\",\n" + "        \"com.mobile.auth.gatewayauth\",\n" + "        \"com.google.android.gms.ads\"\n" + "};\n\n" + "另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
             return null;
         }
         rootFrameLayout = new WeakReference<>(decorView);
@@ -1029,11 +1026,10 @@ public abstract class BaseDialog implements LifecycleOwner {
     }
 
     protected void haptic(View v) {
-        if (v != null)
-            if (DialogX.useHaptic && isHapticFeedbackEnabled == -1)
-                v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
-            else if (isHapticFeedbackEnabled == 1)
-                v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
+        if (v != null) if (DialogX.useHaptic && isHapticFeedbackEnabled == -1)
+            v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
+        else if (isHapticFeedbackEnabled == 1)
+            v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
     }
 
     protected boolean isHide;
@@ -1061,4 +1057,22 @@ public abstract class BaseDialog implements LifecycleOwner {
         refreshUI();
         return this;
     }
+
+    /**
+     * 启动前执行
+     *
+     * @return 若返回 true 表示拦截启动流程
+     */
+    public boolean preShow(BaseDialog dialog) {
+        return false;
+    }
+
+    /**
+     * 关闭前执行
+     *
+     * @return 若返回 true 表示拦截退出流程
+     */
+    public boolean preDismiss(BaseDialog dialog) {
+        return false;
+    }
 }

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

@@ -1,6 +1,7 @@
 package com.kongzue.dialogx.interfaces;
 
 import android.app.Activity;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -154,6 +155,7 @@ public abstract class OnBindView<D> {
             waitBind(parentView, null);
             return;
         }
+        Log.e(">>>", "bindParent: getCustomView().getParent()=" + getCustomView().getParent() + "  parentView="+parentView );
         if (getCustomView().getParent() == parentView || parentView.getTag(PARENT_FLAG) == getCustomView().toString()) {
             return;
         }

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

@@ -437,18 +437,43 @@ public class MainActivity extends BaseActivity {
         btnContextMenu.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                PopMenu.show("添加", "编辑", "删除", "分享")
-                        .setIconResIds(R.mipmap.img_dialogx_demo_add, R.mipmap.img_dialogx_demo_edit, R.mipmap.img_dialogx_demo_delete, R.mipmap.img_dialogx_demo_share)
+                new PopMenu() {
+                    @Override
+                    public boolean preDismiss(BaseDialog dialog) {
+                        log(System.currentTimeMillis() + " preDismissEvent");
+                        return super.preDismiss(dialog);
+                    }
+                }
+                        .setMenus("添加", "编辑", "删除", "分享")
                         .setOnMenuItemClickListener(new OnMenuItemClickListener<PopMenu>() {
                             @Override
                             public boolean onClick(PopMenu dialog, CharSequence text, int index) {
-                                if (index == 0) {
-                                    dialog.setMenuList(new String[]{"产品A", "产品B", "产品C"});
-                                    return true;
-                                }
+                                log(System.currentTimeMillis() + " onItemClickEvent");
                                 return false;
                             }
-                        });
+                        })
+                        .onDismiss(new DialogXRunnable<PopMenu>() {
+                            @Override
+                            public void run(PopMenu dialog) {
+                                log(System.currentTimeMillis() + " onDismissEvent");
+                            }
+                        })
+                        .show();
+                ;
+
+
+//                PopMenu.show("添加", "编辑", "删除", "分享")
+//                        .setIconResIds(R.mipmap.img_dialogx_demo_add, R.mipmap.img_dialogx_demo_edit, R.mipmap.img_dialogx_demo_delete, R.mipmap.img_dialogx_demo_share)
+//                        .setOnMenuItemClickListener(new OnMenuItemClickListener<PopMenu>() {
+//                            @Override
+//                            public boolean onClick(PopMenu dialog, CharSequence text, int index) {
+//                                if (index == 0) {
+//                                    dialog.setMenuList(new String[]{"产品A", "产品B", "产品C"});
+//                                    return true;
+//                                }
+//                                return false;
+//                            }
+//                        });
             }
         });