kongzue преди 2 години
родител
ревизия
ddf7a99cb4

+ 139 - 138
DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java

@@ -38,7 +38,7 @@ import com.kongzue.dialogx.util.views.MaxRelativeLayout;
  * @createTime: 2020/10/20 11:59
  */
 public class CustomDialog extends BaseDialog {
-
+    
     public static int overrideEnterDuration = -1;
     public static int overrideExitDuration = -1;
     public static int overrideEnterAnimRes = 0;
@@ -59,14 +59,14 @@ public class CustomDialog extends BaseDialog {
     protected boolean bkgInterceptTouch = true;
     protected OnBackgroundMaskClickListener<CustomDialog> onBackgroundMaskClickListener;
     protected DialogXAnimInterface<CustomDialog> dialogXAnimImpl;
-
+    
     protected View baseView;
     protected int alignViewGravity = -1;                                    //指定菜单相对 baseView 的位置
     protected int width = -1;                                               //指定菜单宽度
     protected int height = -1;                                              //指定菜单高度
     protected int[] baseViewLoc;
     protected int[] marginRelativeBaseView = new int[4];
-
+    
     public enum ALIGN {
         CENTER,
         TOP,
@@ -86,36 +86,36 @@ public class CustomDialog extends BaseDialog {
         RIGHT_TOP,
         RIGHT_BOTTOM
     }
-
+    
     protected CustomDialog() {
         super();
     }
-
+    
     public static CustomDialog build() {
         return new CustomDialog();
     }
-
+    
     public static CustomDialog build(OnBindView<CustomDialog> onBindView) {
         return new CustomDialog().setCustomView(onBindView);
     }
-
+    
     public CustomDialog(OnBindView<CustomDialog> onBindView) {
         this.onBindView = onBindView;
     }
-
+    
     public static CustomDialog show(OnBindView<CustomDialog> onBindView) {
         CustomDialog customDialog = new CustomDialog(onBindView);
         customDialog.show();
         return customDialog;
     }
-
+    
     public static CustomDialog show(OnBindView<CustomDialog> onBindView, ALIGN align) {
         CustomDialog customDialog = new CustomDialog(onBindView);
         customDialog.align = align;
         customDialog.show();
         return customDialog;
     }
-
+    
     public CustomDialog show() {
         if (isHide && getDialogView() != null && isShow) {
             if (hideWithExitAnim && getDialogImpl() != null && getDialogImpl().boxCustom != null) {
@@ -143,7 +143,7 @@ public class CustomDialog extends BaseDialog {
         show(dialogView);
         return this;
     }
-
+    
     public CustomDialog show(Activity activity) {
         super.beforeShow();
         if (getDialogView() == null) {
@@ -154,30 +154,32 @@ public class CustomDialog extends BaseDialog {
         show(activity, dialogView);
         return this;
     }
-
+    
     private ViewTreeObserver viewTreeObserver;
     private ViewTreeObserver.OnDrawListener baseViewDrawListener;
-
+    
     public class DialogImpl implements DialogConvertViewInterface {
-
+        
         public DialogXBaseRelativeLayout boxRoot;
         public MaxRelativeLayout boxCustom;
-
+        
         public DialogImpl(View convertView) {
             if (convertView == null) return;
             boxRoot = convertView.findViewById(R.id.box_root);
             boxCustom = convertView.findViewById(R.id.box_custom);
-
+            
             init();
             dialogImpl = this;
             refreshView();
         }
-
+        
         @Override
         public void init() {
             if (baseViewLoc == null && baseView != null) {
                 baseViewLoc = new int[4];
                 baseView.getLocationOnScreen(baseViewLoc);
+                baseViewLoc[2] = baseView.getWidth();
+                baseViewLoc[3] = baseView.getHeight();
             }
             boxRoot.setParentDialog(me);
             boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
@@ -185,16 +187,16 @@ public class CustomDialog extends BaseDialog {
                 public void onShow() {
                     isShow = true;
                     preShow = false;
-
+                    
                     lifecycle.setCurrentState(Lifecycle.State.CREATED);
-
+                    
                     getDialogLifecycleCallback().onShow(me);
                     CustomDialog.this.onShow(me);
                     onDialogShow();
-
+                    
                     boxCustom.setVisibility(View.GONE);
                 }
-
+                
                 @Override
                 public void onDismiss() {
                     isShow = false;
@@ -206,7 +208,7 @@ public class CustomDialog extends BaseDialog {
                     System.gc();
                 }
             });
-
+            
             boxRoot.setOnBackPressedListener(new DialogXBaseRelativeLayout.PrivateBackPressedListener() {
                 @Override
                 public boolean onBackPressed() {
@@ -222,7 +224,7 @@ public class CustomDialog extends BaseDialog {
                     return true;
                 }
             });
-
+            
             boxRoot.post(new Runnable() {
                 @Override
                 public void run() {
@@ -238,17 +240,17 @@ public class CustomDialog extends BaseDialog {
                     if (getDialogImpl().boxCustom != null) {
                         getDialogImpl().boxCustom.setVisibility(View.VISIBLE);
                     }
-
+                    
                     lifecycle.setCurrentState(Lifecycle.State.RESUMED);
                 }
             });
-
+            
             onDialogInit();
         }
-
+        
         boolean initSetCustomViewLayoutListener = false;
         ALIGN alignCache;
-
+        
         @Override
         public void refreshView() {
             if (boxRoot == null || getTopActivity() == null) {
@@ -262,7 +264,7 @@ public class CustomDialog extends BaseDialog {
                         rlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                         boxCustom.setLayoutParams(rlp);
                     }
-
+                    
                     Runnable onLayoutChangeRunnable = new Runnable() {
                         @Override
                         public void run() {
@@ -280,7 +282,7 @@ public class CustomDialog extends BaseDialog {
                                     calX = (baseViewLeft + baseView.getMeasuredWidth() / 2 - boxCustom.getWidth() / 2);
                                     calY = (baseViewTop + baseView.getMeasuredHeight() / 2 - boxCustom.getHeight() / 2);
                                 }
-
+                                
                                 if (isAlignBaseViewGravity(Gravity.TOP)) {
                                     calY = baseViewTop - boxCustom.getHeight() - marginRelativeBaseView[3];
                                 }
@@ -293,17 +295,19 @@ public class CustomDialog extends BaseDialog {
                                 if (isAlignBaseViewGravity(Gravity.BOTTOM)) {
                                     calY = baseViewTop + baseView.getHeight() + marginRelativeBaseView[1];
                                 }
-                                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);
-
+                                int widthCache = width == 0 ? baseView.getWidth() : width;
+                                int heightCache = height == 0 ? baseView.getHeight() : height;
+                                baseViewLoc[2] = widthCache > 0 ? widthCache : baseViewLoc[2];
+                                baseViewLoc[3] = heightCache > 0 ? heightCache : baseViewLoc[3];
+                                
+                                if (calX != 0 && calX != boxCustom.getX()) boxCustom.setX(calX);
+                                if (calY != 0 && calY != boxCustom.getY()) boxCustom.setY(calY);
+                                
                                 onGetBaseViewLoc(baseViewLoc);
                             }
                         }
                     };
-
+                    
                     viewTreeObserver = boxCustom.getViewTreeObserver();
                     viewTreeObserver.addOnDrawListener(baseViewDrawListener = new ViewTreeObserver.OnDrawListener() {
                         @Override
@@ -311,18 +315,15 @@ public class CustomDialog 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) {
-                                        onLayoutChangeRunnable.run();
-                                    }
+                                if (getDialogImpl() != null && isShow) {
+                                    baseViewLoc[0] = baseViewLocCache[0];
+                                    baseViewLoc[1] = baseViewLocCache[1];
+                                    onLayoutChangeRunnable.run();
                                 }
                             } else {
-                                if (viewTreeObserver != null) {
-                                    viewTreeObserver.removeOnDrawListener(this);
-                                    viewTreeObserver = null;
-                                    baseViewDrawListener = null;
-                                }
+                                removeDrawListener(viewTreeObserver, this);
+                                viewTreeObserver = null;
+                                baseViewDrawListener = null;
                             }
                         }
                     });
@@ -393,7 +394,7 @@ public class CustomDialog extends BaseDialog {
                     boxCustom.setLayoutParams(rlp);
                 }
             }
-
+            
             boxRoot.setAutoUnsafePlacePadding(autoUnsafePlacePadding);
             if (bkgInterceptTouch) {
                 if (isCancelable()) {
@@ -411,30 +412,30 @@ public class CustomDialog extends BaseDialog {
             } else {
                 boxRoot.setClickable(false);
             }
-
+            
             if (onBindView != null && onBindView.getCustomView() != null && boxCustom != null) {
                 onBindView.bindParent(boxCustom, me);
             }
-
+            
             if (boxCustom != null) {
                 if (width != -1) {
                     boxCustom.setMaxWidth(width);
                     boxCustom.setMinimumWidth(width);
                 }
-
+                
                 if (height != -1) {
                     boxCustom.setMaxHeight(height);
                     boxCustom.setMinimumHeight(height);
                 }
             }
-
+            
             boxRoot.setBackgroundColor(getMaskColor());
-
+            
             onDialogRefreshUI();
         }
-
+        
         long exitAnimDurationTemp = -1;
-
+        
         @Override
         public void doDismiss(View v) {
             if (v != null) v.setEnabled(false);
@@ -444,7 +445,7 @@ public class CustomDialog extends BaseDialog {
                     @Override
                     public void run() {
                         getDialogXAnimImpl().doExitAnim(CustomDialog.this, new ObjectRunnable<Float>() {
-
+                            
                             @Override
                             public void run(Float animProgress) {
                                 float value = animProgress;
@@ -472,7 +473,7 @@ public class CustomDialog extends BaseDialog {
                 });
             }
         }
-
+        
         protected DialogXAnimInterface<CustomDialog> getDialogXAnimImpl() {
             if (dialogXAnimImpl == null) {
                 dialogXAnimImpl = new DialogXAnimInterface<CustomDialog>() {
@@ -486,9 +487,9 @@ public class CustomDialog extends BaseDialog {
                             boxCustom.setVisibility(View.VISIBLE);
                             boxCustom.startAnimation(enterAnim);
                         }
-
-                        boxRoot.setBackgroundColor(maskColor);
-
+                        
+                        if (maskColor != Color.TRANSPARENT) boxRoot.setBackgroundColor(maskColor);
+                        
                         ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
                         bkgAlpha.setDuration(enterAnim.getDuration());
                         bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@@ -499,7 +500,7 @@ public class CustomDialog extends BaseDialog {
                         });
                         bkgAlpha.start();
                     }
-
+                    
                     @Override
                     public void doExitAnim(CustomDialog customDialog, ObjectRunnable<Float> animProgress) {
                         if (getDialogImpl() == null || getDialogImpl().boxCustom == null) {
@@ -512,7 +513,7 @@ public class CustomDialog extends BaseDialog {
                         if (exitAnimResId != 0) {
                             exitAnimResIdTemp = exitAnimResId;
                         }
-
+                        
                         if (boxCustom != null) {
                             Animation exitAnim = AnimationUtils.loadAnimation(getTopActivity() == null ? boxCustom.getContext() : getTopActivity(), exitAnimResIdTemp);
                             exitAnimDurationTemp = exitAnim.getDuration();
@@ -525,7 +526,7 @@ public class CustomDialog extends BaseDialog {
                             exitAnim.setDuration(exitAnimDurationTemp);
                             boxCustom.startAnimation(exitAnim);
                         }
-
+                        
                         ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
                         bkgAlpha.setDuration(exitAnimDurationTemp);
                         bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@@ -541,7 +542,7 @@ public class CustomDialog extends BaseDialog {
             return dialogXAnimImpl;
         }
     }
-
+    
     private void removeDrawListener(ViewTreeObserver viewTreeObserver, ViewTreeObserver.OnDrawListener listener) {
         if (viewTreeObserver == null || listener == null || !viewTreeObserver.isAlive()) {
             return;
@@ -551,7 +552,7 @@ public class CustomDialog extends BaseDialog {
         } catch (Exception e) {
         }
     }
-
+    
     private Animation getEnterAnimation() {
         Animation enterAnim;
         if (enterAnimResId == R.anim.anim_dialogx_default_enter &&
@@ -609,15 +610,15 @@ public class CustomDialog extends BaseDialog {
         enterAnim.setDuration(enterAnimDurationTemp);
         return enterAnim;
     }
-
+    
     protected void onGetBaseViewLoc(int[] baseViewLoc) {
     }
-
+    
     @Override
     public String dialogKey() {
         return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
     }
-
+    
     public void refreshUI() {
         if (getDialogImpl() == null) return;
         runOnMain(new Runnable() {
@@ -627,7 +628,7 @@ public class CustomDialog extends BaseDialog {
             }
         });
     }
-
+    
     public void dismiss() {
         runOnMain(new Runnable() {
             @Override
@@ -637,38 +638,38 @@ public class CustomDialog extends BaseDialog {
             }
         });
     }
-
+    
     public DialogLifecycleCallback<CustomDialog> getDialogLifecycleCallback() {
         return dialogLifecycleCallback == null ? new DialogLifecycleCallback<CustomDialog>() {
         } : dialogLifecycleCallback;
     }
-
+    
     public CustomDialog setDialogLifecycleCallback(DialogLifecycleCallback<CustomDialog> dialogLifecycleCallback) {
         this.dialogLifecycleCallback = dialogLifecycleCallback;
         if (isShow) dialogLifecycleCallback.onShow(me);
         return this;
     }
-
+    
     public OnBackPressedListener<CustomDialog> getOnBackPressedListener() {
         return (OnBackPressedListener<CustomDialog>) onBackPressedListener;
     }
-
+    
     public CustomDialog setOnBackPressedListener(OnBackPressedListener<CustomDialog> onBackPressedListener) {
         this.onBackPressedListener = onBackPressedListener;
         refreshUI();
         return this;
     }
-
+    
     public CustomDialog setStyle(DialogXStyle style) {
         this.style = style;
         return this;
     }
-
+    
     public CustomDialog setTheme(DialogX.THEME theme) {
         this.theme = theme;
         return this;
     }
-
+    
     public boolean isCancelable() {
         if (privateCancelable != null) {
             return privateCancelable == BOOLEAN.TRUE;
@@ -678,112 +679,112 @@ public class CustomDialog extends BaseDialog {
         }
         return cancelable;
     }
-
+    
     public CustomDialog setCancelable(boolean cancelable) {
         this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
         refreshUI();
         return this;
     }
-
+    
     public CustomDialog.DialogImpl getDialogImpl() {
         return dialogImpl;
     }
-
+    
     public CustomDialog setCustomView(OnBindView<CustomDialog> onBindView) {
         this.onBindView = onBindView;
         refreshUI();
         return this;
     }
-
+    
     public View getCustomView() {
         if (onBindView == null) return null;
         return onBindView.getCustomView();
     }
-
+    
     public CustomDialog removeCustomView() {
         this.onBindView.clean();
         refreshUI();
         return this;
     }
-
+    
     public int getEnterAnimResId() {
         return enterAnimResId;
     }
-
+    
     public CustomDialog setEnterAnimResId(int enterAnimResId) {
         this.enterAnimResId = enterAnimResId;
         return this;
     }
-
+    
     public int getExitAnimResId() {
         return exitAnimResId;
     }
-
+    
     public CustomDialog setExitAnimResId(int exitAnimResId) {
         this.exitAnimResId = exitAnimResId;
         return this;
     }
-
+    
     public CustomDialog setAnimResId(int enterAnimResId, int exitAnimResId) {
         this.enterAnimResId = enterAnimResId;
         this.exitAnimResId = exitAnimResId;
         return this;
     }
-
+    
     public ALIGN getAlign() {
         return align;
     }
-
+    
     public CustomDialog setAlign(ALIGN align) {
         this.align = align;
         refreshUI();
         return this;
     }
-
+    
     public boolean isAutoUnsafePlacePadding() {
         return autoUnsafePlacePadding;
     }
-
+    
     public CustomDialog setAutoUnsafePlacePadding(boolean autoUnsafePlacePadding) {
         this.autoUnsafePlacePadding = autoUnsafePlacePadding;
         refreshUI();
         return this;
     }
-
+    
     public CustomDialog setFullScreen(boolean fullscreen) {
         this.autoUnsafePlacePadding = !autoUnsafePlacePadding;
         refreshUI();
         return this;
     }
-
+    
     public CustomDialog setMaskColor(@ColorInt int maskColor) {
         this.maskColor = maskColor;
         refreshUI();
         return this;
     }
-
+    
     public int getMaskColor() {
         return maskColor;
     }
-
+    
     public long getEnterAnimDuration() {
         return enterAnimDuration;
     }
-
+    
     public CustomDialog setEnterAnimDuration(long enterAnimDuration) {
         this.enterAnimDuration = enterAnimDuration;
         return this;
     }
-
+    
     public long getExitAnimDuration() {
         return exitAnimDuration;
     }
-
+    
     public CustomDialog setExitAnimDuration(long exitAnimDuration) {
         this.exitAnimDuration = exitAnimDuration;
         return this;
     }
-
+    
     @Override
     public void restartDialog() {
         if (dialogView != null) {
@@ -806,16 +807,16 @@ public class CustomDialog extends BaseDialog {
         if (getDialogImpl() != null && getDialogImpl().boxCustom != null) {
             getDialogImpl().boxCustom.removeAllViews();
         }
-
+        
         enterAnimDuration = 0;
         dialogView = createView(R.layout.layout_dialogx_custom);
         dialogImpl = new DialogImpl(dialogView);
         if (dialogView != null) dialogView.setTag(me);
         show(dialogView);
     }
-
+    
     private boolean isHide;
-
+    
     public void hide() {
         isHide = true;
         hideWithExitAnim = false;
@@ -823,9 +824,9 @@ public class CustomDialog extends BaseDialog {
             getDialogView().setVisibility(View.GONE);
         }
     }
-
+    
     protected boolean hideWithExitAnim;
-
+    
     public void hideWithExitAnim() {
         hideWithExitAnim = true;
         isHide = true;
@@ -846,31 +847,31 @@ public class CustomDialog extends BaseDialog {
             });
         }
     }
-
+    
     @Override
     protected void shutdown() {
         dismiss();
     }
-
+    
     public CustomDialog setDialogImplMode(DialogX.IMPL_MODE dialogImplMode) {
         this.dialogImplMode = dialogImplMode;
         return this;
     }
-
+    
     public boolean isBkgInterceptTouch() {
         return bkgInterceptTouch;
     }
-
+    
     public CustomDialog setBkgInterceptTouch(boolean bkgInterceptTouch) {
         this.bkgInterceptTouch = bkgInterceptTouch;
         refreshUI();
         return this;
     }
-
+    
     public int getAlignBaseViewGravity() {
         return alignViewGravity;
     }
-
+    
     /**
      * 判断是否有设置对应的位置关系
      *
@@ -880,7 +881,7 @@ public class CustomDialog extends BaseDialog {
     public boolean isAlignBaseViewGravity(int gravity) {
         return (alignViewGravity & gravity) == gravity;
     }
-
+    
     public CustomDialog setAlignBaseViewGravity(View baseView, int alignGravity) {
         this.baseView = baseView;
         this.alignViewGravity = alignGravity;
@@ -889,7 +890,7 @@ public class CustomDialog extends BaseDialog {
         setFullScreen(true);
         return this;
     }
-
+    
     public CustomDialog setAlignBaseView(View baseView) {
         this.baseView = baseView;
         baseViewLoc = new int[4];
@@ -897,7 +898,7 @@ public class CustomDialog extends BaseDialog {
         setFullScreen(true);
         return this;
     }
-
+    
     public CustomDialog setAlignBaseViewGravity(int alignGravity) {
         this.alignViewGravity = alignGravity;
         if (baseView != null) {
@@ -907,79 +908,79 @@ public class CustomDialog extends BaseDialog {
         setFullScreen(true);
         return this;
     }
-
+    
     public CustomDialog setAlignBaseViewGravity(View baseView, int alignGravity, int marginLeft,
                                                 int marginTop, int marginRight, int marginBottom) {
         this.marginRelativeBaseView = new int[]{marginLeft, marginTop, marginRight, marginBottom};
         refreshUI();
         return setAlignBaseViewGravity(baseView, alignGravity);
     }
-
+    
     public int[] getBaseViewMargin() {
         return marginRelativeBaseView;
     }
-
+    
     public CustomDialog setBaseViewMargin(int[] marginRelativeBaseView) {
         this.marginRelativeBaseView = marginRelativeBaseView;
         refreshUI();
         return this;
     }
-
+    
     public CustomDialog setBaseViewMargin(int marginLeft, int marginTop,
                                           int marginRight, int marginBottom) {
         this.marginRelativeBaseView = new int[]{marginLeft, marginTop, marginRight, marginBottom};
         refreshUI();
         return this;
     }
-
+    
     public CustomDialog setBaseViewMarginLeft(int marginLeft) {
         this.marginRelativeBaseView[0] = marginLeft;
         refreshUI();
         return this;
     }
-
+    
     public CustomDialog setBaseViewMarginTop(int marginTop) {
         this.marginRelativeBaseView[1] = marginTop;
         refreshUI();
         return this;
     }
-
+    
     public CustomDialog setBaseViewMarginRight(int marginRight) {
         this.marginRelativeBaseView[2] = marginRight;
         refreshUI();
         return this;
     }
-
+    
     public CustomDialog setBaseViewMarginBottom(int marginBottom) {
         this.marginRelativeBaseView[3] = marginBottom;
         refreshUI();
         return this;
     }
-
+    
     public int getBaseViewMarginLeft(int marginLeft) {
         return this.marginRelativeBaseView[0];
     }
-
+    
     public int getBaseViewMarginTop(int marginLeft) {
         return this.marginRelativeBaseView[1];
     }
-
+    
     public int getBaseViewMarginRight(int marginLeft) {
         return this.marginRelativeBaseView[2];
     }
-
+    
     public int getBaseViewMarginBottom(int marginLeft) {
         return this.marginRelativeBaseView[3];
     }
-
+    
     public View getBaseView() {
         return baseView;
     }
-
+    
     public int getWidth() {
         return width;
     }
-
+    
     /**
      * 设置对话框 UI 宽度(单位:像素)
      *
@@ -991,11 +992,11 @@ public class CustomDialog extends BaseDialog {
         refreshUI();
         return this;
     }
-
+    
     public int getHeight() {
         return height;
     }
-
+    
     /**
      * 设置对话框 UI 高度(单位:像素)
      *
@@ -1007,37 +1008,37 @@ public class CustomDialog extends BaseDialog {
         refreshUI();
         return this;
     }
-
+    
     public OnBackgroundMaskClickListener<CustomDialog> getOnBackgroundMaskClickListener() {
         return onBackgroundMaskClickListener;
     }
-
+    
     public CustomDialog setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener<CustomDialog> onBackgroundMaskClickListener) {
         this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
         return this;
     }
-
+    
     public DialogXAnimInterface<CustomDialog> getDialogXAnimImpl() {
         return dialogXAnimImpl;
     }
-
+    
     public CustomDialog setDialogXAnimImpl(DialogXAnimInterface<CustomDialog> dialogXAnimImpl) {
         this.dialogXAnimImpl = dialogXAnimImpl;
         return this;
     }
-
+    
     public CustomDialog setRootPadding(int padding) {
         this.screenPaddings = new int[]{padding, padding, padding, padding};
         refreshUI();
         return this;
     }
-
+    
     public CustomDialog setRootPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
         this.screenPaddings = new int[]{paddingLeft, paddingTop, paddingRight, paddingBottom};
         refreshUI();
         return this;
     }
-
+    
     /**
      * 用于使用 new 构建实例时,override 的生命周期事件
      * 例如:
@@ -1050,9 +1051,9 @@ public class CustomDialog extends BaseDialog {
      * }
      */
     public void onShow(CustomDialog dialog) {
-
+    
     }
-
+    
     /**
      * 用于使用 new 构建实例时,override 的生命周期事件
      * 例如:
@@ -1074,6 +1075,6 @@ public class CustomDialog extends BaseDialog {
      */
     //用于使用 new 构建实例时,override 的生命周期事件
     public void onDismiss(CustomDialog dialog) {
-
+    
     }
 }

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

@@ -30,6 +30,8 @@ import com.kongzue.dialogx.interfaces.OnBindView;
 import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
 import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
 
+import java.util.Arrays;
+
 /**
  * @author: Kongzue
  * @github: https://github.com/kongzue/
@@ -566,9 +568,14 @@ public class GuideDialog extends CustomDialog {
         }
     }
     
+    int[] baseViewLocCache;
+    
     @Override
     protected void onGetBaseViewLoc(int[] baseViewLoc) {
-        super.onGetBaseViewLoc(baseViewLoc);
+        if (Arrays.equals(baseViewLoc, baseViewLocCache)) {
+            return;
+        }
+        log("a:" + baseViewLoc[0]);
         if (getDialogImpl() == null) {
             return;
         }
@@ -623,8 +630,10 @@ public class GuideDialog extends CustomDialog {
         }
         stageLightPaint.setXfermode(null);
         canvas.drawColor(maskColor == -1 ? getColor(R.color.black50) : maskColor, PorterDuff.Mode.SRC_OUT);
+        
         BitmapDrawable bkgDrawable = new BitmapDrawable(getResources(), bkg);
         getDialogImpl().boxRoot.setBackground(bkgDrawable);
+        baseViewLocCache = Arrays.copyOf(baseViewLoc, 4);
     }
     
     Paint stageLightPaint;

+ 93 - 92
app/src/main/java/com/kongzue/dialogxdemo/activity/MainActivity.java

@@ -107,7 +107,7 @@ import java.util.Random;
 @DarkNavigationBarTheme(true)
 @NavigationBarBackgroundColorRes(R.color.emptyNavBar)
 public class MainActivity extends BaseActivity {
-
+    
     private ConstraintLayout boxTitle;
     private TextView txtTitle;
     private ImageView btnShare;
@@ -167,7 +167,7 @@ public class MainActivity extends BaseActivity {
     private MaterialButton btnShowBreak;
     private MaterialButton btnListDialog;
     private TextView txtVer;
-
+    
     @Override
     public void initViews() {
         boxTitle = findViewById(R.id.box_title);
@@ -230,11 +230,11 @@ public class MainActivity extends BaseActivity {
         btnListDialog = findViewById(R.id.btn_listDialog);
         txtVer = findViewById(R.id.txt_ver);
     }
-
+    
     @Override
     public void initDatas(JumpParameter parameter) {
         getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
-
+        
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
             getWindow().getDecorView().setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                 @Override
@@ -247,7 +247,7 @@ public class MainActivity extends BaseActivity {
         } else {
             getRootView().setFitsSystemWindows(true);
         }
-
+        
         refreshUIMode();
         boolean showBreak = parameter.getBoolean("showBreak");
         if (showBreak) {
@@ -277,7 +277,7 @@ public class MainActivity extends BaseActivity {
                     })
                     .setCancelable(false);
         }
-
+        
         switch (DialogX.implIMPLMode) {
             case VIEW:
                 rdoModeView.setChecked(true);
@@ -292,7 +292,7 @@ public class MainActivity extends BaseActivity {
                 rdoModeFloatingActivity.setChecked(true);
                 break;
         }
-
+        
         txtVer.setText("当前版本:" + BuildConfig.VERSION_NAME);
 
 //        //合并处理演示,在 onDismiss 中获取用户选择进行统一处理,以防止编写大量可能在不同选择下都要处理的重复代码
@@ -343,15 +343,15 @@ public class MainActivity extends BaseActivity {
 //                .setCancelButton("Cancel")
 //                .show();
     }
-
+    
     //用于模拟进度提示
     private CycleRunner cycleRunner;
     private float progress = 0;
     private int waitId;
-
+    
     private TextView btnReplyCommit;
     private EditText editReplyCommit;
-
+    
     private TextView btnCancel;
     private TextView btnSubmit;
     private RelativeLayout boxUserName;
@@ -359,17 +359,17 @@ public class MainActivity extends BaseActivity {
     private RelativeLayout boxPassword;
     private EditText editPassword;
     private TextView btnLicense;
-
+    
     private TextView btnClose;
     private WebView webView;
-
+    
     private String[] singleSelectMenuText = new String[]{"拒绝", "询问", "始终允许", "仅在使用中允许"};
     private int selectMenuIndex;
-
+    
     private String[] multiSelectMenuText = new String[]{"上海", "北京", "广州", "深圳"};
     private int[] selectMenuIndexArray;
     private String multiSelectMenuResultCache;
-
+    
     @Override
     public void setEvents() {
         grpMode.addOnButtonCheckedListener(new MaterialButtonToggleGroup.OnButtonCheckedListener() {
@@ -392,7 +392,7 @@ public class MainActivity extends BaseActivity {
                 }
             }
         });
-
+        
         grpTheme.addOnButtonCheckedListener(new MaterialButtonToggleGroup.OnButtonCheckedListener() {
             @Override
             public void onButtonChecked(MaterialButtonToggleGroup group, int checkedId, boolean isChecked) {
@@ -409,7 +409,7 @@ public class MainActivity extends BaseActivity {
                 }
             }
         });
-
+        
         grpStyle.addOnButtonCheckedListener(new MaterialButtonToggleGroup.OnButtonCheckedListener() {
             @Override
             public void onButtonChecked(MaterialButtonToggleGroup group, int checkedId, boolean isChecked) {
@@ -436,14 +436,14 @@ public class MainActivity extends BaseActivity {
                 }
             }
         });
-
+        
         btnShare.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 openUrl("https://github.com/kongzue/DialogX");
             }
         });
-
+        
         btnContextMenu.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -477,7 +477,7 @@ public class MainActivity extends BaseActivity {
                         });
             }
         });
-
+        
         btnSelectMenu.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
@@ -491,7 +491,7 @@ public class MainActivity extends BaseActivity {
                         });
             }
         });
-
+        
         btnFullScreenDialogFragment.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -505,12 +505,12 @@ public class MainActivity extends BaseActivity {
                 FullScreenDialog.show(new OnBindView<FullScreenDialog>(customFragment) {
                     @Override
                     public void onBind(FullScreenDialog dialog, View v) {
-
+                    
                     }
                 });
             }
         });
-
+        
         btnMessageDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
@@ -525,7 +525,7 @@ public class MainActivity extends BaseActivity {
                         });
             }
         });
-
+        
         btnSelectDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -537,7 +537,7 @@ public class MainActivity extends BaseActivity {
                 messageDialog.show();
             }
         });
-
+        
         btnInputDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
@@ -553,7 +553,7 @@ public class MainActivity extends BaseActivity {
                         .show();
             }
         });
-
+        
         btnWaitDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -573,11 +573,11 @@ public class MainActivity extends BaseActivity {
                 }, 1500);
             }
         });
-
+        
         btnWaitAndTipDialog.setOnClickListener(new View.OnClickListener() {
-
+            
             boolean closeFlag = false;
-
+            
             @Override
             public void onClick(View v) {
                 closeFlag = false;
@@ -603,28 +603,28 @@ public class MainActivity extends BaseActivity {
                 }, 1500 + new Random().nextInt(1000));
             }
         });
-
+        
         btnTipSuccess.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 TipDialog.show("Success!", WaitDialog.TYPE.SUCCESS);
             }
         });
-
+        
         btnTipWarning.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 TipDialog.show("Warning!", WaitDialog.TYPE.WARNING);
             }
         });
-
+        
         btnTipError.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 TipDialog.show("Error!", WaitDialog.TYPE.ERROR);
             }
         });
-
+        
         btnTipProgress.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -670,7 +670,7 @@ public class MainActivity extends BaseActivity {
                 }, 3000);
             }
         });
-
+        
         btnBottomDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -697,7 +697,7 @@ public class MainActivity extends BaseActivity {
                                 log("#onSlideClose");
                                 return super.onSlideClose(dialog);
                             }
-
+                            
                             @Override
                             public boolean onSlideTouchEvent(BottomDialog dialog, View v, MotionEvent event) {
                                 log("#onSlideTouchEvent: action=" + event.getAction() + " y=" + event.getY());
@@ -707,7 +707,7 @@ public class MainActivity extends BaseActivity {
                         .show();
             }
         });
-
+        
         btnBottomMenu.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -782,7 +782,7 @@ public class MainActivity extends BaseActivity {
                 }
             }
         });
-
+        
         btnBottomReply.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -809,7 +809,7 @@ public class MainActivity extends BaseActivity {
                         .setAllowInterceptTouch(false);
             }
         });
-
+        
         btnCustomMessageDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -817,12 +817,12 @@ public class MainActivity extends BaseActivity {
                         .setCustomView(new OnBindView<MessageDialog>(R.layout.layout_custom_view) {
                             @Override
                             public void onBind(MessageDialog dialog, View v) {
-
+                            
                             }
                         });
             }
         });
-
+        
         btnCustomInputDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -830,12 +830,12 @@ public class MainActivity extends BaseActivity {
                         .setCustomView(new OnBindView<MessageDialog>(R.layout.layout_custom_view) {
                             @Override
                             public void onBind(MessageDialog dialog, View v) {
-
+                            
                             }
                         });
             }
         });
-
+        
         btnCustomBottomMenu.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -851,27 +851,28 @@ public class MainActivity extends BaseActivity {
                         .setCustomView(new OnBindView<BottomDialog>(R.layout.layout_custom_view) {
                             @Override
                             public void onBind(BottomDialog dialog, View v) {
-
+                            
                             }
                         });
             }
         });
-
+        
         btnShowGuide.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 GuideDialog.show(R.mipmap.img_guide_tip);
             }
         });
-
+        
         btnShowGuideBaseView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
+                btnFullScreenDialogLogin.animate().x(0).setDuration(3000);
                 GuideDialog.show(btnFullScreenDialogLogin, R.mipmap.img_tip_login)
                         .setBaseViewMarginTop(-dip2px(30));
             }
         });
-
+        
         btnShowGuideBaseViewRectangle.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -897,14 +898,14 @@ public class MainActivity extends BaseActivity {
                         });
             }
         });
-
+        
         btnShowBreak.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 jump(MainActivity.class, new JumpParameter().put("showBreak", true).put("fromActivity", getInstanceKey()));
             }
         });
-
+        
         btnListDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -937,15 +938,15 @@ public class MainActivity extends BaseActivity {
                 );
             }
         });
-
+        
         btnFullScreenDialogLogin.setOnClickListener(new View.OnClickListener() {
-
+            
             /**
              * 采用异步加载布局防止卡顿测试
              */
-
+            
             OnBindView<FullScreenDialog> onBindView;
-
+            
             @Override
             public void onClick(View v) {
                 onBindView = new OnBindView<FullScreenDialog>(R.layout.layout_full_login, true) {
@@ -958,14 +959,14 @@ public class MainActivity extends BaseActivity {
                         boxPassword = v.findViewById(R.id.box_password);
                         editPassword = v.findViewById(R.id.edit_password);
                         btnLicense = v.findViewById(R.id.btn_license);
-
+                        
                         initFullScreenLoginDemo(dialog);
                     }
                 };
                 FullScreenDialog.show(onBindView);
             }
         });
-
+        
         btnFullScreenDialogWebPage.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -974,14 +975,14 @@ public class MainActivity extends BaseActivity {
                             public void onBind(final FullScreenDialog dialog, View v) {
                                 btnClose = v.findViewById(R.id.btn_close);
                                 webView = v.findViewById(R.id.webView);
-
+                                
                                 btnClose.setOnClickListener(new View.OnClickListener() {
                                     @Override
                                     public void onClick(View v) {
                                         dialog.dismiss();
                                     }
                                 });
-
+                                
                                 WebSettings webSettings = webView.getSettings();
                                 webSettings.setJavaScriptEnabled(true);
                                 webSettings.setLoadWithOverviewMode(true);
@@ -991,7 +992,7 @@ public class MainActivity extends BaseActivity {
                                 webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
                                 webSettings.setLoadsImagesAutomatically(true);
                                 webSettings.setDefaultTextEncodingName("utf-8");
-
+                                
                                 webView.setWebViewClient(new WebViewClient() {
                                     @Override
                                     public boolean shouldOverrideUrlLoading(WebView view, String url) {
@@ -1003,20 +1004,20 @@ public class MainActivity extends BaseActivity {
                                         }
                                         return true;
                                     }
-
+                                    
                                     @Override
                                     public void onPageFinished(WebView view, String url) {
                                         super.onPageFinished(view, url);
                                     }
                                 });
-
+                                
                                 webView.loadUrl("https://github.com/kongzue/DialogX");
                             }
                         })
                         .show();
             }
         });
-
+        
         btnCustomDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1081,14 +1082,14 @@ public class MainActivity extends BaseActivity {
                 ;
             }
         });
-
+        
         btnCustomDialogAlign.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 CustomDialog.show(new OnBindView<CustomDialog>(R.layout.layout_custom_dialog_align) {
-
+                            
                             private TextView btnSelectPositive;
-
+                            
                             @Override
                             public void onBind(final CustomDialog dialog, View v) {
                                 btnSelectPositive = v.findViewById(R.id.btn_selectPositive);
@@ -1110,14 +1111,14 @@ public class MainActivity extends BaseActivity {
                         .show();
             }
         });
-
+        
         btnPoptip.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 PopTip.show("这是一个提示");
             }
         });
-
+        
         btnPoptipBigMessage.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1135,14 +1136,14 @@ public class MainActivity extends BaseActivity {
                 }
             }
         });
-
+        
         btnPoptipSuccess.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 PopTip.show("操作已完成").iconSuccess();
             }
         });
-
+        
         btnPoptipWarning.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1154,14 +1155,14 @@ public class MainActivity extends BaseActivity {
                 }).iconWarning();
             }
         });
