Просмотр исходного кода

0.0.48.beta2
- PopNotification 默认支持了向上滑动关闭操作,如不需要可通过 `.setSlideToClose(false)` 关闭;
- PopMenu、GuideDialog、CustomDialog 的基于 baseView 显示现在将实时跟踪 baseView 的位置进行显示;
- bug 修复;

myzcxhh@live.cn 2 лет назад
Родитель
Сommit
77706a0169

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

@@ -288,8 +288,8 @@ public class CustomDialog extends BaseDialog {
                                 if (isAlignBaseViewGravity(Gravity.BOTTOM)) {
                                     calY = baseViewTop + baseView.getHeight() + marginRelativeBaseView[1];
                                 }
-                                baseViewLoc[2] = baseView.getWidth();
-                                baseViewLoc[3] = baseView.getHeight();
+                                baseViewLoc[2] = width == 0 ? baseView.getWidth() : width;
+                                baseViewLoc[3] = height == 0 ? baseView.getHeight() : height;
 
                                 if (calX != 0) boxCustom.setX(calX);
                                 if (calY != 0) boxCustom.setY(calY);
@@ -302,8 +302,14 @@ public class CustomDialog extends BaseDialog {
                     boxCustom.getViewTreeObserver().addOnDrawListener(baseViewDrawListener = new ViewTreeObserver.OnDrawListener() {
                         @Override
                         public void onDraw() {
-                            baseView.getLocationOnScreen(baseViewLoc);
-                            onLayoutChangeRunnable.run();
+                            int[] baseViewLocCache = new int[2];
+                            baseView.getLocationOnScreen(baseViewLocCache);
+                            if (baseViewLoc == null || baseViewLocCache[0] != baseViewLoc[0] || baseViewLocCache[1] != baseViewLoc[1]) {
+                                baseViewLoc = baseViewLocCache;
+                                if (getDialogImpl() != null) {
+                                    onLayoutChangeRunnable.run();
+                                }
+                            }
                         }
                     });
                     initSetCustomViewLayoutListener = true;

+ 21 - 17
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopMenu.java

@@ -243,24 +243,28 @@ public class PopMenu extends BaseDialog {
             baseView.getViewTreeObserver().addOnDrawListener(baseViewDrawListener = new ViewTreeObserver.OnDrawListener() {
                 @Override
                 public void onDraw() {
-                    if (getDialogImpl() != null) {
-                        baseViewLoc = new int[2];
-                        baseView.getLocationOnScreen(baseViewLoc);
-
-                        int width = baseView.getWidth();
-                        int height = baseView.getHeight();
-
-                        int left = baseViewLoc[0];
-                        int top = baseViewLoc[1] + (overlayBaseView ? 0 : height);
-
-                        log("top: " + top);
-
-                        getDialogImpl().boxBody.setX(left);
-                        getDialogImpl().boxBody.setY(top);
+                    int[] baseViewLocCache = new int[2];
+                    baseView.getLocationOnScreen(baseViewLocCache);
+                    if (baseViewLoc == null || baseViewLocCache[0] != baseViewLoc[0] || baseViewLocCache[1] != baseViewLoc[1]) {
+                        if (getDialogImpl() != null) {
+                            baseViewLoc = baseViewLocCache;
+                            int width = PopMenu.this.width == 0 ? baseView.getWidth() : PopMenu.this.width;
+                            int height = PopMenu.this.height == 0 ? baseView.getHeight() : PopMenu.this.height;
+
+                            int left = baseViewLoc[0];
+                            int top = baseViewLoc[1] + (overlayBaseView ? 0 : height);
+
+                            if (left != getDialogImpl().boxBody.getX()) {
+                                getDialogImpl().boxBody.setX(left);
+                            }
+                            if (top != getDialogImpl().boxBody.getY()) {
+                                getDialogImpl().boxBody.setY(top);
+                            }
 
-                        if (width != 0 && getDialogImpl().boxBody.getWidth() != width) {
-                            RelativeLayout.LayoutParams rLp = new RelativeLayout.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT);
-                            getDialogImpl().boxBody.setLayoutParams(rLp);
+                            if (width != 0 && getDialogImpl().boxBody.getWidth() != width) {
+                                RelativeLayout.LayoutParams rLp = new RelativeLayout.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT);
+                                getDialogImpl().boxBody.setLayoutParams(rLp);
+                            }
                         }
                     }
                 }

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

@@ -428,7 +428,9 @@ public class MainActivity extends BaseActivity {
         btnSelectMenu.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
+                view.animate().y(view.getY()-dip2px(100)).setDuration(5000);
                 PopMenu.show(view, new String[]{"选项1", "选项2", "选项3"})
+                        .setWidth(dip2px(250))
                         .setOnMenuItemClickListener(new OnMenuItemClickListener<PopMenu>() {
                             @Override
                             public boolean onClick(PopMenu dialog, CharSequence text, int index) {

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