* 记录这个值的目的是,当用户向下滑动时,判断情况该回到这个位置还是关闭对话框,
* 并阻止当内容高度已经完全显示时的继续向上滑动操作。
*/
public float bkgEnterAimY = -1;
@Override
public void init() {
if (titleTextInfo == null) titleTextInfo = DialogX.menuTitleInfo;
if (titleTextInfo == null) titleTextInfo = DialogX.titleTextInfo;
if (messageTextInfo == null) messageTextInfo = DialogX.messageTextInfo;
if (okTextInfo == null) okTextInfo = DialogX.okButtonTextInfo;
if (okTextInfo == null) okTextInfo = DialogX.buttonTextInfo;
if (cancelTextInfo == null) cancelTextInfo = DialogX.buttonTextInfo;
if (otherTextInfo == null) otherTextInfo = DialogX.buttonTextInfo;
if (backgroundColor == -1) backgroundColor = DialogX.backgroundColor;
if (cancelText == null) cancelText = DialogX.cancelButtonText;
txtDialogTitle.getPaint().setFakeBoldText(true);
if (btnCancel != null) btnCancel.getPaint().setFakeBoldText(true);
if (btnSelectPositive != null) btnSelectPositive.getPaint().setFakeBoldText(true);
if (btnSelectOther != null) btnSelectOther.getPaint().setFakeBoldText(true);
boxRoot.setParentDialog(me);
boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
@Override
public void onShow() {
bkg.setY(getRootFrameLayout().getMeasuredHeight());
isShow = true;
boxRoot.setAlpha(0f);
boxContent.getViewTreeObserver().addOnGlobalLayoutListener(onContentViewLayoutChangeListener);
getDialogLifecycleCallback().onShow(me);
onDialogInit(dialogImpl);
boxRoot.post(new Runnable() {
@Override
public void run() {
if (style.messageDialogBlurSettings() != null && style.messageDialogBlurSettings().blurBackground() && boxBody != null && boxCancel != null) {
int blurFrontColor = getResources().getColor(style.messageDialogBlurSettings().blurForwardColorRes(isLightTheme()));
blurView = new BlurView(bkg.getContext(), null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(bkg.getWidth(), bkg.getHeight());
blurView.setOverlayColor(backgroundColor == -1 ? blurFrontColor : backgroundColor);
blurView.setTag("blurView");
blurView.setRadiusPx(style.messageDialogBlurSettings().blurBackgroundRoundRadiusPx());
boxBody.addView(blurView, 0, params);
cancelBlurView = new BlurView(boxCancel.getContext(), null);
RelativeLayout.LayoutParams cancelButtonLp = new RelativeLayout.LayoutParams(boxCancel.getWidth(), boxCancel.getHeight());
cancelBlurView.setOverlayColor(backgroundColor == -1 ? blurFrontColor : backgroundColor);
cancelBlurView.setTag("blurView");
cancelBlurView.setRadiusPx(style.messageDialogBlurSettings().blurBackgroundRoundRadiusPx());
boxCancel.addView(cancelBlurView, 0, cancelButtonLp);
}
}
});
}
@Override
public void onDismiss() {
isShow = false;
getDialogLifecycleCallback().onDismiss(me);
}
});
if (btnCancel != null) {
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (cancelButtonClickListener != null) {
if (!cancelButtonClickListener.onClick(me, v)) {
dismiss();
}
} else {
dismiss();
}
}
});
}
if (btnSelectOther != null) {
btnSelectOther.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (otherButtonClickListener != null) {
if (!otherButtonClickListener.onClick(me, v)) {
dismiss();
}
} else {
dismiss();
}
}
});
}
if (btnSelectPositive != null) {
btnSelectPositive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (okButtonClickListener != null) {
if (!okButtonClickListener.onClick(me, v)) {
dismiss();
}
} else {
dismiss();
}
}
});
}
if (imgSplit != null) {
int dividerRes = style.overrideBottomDialogRes().overrideMenuDividerDrawableRes(isLightTheme());
int dividerHeight = style.overrideBottomDialogRes().overrideMenuDividerHeight(isLightTheme());
if (dividerRes != 0) imgSplit.setBackgroundResource(dividerRes);
if (dividerHeight != 0) {
ViewGroup.LayoutParams lp = imgSplit.getLayoutParams();
lp.height = dividerHeight;
imgSplit.setLayoutParams(lp);
}
}
boxRoot.setOnBackPressedListener(new OnBackPressedListener() {
@Override
public boolean onBackPressed() {
if (onBackPressedListener != null && onBackPressedListener.onBackPressed()) {
dismiss();
return false;
}
if (isCancelable()) {
dismiss();
}
return false;
}
});
bottomDialogTouchEventInterceptor = new BottomDialogTouchEventInterceptor(me, dialogImpl);
boxRoot.post(new Runnable() {
@Override
public void run() {
long enterAnimDurationTemp = 300;
/**
* 对于非支持滑动展开的对话框,直接使用从下往上的资源动画实现
* 其他情况不适用,请参考 onContentViewLayoutChangeListener 的代码实现。
*/
if (style.overrideBottomDialogRes() == null || !style.overrideBottomDialogRes().touchSlide()) {
//bkg.setY(getRootFrameLayout().getMeasuredHeight());
Animation enterAnim = AnimationUtils.loadAnimation(getContext(), R.anim.anim_dialogx_bottom_enter);
enterAnimDurationTemp = enterAnim.getDuration();
if (overrideEnterDuration >= 0) {
enterAnimDurationTemp = overrideEnterDuration;
}
if (enterAnimDuration >= 0) {
enterAnimDurationTemp = enterAnimDuration;
}
enterAnim.setDuration(enterAnimDurationTemp);
enterAnim.setInterpolator(new DecelerateInterpolator(2f));
bkg.setY(bkgEnterAimY);
bkg.startAnimation(enterAnim);
}
boxRoot.animate()
.setDuration(enterAnimDurationTemp)
.alpha(1f)
.setInterpolator(new DecelerateInterpolator())
.setListener(null);
}
});
}
private boolean isEnterAnimFinished = false;
private ViewTreeObserver.OnGlobalLayoutListener onContentViewLayoutChangeListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (boxContent != null) {
if (style.overrideBottomDialogRes() != null &&style.overrideBottomDialogRes().touchSlide()) {
//若内容布已经超出屏幕可用范围,且预设的对话框最大高度已知
if (bkg.isChildScrollViewCanScroll() && bottomDialogMaxHeight != 0) {
//先将内容布局放置到屏幕底部以外区域,然后执行上移动画
if (!isEnterAnimFinished)bkg.setY(getRootFrameLayout().getMeasuredHeight());
//执行上移动画
if (bottomDialogMaxHeight <= 1) {
//bottomDialogMaxHeight 值若为小于 1 的小数,视为比例
bkgEnterAimY = boxBkg.getHeight() - bkg.getHeight() * bottomDialogMaxHeight;
} else {
bkgEnterAimY = boxBkg.getHeight() - bottomDialogMaxHeight;
}
long enterAnimDurationTemp = 300;
if (overrideEnterDuration >= 0) {
enterAnimDurationTemp = overrideEnterDuration;
}
if (enterAnimDuration >= 0) {
enterAnimDurationTemp = enterAnimDuration;
}
ObjectAnimator keepBottomAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), bkgEnterAimY);
keepBottomAnim.setDuration(enterAnimDurationTemp);
keepBottomAnim.setInterpolator(new DecelerateInterpolator(2f));
keepBottomAnim.start();
} else {
bkgEnterAimY = boxBkg.getHeight() - bkg.getHeight();
if (!isEnterAnimFinished)bkg.setY(boxRoot.getHeight());
bkg.post(new Runnable() {
@Override
public void run() {
ObjectAnimator enterAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), bkgEnterAimY);
long enterAnimDurationTemp = 300;
if (overrideEnterDuration >= 0) {
enterAnimDurationTemp = overrideEnterDuration;
}
if (enterAnimDuration >= 0) {
enterAnimDurationTemp = enterAnimDuration;
}
enterAnim.setDuration(enterAnimDurationTemp);
enterAnim.setInterpolator(new DecelerateInterpolator(2f));
enterAnim.start();
}
});
}
}else{
bkgEnterAimY = boxBkg.getHeight() - bkg.getHeight();
}
}
isEnterAnimFinished = true;
}
};
@Override
public void refreshView() {
if (backgroundColor != -1) {
tintColor(bkg, backgroundColor);
if (blurView != null && cancelBlurView != null) {
blurView.setOverlayColor(backgroundColor);
cancelBlurView.setOverlayColor(backgroundColor);
}
}
showText(txtDialogTitle, title);
showText(txtDialogTip, message);
useTextInfo(txtDialogTitle, titleTextInfo);
useTextInfo(txtDialogTip, messageTextInfo);
useTextInfo(btnCancel, cancelTextInfo);
useTextInfo(btnSelectOther, otherTextInfo);
useTextInfo(btnSelectPositive, okTextInfo);
if (isCancelable()) {
boxRoot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
doDismiss(v);
}
});
} else {
boxRoot.setOnClickListener(null);
}
boxBkg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boxRoot.callOnClick();
}
});
if (maskColor != -1) boxRoot.setBackgroundColor(maskColor);
if (onBindView != null && onBindView.getCustomView() != null) {
onBindView.bindParent(boxCustom, me);
}
if (isAllowInterceptTouch() && isCancelable()) {
if (imgTab != null) imgTab.setVisibility(View.VISIBLE);
} else {
if (imgTab != null) imgTab.setVisibility(View.GONE);
}
bottomDialogTouchEventInterceptor.refresh(me, this);
if (imgSplit != null) {
if (txtDialogTitle.getVisibility() == View.VISIBLE || txtDialogTip.getVisibility() == View.VISIBLE) {
imgSplit.setVisibility(View.VISIBLE);
} else {
imgSplit.setVisibility(View.GONE);
}
}
if (boxCancel != null) {
if (isNull(cancelText)) {
boxCancel.setVisibility(View.GONE);
} else {
boxCancel.setVisibility(View.VISIBLE);
}
}
showText(btnSelectPositive, okText);
showText(btnCancel, cancelText);
showText(btnSelectOther, otherText);
}
@Override
public void doDismiss(View v) {
if (v != null) v.setEnabled(false);
if (boxContent != null)
boxContent.getViewTreeObserver().removeOnGlobalLayoutListener(onContentViewLayoutChangeListener);
ObjectAnimator exitAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), boxBkg.getHeight());
long exitAnimDurationTemp = 300;
if (overrideExitDuration >= 0) {
exitAnimDurationTemp = overrideExitDuration;
}
if (exitAnimDuration >= 0) {
exitAnimDurationTemp = exitAnimDuration;
}
exitAnim.setDuration(exitAnimDurationTemp);
exitAnim.start();
boxRoot.animate()
.alpha(0f)
.setInterpolator(new AccelerateInterpolator())
.setDuration(exitAnimDurationTemp);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
dismiss(dialogView);
}
}, exitAnimDurationTemp);
}
public void preDismiss() {
if (isCancelable()) {
doDismiss(boxRoot);
} else {
long exitAnimDurationTemp = 300;
if (overrideExitDuration >= 0) {
exitAnimDurationTemp = overrideExitDuration;
}
if (exitAnimDuration >= 0) {
exitAnimDurationTemp = exitAnimDuration;
}
ObjectAnimator exitAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), bkgEnterAimY);
exitAnim.setDuration(exitAnimDurationTemp);
exitAnim.start();
}
}
}
protected void onDialogInit(DialogImpl dialog) {
}
public void refreshUI() {
runOnMain(new Runnable() {
@Override
public void run() {
if (dialogImpl != null) dialogImpl.refreshView();
}
});
}
public void dismiss() {
if (dialogImpl == null) return;
dialogImpl.doDismiss(null);
}
public DialogLifecycleCallback