-
+        
         btnPoptipError.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 PopTip.show("无法连接网络").iconError();
             }
         });
-
+        
         btnBottomSelectMenu.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1184,7 +1185,7 @@ public class MainActivity extends BaseActivity {
                         .setSelection(selectMenuIndex);
             }
         });
-
+        
         btnBottomMultiSelectMenu.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1211,7 +1212,7 @@ public class MainActivity extends BaseActivity {
                         .setSelection(selectMenuIndexArray);
             }
         });
-
+        
         btnBottomCustomRecycleView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1250,7 +1251,7 @@ public class MainActivity extends BaseActivity {
                         .show();
             }
         });
-
+        
         btnPopnotification.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1265,7 +1266,7 @@ public class MainActivity extends BaseActivity {
                         });
             }
         });
-
+        
         btnPopnotificationBigMessage.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1283,7 +1284,7 @@ public class MainActivity extends BaseActivity {
                         .showLong();
             }
         });
-
+        
         btnPopnotificationOverlay.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1298,17 +1299,17 @@ public class MainActivity extends BaseActivity {
                         return;
                     }
                 }
-
+                
                 Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.img_demo_avatar);
                 notificationIndex++;
                 Toast.makeText(me, "会在1秒后显示悬浮窗!", Toast.LENGTH_LONG).show();
