فهرست منبع

0.0.48.beta7
- 针对 MessageDialog、InputDialog、BottomDialog、BottomMenu 增加了 `.getButtonSelectResult()` 可获取一个 BUTTON_SELECT_RESULT 的枚举返回用户点击选择的按钮,包含以下状态:
```
NONE, //未做出选择
BUTTON_OK, //选择了确定按钮
BUTTON_CANCEL, //选择了取消按钮
BUTTON_OTHER //选择了其他按钮
```
开发者可以在用户选择后,例如在 `DialogLifecycle#onDismiss` 事件中对用户的选择进行统一处理,减少重复代码量;
- 尝试性修复了 CustomDialog 存在的空指针问题;
- 修复了 PopNotification 在 Material 主题下只显示 message 消息时布局异常的问题(其他主题请等待后续更新);
- 修复 PopMenu 存在的菜单位置异常 bug;

myzcxhh@live.cn 2 سال پیش
والد
کامیت
36a4588c23

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

@@ -76,6 +76,7 @@ public class BottomDialog extends BaseDialog {
     protected float backgroundRadius = -1;
     protected Drawable titleIcon;
     protected DialogXAnimInterface<BottomDialog> dialogXAnimImpl;
+    protected BUTTON_SELECT_RESULT buttonSelectResult = BUTTON_SELECT_RESULT.NONE;
 
     protected TextInfo titleTextInfo;
     protected TextInfo messageTextInfo;
@@ -311,6 +312,8 @@ public class BottomDialog extends BaseDialog {
 
         @Override
         public void init() {
+            buttonSelectResult = BUTTON_SELECT_RESULT.NONE;
+
             if (titleTextInfo == null) titleTextInfo = DialogX.titleTextInfo;
             if (messageTextInfo == null) messageTextInfo = DialogX.messageTextInfo;
             if (okTextInfo == null) okTextInfo = DialogX.okButtonTextInfo;
@@ -389,6 +392,7 @@ public class BottomDialog extends BaseDialog {
                 btnCancel.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
+                        buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_CANCEL;
                         if (cancelButtonClickListener != null) {
                             if (!cancelButtonClickListener.onClick(me, v)) {
                                 dismiss();
@@ -400,6 +404,7 @@ public class BottomDialog extends BaseDialog {
                 });
             }
             if (btnSelectOther != null) {
+                buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_OTHER;
                 btnSelectOther.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
@@ -414,6 +419,7 @@ public class BottomDialog extends BaseDialog {
                 });
             }
             if (btnSelectPositive != null) {
+                buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_OK;
                 btnSelectPositive.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
@@ -1222,4 +1228,8 @@ public class BottomDialog extends BaseDialog {
         refreshUI();
         return this;
     }
+
+    public BUTTON_SELECT_RESULT getButtonSelectResult() {
+        return buttonSelectResult;
+    }
 }

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

@@ -228,7 +228,9 @@ public class CustomDialog extends BaseDialog {
                         @Override
                         public void run(Float animProgress) {
                             float value = animProgress;
-                            boxRoot.setBkgAlpha(value);
+                            if (boxRoot != null) {
+                                boxRoot.setBkgAlpha(value);
+                            }
                         }
                     });
                     if (getDialogImpl().boxCustom != null) {
@@ -474,6 +476,9 @@ public class CustomDialog extends BaseDialog {
                 dialogXAnimImpl = new DialogXAnimInterface<CustomDialog>() {
                     @Override
                     public void doShowAnim(CustomDialog customDialog, ObjectRunnable<Float> animProgress) {
+                        if (getDialogImpl() == null || getDialogImpl().boxCustom == null) {
+                            return;
+                        }
                         Animation enterAnim = getEnterAnimation();
                         if (boxCustom != null) {
                             boxCustom.setVisibility(View.VISIBLE);
@@ -495,6 +500,9 @@ public class CustomDialog extends BaseDialog {
 
                     @Override
                     public void doExitAnim(CustomDialog customDialog, ObjectRunnable<Float> animProgress) {
+                        if (getDialogImpl() == null || getDialogImpl().boxCustom == null) {
+                            return;
+                        }
                         int exitAnimResIdTemp = R.anim.anim_dialogx_default_exit;
                         if (overrideExitAnimRes != 0) {
                             exitAnimResIdTemp = overrideExitAnimRes;

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

@@ -80,6 +80,7 @@ public class MessageDialog extends BaseDialog {
     protected int customExitAnimResId;
     protected DialogXAnimInterface<MessageDialog> dialogXAnimImpl;
     protected OnBackPressedListener<MessageDialog> onBackPressedListener;
+    protected BUTTON_SELECT_RESULT buttonSelectResult = BUTTON_SELECT_RESULT.NONE;
     
     protected DialogLifecycleCallback<MessageDialog> dialogLifecycleCallback;
     protected OnBackgroundMaskClickListener<MessageDialog> onBackgroundMaskClickListener;
@@ -310,12 +311,13 @@ public class MessageDialog extends BaseDialog {
             btnSelectNegative = convertView.findViewById(R.id.btn_selectNegative);
             btnSelectPositive = convertView.findViewById(R.id.btn_selectPositive);
             init();
-            
+
             dialogImpl = this;
             refreshView();
         }
         
         public void init() {
+            buttonSelectResult = BUTTON_SELECT_RESULT.NONE;
             if (titleTextInfo == null) titleTextInfo = DialogX.titleTextInfo;
             if (messageTextInfo == null) messageTextInfo = DialogX.messageTextInfo;
             if (okTextInfo == null) okTextInfo = DialogX.okButtonTextInfo;
@@ -424,6 +426,7 @@ public class MessageDialog extends BaseDialog {
             btnSelectPositive.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
+                    buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_OK;
                     if (txtInput != null) {
                         imeShow(txtInput, false);
                     }
@@ -446,6 +449,7 @@ public class MessageDialog extends BaseDialog {
             btnSelectNegative.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
+                    buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_CANCEL;
                     if (txtInput != null) {
                         imeShow(txtInput, false);
                     }
@@ -468,6 +472,7 @@ public class MessageDialog extends BaseDialog {
             btnSelectOther.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
+                    buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_OTHER;
                     if (txtInput != null) {
                         imeShow(txtInput, false);
                     }
@@ -1402,4 +1407,8 @@ public class MessageDialog extends BaseDialog {
         refreshUI();
         return this;
     }
+
+    public BUTTON_SELECT_RESULT getButtonSelectResult() {
+        return buttonSelectResult;
+    }
 }

+ 61 - 53
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopMenu.java

@@ -6,8 +6,6 @@ import android.animation.ValueAnimator;
 import android.graphics.Outline;
 import android.graphics.drawable.GradientDrawable;
 import android.os.Build;
-import android.os.Handler;
-import android.os.Looper;
 import android.text.TextUtils;
 import android.view.Gravity;
 import android.view.View;
@@ -37,7 +35,7 @@ import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
 import com.kongzue.dialogx.interfaces.OnBindView;
 import com.kongzue.dialogx.interfaces.OnIconChangeCallBack;
 import com.kongzue.dialogx.interfaces.OnMenuItemClickListener;
-import com.kongzue.dialogx.util.BottomMenuArrayAdapter;
+import com.kongzue.dialogx.util.DialogXViewLoc;
 import com.kongzue.dialogx.util.ObjectRunnable;
 import com.kongzue.dialogx.util.PopMenuArrayAdapter;
 import com.kongzue.dialogx.util.TextInfo;
@@ -86,7 +84,7 @@ public class PopMenu extends BaseDialog {
     protected int alignGravity = -1;                                        //指定菜单相对 baseView 的位置
 
     //记录 baseView 位置
-    protected int[] baseViewLoc = new int[2];
+    protected DialogXViewLoc baseViewLoc = new DialogXViewLoc();
 
     public PopMenu() {
         super();
@@ -207,6 +205,7 @@ public class PopMenu extends BaseDialog {
 
     private ViewTreeObserver viewTreeObserver;
     private ViewTreeObserver.OnDrawListener baseViewDrawListener;
+    private boolean isAnimRunning;
 
     public PopMenu show() {
         if (isHide && getDialogView() != null && isShow) {
@@ -248,14 +247,14 @@ public class PopMenu extends BaseDialog {
                     int[] baseViewLocCache = new int[2];
                     if (baseView != null) {
                         baseView.getLocationOnScreen(baseViewLocCache);
-                        if (baseViewLoc == null || baseViewLocCache[0] != baseViewLoc[0] || baseViewLocCache[1] != baseViewLoc[1]) {
-                            baseViewLoc = baseViewLocCache;
-                            if (getDialogImpl() != null) {
-                                if (getDialogImpl().boxBody.getX() < 0 && getDialogImpl().boxBody.getY() < 0) {
-                                    setDefaultMenuBodyLoc();
-                                } else {
-                                    refreshMenuBodyLoc();
-                                }
+                        if (!isAnimRunning && getDialogImpl() != null && !baseViewLoc.isSameLoc(baseViewLocCache)) {
+                            baseViewLoc.set(baseViewLocCache);
+                            if (getDialogImpl().boxBody.getX() < 0 && getDialogImpl().boxBody.getY() < 0) {
+                                //初始化时设置
+                                setInitMenuBodyLoc();
+                            } else {
+                                //根据条件调整位置
+                                refreshMenuBodyLoc();
                             }
                         }
                     } else {
@@ -271,29 +270,33 @@ public class PopMenu extends BaseDialog {
         return this;
     }
 
-    private void setDefaultMenuBodyLoc() {
+    private void setInitMenuBodyLoc() {
         if (getDialogImpl() == null || getDialogImpl().boxRoot == null) {
             return;
         }
-        int width = PopMenu.this.width == 0 ? baseView.getWidth() : PopMenu.this.width;
-        int height = PopMenu.this.height == 0 ? 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;
 
-        int left = baseViewLoc[0];
-        int top = baseViewLoc[1] + (overlayBaseView ? 0 : height) + selectItemYDeviation;
+        int left = (int) baseViewLoc.getX();
+        int top = (int) (baseViewLoc.getY() + (overlayBaseView ? 0 : mHeight) + selectItemYDeviation);
 
         if (left != getDialogImpl().boxBody.getX()) {
+            menuLocX = left;
             getDialogImpl().boxBody.setX(left);
         }
         if (top != getDialogImpl().boxBody.getY()) {
+            menuLocY = top;
             getDialogImpl().boxBody.setY(top);
         }
 
-        if (width != 0 && getDialogImpl().boxBody.getWidth() != width) {
-            RelativeLayout.LayoutParams rLp = new RelativeLayout.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT);
+        if (mWidth != 0 && getDialogImpl().boxBody.getWidth() != mWidth) {
+            RelativeLayout.LayoutParams rLp = new RelativeLayout.LayoutParams(mWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
             getDialogImpl().boxBody.setLayoutParams(rLp);
         }
     }
 
+    private int menuLocX = -1, menuLocY = -1;
+
     private void refreshMenuBodyLoc() {
         if (getDialogImpl() == null || getDialogImpl().boxRoot == null) {
             return;
@@ -301,8 +304,8 @@ public class PopMenu extends BaseDialog {
         MaxRelativeLayout boxBody = getDialogImpl().boxBody;
         DialogXBaseRelativeLayout boxRoot = getDialogImpl().boxRoot;
         //菜单位置计算逻辑
-        int baseViewLeft = baseViewLoc[0];
-        int baseViewTop = baseViewLoc[1];
+        int baseViewLeft = (int) baseViewLoc.getX();
+        int baseViewTop = (int) baseViewLoc.getY();
         int calX = 0, calY = 0;
         if (alignGravity != -1) {
             if (isAlignGravity(Gravity.CENTER_VERTICAL)) {
@@ -322,23 +325,23 @@ public class PopMenu extends BaseDialog {
             if (overlayBaseView) {
                 //菜单覆盖在 baseView 上时
                 if (isAlignGravity(Gravity.TOP)) {
-                    calY = (baseViewTop - boxBody.getHeight() + baseView.getHeight());
+                    calY = (baseViewTop + baseView.getMeasuredHeight() - boxBody.getHeight());
                 }
                 if (isAlignGravity(Gravity.LEFT)) {
-                    calX = (baseViewLeft);
+                    calX = Math.max(0, (baseViewLeft + baseView.getMeasuredWidth() - boxBody.getWidth()));
                 }
                 if (isAlignGravity(Gravity.RIGHT)) {
-                    calX = (baseViewLeft + (getWidth() > 0 ? baseView.getMeasuredWidth() - width : 0));
+                    calX = baseViewLeft;
                 }
                 if (isAlignGravity(Gravity.BOTTOM)) {
-                    calY = (baseViewTop);
+                    calY = baseViewTop;
                 }
             } else {
                 if (isAlignGravity(Gravity.TOP)) {
                     calY = (Math.max(0, baseViewTop - boxBody.getHeight()));
                 }
                 if (isAlignGravity(Gravity.LEFT)) {
-                    calX = (Math.max(0, baseViewLeft - boxBody.getWidth()));
+                    calX = Math.max(0, (baseViewLeft - boxBody.getWidth()));
                 }
                 if (isAlignGravity(Gravity.RIGHT)) {
                     calX = (Math.max(0, baseViewLeft + baseView.getWidth()));
@@ -362,10 +365,20 @@ public class PopMenu extends BaseDialog {
                 }
             }
 
-            if (calX != 0) boxBody.setX(calX);
-            if (calY != 0) boxBody.setY(calY);
+            menuLocX = calX;
+            boxBody.setX(calX);
+
+            menuLocY = calY;
+            calY = calY + selectItemYDeviation;
+            boxBody.setY(calY);
+
+            int mWidth = PopMenu.this.width == -1 ? baseView.getWidth() : PopMenu.this.width;
+            if (mWidth != 0 && getDialogImpl().boxBody.getWidth() != mWidth) {
+                RelativeLayout.LayoutParams rLp = new RelativeLayout.LayoutParams(mWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
+                getDialogImpl().boxBody.setLayoutParams(rLp);
+            }
         } else {
-            setDefaultMenuBodyLoc();
+            setInitMenuBodyLoc();
         }
     }
 
@@ -626,50 +639,45 @@ public class PopMenu extends BaseDialog {
                             }
 
                             refreshMenuBodyLoc();
+                            selectItemYDeviation = (int) (menuLocY - baseViewLoc.getY());
 
                             //展开动画
-                            Animation enterAnim = new Animation() {
+                            ValueAnimator enterAnim = ValueAnimator.ofFloat(0f, 1f);
+                            enterAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                                 @Override
-                                protected void applyTransformation(float interpolatedTime, Transformation t) {
+                                public void onAnimationUpdate(ValueAnimator animation) {
+                                    float interpolatedTime = (float) animation.getAnimatedValue();
                                     int aimHeight = interpolatedTime == 1 ? ViewGroup.LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime);
                                     boxBody.getLayoutParams().height = aimHeight;
                                     boxBody.getLayoutParams().width = getWidth() == -1 ? baseView.getWidth() : getWidth();
                                     if ((boxBody.getY() + aimHeight) > boxRoot.getSafeHeight()) {
                                         boxBody.setY(boxRoot.getSafeHeight() - aimHeight);
                                     }
-
+                                    float calX = menuLocX != -1 ? menuLocX : baseViewLoc.getX();
+                                    float calY = baseViewLoc.getY() + selectItemYDeviation * interpolatedTime;
+                                    if ((calX + boxBody.getWidth()) > boxRoot.getUseAreaWidth()) {
+                                        calX = boxRoot.getUseAreaWidth() - boxBody.getWidth();
+                                    }
+                                    if ((calY + boxBody.getHeight()) > boxRoot.getUseAreaHeight()) {
+                                        calY = boxRoot.getUseAreaHeight() - boxBody.getHeight();
+                                    }
                                     if (!offScreen) {
-                                        float calX = baseViewLoc[0];
-                                        float calY = baseViewLoc[1] + selectItemYDeviation;
-
                                         if (calX < 0) {
                                             calX = 0;
                                         }
-                                        if ((calX + boxBody.getWidth()) > boxRoot.getUseAreaWidth()) {
-                                            calX = boxRoot.getUseAreaWidth() - boxBody.getWidth();
-                                        }
                                         if (calY < 0) {
                                             calY = 0;
                                         }
-                                        if ((calY + boxBody.getHeight()) > boxRoot.getUseAreaHeight()) {
-                                            calY = boxRoot.getUseAreaHeight() - boxBody.getHeight();
-                                        }
-                                        boxBody.setX(calX);
-                                        boxBody.setY(calY);
                                     }
+                                    boxBody.setX(calX);
+                                    boxBody.setY(calY);
 
                                     boxBody.requestLayout();
-                                    refreshMenuBodyLoc();
                                 }
-
-                                @Override
-                                public boolean willChangeBounds() {
-                                    return true;
-                                }
-                            };
+                            });
                             enterAnim.setInterpolator(new DecelerateInterpolator(2f));
                             enterAnim.setDuration(enterAnimDurationTemp);
-                            boxBody.startAnimation(enterAnim);
+                            enterAnim.start();
                             boxBody.setVisibility(View.VISIBLE);
 
                             //模糊背景
@@ -681,7 +689,7 @@ public class PopMenu extends BaseDialog {
                                 blurView = new BlurView(getOwnActivity(), null);
                                 RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(boxBody.getWidth(), targetHeight);
                                 blurView.setOverlayColor(backgroundColor == -1 ? blurFrontColor : backgroundColor);
-                                blurView.setOverrideOverlayColor(backgroundColor!=-1);
+                                blurView.setOverrideOverlayColor(backgroundColor != -1);
                                 blurView.setTag("blurView");
                                 blurView.setRadiusPx(getStyle().popMenuSettings().blurBackgroundSettings().blurBackgroundRoundRadiusPx());
                                 boxBody.addView(blurView, 0, params);
@@ -712,7 +720,7 @@ public class PopMenu extends BaseDialog {
                                         blurView = new BlurView(getOwnActivity(), null);
                                         RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(boxBody.getWidth(), boxBody.getHeight());
                                         blurView.setOverlayColor(backgroundColor == -1 ? blurFrontColor : backgroundColor);
-                                        blurView.setOverrideOverlayColor(backgroundColor!=-1);
+                                        blurView.setOverrideOverlayColor(backgroundColor != -1);
                                         blurView.setTag("blurView");
                                         blurView.setRadiusPx(getStyle().popMenuSettings().blurBackgroundSettings().blurBackgroundRoundRadiusPx());
                                         boxBody.addView(blurView, 0, params);

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

@@ -441,7 +441,7 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
     }
 
     protected Timer autoDismissTimer;
-    protected long autoDismissDelay;
+    protected long autoDismissDelay = Long.MIN_VALUE;
 
     public PopNotification autoDismiss(long delay) {
         autoDismissDelay = delay;
@@ -463,8 +463,12 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
         autoDismiss(autoDismissDelay);
     }
 
+    private boolean isNoSetCustomDelay(){
+        return autoDismissDelay == Long.MIN_VALUE;
+    }
+
     public PopNotification showShort() {
-        autoDismiss(2000);
+        if (isNoSetCustomDelay())autoDismiss(2000);
         if (!preShow && !isShow) {
             show();
         }
@@ -625,7 +629,7 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
                         blurView = new BlurView(getOwnActivity(), null);
                         RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(boxBody.getWidth(), boxBody.getHeight());
                         blurView.setOverlayColor(backgroundColor == -1 ? blurFrontColor : backgroundColor);
-                        blurView.setOverrideOverlayColor(backgroundColor!=-1);
+                        blurView.setOverrideOverlayColor(backgroundColor != -1);
                         blurView.setTag("blurView");
                         blurView.setRadiusPx(getStyle().popNotificationSettings().blurBackgroundSettings().blurBackgroundRoundRadiusPx());
                         blurBody.setContentView(boxBody);

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

@@ -72,6 +72,13 @@ public abstract class BaseDialog implements LifecycleOwner {
     protected WeakReference<DialogXFloatingWindowActivity> floatingWindowActivity;
     private WeakReference<DialogListBuilder> dialogListBuilder;
     protected LifecycleRegistry lifecycle = new LifecycleRegistry(this);
+
+    public enum BUTTON_SELECT_RESULT{
+        NONE,           //未做出选择
+        BUTTON_OK,      //选择了确定按钮
+        BUTTON_CANCEL,  //选择了取消按钮
+        BUTTON_OTHER    //选择了其他按钮
+    }
     
     public static void init(Context context) {
         if (context == null) {

+ 67 - 0
DialogX/src/main/java/com/kongzue/dialogx/util/DialogXViewLoc.java

@@ -0,0 +1,67 @@
+package com.kongzue.dialogx.util;
+
+public class DialogXViewLoc {
+    private float x;
+    private float y;
+    private float w;
+    private float h;
+
+    public float getX() {
+        return x;
+    }
+
+    public DialogXViewLoc setX(float x) {
+        this.x = x;
+        return this;
+    }
+
+    public float getY() {
+        return y;
+    }
+
+    public DialogXViewLoc setY(float y) {
+        this.y = y;
+        return this;
+    }
+
+    public float getW() {
+        return w;
+    }
+
+    public DialogXViewLoc setW(float w) {
+        this.w = w;
+        return this;
+    }
+
+    public float getH() {
+        return h;
+    }
+
+    public DialogXViewLoc setH(float h) {
+        this.h = h;
+        return this;
+    }
+
+    public boolean isSameLoc(int[] loc){
+        if (loc.length == 2) {
+            return x == loc[0] && y == loc[1];
+        }
+        if (loc.length == 4) {
+            return x == loc[0] && y == loc[1] && w == loc[2] && h == loc[3];
+        }
+        return false;
+    }
+
+    public void set(int[] loc) {
+        if (loc.length == 2) {
+            x = loc[0];
+            y = loc[1];
+        }
+        if (loc.length == 4) {
+            x = loc[0];
+            y = loc[1];
+            w = loc[2];
+            h = loc[3];
+        }
+    }
+}

+ 13 - 15
DialogX/src/main/res/layout/layout_dialogx_popnotification_material.xml

@@ -33,16 +33,16 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center_vertical"
-            android:orientation="vertical">
+            android:orientation="vertical"
+            android:paddingTop="15dp"
+            android:paddingBottom="15dp">
 
             <TextView
                 android:id="@+id/txt_dialogx_pop_title"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="20dp"
-                android:layout_marginTop="15dp"
                 android:layout_marginRight="15dp"
-                android:layout_marginBottom="15dp"
                 android:gravity="left|center_vertical"
                 android:text="Notification!"
                 android:textColor="@color/black"
@@ -54,39 +54,37 @@
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="20dp"
-                android:layout_marginTop="-15dp"
+                android:layout_marginTop="2dp"
                 android:layout_marginRight="15dp"
-                android:layout_marginBottom="15dp"
+                android:layout_marginBottom="2dp"
                 android:visibility="gone"
                 android:gravity="left|center_vertical"
                 android:text="Notification!"
                 android:textColor="@color/black70"
-                android:textSize="14dp"/>
+                android:textSize="14dp" />
+
+            <RelativeLayout
+                android:id="@+id/box_custom"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content" />
 
             <TextView
                 android:id="@+id/txt_dialogx_button"
                 android:layout_width="wrap_content"
                 android:layout_height="match_parent"
                 android:layout_marginLeft="10dp"
-                android:layout_marginTop="-15dp"
                 android:layout_marginRight="5dp"
-                android:layout_marginBottom="10dp"
                 android:background="@drawable/button_dialogx_material_light"
                 android:gravity="left|center_vertical"
                 android:paddingLeft="10dp"
+                android:visibility="gone"
                 android:paddingTop="5dp"
                 android:paddingRight="10dp"
                 android:paddingBottom="5dp"
                 android:singleLine="true"
                 android:text="Dismiss"
                 android:textColor="@color/dialogxColorBlue"
-                android:textSize="14dp"
-                android:visibility="gone" />
-
-            <RelativeLayout
-                android:id="@+id/box_custom"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content" />
+                android:textSize="14dp" />
         </LinearLayout>
 
     </com.kongzue.dialogx.util.views.MaxLinearLayout>

+ 13 - 16
DialogX/src/main/res/layout/layout_dialogx_popnotification_material_dark.xml

@@ -33,16 +33,16 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center_vertical"
-            android:orientation="vertical">
+            android:orientation="vertical"
+            android:paddingTop="15dp"
+            android:paddingBottom="15dp">
 
             <TextView
                 android:id="@+id/txt_dialogx_pop_title"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="20dp"
-                android:layout_marginTop="15dp"
                 android:layout_marginRight="15dp"
-                android:layout_marginBottom="15dp"
                 android:gravity="left|center_vertical"
                 android:text="Notification!"
                 android:textColor="@color/white"
@@ -54,23 +54,27 @@
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="20dp"
-                android:layout_marginTop="-15dp"
+                android:layout_marginTop="2dp"
                 android:layout_marginRight="15dp"
-                android:layout_marginBottom="15dp"
-                android:visibility="gone"
+                android:layout_marginBottom="2dp"
                 android:gravity="left|center_vertical"
                 android:text="Notification!"
                 android:textColor="@color/white70"
-                android:textSize="14dp"/>
+                android:textSize="14dp"
+                android:visibility="gone" />
+
+            <RelativeLayout
+                android:id="@+id/box_custom"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:visibility="gone" />
 
             <TextView
                 android:id="@+id/txt_dialogx_button"
                 android:layout_width="wrap_content"
                 android:layout_height="match_parent"
                 android:layout_marginLeft="10dp"
-                android:layout_marginTop="-15dp"
                 android:layout_marginRight="5dp"
-                android:layout_marginBottom="10dp"
                 android:background="@drawable/button_dialogx_material_night"
                 android:gravity="left|center_vertical"
                 android:paddingLeft="10dp"
@@ -82,15 +86,8 @@
                 android:textColor="@color/dialogxPopButtonBlueDark"
                 android:textSize="14dp"
                 android:visibility="gone" />
-
-            <RelativeLayout
-                android:id="@+id/box_custom"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:visibility="gone" />
         </LinearLayout>
 
-
     </com.kongzue.dialogx.util.views.MaxLinearLayout>
 
 </com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout>

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

@@ -4,6 +4,7 @@ import android.animation.ValueAnimator;
 import android.content.ActivityNotFoundException;
 import android.content.Context;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -46,6 +47,7 @@ import androidx.recyclerview.widget.RecyclerView;
 import com.google.android.material.button.MaterialButton;
 import com.google.android.material.button.MaterialButtonToggleGroup;
 import com.kongzue.baseframework.BaseActivity;
+import com.kongzue.baseframework.BaseApp;
 import com.kongzue.baseframework.interfaces.DarkNavigationBarTheme;
 import com.kongzue.baseframework.interfaces.DarkStatusBarTheme;
 import com.kongzue.baseframework.interfaces.Layout;
@@ -87,6 +89,7 @@ import com.kongzue.dialogx.util.InputInfo;
 import com.kongzue.dialogx.util.ObjectRunnable;
 import com.kongzue.dialogx.util.TextInfo;
 import com.kongzue.dialogx.util.views.ActivityScreenShotImageView;
+import com.kongzue.dialogxdemo.App;
 import com.kongzue.dialogxdemo.BuildConfig;
 import com.kongzue.dialogxdemo.R;
 import com.kongzue.dialogxdemo.custom.recycleview.CustomRecycleViewAdapter;
@@ -289,6 +292,27 @@ public class MainActivity extends BaseActivity {
         }
 
         txtVer.setText("当前版本:" + BuildConfig.VERSION_NAME);
+
+//        //合并处理演示,在 onDismiss 中获取用户选择进行统一处理,以防止编写大量可能在不同选择下都要处理的重复代码
+//        MessageDialog.show("Title", "Ask Question", "OK", "NO", "OTHER").setDialogLifecycleCallback(new DialogLifecycleCallback<MessageDialog>() {
+//            @Override
+//            public void onDismiss(MessageDialog dialog) {
+//                /**
+//                 * dialog.getButtonSelectResult() 支持 MessageDialog 和 BottomDialog
+//                 * 两种具有选择功能的对话框。
+//                 * 包含四种状态:
+//                 * NONE,           //未做出选择
+//                 * BUTTON_OK,      //选择了确定按钮
+//                 * BUTTON_CANCEL,  //选择了取消按钮
+//                 * BUTTON_OTHER    //选择了其他按钮
+//                 */
+//                if (dialog.getButtonSelectResult() == BaseDialog.BUTTON_SELECT_RESULT.BUTTON_OK) {
+//                    MessageDialog.show("Title", "You Select OK Button!", "OK");
+//                } else {
+//                    TipDialog.show("Other Select!", WaitDialog.TYPE.WARNING);
+//                }
+//            }
+//        });
     }
 
     //用于模拟进度提示
@@ -506,12 +530,12 @@ public class MainActivity extends BaseActivity {
             public void onClick(View v) {
                 WaitDialog.show("Please Wait!")
                         .setOnBackPressedListener(new OnBackPressedListener<WaitDialog>() {
-                    @Override
-                    public boolean onBackPressed(WaitDialog dialog) {
-                        PopTip.show("按下返回");
-                        return false;
-                    }
-                });
+                            @Override
+                            public boolean onBackPressed(WaitDialog dialog) {
+                                PopTip.show("按下返回");
+                                return false;
+                            }
+                        });
                 runDelayed(new Runnable() {
                     @Override
                     public void run() {
@@ -1208,8 +1232,7 @@ public class MainActivity extends BaseActivity {
                                 TipDialog.show("点击了通知");
                                 return false;
                             }
-                        })
-                        .showLong();
+                        });
             }
         });
 

+ 1 - 1
gradle.properties

@@ -19,6 +19,6 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.48.beta6
+BUILD_VERSION=0.0.48.beta7
 BUILD_VERSION_INT=47
 DIALOGX_STYLE_VERSION=5