ソースを参照

update 0.0.26 ver.

kongzue 4 年 前
コミット
5527531da5

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

@@ -177,6 +177,7 @@ public class BottomDialog extends BaseDialog {
         
         
         dialogView = createView(layoutId);
         dialogView = createView(layoutId);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(dialogView);
         show(dialogView);
     }
     }
     
     
@@ -189,6 +190,7 @@ public class BottomDialog extends BaseDialog {
         
         
         dialogView = createView(layoutId);
         dialogView = createView(layoutId);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(activity, dialogView);
         show(activity, dialogView);
     }
     }
     
     

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

@@ -79,6 +79,7 @@ public class CustomDialog extends BaseDialog {
         super.beforeShow();
         super.beforeShow();
         dialogView = createView(R.layout.layout_dialogx_custom);
         dialogView = createView(R.layout.layout_dialogx_custom);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(dialogView);
         show(dialogView);
     }
     }
     
     
@@ -86,6 +87,7 @@ public class CustomDialog extends BaseDialog {
         super.beforeShow();
         super.beforeShow();
         dialogView = createView(R.layout.layout_dialogx_custom);
         dialogView = createView(R.layout.layout_dialogx_custom);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(activity, dialogView);
         show(activity, dialogView);
     }
     }
     
     

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

@@ -74,6 +74,7 @@ public class FullScreenDialog extends BaseDialog {
         super.beforeShow();
         super.beforeShow();
         dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
         dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(dialogView);
         show(dialogView);
     }
     }
     
     
@@ -81,6 +82,7 @@ public class FullScreenDialog extends BaseDialog {
         super.beforeShow();
         super.beforeShow();
         dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
         dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(activity, dialogView);
         show(activity, dialogView);
     }
     }
     
     

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

@@ -195,6 +195,7 @@ public class MessageDialog extends BaseDialog {
         
         
         dialogView = createView(layoutId);
         dialogView = createView(layoutId);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(dialogView);
         show(dialogView);
     }
     }
     
     
@@ -205,6 +206,7 @@ public class MessageDialog extends BaseDialog {
         
         
         dialogView = createView(layoutId);
         dialogView = createView(layoutId);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(activity, dialogView);
         show(activity, dialogView);
     }
     }
     
     

+ 10 - 4
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopTip.java

@@ -261,6 +261,7 @@ public class PopTip extends BaseDialog {
         }
         }
         dialogView = createView(layoutResId);
         dialogView = createView(layoutResId);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(dialogView);
         show(dialogView);
     }
     }
     
     
@@ -284,6 +285,7 @@ public class PopTip extends BaseDialog {
         }
         }
         dialogView = createView(layoutResId);
         dialogView = createView(layoutResId);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(activity, dialogView);
         show(activity, dialogView);
     }
     }
     
     
@@ -314,6 +316,10 @@ public class PopTip extends BaseDialog {
         return this;
         return this;
     }
     }
     
     
