Browse Source

0.0.48.beta19
- 优化了 FullScreenDialog 的流畅度;
- 修复了 PopMenu 可能在特殊情况下的位置闪动问题;
- 增加了特殊异常情况下的错误提示:当 DialogX 的启动 activity 为空或绑定的 activity 的 decorView 为空时给出具体错误提示;

Kongzue 2 years ago
parent
commit
ffda1ebbcf

+ 11 - 7
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopMenu.java

@@ -277,11 +277,13 @@ public class PopMenu extends BaseDialog {
         getDialogImpl().boxBody.setTag(null);
         DialogXViewLoc loc = getMenuLoc();
         getDialogImpl().boxBody.setTag(loc);
-        if (loc.getX() != getDialogImpl().boxBody.getX()) {
-            getDialogImpl().boxBody.setX(loc.getX());
-        }
-        if (loc.getY() != getDialogImpl().boxBody.getY()) {
-            getDialogImpl().boxBody.setY(loc.getY());
+        if (!isEnterAnimRunning) {
+            if (loc.getX() != getDialogImpl().boxBody.getX()) {
+                getDialogImpl().boxBody.setX(loc.getX());
+            }
+            if (loc.getY() != getDialogImpl().boxBody.getY()) {
+                getDialogImpl().boxBody.setY(loc.getY());
+            }
         }
         if (getDialogImpl().boxBody.getWidth() != loc.getW()) {
             RelativeLayout.LayoutParams rLp = new RelativeLayout.LayoutParams((int) loc.getW(), ViewGroup.LayoutParams.WRAP_CONTENT);
@@ -421,6 +423,7 @@ public class PopMenu extends BaseDialog {
 
     protected PopMenuArrayAdapter menuListAdapter;
     protected int selectItemYDeviation; //如果找到了选中菜单,这里记录的是其位置的 Y 偏差值
+    protected boolean isEnterAnimRunning;
 
     public class DialogImpl implements DialogConvertViewInterface {
 
@@ -690,6 +693,7 @@ public class PopMenu extends BaseDialog {
                                     if (!isShow || getDialogImpl() == null || getDialogImpl().boxBody == null)
                                         return;
                                     float animatedValue = (float) animation.getAnimatedValue();
+                                    isEnterAnimRunning = !(animatedValue == 1f);
                                     DialogXViewLoc loc = getMenuLoc();
 
                                     int aimHeight = animatedValue == 1f ? ViewGroup.LayoutParams.WRAP_CONTENT : (int) (targetHeight * animatedValue);
@@ -1259,11 +1263,11 @@ public class PopMenu extends BaseDialog {
     public void onDismiss(PopMenu dialog) {
 
     }
-    
+
     public MenuItemLayoutRefreshCallback<PopMenu> getMenuMenuItemLayoutRefreshCallback() {
         return menuMenuItemLayoutRefreshCallback;
     }
-    
+
     public PopMenu setMenuMenuItemLayoutRefreshCallback(MenuItemLayoutRefreshCallback<PopMenu> menuMenuItemLayoutRefreshCallback) {
         this.menuMenuItemLayoutRefreshCallback = menuMenuItemLayoutRefreshCallback;
         return this;

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

@@ -602,9 +602,24 @@ public abstract class BaseDialog implements LifecycleOwner {
         Activity activity = getOwnActivity();
         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");
+                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");
             return null;
         }
         rootFrameLayout = new WeakReference<>(decorView);

+ 3 - 17
DialogX/src/main/java/com/kongzue/dialogx/util/views/ActivityScreenShotImageView.java

@@ -112,23 +112,9 @@ public class ActivityScreenShotImageView extends ImageView {
     private void doScreenshotActivityAndZoom() {
         ViewGroup decorView = getDecorView();
         if (decorView == null) return;
-//        View lastChildView = decorView.getChildAt(decorView.getChildCount() - 1);
-//        Log.e(">>>", "lastChildView: \t"+lastChildView );
-//        Log.e(">>>", "dialog.getDialogView: \t"+dialog.getDialogView() );
-//        if (lastChildView == dialog.getDialogView()) {
-//            decorView = (ViewGroup) decorView.getChildAt(0);
-//        }
-        View contentView = decorView;
-        //先执行一次绘制,防止出现闪屏问题
-        if (!inited) drawViewImage(contentView);
-        contentView.post(new Runnable() {
-            @Override
-            public void run() {
-                //当view渲染完成后再次通知刷新一下界面(当旋转屏幕执行时,很可能出现渲染延迟的问题)
-                drawViewImage(contentView);
-                inited = true;
-            }
-        });
+        drawViewImage(decorView);
+        setVisibility(VISIBLE);
+        inited = true;
     }
 
     private ViewGroup getDecorView() {

+ 2 - 2
DialogX/src/main/res/layout/layout_dialogx_fullscreen.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
@@ -45,4 +45,4 @@
 
     </com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout>
 
-</RelativeLayout>
+</FrameLayout>

+ 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.beta18
+BUILD_VERSION=0.0.48.beta19
 BUILD_VERSION_INT=47
 DIALOGX_STYLE_VERSION=5