@Override
        public void refreshView() {
            if (boxRoot == null || getOwnActivity() == null) {
                return;
            }

            boxCustom.setMaxWidth(getMaxWidth());
            boxCustom.setMaxHeight(getMaxHeight());
            boxCustom.setMinimumWidth(getMinWidth());
            boxCustom.setMinimumHeight(getMinHeight());

            boxRoot.setAutoUnsafePlacePadding(isEnableImmersiveMode());
            boxRoot.setRootPadding(screenPaddings[0], screenPaddings[1], screenPaddings[2], screenPaddings[3]);
            if (baseView() != null) {
                if (!initSetCustomViewLayoutListener) {
                    if (boxCustom != null) {
                        RelativeLayout.LayoutParams rlp;
                        rlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        boxCustom.setLayoutParams(rlp);
                    }

                    Runnable onLayoutChangeRunnable = new Runnable() {
                        @Override
                        public void run() {
                            int baseViewLeft = baseViewLoc[0] - (int) boxRoot.getX();
                            int baseViewTop = baseViewLoc[1] - (int) boxRoot.getY();
                            int calX = 0, calY = 0;
                            if (alignViewGravity != -1) {
                                if (isAlignBaseViewGravity(Gravity.CENTER_VERTICAL)) {
                                    calY = (baseViewTop + baseView().getMeasuredHeight() / 2 - boxCustom.getHeight() / 2);
                                }
                                if (isAlignBaseViewGravity(Gravity.CENTER_HORIZONTAL)) {
                                    calX = (baseViewLeft + baseView().getMeasuredWidth() / 2 - boxCustom.getWidth() / 2);
                                }
                                if (isAlignBaseViewGravity(Gravity.CENTER)) {
                                    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];
                                }
                                if (isAlignBaseViewGravity(Gravity.LEFT)) {
                                    calX = baseViewLeft - boxCustom.getWidth() - marginRelativeBaseView[2];
                                }
                                if (isAlignBaseViewGravity(Gravity.RIGHT)) {
                                    calX = baseViewLeft + baseView().getWidth() + marginRelativeBaseView[0];
                                }
                                if (isAlignBaseViewGravity(Gravity.BOTTOM)) {
                                    calY = baseViewTop + baseView().getHeight() + marginRelativeBaseView[1];
                                }
                                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.addOnPreDrawListener(baseViewDrawListener = new ViewTreeObserver.OnPreDrawListener() {
                        @Override
                        public boolean onPreDraw() {
                            int[] baseViewLocCache = new int[2];
                            if (baseView() != null) {
                                baseView().getLocationInWindow(baseViewLocCache);
                                if (getDialogImpl() != null && isShow && baseView().getVisibility() == View.VISIBLE) {
                                    if (baseViewLocCache[0] != 0) {
                                        baseViewLoc[0] = baseViewLocCache[0];
                                    }
                                    if (baseViewLocCache[1] != 0) {
                                        baseViewLoc[1] = baseViewLocCache[1];
                                    }
                                    onLayoutChangeRunnable.run();
                                }
                            } else {
                                removeDrawListener(viewTreeObserver, this);
                                viewTreeObserver = null;
                                baseViewDrawListener = null;
                            }
                            return true;
                        }
                    });
                    initSetCustomViewLayoutListener = true;
                }
            } else {
                if (boxCustom != null) {
                    RelativeLayout.LayoutParams rlp;
                    rlp = ((RelativeLayout.LayoutParams) boxCustom.getLayoutParams());
                    if (rlp == null || (alignCache != null && alignCache != align)) {
                        rlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    }
                    switch (align) {
                        case TOP_LEFT:
                        case LEFT_TOP:
                            rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                            break;
                        case TOP:
                        case TOP_CENTER:
                            rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                            rlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
                            break;
                        case TOP_RIGHT:
                        case RIGHT_TOP:
                            rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                            break;
                        case BOTTOM_LEFT:
                        case LEFT_BOTTOM:
                            rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                            break;
                        case BOTTOM:
                        case BOTTOM_CENTER:
                            rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                            rlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
                            break;
                        case BOTTOM_RIGHT:
                        case RIGHT_BOTTOM:
                            rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                            break;
                        case CENTER:
                            rlp.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
                            rlp.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                            rlp.addRule(RelativeLayout.CENTER_IN_PARENT);
                            break;
                        case LEFT:
                        case LEFT_CENTER:
                            rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                            rlp.addRule(RelativeLayout.CENTER_VERTICAL);
                            break;
                        case RIGHT:
                        case RIGHT_CENTER:
                            rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                            rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                            rlp.addRule(RelativeLayout.CENTER_VERTICAL);
                            break;
                    }
                    alignCache = align;
                    boxCustom.setLayoutParams(rlp);
                }
            }

            if (bkgInterceptTouch) {
                if (isCancelable()) {
                    boxRoot.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (onBackgroundMaskClickListener == null || !onBackgroundMaskClickListener.onClick(me, v)) {
                                doDismiss(v);
                            }
                        }
                    });
                } else {
                    boxRoot.setOnClickListener(null);
                }
            } 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();
        }
@author: Kongzue
@github: https://github.com/kongzue/
@homepage: http://kongzue.com/
@mail: myzcxhh@live.cn
@createTime: 2020/10/20 11:59
DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java