+    public PopTip showAlways() {
+        return noAutoDismiss();
+    }
+    
     public PopTip noAutoDismiss() {
     public PopTip noAutoDismiss() {
         autoDismiss(TIME_NO_AUTO_DISMISS_DELAY);
         autoDismiss(TIME_NO_AUTO_DISMISS_DELAY);
         return this;
         return this;
@@ -349,6 +355,10 @@ public class PopTip extends BaseDialog {
             boxRoot.setFocusable(false);
             boxRoot.setFocusable(false);
             boxRoot.setFocusableInTouchMode(false);
             boxRoot.setFocusableInTouchMode(false);
             boxRoot.setAutoUnsafePlacePadding(false);
             boxRoot.setAutoUnsafePlacePadding(false);
+    
+            if (autoDismissTimer == null) {
+                showShort();
+            }
             
             
             boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
             boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
                 @Override
                 @Override
@@ -359,10 +369,6 @@ public class PopTip extends BaseDialog {
                     getDialogLifecycleCallback().onShow(me);
                     getDialogLifecycleCallback().onShow(me);
                     
                     
                     if (onBindView != null) onBindView.onBind(me, onBindView.getCustomView());
                     if (onBindView != null) onBindView.onBind(me, onBindView.getCustomView());
-                    
-                    if (autoDismissTimer == null) {
-                        showShort();
-                    }
                 }
                 }
                 
                 
                 @Override
                 @Override

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

@@ -162,6 +162,7 @@ public class WaitDialog extends BaseDialog {
         super.beforeShow();
         super.beforeShow();
         dialogView = createView(R.layout.layout_dialogx_wait);
         dialogView = createView(R.layout.layout_dialogx_wait);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(dialogView);
         show(dialogView);
         return this;
         return this;
     }
     }
@@ -170,6 +171,7 @@ public class WaitDialog extends BaseDialog {
         super.beforeShow();
         super.beforeShow();
         dialogView = createView(R.layout.layout_dialogx_wait);
         dialogView = createView(R.layout.layout_dialogx_wait);
         dialogImpl = new DialogImpl(dialogView);
         dialogImpl = new DialogImpl(dialogView);
+        dialogView.setTag(getClass().getSimpleName() + "(" +Integer.toHexString(hashCode()) + ")");
         show(activity, dialogView);
         show(activity, dialogView);
         return this;
         return this;
     }
     }

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