-
+                
                 //跳转到桌面
                 Intent intent = new Intent(Intent.ACTION_MAIN);
                 intent.addCategory(Intent.CATEGORY_HOME);
                 intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
                 startActivity(intent);
-
+                
                 //等待一秒后显示
                 new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
                     @Override
@@ -1332,9 +1333,9 @@ public class MainActivity extends BaseActivity {
             }
         });
     }
-
+    
     int notificationIndex;
-
+    
     private void initFullScreenLoginDemo(final FullScreenDialog fullScreenDialog) {
         btnCancel.setOnClickListener(new View.OnClickListener() {
             @Override
@@ -1342,17 +1343,17 @@ public class MainActivity extends BaseActivity {
                 fullScreenDialog.dismiss();
             }
         });
-
+        
         btnCancel.setText("取消");
         btnSubmit.setText("下一步");
-
+        
         btnLicense.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 PopTip.show("点击用户服务条款");
             }
         });
-
+        
         btnSubmit.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1361,29 +1362,29 @@ public class MainActivity extends BaseActivity {
                     TipDialog.show("请输入账号", TipDialog.TYPE.WARNING);
                     return;
                 }
-
+                
                 boxUserName.animate().x(-getDisplayWidth()).setDuration(300);
                 boxPassword.setX(getDisplayWidth());
                 boxPassword.setVisibility(View.VISIBLE);
                 boxPassword.animate().x(0).setDuration(300);
