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

0.0.50.beta14
- MessageDialog 增加菜单显示,感谢 @Sky-JD 的代码贡献;
- 修复 MIUI 主题下 MessageDialog 的底部沉浸式问题;

Kongzue 1 жил өмнө
parent
commit
23918f377a

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

@@ -0,0 +1,5 @@
+package com.kongzue.dialogx.interfaces;
+
+public interface DialogXSafetyModeInterface {
+    int getDialogXSafetyMode();
+}

+ 43 - 14
DialogX/src/main/java/com/kongzue/dialogx/util/views/DialogXBaseRelativeLayout.java

@@ -24,6 +24,7 @@ import com.kongzue.dialogx.DialogX;
 import com.kongzue.dialogx.R;
 import com.kongzue.dialogx.interfaces.BaseDialog;
 import com.kongzue.dialogx.interfaces.DialogXBaseBottomDialog;
+import com.kongzue.dialogx.interfaces.DialogXSafetyModeInterface;
 import com.kongzue.dialogx.interfaces.NoTouchInterface;
 import com.kongzue.dialogx.interfaces.OnSafeInsetsChangeListener;
 
@@ -38,7 +39,7 @@ import java.lang.ref.WeakReference;
  */
 public class DialogXBaseRelativeLayout extends RelativeLayout {
 
-    public static boolean debugMode = false;
+    public static boolean debugMode = true;
 
     private OnSafeInsetsChangeListener onSafeInsetsChangeListener;
     private WeakReference<BaseDialog> parentDialog;
@@ -118,11 +119,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
                         boolean imeVisible = windowInsetsCompat.isVisible(WindowInsetsCompat.Type.ime());
                         if (!imeVisible && navigationBarsVisible) {
                             systemBarInsets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.systemBars());
-                            if (systemBarInsets.bottom == bottom &&
-                                    systemBarInsets.top == top &&
-                                    systemBarInsets.left == start &&
-                                    systemBarInsets.right == end
-                            ) {
+                            if (systemBarInsets.bottom == bottom && systemBarInsets.top == top && systemBarInsets.left == start && systemBarInsets.right == end) {
                                 systemBarInsets = null;
                             }
                         }
@@ -166,21 +163,53 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
 
     public void setUnsafePadding(@Px int start, @Px int top, @Px int end, @Px int bottom) {
         log("KONGZUE DEBUG DIALOGX: setUnsafePadding=" + getParentDialog() + " t=" + top + " b=" + bottom);
-        if (getParentDialog() instanceof DialogXBaseBottomDialog) {
-            log("  KONGZUE DEBUG DIALOGX: isDialogXBaseBottomDialog");
-            ViewGroup bkgView = findViewById(R.id.bkg);
-            if (!((DialogXBaseBottomDialog) getParentDialog()).isBottomNonSafetyAreaBySelf() && bkgView != null) {
-                log("    KONGZUE DEBUG DIALOGX: bkgView.setPadding b=" + bottom);
-                bkgView.setPadding(0, 0, 0, bottom);
+        if (DialogX.ignoreUnsafeInsetsHorizontal) {
+            log("  KONGZUE DEBUG DIALOGX: ignoreUnsafeInsetsHorizontal, start and end set 0");
+            start = 0;
+            end = 0;
+        }
+        if (isAlignBottomDialog(getParentDialog())) {
+            log("  KONGZUE DEBUG DIALOGX: Dialog is align bottom");
+            View dialogXSafetyArea = findViewWithTag("DialogXSafetyArea");
+            if (dialogXSafetyArea instanceof DialogXSafetyModeInterface) {
+                int dialogxSafetyMode = ((DialogXSafetyModeInterface) dialogXSafetyArea).getDialogXSafetyMode();
+                boolean hasTop = (dialogxSafetyMode & 0x1) != 0;
+                boolean hasLeft = (dialogxSafetyMode & 0x2) != 0;
+                boolean hasBottom = (dialogxSafetyMode & 0x4) != 0;
+                boolean hasRight = (dialogxSafetyMode & 0x8) != 0;
+                log("    KONGZUE DEBUG DIALOGX: dialogXSafetyArea" + dialogXSafetyArea + " hasLeft=" + hasLeft + "hasTop=" + hasTop + " hasRight=" + hasRight + " hasBottom=" + hasBottom);
+                dialogXSafetyArea.setPadding(hasLeft ? start : 0, hasTop ? top : 0, hasRight ? end : 0, hasBottom ? bottom : 0);
+                if (hasTop) {
+                    top = 0;
+                }
+                if (hasLeft) {
+                    start = 0;
+                }
+                if (hasRight) {
+                    end = 0;
+                }
+                if (hasBottom) {
+                    bottom = 0;
+                }
+            } else {
+                ViewGroup bkgView = findViewById(R.id.bkg);
+                if (!((DialogXBaseBottomDialog) getParentDialog()).isBottomNonSafetyAreaBySelf() && bkgView != null) {
+                    log("    KONGZUE DEBUG DIALOGX: bkgView.setPadding b=" + bottom);
+                    bkgView.setPadding(0, 0, 0, bottom);
+                }
+                bottom = 0;
             }
-            bottom = 0;
         }
         if (isAutoUnsafePlacePadding()) {
             log("  KONGZUE DEBUG DIALOGX: root.setPadding t=" + top + " b=" + bottom);
-            setPadding(DialogX.ignoreUnsafeInsetsHorizontal ? 0 : start, top, DialogX.ignoreUnsafeInsetsHorizontal ? 0 : end, bottom);
+            setPadding(start, top, end, bottom);
         }
     }
 
+    private boolean isAlignBottomDialog(BaseDialog parentDialog) {
+        return getParentDialog() instanceof DialogXBaseBottomDialog || findViewWithTag("DialogXSafetyArea") instanceof DialogXSafetyModeInterface;
+    }
+
     @Override
     public boolean dispatchKeyEvent(KeyEvent event) {
         log("#dispatchKeyEvent: KeyCode=" + event.getKeyCode());

+ 13 - 7
DialogX/src/main/java/com/kongzue/dialogx/util/views/MaxRelativeLayout.java

@@ -7,17 +7,13 @@ import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.os.Build;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
-import android.view.ViewGroup;
 import android.widget.RelativeLayout;
-import android.widget.ScrollView;
 
 import com.kongzue.dialogx.DialogX;
 import com.kongzue.dialogx.R;
-
-import static android.view.View.MeasureSpec.EXACTLY;
+import com.kongzue.dialogx.interfaces.DialogXSafetyModeInterface;
 
 /**
  * @author: Kongzue
@@ -26,7 +22,7 @@ import static android.view.View.MeasureSpec.EXACTLY;
  * @mail: myzcxhh@live.cn
  * @createTime: 2019/9/24 17:34
  */
-public class MaxRelativeLayout extends RelativeLayout {
+public class MaxRelativeLayout extends RelativeLayout implements DialogXSafetyModeInterface {
 
     private int maxWidth;
     private int maxHeight;
@@ -35,6 +31,7 @@ public class MaxRelativeLayout extends RelativeLayout {
     private boolean lockWidth;
     private boolean interceptTouch = true;
     private View contentView;
+    private int dialogXSafetyMode;
 
     public MaxRelativeLayout(Context context) {
         super(context);
@@ -62,7 +59,7 @@ public class MaxRelativeLayout extends RelativeLayout {
             minHeight = a.getDimensionPixelSize(R.styleable.DialogXMaxLayout_minLayoutHeight, 0);
             lockWidth = a.getBoolean(R.styleable.DialogXMaxLayout_lockWidth, false);
             interceptTouch = a.getBoolean(R.styleable.DialogXMaxLayout_interceptTouch, true);
-
+            dialogXSafetyMode = a.getInt(R.styleable.DialogXMaxLayout_dialogXSafetyMode, 0);
             a.recycle();
         }
         minWidth = minWidth == 0 ? getMinimumWidth() : minWidth;
@@ -214,4 +211,13 @@ public class MaxRelativeLayout extends RelativeLayout {
     public boolean onInterceptTouchEvent(MotionEvent ev) {
         return reInterceptTouch;
     }
+
+    public int getDialogXSafetyMode() {
+        return dialogXSafetyMode;
+    }
+
+    public MaxRelativeLayout setDialogXSafetyMode(int dialogXSafetyMode) {
+        this.dialogXSafetyMode = dialogXSafetyMode;
+        return this;
+    }
 }

+ 8 - 0
DialogX/src/main/res/values/attrs.xml

@@ -8,6 +8,14 @@
         <attr name="minLayoutHeight" format="dimension"/>
         <attr name="lockWidth" format="boolean"/>
         <attr name="interceptTouch" format="boolean"/>
+
+        <attr name="dialogXSafetyMode" format="flags">
+            <flag name="none" value="0"/>
+            <flag name="top" value="0x1"/>
+            <flag name="left" value="0x2"/>
+            <flag name="bottom" value="0x4"/>
+            <flag name="right" value="0x8"/>
+        </attr>
     </declare-styleable>
 
     <declare-styleable name="RealtimeBlurView">

+ 3 - 3
DialogXMIUIStyle/src/main/res/layout/layout_dialogx_bottom_miui.xml

@@ -90,10 +90,10 @@
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_gravity="center_horizontal"
-                    android:layout_marginLeft="26dp"
+                    android:layout_marginLeft="15dp"
                     android:layout_marginTop="10dp"
-                    android:layout_marginRight="26dp"
-                    android:layout_marginBottom="20dp"
+                    android:layout_marginRight="15dp"
+                    android:layout_marginBottom="10dp"
                     android:gravity="right|center_vertical"
                     android:orientation="horizontal">
 

+ 3 - 3
DialogXMIUIStyle/src/main/res/layout/layout_dialogx_bottom_miui_dark.xml

@@ -90,10 +90,10 @@
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_gravity="center_horizontal"
-                    android:layout_marginLeft="26dp"
+                    android:layout_marginLeft="15dp"
                     android:layout_marginTop="10dp"
-                    android:layout_marginRight="26dp"
-                    android:layout_marginBottom="20dp"
+                    android:layout_marginRight="15dp"
+                    android:layout_marginBottom="10dp"
                     android:gravity="right|center_vertical"
                     android:orientation="horizontal">
 

+ 5 - 2
DialogXMIUIStyle/src/main/res/layout/layout_dialogx_miui.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/box_root"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
@@ -16,7 +17,9 @@
             android:layout_height="wrap_content"
             android:layout_alignParentBottom="true"
             android:layout_centerHorizontal="true"
-            android:background="@drawable/rect_dialogx_miui_bkg_light">
+            android:background="@drawable/rect_dialogx_miui_bkg_light"
+            android:tag="DialogXSafetyArea"
+            app:dialogXSafetyMode="bottom">
 
             <LinearLayout
                 android:layout_width="match_parent"
@@ -109,7 +112,7 @@
                     android:layout_gravity="center_horizontal"
                     android:layout_marginLeft="15dp"
                     android:layout_marginRight="15dp"
-                    android:layout_marginBottom="20dp"
+                    android:layout_marginBottom="10dp"
                     android:gravity="right|center_vertical"
                     android:orientation="horizontal">
 

+ 5 - 2
DialogXMIUIStyle/src/main/res/layout/layout_dialogx_miui_dark.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/box_root"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
@@ -16,7 +17,9 @@
             android:layout_height="wrap_content"
             android:layout_alignParentBottom="true"
             android:layout_centerHorizontal="true"
-            android:background="@drawable/rect_dialogx_miui_bkg_night">
+            android:background="@drawable/rect_dialogx_miui_bkg_night"
+            android:tag="DialogXSafetyArea"
+            app:dialogXSafetyMode="bottom">
 
             <LinearLayout
                 android:layout_width="match_parent"
@@ -108,7 +111,7 @@
                     android:layout_gravity="center_horizontal"
                     android:layout_marginLeft="15dp"
                     android:layout_marginRight="15dp"
-                    android:layout_marginBottom="20dp"
+                    android:layout_marginBottom="10dp"
                     android:gravity="right|center_vertical"
                     android:orientation="horizontal">
 

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

@@ -754,8 +754,6 @@ public class MainActivity extends BaseActivity {
                                 return super.onSlideTouchEvent(dialog, v, event);
                             }
                         })
-
-                        .setMinHeight(dip2px(400))
                         .show();
             }
         });