@@ -43,7 +43,7 @@ public class BaseDialog {
             public void getActivity(Activity activity) {
             public void getActivity(Activity activity) {
                 try {
                 try {
                     contextWeakReference = new WeakReference<>(activity);
                     contextWeakReference = new WeakReference<>(activity);
-                    rootFrameLayout = new WeakReference<>((FrameLayout) activity.getWindow().getDecorView().findViewById(android.R.id.content));
+                    rootFrameLayout = new WeakReference<>((FrameLayout) activity.getWindow().getDecorView());
                 } catch (Exception e) {
                 } catch (Exception e) {
                     error("DialogX.init: 初始化异常,找不到Activity的根布局");
                     error("DialogX.init: 初始化异常,找不到Activity的根布局");
                 }
                 }
@@ -61,7 +61,7 @@ public class BaseDialog {
     
     
     public static void show(final View view) {
     public static void show(final View view) {
         if (rootFrameLayout == null || view == null || rootFrameLayout.get() == null) return;
         if (rootFrameLayout == null || view == null || rootFrameLayout.get() == null) return;
-        view.setTag(rootFrameLayout.get());
+        log(view.getTag() + ".show");
         rootFrameLayout.get().post(new Runnable() {
         rootFrameLayout.get().post(new Runnable() {
             @Override
             @Override
             public void run() {
             public void run() {
@@ -72,9 +72,9 @@ public class BaseDialog {
     
     
     public static void show(Activity activity, final View view) {
     public static void show(Activity activity, final View view) {
         if (activity == null || view == null) return;
         if (activity == null || view == null) return;
-        final ViewGroup activityRootView = activity.getWindow().getDecorView().findViewById(android.R.id.content);
+        log(view.getTag() + ".show");
+        final FrameLayout activityRootView = (FrameLayout) activity.getWindow().getDecorView();
         if (activityRootView == null) return;
         if (activityRootView == null) return;
-        view.setTag(activityRootView);
         activityRootView.post(new Runnable() {
         activityRootView.post(new Runnable() {
             @Override
             @Override
             public void run() {
             public void run() {
@@ -84,11 +84,12 @@ public class BaseDialog {
     }
     }
     
     
     public static void dismiss(View dialogView) {
     public static void dismiss(View dialogView) {
+        log(dialogView.getTag() + ".dismiss");
         if (rootFrameLayout == null || dialogView == null) return;
         if (rootFrameLayout == null || dialogView == null) return;
-        if (dialogView.getTag() == null || !(dialogView.getTag() instanceof ViewGroup)) {
+        if (dialogView.getParent() == null || !(dialogView.getParent() instanceof ViewGroup)) {
             rootFrameLayout.get().removeView(dialogView);
             rootFrameLayout.get().removeView(dialogView);
         } else {
         } else {
-            ((ViewGroup) dialogView.getTag()).removeView(dialogView);
+            ((ViewGroup) dialogView.getParent()).removeView(dialogView);
         }
         }
     }
     }
     
     

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

@@ -88,7 +88,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     
     
     @Override
     @Override
     public boolean dispatchKeyEvent(KeyEvent event) {
     public boolean dispatchKeyEvent(KeyEvent event) {
-        if (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
+        if (isAttachedToWindow() && event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
             if (onBackPressedListener != null) {
             if (onBackPressedListener != null) {
                 onBackPressedListener.onBackPressed();
                 onBackPressedListener.onBackPressed();
             }
             }

+ 2 - 2
README.md

@@ -106,7 +106,7 @@ DialogX 采用了主题分离结构,主框架仅包含 Material 设计风格
 想要在您的项目引入 DialogX,您需要在 app 的 build.gradle 文件中找到 `dependencies{}` 代码块,并在其中加入以下语句:
 想要在您的项目引入 DialogX,您需要在 app 的 build.gradle 文件中找到 `dependencies{}` 代码块,并在其中加入以下语句:
 
 
 ```
 ```
-implementation 'com.kongzue.dialogx:DialogX:0.0.25'
+implementation 'com.kongzue.dialogx:DialogX:0.0.26'
 ```
 ```
 
 
 若有需要,也可以手动配置 Maven:
 若有需要,也可以手动配置 Maven:
@@ -115,7 +115,7 @@ implementation 'com.kongzue.dialogx:DialogX:0.0.25'
 <dependency>
 <dependency>
   <groupId>com.kongzue.dialogx</groupId>
   <groupId>com.kongzue.dialogx</groupId>
   <artifactId>DialogX</artifactId>
   <artifactId>DialogX</artifactId>
-  <version>0.0.25</version>
+  <version>0.0.26</version>
   <type>pom</type>
   <type>pom</type>
 </dependency>
 </dependency>
 ```
 ```

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

@@ -5,6 +5,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.Intent;
 import android.graphics.Color;
 import android.graphics.Color;
 import android.net.Uri;
 import android.net.Uri;
+import android.os.Handler;
 import android.view.View;
 import android.view.View;
 import android.view.inputmethod.InputMethodManager;
 import android.view.inputmethod.InputMethodManager;
 import android.webkit.WebSettings;
 import android.webkit.WebSettings;
@@ -630,13 +631,13 @@ public class MainActivity extends BaseActivity {
                 if (rdoIos.isChecked()) {
                 if (rdoIos.isChecked()) {
                     PopTip.show(R.mipmap.img_air_pods_pro, "AirPods Pro 已连接").setAutoTintIconInLightOrDarkMode(false).showLong();
                     PopTip.show(R.mipmap.img_air_pods_pro, "AirPods Pro 已连接").setAutoTintIconInLightOrDarkMode(false).showLong();
                 } else {
                 } else {
-                    PopTip.show(R.mipmap.img_mail_line_white, "邮件已发送", "撤回").showLong().setButton(new OnDialogButtonClickListener<PopTip>() {
+                    PopTip.show(R.mipmap.img_mail_line_white, "邮件已发送", "撤回").setButton(new OnDialogButtonClickListener<PopTip>() {
                         @Override
                         @Override
                         public boolean onClick(PopTip popTip, View v) {
                         public boolean onClick(PopTip popTip, View v) {
                             //点击“撤回”按钮回调
                             //点击“撤回”按钮回调
                             return false;
                             return false;
                         }
                         }
-                    });
+                    }).showLong();
                 }
                 }
             }
             }
         });
         });

+ 2 - 2
gradle.properties

@@ -18,5 +18,5 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 android.enableJetifier=true
 
 
-BUILD_VERSION=0.0.25
-BUILD_VERSION_INT=25
+BUILD_VERSION=0.0.26
+BUILD_VERSION_INT=26