-
+                
                 editPassword.setFocusable(true);
                 editPassword.requestFocus();
-
+                
                 btnCancel.setText("上一步");
                 btnCancel.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
                         boxUserName.animate().x(0).setDuration(300);
                         boxPassword.animate().x(getDisplayWidth()).setDuration(300);
-
+                        
                         editUserName.setFocusable(true);
                         editUserName.requestFocus();
-
+                        
                         initFullScreenLoginDemo(fullScreenDialog);
                     }
                 });
-
+                
                 btnSubmit.setText("登录");
                 btnSubmit.setOnClickListener(new View.OnClickListener() {
                     @Override
@@ -1410,13 +1411,13 @@ public class MainActivity extends BaseActivity {
             }
         });
     }
-
+    
     @Override
     public void onBackPressed() {
         log("#MainActivity.onBackPressed");
         super.onBackPressed();
     }
-
+    
     public void showIME(EditText editText) {
         if (editText == null) {
             return;
@@ -1426,14 +1427,14 @@ public class MainActivity extends BaseActivity {
         InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
         imm.showSoftInput(editText, InputMethodManager.RESULT_UNCHANGED_SHOWN);
     }
-
+    
     @Override
     public void onConfigurationChanged(@NonNull Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
         refreshUIMode();
-
+        
     }
-
+    
     /**
      * 刷新亮暗色模式界面变化
      */