dialogLifeCycleListener;
+
+ //是否自动在主线程执行
+ public static boolean autoRunOnUIThread = true;
+
+ //使用振动反馈
+ public static boolean useHaptic = true;
+
+ /**
+ * 声明:若 Activity 已使用沉浸式适配请开启(已废弃)
+ *
+ * 请注意,若你没有使用沉浸式适配,请关闭此选项,此选项将影响对话框布局是否允许延伸至导航栏背后显示
+ */
+ @Deprecated
+ public static boolean useActivityLayoutTranslationNavigationBar = false;
+
+ /**
+ * 设置 BottomDialog 导航栏背景颜色
+ * 彩蛋:a_man 私人定制款属性
+ */
+ public static int bottomDialogNavbarColor = Color.TRANSPARENT;
+
+ //触摸滑动触发阈值,影响 BottomDialog、FullScreenDialog 下滑关闭触发距离,单位:像素
+ public static int touchSlideTriggerThreshold = dip2px(35);
+
+ //Window 模式使用全局悬浮窗,需要 SYSTEM_ALERT_WINDOW 权限
+ public static boolean globalHoverWindow = false;
+
+ //部分插屏广告 SDK 可能出现背景黑屏的问题,在这里配置需要 DialogX 屏蔽的 Activity 的包名以屏蔽对该 activity 的支持:
+ public static String[] unsupportedActivitiesPackageNames = new String[]{
+ "com.bytedance.sdk.openadsdk.stub.activity",
+ "com.mobile.auth.gatewayauth",
+ "com.google.android.gms.ads"
+ };
+
+ public static int defaultMessageDialogBackgroundRadius = -1;
+
+ public static int defaultBottomDialogBackgroundRadius = -1;
+
+ public static int defaultFullScreenDialogBackgroundRadius = -1;
+
+ public static int defaultWaitAndTipDialogBackgroundRadius = -1;
+
+ public static int defaultPopMenuBackgroundRadius = -1;
+
+ public static int defaultPopTipBackgroundRadius = -1;
+
+ public static int defaultPopNotificationBackgroundRadius = -1;
+
+ //开启沉浸式适配
+ public static boolean enableImmersiveMode = true;
+
+ //沉浸式忽略左右的非安全区
+ public static boolean ignoreUnsafeInsetsHorizontal = false;
+
+ public enum THEME {
+ LIGHT, DARK, AUTO
+ }
+
+ public enum IMPL_MODE {
+ VIEW, WINDOW, DIALOG_FRAGMENT, FLOATING_ACTIVITY
+ }
+
+ public static void init(Context context) {
+ if (context == null) {
+ error(ERROR_INIT_TIPS);
+ return;
+ }
+ BaseDialog.init(context);
+ }
+
+ public static void error(Object o) {
+ if (DEBUGMODE) Log.e(">>>", o.toString());
+ }
+
+ private static int dip2px(float dpValue) {
+ final float scale = Resources.getSystem().getDisplayMetrics().density;
+ return (int) (dpValue * scale + 0.5f);
+ }
+
+ public static DialogListBuilder showDialogList(BaseDialog... dialogs) {
+ return DialogListBuilder.create(dialogs).show();
+ }
+
+ // 默认消息对话框标题文本
+ public static CharSequence defaultMessageDialogTitleText;
+
+ // 等待提示框默认文本
+ public static CharSequence defaultWaitDialogWaitingText;
+
+ // 成功提示框默认文本
+ public static CharSequence defaultTipDialogSuccessText;
+
+ // 错误提示框默认文本
+ public static CharSequence defaultTipDialogErrorText;
+
+ // 警告提示框默认文本
+ public static CharSequence defaultTipDialogWarningText;
+}
diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java
new file mode 100644
index 0000000..fb5084e
--- /dev/null
+++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java
@@ -0,0 +1,1449 @@
+package com.kongzue.dialogx.dialogs;
+
+import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
+import android.app.Activity;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Outline;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
+import android.os.Build;
+import android.text.TextUtils;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewOutlineProvider;
+import android.view.animation.DecelerateInterpolator;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.ColorRes;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleOwner;
+
+import com.kongzue.dialogx.DialogX;
+import com.kongzue.dialogx.R;
+import com.kongzue.dialogx.interfaces.BaseDialog;
+import com.kongzue.dialogx.interfaces.BaseOnDialogClickCallback;
+import com.kongzue.dialogx.interfaces.BlurViewType;
+import com.kongzue.dialogx.interfaces.BottomDialogSlideEventLifecycleCallback;
+import com.kongzue.dialogx.interfaces.DialogConvertViewInterface;
+import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
+import com.kongzue.dialogx.interfaces.DialogXAnimInterface;
+import com.kongzue.dialogx.interfaces.DialogXBaseBottomDialog;
+import com.kongzue.dialogx.interfaces.DialogXRunnable;
+import com.kongzue.dialogx.interfaces.DialogXStyle;
+import com.kongzue.dialogx.interfaces.OnBackPressedListener;
+import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
+import com.kongzue.dialogx.interfaces.OnBindView;
+import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
+import com.kongzue.dialogx.interfaces.OnMenuButtonClickListener;
+import com.kongzue.dialogx.interfaces.ScrollController;
+import com.kongzue.dialogx.util.BottomDialogTouchEventInterceptor;
+import com.kongzue.dialogx.util.TextInfo;
+import com.kongzue.dialogx.util.views.DialogScrollView;
+import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
+import com.kongzue.dialogx.util.views.MaxRelativeLayout;
+
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author: Kongzue
+ * @github: https://github.com/kongzue/
+ * @homepage: http://kongzue.com/
+ * @mail: myzcxhh@live.cn
+ * @createTime: 2020/10/6 15:17
+ */
+public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog {
+
+ public static int overrideEnterDuration = -1;
+ public static int overrideExitDuration = -1;
+ public static BOOLEAN overrideCancelable;
+ protected OnBindView onBindView;
+ protected CharSequence title;
+ protected CharSequence message;
+ protected CharSequence cancelText;
+ protected CharSequence okText;
+ protected CharSequence otherText;
+ protected boolean allowInterceptTouch = true;
+ protected boolean bottomNonSafetyAreaBySelf = false;
+ protected Integer maskColor = null;
+ protected BaseOnDialogClickCallback cancelButtonClickListener;
+ protected BaseOnDialogClickCallback okButtonClickListener;
+ protected BaseOnDialogClickCallback otherButtonClickListener;
+ protected OnBackgroundMaskClickListener onBackgroundMaskClickListener;
+ protected OnBackPressedListener onBackPressedListener;
+ protected BOOLEAN privateCancelable;
+ protected boolean bkgInterceptTouch = true;
+ protected float backgroundRadius = DialogX.defaultBottomDialogBackgroundRadius;
+ protected Drawable titleIcon;
+ protected DialogXAnimInterface dialogXAnimImpl;
+ protected BUTTON_SELECT_RESULT buttonSelectResult = BUTTON_SELECT_RESULT.NONE;
+ protected boolean scrollableWhenContentLargeThanVisibleRange = true;
+
+ protected TextInfo titleTextInfo;
+ protected TextInfo messageTextInfo;
+ protected TextInfo menuTextInfo;
+ protected TextInfo cancelTextInfo = new TextInfo().setBold(true);
+ protected TextInfo okTextInfo = new TextInfo().setBold(true);
+ protected TextInfo otherTextInfo = new TextInfo().setBold(true);
+
+ /**
+ * 此值用于,当禁用滑动时(style.overrideBottomDialogRes.touchSlide = false时)的最大显示高度。
+ * 0:不限制,最大显示到屏幕可用高度。
+ */
+ protected float bottomDialogMaxHeight = 0f;
+
+ protected DialogLifecycleCallback dialogLifecycleCallback;
+
+ protected BottomDialog me = this;
+
+ protected BottomDialog() {
+ super();
+ }
+
+ @Override
+ public String dialogKey() {
+ return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
+ }
+
+ public static BottomDialog build() {
+ return new BottomDialog();
+ }
+
+ public static BottomDialog build(DialogXStyle style) {
+ return new BottomDialog().setStyle(style);
+ }
+
+ public static BottomDialog build(OnBindView onBindView) {
+ return new BottomDialog().setCustomView(onBindView);
+ }
+
+ public BottomDialog(CharSequence title, CharSequence message) {
+ this.title = title;
+ this.message = message;
+ }
+
+ public BottomDialog(int titleResId, int messageResId) {
+ this.title = getString(titleResId);
+ this.message = getString(messageResId);
+ }
+
+ public static BottomDialog show(CharSequence title, CharSequence message) {
+ BottomDialog bottomDialog = new BottomDialog(title, message);
+ bottomDialog.show();
+ return bottomDialog;
+ }
+
+ public static BottomDialog show(int titleResId, int messageResId) {
+ BottomDialog bottomDialog = new BottomDialog(titleResId, messageResId);
+ bottomDialog.show();
+ return bottomDialog;
+ }
+
+ public BottomDialog(CharSequence title, CharSequence message, OnBindView onBindView) {
+ this.title = title;
+ this.message = message;
+ this.onBindView = onBindView;
+ }
+
+ public BottomDialog(int titleResId, int messageResId, OnBindView onBindView) {
+ this.title = getString(titleResId);
+ this.message = getString(messageResId);
+ this.onBindView = onBindView;
+ }
+
+ public static BottomDialog show(CharSequence title, CharSequence message, OnBindView onBindView) {
+ BottomDialog bottomDialog = new BottomDialog(title, message, onBindView);
+ bottomDialog.show();
+ return bottomDialog;
+ }
+
+ public static BottomDialog show(int titleResId, int messageResId, OnBindView onBindView) {
+ BottomDialog bottomDialog = new BottomDialog(titleResId, messageResId, onBindView);
+ bottomDialog.show();
+ return bottomDialog;
+ }
+
+ public BottomDialog(CharSequence title, OnBindView onBindView) {
+ this.title = title;
+ this.onBindView = onBindView;
+ }
+
+ public BottomDialog(int titleResId, OnBindView onBindView) {
+ this.title = getString(titleResId);
+ this.onBindView = onBindView;
+ }
+
+ public static BottomDialog show(CharSequence title, OnBindView onBindView) {
+ BottomDialog bottomDialog = new BottomDialog(title, onBindView);
+ bottomDialog.show();
+ return bottomDialog;
+ }
+
+ public static BottomDialog show(int titleResId, OnBindView onBindView) {
+ BottomDialog bottomDialog = new BottomDialog(titleResId, onBindView);
+ bottomDialog.show();
+ return bottomDialog;
+ }
+
+ public BottomDialog(OnBindView onBindView) {
+ this.onBindView = onBindView;
+ }
+
+ public static BottomDialog show(OnBindView onBindView) {
+ BottomDialog bottomDialog = new BottomDialog(onBindView);
+ bottomDialog.show();
+ return bottomDialog;
+ }
+
+ public BottomDialog show() {
+ if (isHide && getDialogView() != null && isShow) {
+ if (hideWithExitAnim && getDialogImpl() != null) {
+ getDialogView().setVisibility(View.VISIBLE);
+ getDialogImpl().getDialogXAnimImpl().doShowAnim(me, getDialogImpl().bkg);
+ } else {
+ getDialogView().setVisibility(View.VISIBLE);
+ }
+ return this;
+ }
+ super.beforeShow();
+ if (getDialogView() == null) {
+ int layoutId = isLightTheme() ? R.layout.layout_dialogx_bottom_material : R.layout.layout_dialogx_bottom_material_dark;
+ if (style.overrideBottomDialogRes() != null) {
+ layoutId = style.overrideBottomDialogRes().overrideDialogLayout(isLightTheme());
+ }
+
+ View dialogView = createView(layoutId);
+ dialogImpl = new DialogImpl(dialogView);
+ if (dialogView != null) dialogView.setTag(me);
+ show(dialogView);
+ } else {
+ show(getDialogView());
+ }
+ return this;
+ }
+
+ public void show(Activity activity) {
+ super.beforeShow();
+ if (getDialogView() == null) {
+ int layoutId = isLightTheme() ? R.layout.layout_dialogx_bottom_material : R.layout.layout_dialogx_bottom_material_dark;
+ if (style.overrideBottomDialogRes() != null) {
+ layoutId = style.overrideBottomDialogRes().overrideDialogLayout(isLightTheme());
+ }
+
+ View dialogView = createView(layoutId);
+ dialogImpl = new DialogImpl(dialogView);
+ if (dialogView != null) dialogView.setTag(me);
+ show(activity, dialogView);
+ } else {
+ show(activity, getDialogView());
+ }
+ }
+
+ protected DialogImpl dialogImpl;
+
+ public class DialogImpl implements DialogConvertViewInterface {
+
+ private BottomDialogTouchEventInterceptor bottomDialogTouchEventInterceptor;
+
+ public DialogXBaseRelativeLayout boxRoot;
+ public RelativeLayout boxBkg;
+ public MaxRelativeLayout bkg;
+ public ImageView imgTab;
+ public ViewGroup boxBody;
+ public TextView txtDialogTitle;
+ public ScrollController scrollView;
+ public LinearLayout boxContent;
+ public TextView txtDialogTip;
+ public View imgSplit;
+ public ViewGroup boxList;
+ public RelativeLayout boxCustom;
+ public ViewGroup boxCancel;
+ public ImageView splitSelectPositive;
+ public ImageView splitSelectOther;
+
+ public LinearLayout boxButton;
+ public TextView btnSelectNegative;
+ public TextView btnSelectOther;
+ public TextView btnSelectPositive;
+
+ private List blurViews;
+
+ public DialogImpl(View convertView) {
+ if (convertView == null) return;
+ setDialogView(convertView);
+ boxRoot = convertView.findViewById(R.id.box_root);
+ boxBkg = convertView.findViewById(R.id.box_bkg);
+ bkg = convertView.findViewById(R.id.bkg);
+ imgTab = convertView.findViewById(R.id.img_tab);
+ boxBody = convertView.findViewById(R.id.box_body);
+ txtDialogTitle = convertView.findViewById(R.id.txt_dialog_title);
+ scrollView = convertView.findViewById(R.id.scrollView);
+ boxContent = convertView.findViewById(R.id.box_content);
+ txtDialogTip = convertView.findViewById(R.id.txt_dialog_tip);
+ imgSplit = convertView.findViewWithTag("split");
+ boxList = convertView.findViewById(R.id.box_list);
+ boxCustom = convertView.findViewById(R.id.box_custom);
+
+ if (!scrollableWhenContentLargeThanVisibleRange) {
+ ViewGroup bodyContent = (ViewGroup) txtDialogTitle.getParent();
+ ((ViewGroup) boxContent.getParent()).removeView(boxContent);
+ bodyContent.addView(boxContent, 1, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+ }
+ boxCancel = convertView.findViewWithTag("cancelBox");
+
+ boxButton = convertView.findViewById(R.id.box_button);
+ btnSelectNegative = convertView.findViewById(R.id.btn_selectNegative);
+ btnSelectOther = convertView.findViewById(R.id.btn_selectOther);
+ btnSelectPositive = convertView.findViewById(R.id.btn_selectPositive);
+ splitSelectPositive = convertView.findViewWithTag("imgPositiveButtonSplit");
+ splitSelectOther = convertView.findViewWithTag("imgOtherButtonSplit");
+
+ blurViews = findAllBlurView(convertView);
+
+ init();
+ dialogImpl = this;
+ refreshView();
+ }
+
+ public void reBuild() {
+ init();
+ dialogImpl = this;
+ refreshView();
+ }
+
+ /**
+ * 此值记录了BottomDialog启动后的位置
+ * ·当内容高度大于屏幕安全区高度时,BottomDialog会以全屏方式启动,但一开始只会展开到 0.8×屏幕高度,
+ * 此时可以再次上划查看全部内容。
+ * ·当内容高度小于屏幕安全区高度时,BottomDialog会以内容高度启动。
+ *
+ * 记录这个值的目的是,当用户向下滑动时,判断情况该回到这个位置还是关闭对话框,
+ * 并阻止当内容高度已经完全显示时的继续向上滑动操作。
+ */
+ public float bkgEnterAimY = -1;
+
+ @Override
+ public void init() {
+ buttonSelectResult = BUTTON_SELECT_RESULT.NONE;
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ getDialogView().setTranslationZ(getThisOrderIndex());
+ }
+
+ 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 == null) backgroundColor = DialogX.backgroundColor;
+ if (cancelText == null) cancelText = DialogX.cancelButtonText;
+
+ if (txtDialogTitle != null) txtDialogTitle.getPaint().setFakeBoldText(true);
+ if (btnSelectNegative != null) btnSelectNegative.getPaint().setFakeBoldText(true);
+ if (btnSelectPositive != null) btnSelectPositive.getPaint().setFakeBoldText(true);
+ if (btnSelectOther != null) btnSelectOther.getPaint().setFakeBoldText(true);
+
+ boxBkg.setY(getRootFrameLayout() == null ? Resources.getSystem().getDisplayMetrics().heightPixels : getRootFrameLayout().getMeasuredHeight());
+
+ boxRoot.setParentDialog(me);
+ boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
+ @Override
+ public void onShow() {
+
+ isShow = true;
+ preShow = false;
+
+ setLifecycleState(Lifecycle.State.CREATED);
+ getDialogLifecycleCallback().onShow(me);
+ BottomDialog.this.onShow(me);
+
+ onDialogShow();
+
+ refreshUI();
+ }
+
+ @Override
+ public void onDismiss() {
+ isShow = false;
+ getDialogLifecycleCallback().onDismiss(me);
+ BottomDialog.this.onDismiss(me);
+ setLifecycleState(Lifecycle.State.DESTROYED);
+ dialogImpl = null;
+ bottomDialogTouchEventInterceptor = null;
+ dialogLifecycleCallback = null;
+ System.gc();
+ }
+ });
+
+ if (btnSelectNegative != null) {
+ btnSelectNegative.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ haptic(v);
+ buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_CANCEL;
+ if (cancelButtonClickListener != null) {
+ if (cancelButtonClickListener instanceof OnDialogButtonClickListener) {
+ if (!((OnDialogButtonClickListener) cancelButtonClickListener).onClick(me, v)) {
+ dismiss();
+ }
+ } else if (cancelButtonClickListener instanceof OnMenuButtonClickListener) {
+ if (!((OnMenuButtonClickListener) cancelButtonClickListener).onClick(me, v)) {
+ dismiss();
+ }
+ }
+ } else {
+ dismiss();
+ }
+ }
+ });
+ }
+ if (btnSelectOther != null) {
+ btnSelectOther.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ haptic(v);
+ buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_OTHER;
+ if (otherButtonClickListener != null) {
+ if (otherButtonClickListener instanceof OnDialogButtonClickListener) {
+ if (!((OnDialogButtonClickListener) otherButtonClickListener).onClick(me, v)) {
+ dismiss();
+ }
+ } else if (otherButtonClickListener instanceof OnMenuButtonClickListener) {
+ if (!((OnMenuButtonClickListener) otherButtonClickListener).onClick(me, v)) {
+ dismiss();
+ }
+ }
+ } else {
+ dismiss();
+ }
+ }
+ });
+ }
+ if (btnSelectPositive != null) {
+ btnSelectPositive.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ haptic(v);
+ buttonSelectResult = BUTTON_SELECT_RESULT.BUTTON_OK;
+ if (okButtonClickListener != null) {
+ if (okButtonClickListener instanceof OnDialogButtonClickListener) {
+ if (!((OnDialogButtonClickListener) okButtonClickListener).onClick(me, v)) {
+ dismiss();
+ }
+ } else if (okButtonClickListener instanceof OnMenuButtonClickListener) {
+ if (!((OnMenuButtonClickListener) 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 DialogXBaseRelativeLayout.PrivateBackPressedListener() {
+ @Override
+ public boolean onBackPressed() {
+ if (onBackPressedListener != null) {
+ if (onBackPressedListener.onBackPressed(me)) {
+ dismiss();
+ }
+ } else {
+ if (isCancelable()) {
+ dismiss();
+ }
+ }
+ return true;
+ }
+ });
+
+ boxBkg.post(new Runnable() {
+ @Override
+ public void run() {
+ getDialogXAnimImpl().doShowAnim(BottomDialog.this, bkg);
+
+ Integer blurFrontColor = null;
+ Float dialogXRadius = null;
+ if (style.messageDialogBlurSettings() != null) {
+ blurFrontColor = getColorNullable(getIntStyleAttr(style.messageDialogBlurSettings().blurForwardColorRes(isLightTheme())));
+ dialogXRadius = getFloatStyleAttr((float) style.messageDialogBlurSettings().blurBackgroundRoundRadiusPx());
+ }
+
+ if (blurViews != null) {
+ for (View blurView : blurViews) {
+ ((BlurViewType) blurView).setOverlayColor(backgroundColor == null ? blurFrontColor : backgroundColor);
+ ((BlurViewType) blurView).setRadiusPx(dialogXRadius);
+ }
+ }
+ }
+ });
+
+ runOnMainDelay(new Runnable() {
+ @Override
+ public void run() {
+ bottomDialogTouchEventInterceptor = new BottomDialogTouchEventInterceptor(me, dialogImpl);
+ }
+ }, getEnterAnimationDuration());
+
+ onDialogInit();
+ }
+
+ @Override
+ public void refreshView() {
+ if (boxRoot == null || getOwnActivity() == null) {
+ return;
+ }
+
+ bkg.setMaxWidth(getMaxWidth());
+ bkg.setMaxHeight(getMaxHeight());
+ bkg.setMinimumWidth(getMinWidth());
+ bkg.setMinimumHeight(getMinHeight());
+
+ boxRoot.setAutoUnsafePlacePadding(isEnableImmersiveMode());
+ boxRoot.setRootPadding(screenPaddings[0], screenPaddings[1], screenPaddings[2], screenPaddings[3]);
+ if (backgroundColor != null) {
+ tintColor(bkg, backgroundColor);
+ if (style.tintButtonBackground()) {
+ tintColor(btnSelectOther, backgroundColor);
+ tintColor(btnSelectNegative, backgroundColor);
+ tintColor(btnSelectPositive, backgroundColor);
+ }
+
+ if (blurViews != null) {
+ for (View blurView : blurViews) {
+ ((BlurViewType) blurView).setOverlayColor(backgroundColor);
+ }
+ }
+ }
+
+ showText(txtDialogTitle, title);
+ showText(txtDialogTip, message);
+
+ useTextInfo(txtDialogTitle, titleTextInfo);
+ useTextInfo(txtDialogTip, messageTextInfo);
+ useTextInfo(btnSelectNegative, cancelTextInfo);
+ useTextInfo(btnSelectOther, otherTextInfo);
+ useTextInfo(btnSelectPositive, okTextInfo);
+
+ if (boxButton != null) {
+ boxButton.setVisibility((btnSelectNegative != null && btnSelectNegative.getVisibility() == View.VISIBLE) ||
+ (btnSelectOther != null && btnSelectOther.getVisibility() == View.VISIBLE) ||
+ (btnSelectPositive != null && btnSelectPositive.getVisibility() == View.VISIBLE) ?
+ View.VISIBLE : View.GONE);
+ }
+ if (titleIcon != null) {
+ int size = (int) txtDialogTitle.getTextSize();
+ titleIcon.setBounds(0, 0, size, size);
+ txtDialogTitle.setCompoundDrawablePadding(dip2px(10));
+ txtDialogTitle.setCompoundDrawables(titleIcon, null, null, null);
+ }
+
+ 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);
+ }
+ boxBkg.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ boxRoot.callOnClick();
+ }
+ });
+ if (backgroundRadius > -1) {
+ if (bkg.getBackground() instanceof GradientDrawable) {
+ GradientDrawable gradientDrawable = (GradientDrawable) bkg.getBackground();
+ if (gradientDrawable != null)
+ gradientDrawable.setCornerRadii(new float[]{backgroundRadius, backgroundRadius, backgroundRadius, backgroundRadius, 0, 0, 0, 0});
+ }
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
+ bkg.setOutlineProvider(new ViewOutlineProvider() {
+ @Override
+ public void getOutline(View view, Outline outline) {
+ outline.setRoundRect(0, 0, view.getWidth(), (int) (view.getHeight() + backgroundRadius), backgroundRadius);
+ }
+ });
+ bkg.setClipToOutline(true);
+ }
+
+ if (blurViews != null) {
+ for (View blurView : blurViews) {
+ ((BlurViewType) blurView).setRadiusPx(backgroundRadius);
+ }
+ }
+ }
+
+ if (maskColor != null) {
+ boxRoot.setBackground(new ColorDrawable(maskColor));
+ }
+
+ if (onBindView != null && onBindView.getCustomView() != null) {
+ onBindView.bindParent(boxCustom, me);
+ if (onBindView.getCustomView() instanceof ScrollController) {
+ if (scrollView instanceof DialogScrollView) {
+ ((DialogScrollView) scrollView).setVerticalScrollBarEnabled(false);
+ }
+ scrollView = (ScrollController) onBindView.getCustomView();
+ } else {
+ View scrollController = onBindView.getCustomView().findViewWithTag("ScrollController");
+ if (scrollController instanceof ScrollController) {
+ if (scrollView instanceof DialogScrollView) {
+ ((DialogScrollView) scrollView).setVerticalScrollBarEnabled(false);
+ }
+ scrollView = (ScrollController) scrollController;
+ }
+ }
+ }
+
+ if (isAllowInterceptTouch() && isCancelable()) {
+ if (imgTab != null) imgTab.setVisibility(View.VISIBLE);
+ } else {
+ if (imgTab != null) imgTab.setVisibility(View.GONE);
+ }
+
+ if (bottomDialogTouchEventInterceptor != null) {
+ 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(btnSelectNegative, cancelText);
+ showText(btnSelectOther, otherText);
+ if (splitSelectPositive != null) {
+ splitSelectPositive.setVisibility(btnSelectPositive.getVisibility());
+ }
+ if (splitSelectOther != null) {
+ splitSelectOther.setVisibility(btnSelectOther.getVisibility());
+ }
+
+ onDialogRefreshUI();
+ }
+
+ @Override
+ public void doDismiss(View v) {
+ if (BottomDialog.this.preDismiss(BottomDialog.this)) {
+ return;
+ }
+ if (v != null) v.setEnabled(false);
+ if (getOwnActivity() == null) return;
+
+ if (!dismissAnimFlag && getDialogXAnimImpl() != null) {
+ dismissAnimFlag = true;
+
+ getDialogXAnimImpl().doExitAnim(BottomDialog.this, bkg);
+
+ runOnMainDelay(new Runnable() {
+ @Override
+ public void run() {
+ if (boxRoot != null) {
+ boxRoot.setVisibility(View.GONE);
+ }
+ dismiss(getDialogView());
+ }
+ }, getExitAnimationDuration());
+ }
+ }
+
+ public void preDismiss() {
+ if (isCancelable()) {
+ if (getDialogLifecycleCallback() instanceof BottomDialogSlideEventLifecycleCallback) {
+ if (!((BottomDialogSlideEventLifecycleCallback) getDialogLifecycleCallback()).onSlideClose(me)) {
+ doDismiss(boxRoot);
+ }
+ return;
+ }
+ doDismiss(boxRoot);
+ } else {
+ long exitAnimDurationTemp = 300;
+ if (overrideExitDuration >= 0) {
+ exitAnimDurationTemp = overrideExitDuration;
+ }
+ if (exitAnimDuration >= 0) {
+ exitAnimDurationTemp = exitAnimDuration;
+ }
+ ObjectAnimator exitAnim = ObjectAnimator.ofFloat(boxBkg, "y", boxBkg.getY(), boxRoot.getUnsafePlace().top);
+ exitAnim.setDuration(exitAnimDurationTemp);
+ exitAnim.start();
+ }
+ }
+
+ protected DialogXAnimInterface getDialogXAnimImpl() {
+ if (dialogXAnimImpl == null) {
+ dialogXAnimImpl = new DialogXAnimInterface() {
+ @Override
+ public void doShowAnim(BottomDialog dialog, ViewGroup dialogBodyView) {
+ long enterAnimDurationTemp = getEnterAnimationDuration();
+
+ float customDialogTop = 0;
+ if (dialog.isAllowInterceptTouch()) {
+ if (bottomDialogMaxHeight > 0 && bottomDialogMaxHeight <= 1) {
+ customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight * boxBkg.getHeight();
+ } else if (bottomDialogMaxHeight > 1) {
+ customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight;
+ }
+ } else {
+ if (bottomDialogMaxHeight > 0 && bottomDialogMaxHeight <= 1) {
+ customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight * boxBkg.getHeight();
+ } else if (bottomDialogMaxHeight > 1) {
+ customDialogTop = boxBkg.getHeight() - bottomDialogMaxHeight;
+ }
+ boxBkg.setPadding(0, 0, 0, (int) customDialogTop);
+ }
+
+ // 上移动画
+ ObjectAnimator enterAnim = ObjectAnimator.ofFloat(boxBkg, "y", getRootFrameLayout() == null ? Resources.getSystem().getDisplayMetrics().heightPixels : getRootFrameLayout().getMeasuredHeight(), bkgEnterAimY = boxRoot.getUnsafePlace().top + customDialogTop);
+ enterAnim.setDuration(enterAnimDurationTemp);
+ enterAnim.setAutoCancel(true);
+ enterAnim.setInterpolator(new DecelerateInterpolator(2f));
+ enterAnim.start();
+
+ // 遮罩层动画
+ ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
+ bkgAlpha.setDuration(enterAnimDurationTemp);
+ bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ boxRoot.setBkgAlpha((Float) animation.getAnimatedValue());
+ }
+ });
+ bkgAlpha.start();
+ }
+
+ @Override
+ public void doExitAnim(BottomDialog dialog, ViewGroup dialogBodyView) {
+ long exitAnimDurationTemp = getExitAnimationDuration();
+
+ ObjectAnimator exitAnim = ObjectAnimator.ofFloat(boxBkg, "y", boxBkg.getY(), boxBkg.getHeight());
+ exitAnim.setDuration(exitAnimDurationTemp);
+ exitAnim.start();
+
+ ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
+ bkgAlpha.setDuration(exitAnimDurationTemp);
+ bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ boxRoot.setBkgAlpha((Float) animation.getAnimatedValue());
+ }
+ });
+ bkgAlpha.start();
+ }
+ };
+ }
+ return dialogXAnimImpl;
+ }
+
+ public long getExitAnimationDuration() {
+ long exitAnimDurationTemp = 300;
+ if (overrideExitDuration >= 0) {
+ exitAnimDurationTemp = overrideExitDuration;
+ }
+ if (exitAnimDuration != -1) {
+ exitAnimDurationTemp = exitAnimDuration;
+ }
+ return exitAnimDurationTemp;
+ }
+
+ public long getEnterAnimationDuration() {
+ long enterAnimDurationTemp = 300;
+ if (overrideEnterDuration >= 0) {
+ enterAnimDurationTemp = overrideEnterDuration;
+ }
+ if (enterAnimDuration >= 0) {
+ enterAnimDurationTemp = enterAnimDuration;
+ }
+ return enterAnimDurationTemp;
+ }
+
+ public BottomDialogTouchEventInterceptor getBottomDialogTouchEventInterceptor() {
+ return bottomDialogTouchEventInterceptor;
+ }
+ }
+
+ public void refreshUI() {
+ if (getDialogImpl() == null) return;
+ runOnMain(new Runnable() {
+ @Override
+ public void run() {
+ if (dialogImpl != null) dialogImpl.refreshView();
+ }
+ });
+ }
+
+ public void dismiss() {
+ runOnMain(new Runnable() {
+ @Override
+ public void run() {
+ if (dialogImpl == null) return;
+ dialogImpl.doDismiss(null);
+ }
+ });
+ }
+
+ public DialogLifecycleCallback getDialogLifecycleCallback() {
+ return dialogLifecycleCallback == null ? new DialogLifecycleCallback() {
+ } : dialogLifecycleCallback;
+ }
+
+ public BottomDialog setDialogLifecycleCallback(DialogLifecycleCallback dialogLifecycleCallback) {
+ this.dialogLifecycleCallback = dialogLifecycleCallback;
+ if (isShow) dialogLifecycleCallback.onShow(me);
+ return this;
+ }
+
+ public OnBackPressedListener getOnBackPressedListener() {
+ return (OnBackPressedListener) onBackPressedListener;
+ }
+
+ public BottomDialog setOnBackPressedListener(OnBackPressedListener onBackPressedListener) {
+ this.onBackPressedListener = onBackPressedListener;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setStyle(DialogXStyle style) {
+ this.style = style;
+ return this;
+ }
+
+ public BottomDialog setTheme(DialogX.THEME theme) {
+ this.theme = theme;
+ return this;
+ }
+
+ public boolean isCancelable() {
+ if (privateCancelable != null) {
+ return privateCancelable == BOOLEAN.TRUE;
+ }
+ if (overrideCancelable != null) {
+ return overrideCancelable == BOOLEAN.TRUE;
+ }
+ return cancelable;
+ }
+
+ public BottomDialog setCancelable(boolean cancelable) {
+ this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
+ refreshUI();
+ return this;
+ }
+
+ public DialogImpl getDialogImpl() {
+ return dialogImpl;
+ }
+
+ public CharSequence getTitle() {
+ return title;
+ }
+
+ public BottomDialog setTitle(CharSequence title) {
+ this.title = title;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setTitle(int titleResId) {
+ this.title = getString(titleResId);
+ refreshUI();
+ return this;
+ }
+
+ public CharSequence getMessage() {
+ return message;
+ }
+
+ public BottomDialog setMessage(CharSequence message) {
+ this.message = message;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setMessage(int messageResId) {
+ this.message = getString(messageResId);
+ refreshUI();
+ return this;
+ }
+
+ public CharSequence getCancelButton() {
+ return cancelText;
+ }
+
+ public BottomDialog setCancelButton(CharSequence cancelText) {
+ this.cancelText = cancelText;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setCancelButton(int cancelTextResId) {
+ this.cancelText = getString(cancelTextResId);
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setCancelButton(OnDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ return this;
+ }
+
+ public BottomDialog setCancelButton(CharSequence cancelText, OnDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelText = cancelText;
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setCancelButton(int cancelTextResId, OnDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelText = getString(cancelTextResId);
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setCustomView(OnBindView onBindView) {
+ this.onBindView = onBindView;
+ refreshUI();
+ return this;
+ }
+
+ public View getCustomView() {
+ if (onBindView == null) return null;
+ return onBindView.getCustomView();
+ }
+
+ public BottomDialog removeCustomView() {
+ this.onBindView.clean();
+ refreshUI();
+ return this;
+ }
+
+ public boolean isAllowInterceptTouch() {
+ if (style.overrideBottomDialogRes() == null) {
+ return false;
+ } else {
+ return allowInterceptTouch && style.overrideBottomDialogRes().touchSlide();
+ }
+ }
+
+ public BottomDialog setAllowInterceptTouch(boolean allowInterceptTouch) {
+ this.allowInterceptTouch = allowInterceptTouch;
+ return this;
+ }
+
+ public OnDialogButtonClickListener getCancelButtonClickListener() {
+ return (OnDialogButtonClickListener) cancelButtonClickListener;
+ }
+
+ public BottomDialog setCancelButtonClickListener(OnDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ return this;
+ }
+
+ public TextInfo getTitleTextInfo() {
+ return titleTextInfo;
+ }
+
+ public BottomDialog setTitleTextInfo(TextInfo titleTextInfo) {
+ this.titleTextInfo = titleTextInfo;
+ refreshUI();
+ return this;
+ }
+
+ public TextInfo getMessageTextInfo() {
+ return messageTextInfo;
+ }
+
+ public BottomDialog setMessageTextInfo(TextInfo messageTextInfo) {
+ this.messageTextInfo = messageTextInfo;
+ refreshUI();
+ return this;
+ }
+
+ public TextInfo getCancelTextInfo() {
+ return cancelTextInfo;
+ }
+
+ public BottomDialog setCancelTextInfo(TextInfo cancelTextInfo) {
+ this.cancelTextInfo = cancelTextInfo;
+ refreshUI();
+ return this;
+ }
+
+ public TextInfo getOkTextInfo() {
+ return okTextInfo;
+ }
+
+ public BottomDialog setOkTextInfo(TextInfo okTextInfo) {
+ this.okTextInfo = okTextInfo;
+ return this;
+ }
+
+ public TextInfo getOtherTextInfo() {
+ return otherTextInfo;
+ }
+
+ public BottomDialog setOtherTextInfo(TextInfo otherTextInfo) {
+ this.otherTextInfo = otherTextInfo;
+ return this;
+ }
+
+ public int getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public BottomDialog setBackgroundColor(@ColorInt int backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setBackgroundColorRes(@ColorRes int backgroundRes) {
+ this.backgroundColor = getColor(backgroundRes);
+ refreshUI();
+ return this;
+ }
+
+ public CharSequence getOkButton() {
+ return okText;
+ }
+
+ public BottomDialog setOkButton(CharSequence okText) {
+ this.okText = okText;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setOkButton(int OkTextResId) {
+ this.okText = getString(OkTextResId);
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setOkButton(OnDialogButtonClickListener OkButtonClickListener) {
+ this.okButtonClickListener = OkButtonClickListener;
+ return this;
+ }
+
+ public BottomDialog setOkButton(CharSequence OkText, OnDialogButtonClickListener OkButtonClickListener) {
+ this.okText = OkText;
+ this.okButtonClickListener = OkButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setOkButton(int OkTextResId, OnDialogButtonClickListener OkButtonClickListener) {
+ this.okText = getString(OkTextResId);
+ this.okButtonClickListener = OkButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public CharSequence getOtherButton() {
+ return otherText;
+ }
+
+ public BottomDialog setOtherButton(CharSequence otherText) {
+ this.otherText = otherText;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setOtherButton(int OtherTextResId) {
+ this.otherText = getString(OtherTextResId);
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setOtherButton(OnDialogButtonClickListener OtherButtonClickListener) {
+ this.otherButtonClickListener = OtherButtonClickListener;
+ return this;
+ }
+
+ public BottomDialog setOtherButton(CharSequence OtherText, OnDialogButtonClickListener OtherButtonClickListener) {
+ this.otherText = OtherText;
+ this.otherButtonClickListener = OtherButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setOtherButton(int OtherTextResId, OnDialogButtonClickListener OtherButtonClickListener) {
+ this.otherText = getString(OtherTextResId);
+ this.otherButtonClickListener = OtherButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setMaskColor(@ColorInt int maskColor) {
+ this.maskColor = maskColor;
+ refreshUI();
+ return this;
+ }
+
+ public long getEnterAnimDuration() {
+ return enterAnimDuration;
+ }
+
+ public BottomDialog setEnterAnimDuration(long enterAnimDuration) {
+ this.enterAnimDuration = enterAnimDuration;
+ return this;
+ }
+
+ public long getExitAnimDuration() {
+ return exitAnimDuration;
+ }
+
+ public BottomDialog setExitAnimDuration(long exitAnimDuration) {
+ this.exitAnimDuration = exitAnimDuration;
+ return this;
+ }
+
+ @Override
+ public void restartDialog() {
+ if (getDialogView() != null) {
+ dismiss(getDialogView());
+ isShow = false;
+ }
+ if (getDialogImpl().boxCustom != null) {
+ getDialogImpl().boxCustom.removeAllViews();
+ }
+ if (getDialogImpl().boxList != null) {
+ getDialogImpl().boxList.removeAllViews();
+ }
+ int layoutId = isLightTheme() ? R.layout.layout_dialogx_bottom_material : R.layout.layout_dialogx_bottom_material_dark;
+ if (style.overrideBottomDialogRes() != null) {
+ layoutId = style.overrideBottomDialogRes().overrideDialogLayout(isLightTheme());
+ }
+
+ enterAnimDuration = 0;
+ View dialogView = createView(layoutId);
+ dialogImpl = new DialogImpl(dialogView);
+ if (dialogView != null) dialogView.setTag(me);
+ show(dialogView);
+ }
+
+ protected boolean isHide;
+
+ public void hide() {
+ isHide = true;
+ hideWithExitAnim = false;
+ if (getDialogView() != null) {
+ getDialogView().setVisibility(View.GONE);
+ }
+ }
+
+ protected boolean hideWithExitAnim;
+
+ public void hideWithExitAnim() {
+ hideWithExitAnim = true;
+ isHide = true;
+ if (getDialogImpl() != null) {
+ getDialogImpl().getDialogXAnimImpl().doExitAnim(me, getDialogImpl().bkg);
+
+ runOnMainDelay(new Runnable() {
+ @Override
+ public void run() {
+ if (getDialogView() != null) {
+ getDialogView().setVisibility(View.GONE);
+ }
+ }
+ }, getDialogImpl().getExitAnimationDuration());
+ }
+ }
+
+ @Override
+ protected void shutdown() {
+ dismiss();
+ }
+
+ public float getBottomDialogMaxHeight() {
+ return bottomDialogMaxHeight;
+ }
+
+ public BottomDialog setBottomDialogMaxHeight(float bottomDialogMaxHeight) {
+ this.bottomDialogMaxHeight = bottomDialogMaxHeight;
+ return this;
+ }
+
+ public BottomDialog setMaxWidth(int maxWidth) {
+ this.maxWidth = maxWidth;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setMaxHeight(int maxHeight) {
+ this.maxHeight = maxHeight;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setMinHeight(int minHeight) {
+ this.minHeight = minHeight;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setMinWidth(int minWidth) {
+ this.minWidth = minWidth;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setDialogImplMode(DialogX.IMPL_MODE dialogImplMode) {
+ this.dialogImplMode = dialogImplMode;
+ return this;
+ }
+
+ public boolean isBkgInterceptTouch() {
+ return bkgInterceptTouch;
+ }
+
+ public BottomDialog setBkgInterceptTouch(boolean bkgInterceptTouch) {
+ this.bkgInterceptTouch = bkgInterceptTouch;
+ return this;
+ }
+
+ public OnBackgroundMaskClickListener getOnBackgroundMaskClickListener() {
+ return (OnBackgroundMaskClickListener) onBackgroundMaskClickListener;
+ }
+
+ public BottomDialog setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener onBackgroundMaskClickListener) {
+ this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
+ return this;
+ }
+
+ public BottomDialog setRadius(float radiusPx) {
+ backgroundRadius = radiusPx;
+ refreshUI();
+ return this;
+ }
+
+ public float getRadius() {
+ return backgroundRadius;
+ }
+
+ public Drawable getTitleIcon() {
+ return titleIcon;
+ }
+
+ public BottomDialog setTitleIcon(Bitmap titleIcon) {
+ this.titleIcon = new BitmapDrawable(getResources(), titleIcon);
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setTitleIcon(int titleIconResId) {
+ this.titleIcon = getResources().getDrawable(titleIconResId);
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setTitleIcon(Drawable titleIcon) {
+ this.titleIcon = titleIcon;
+ refreshUI();
+ return this;
+ }
+
+ public DialogXAnimInterface getDialogXAnimImpl() {
+ return dialogXAnimImpl;
+ }
+
+ public BottomDialog setDialogXAnimImpl(DialogXAnimInterface dialogXAnimImpl) {
+ this.dialogXAnimImpl = dialogXAnimImpl;
+ return this;
+ }
+
+ public BottomDialog setRootPadding(int padding) {
+ this.screenPaddings = new int[]{padding, padding, padding, padding};
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setRootPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
+ this.screenPaddings = new int[]{paddingLeft, paddingTop, paddingRight, paddingBottom};
+ refreshUI();
+ return this;
+ }
+
+ public BUTTON_SELECT_RESULT getButtonSelectResult() {
+ return buttonSelectResult;
+ }
+
+ /**
+ * 用于使用 new 构建实例时,override 的生命周期事件
+ * 例如:
+ * new BottomDialog() {
+ *
+ * @param dialog self
+ * @Override public void onShow(BottomDialog dialog) {
+ * //...
+ * }
+ * }
+ */
+ protected void onShow(BottomDialog dialog) {
+
+ }
+
+ /**
+ * 用于使用 new 构建实例时,override 的生命周期事件
+ * 例如:
+ * new BottomDialog() {
+ *
+ * @param dialog self
+ * @Override public boolean onDismiss(BottomDialog dialog) {
+ * WaitDialog.show("Please Wait...");
+ * if (dialog.getButtonSelectResult() == BUTTON_SELECT_RESULT.BUTTON_OK) {
+ * //点击了OK的情况
+ * //...
+ * } else {
+ * //其他按钮点击、对话框dismiss的情况
+ * //...
+ * }
+ * return false;
+ * }
+ * }
+ */
+ // 用于使用 new 构建实例时,override 的生命周期事件
+ protected void onDismiss(BottomDialog dialog) {
+
+ }
+
+ public boolean isBottomNonSafetyAreaBySelf() {
+ return bottomNonSafetyAreaBySelf;
+ }
+
+ public BottomDialog setBottomNonSafetyAreaBySelf(boolean bottomNonSafetyAreaBySelf) {
+ this.bottomNonSafetyAreaBySelf = bottomNonSafetyAreaBySelf;
+ return this;
+ }
+
+ public boolean isScrollableWhenContentLargeThanVisibleRange() {
+ return scrollableWhenContentLargeThanVisibleRange;
+ }
+
+ public BottomDialog setScrollableWhenContentLargeThanVisibleRange(boolean scrollableWhenContentLargeThanVisibleRange) {
+ this.scrollableWhenContentLargeThanVisibleRange = scrollableWhenContentLargeThanVisibleRange;
+ return this;
+ }
+
+ public BottomDialog setData(String key, Object obj) {
+ if (data == null) data = new HashMap<>();
+ data.put(key, obj);
+ return this;
+ }
+
+ public BottomDialog setHapticFeedbackEnabled(boolean isHapticFeedbackEnabled) {
+ this.isHapticFeedbackEnabled = isHapticFeedbackEnabled ? 1 : 0;
+ return this;
+ }
+
+ public BottomDialog onShow(DialogXRunnable dialogXRunnable) {
+ onShowRunnable = dialogXRunnable;
+ if (isShow() && onShowRunnable != null) {
+ onShowRunnable.run(this);
+ }
+ return this;
+ }
+
+ public BottomDialog onDismiss(DialogXRunnable dialogXRunnable) {
+ onDismissRunnable = dialogXRunnable;
+ return this;
+ }
+
+ public BottomDialog setEnableImmersiveMode(boolean enableImmersiveMode) {
+ this.enableImmersiveMode = enableImmersiveMode;
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog appendMessage(CharSequence message) {
+ this.message = TextUtils.concat(this.message, message);
+ refreshUI();
+ return this;
+ }
+
+ public BottomDialog setThisOrderIndex(int orderIndex) {
+ this.thisOrderIndex = orderIndex;
+ if (getDialogView() != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ getDialogView().setTranslationZ(orderIndex);
+ } else {
+ error("DialogX: " + dialogKey() + " 执行 .setThisOrderIndex(" + orderIndex + ") 失败:系统不支持此方法,SDK-API 版本必须大于 21(LOLLIPOP)");
+ }
+ }
+ return this;
+ }
+
+ public BottomDialog bringToFront() {
+ setThisOrderIndex(getHighestOrderIndex());
+ return this;
+ }
+
+ public BottomDialog setActionRunnable(int actionId, DialogXRunnable runnable) {
+ dialogActionRunnableMap.put(actionId, runnable);
+ return this;
+ }
+
+ public BottomDialog cleanAction(int actionId) {
+ dialogActionRunnableMap.remove(actionId);
+ return this;
+ }
+
+ public BottomDialog cleanAllAction() {
+ dialogActionRunnableMap.clear();
+ return this;
+ }
+
+ // for BaseDialog use
+ public void callDialogDismiss() {
+ dismiss();
+ }
+
+ public BottomDialog bindDismissWithLifecycleOwner(LifecycleOwner owner) {
+ super.bindDismissWithLifecycleOwnerPrivate(owner);
+ return this;
+ }
+}
diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomMenu.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomMenu.java
new file mode 100644
index 0000000..134d52a
--- /dev/null
+++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomMenu.java
@@ -0,0 +1,1605 @@
+package com.kongzue.dialogx.dialogs;
+
+import static android.view.View.OVER_SCROLL_NEVER;
+
+import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
+import android.text.TextUtils;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.LinearLayout;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.ColorRes;
+import androidx.lifecycle.LifecycleOwner;
+
+import com.kongzue.dialogx.DialogX;
+import com.kongzue.dialogx.R;
+import com.kongzue.dialogx.interfaces.BottomMenuListViewTouchEvent;
+import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
+import com.kongzue.dialogx.interfaces.DialogXAnimInterface;
+import com.kongzue.dialogx.interfaces.DialogXRunnable;
+import com.kongzue.dialogx.interfaces.DialogXStyle;
+import com.kongzue.dialogx.interfaces.MenuItemLayoutRefreshCallback;
+import com.kongzue.dialogx.interfaces.MenuItemTextInfoInterceptor;
+import com.kongzue.dialogx.interfaces.OnBackPressedListener;
+import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
+import com.kongzue.dialogx.interfaces.OnBindView;
+import com.kongzue.dialogx.interfaces.OnMenuButtonClickListener;
+import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
+import com.kongzue.dialogx.interfaces.OnIconChangeCallBack;
+import com.kongzue.dialogx.interfaces.OnMenuItemClickListener;
+import com.kongzue.dialogx.interfaces.OnMenuItemSelectListener;
+import com.kongzue.dialogx.interfaces.SELECT_MODE;
+import com.kongzue.dialogx.util.BottomMenuArrayAdapter;
+import com.kongzue.dialogx.util.ItemDivider;
+import com.kongzue.dialogx.util.TextInfo;
+import com.kongzue.dialogx.util.views.DialogListView;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author: Kongzue
+ * @github: https://github.com/kongzue/
+ * @homepage: http://kongzue.com/
+ * @mail: myzcxhh@live.cn
+ * @createTime: 2020/10/6 23:48
+ */
+public class BottomMenu extends BottomDialog {
+
+ protected BottomMenu me = this;
+ protected int selectionIndex = -1;
+ protected SELECT_MODE selectMode = SELECT_MODE.NONE;
+ protected ArrayList selectionItems;
+ protected boolean showSelectedBackgroundTips = false;
+ protected MenuItemLayoutRefreshCallback menuMenuItemLayoutRefreshCallback;
+ protected Map menuUsability = new HashMap();
+ protected ItemDivider itemDivider;
+
+ protected OnMenuItemClickListener onMenuItemClickListener;
+
+ public static BottomMenu build() {
+ return new BottomMenu();
+ }
+
+ public static BottomMenu build(DialogXStyle style) {
+ return new BottomMenu().setStyle(style);
+ }
+
+ public static BottomMenu build(OnBindView onBindView) {
+ return new BottomMenu().setCustomView(onBindView);
+ }
+
+ protected BottomMenu() {
+ super();
+ }
+
+ protected OnIconChangeCallBack onIconChangeCallBack;
+ protected MenuItemTextInfoInterceptor menuItemTextInfoInterceptor;
+ protected DialogListView listView;
+ protected BaseAdapter menuListAdapter;
+ protected List menuList;
+ protected List iconResIds;
+ protected boolean autoTintIconInLightOrDarkMode = true;
+
+ public static BottomMenu show(List menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(List menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu showStringList(List menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.setMenuStringList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu showStringList(List menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.setMenuStringList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(String... menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(String[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, CharSequence message, List menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, CharSequence message, List menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, List menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, List menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu showStringList(CharSequence title, CharSequence message, List menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuStringList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu showStringList(CharSequence title, CharSequence message, List menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuStringList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, CharSequence message, String[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, CharSequence message, String[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, CharSequence message, CharSequence[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, CharSequence message, CharSequence[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(String title, String message, List menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(String title, String message, List menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu showStringList(String title, String message, List menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuStringList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu showStringList(String title, String message, List menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuStringList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(String title, String message, String[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(String title, String message, String[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(String title, String message, CharSequence[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(String title, String message, CharSequence[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.message = message;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, int messageResId, List menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.message = bottomMenu.getString(messageResId);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, List menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu showStringList(int titleResId, int messageResId, List menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.message = bottomMenu.getString(messageResId);
+ bottomMenu.setMenuStringList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, int messageResId, String[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.message = bottomMenu.getString(messageResId);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, int messageResId, CharSequence[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.message = bottomMenu.getString(messageResId);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, int messageResId, List menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.message = bottomMenu.getString(messageResId);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, List menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu showStringList(int titleResId, int messageResId, List menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.message = bottomMenu.getString(messageResId);
+ bottomMenu.setMenuStringList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, int messageResId, String[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.message = bottomMenu.getString(messageResId);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, int messageResId, CharSequence[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.message = bottomMenu.getString(messageResId);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, CharSequence[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, String[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, CharSequence[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(CharSequence title, String[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = title;
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, CharSequence[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, String[] menuList) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, CharSequence[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ public static BottomMenu show(int titleResId, String[] menuList, OnMenuItemClickListener onMenuItemClickListener) {
+ BottomMenu bottomMenu = new BottomMenu();
+ bottomMenu.title = bottomMenu.getString(titleResId);
+ bottomMenu.setMenuList(menuList);
+ bottomMenu.setOnMenuItemClickListener(onMenuItemClickListener);
+ bottomMenu.show();
+ return bottomMenu;
+ }
+
+ private float touchDownY;
+
+ public static final int ITEM_CLICK_DELAY = 100;
+ private long lastClickTime = 0;
+ private int[] resultArray;
+ private CharSequence[] selectTextArray;
+
+ @Override
+ protected void onDialogShow() {
+ if (getDialogImpl() != null) {
+ getDialogImpl().boxList.setVisibility(View.VISIBLE);
+
+ if (!isAllowInterceptTouch()) {
+ getDialogImpl().bkg.setMaxHeight((int) bottomDialogMaxHeight);
+ if (bottomDialogMaxHeight != 0) {
+ dialogImpl.scrollView.lockScroll(true);
+ }
+ }
+
+ int dividerDrawableResId = 0;
+ int dividerHeight = 1;
+ if (style.overrideBottomDialogRes() != null) {
+ dividerDrawableResId = style.overrideBottomDialogRes().overrideMenuDividerDrawableRes(isLightTheme());
+ dividerHeight = style.overrideBottomDialogRes().overrideMenuDividerHeight(isLightTheme());
+ }
+ if (dividerDrawableResId == 0) {
+ dividerDrawableResId = isLightTheme() ? R.drawable.rect_dialogx_material_menu_split_divider : R.drawable.rect_dialogx_material_menu_split_divider_night;
+ }
+
+
+ if (!isLightTheme()) {
+ listView = new DialogListView(getDialogImpl(), getOwnActivity(), R.style.DialogXCompatThemeDark);
+ } else {
+ listView = new DialogListView(getDialogImpl(), getOwnActivity());
+ }
+ listView.setTag("ScrollController");
+ listView.setOverScrollMode(OVER_SCROLL_NEVER);
+ listView.setDivider(getResources().getDrawable(dividerDrawableResId));
+ listView.setDividerHeight(dividerHeight);
+ getDialogImpl().scrollView = listView;
+
+ listView.setBottomMenuListViewTouchEvent(new BottomMenuListViewTouchEvent() {
+ @Override
+ public void down(MotionEvent event) {
+ touchDownY = getDialogImpl().boxBkg.getY();
+ log("#TouchDown: " + touchDownY);
+ }
+ });
+
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ if (!isMenuItemEnable(position)) {
+ return;
+ }
+ haptic(view);
+ long currentTime = System.currentTimeMillis();
+ if (currentTime - lastClickTime > ITEM_CLICK_DELAY) {
+ lastClickTime = currentTime;
+ float deltaY = Math.abs(touchDownY - getDialogImpl().boxBkg.getY());
+ log("#Click:deltaY= " + deltaY);
+ if (deltaY > dip2px(15)) {
+ return;
+ }
+ selectionIndex = position;
+ log("### onMenuItemClickListener=" + onMenuItemClickListener);
+ switch (selectMode) {
+ case NONE:
+ if (onMenuItemClickListener != null) {
+ if (!onMenuItemClickListener.onClick(me, menuList.get(position), position)) {
+ dismiss();
+ }
+ } else {
+ dismiss();
+ }
+ break;
+ case SINGLE:
+ if (onMenuItemClickListener instanceof OnMenuItemSelectListener) {
+ OnMenuItemSelectListener onMenuItemSelectListener = (OnMenuItemSelectListener) onMenuItemClickListener;
+ if (!onMenuItemSelectListener.onClick(me, menuList.get(position), position)) {
+ dismiss();
+ } else {
+ menuListAdapter.notifyDataSetInvalidated();
+ onMenuItemSelectListener.onOneItemSelect(me, menuList.get(position), position, true);
+ }
+ } else {
+ if (onMenuItemClickListener != null) {
+ if (!onMenuItemClickListener.onClick(me, menuList.get(position), position)) {
+ dismiss();
+ }
+ } else {
+ menuListAdapter.notifyDataSetInvalidated();
+ }
+ }
+ break;
+ case MULTIPLE:
+ if (onMenuItemClickListener instanceof OnMenuItemSelectListener) {
+ OnMenuItemSelectListener onMenuItemSelectListener = (OnMenuItemSelectListener) onMenuItemClickListener;
+ if (!onMenuItemSelectListener.onClick(me, menuList.get(position), position)) {
+ dismiss();
+ } else {
+ if (selectionItems.contains(position)) {
+ selectionItems.remove(new Integer(position));
+ } else {
+ selectionItems.add(position);
+ }
+ menuListAdapter.notifyDataSetInvalidated();
+ resultArray = new int[selectionItems.size()];
+ selectTextArray = new CharSequence[selectionItems.size()];
+ for (int i = 0; i < selectionItems.size(); i++) {
+ resultArray[i] = selectionItems.get(i);
+ selectTextArray[i] = menuList.get(resultArray[i]);
+ }
+ onMenuItemSelectListener.onMultiItemSelect(me, selectTextArray, resultArray);
+ }
+ } else {
+ if (onMenuItemClickListener != null) {
+ if (!onMenuItemClickListener.onClick(me, menuList.get(position), position)) {
+ dismiss();
+ }
+ } else {
+ if (selectionItems.contains(position)) {
+ selectionItems.remove(new Integer(position));
+ } else {
+ selectionItems.add(position);
+ }
+ menuListAdapter.notifyDataSetInvalidated();
+ resultArray = new int[selectionItems.size()];
+ selectTextArray = new CharSequence[selectionItems.size()];
+ for (int i = 0; i < selectionItems.size(); i++) {
+ resultArray[i] = selectionItems.get(i);
+ selectTextArray[i] = menuList.get(resultArray[i]);
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ });
+ if (style.overrideBottomDialogRes() != null) {
+ if (style.overrideBottomDialogRes().overrideMenuItemLayout(true, 0, 0, false) != 0) {
+ listView.setSelector(R.color.empty);
+ }
+ }
+
+ ViewGroup.LayoutParams listViewLp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ getDialogImpl().boxList.addView(listView, listViewLp);
+ refreshUI();
+ }
+ }
+
+ @Override
+ public void refreshUI() {
+ if (getDialogImpl() == null) return;
+ if (listView != null) {
+ if (menuListAdapter == null) {
+ menuListAdapter = new BottomMenuArrayAdapter(me, getOwnActivity(), menuList);
+ }
+ if (listView.getAdapter() == null) {
+ listView.setAdapter(menuListAdapter);
+ } else {
+ if (listView.getAdapter() != menuListAdapter) {
+ listView.setAdapter(menuListAdapter);
+ } else {
+ menuListAdapter.notifyDataSetChanged();
+ }
+ }
+ }
+
+ // 部分主题下选中项默认按下效果
+ if (showSelectedBackgroundTips) {
+ if (listView != null) {
+ listView.post(new Runnable() {
+ @Override
+ public void run() {
+ if (menuListAdapter instanceof BottomMenuArrayAdapter && showSelectedBackgroundTips) {
+ BottomMenuArrayAdapter bottomMenuArrayAdapter = ((BottomMenuArrayAdapter) menuListAdapter);
+
+ View selectItemView = listView.getChildAt(getSelection());
+ if (selectItemView != null) {
+ selectItemView.post(new Runnable() {
+ @Override
+ public void run() {
+ selectItemView.setPressed(true);
+ }
+ });
+ }
+ }
+ }
+ });
+ }
+
+ }
+
+ if (itemDivider != null) {
+ listView.setDivider(itemDivider.createDividerDrawable(getOwnActivity(), isLightTheme()));
+ listView.setDividerHeight(itemDivider.getWidth());
+ }
+ super.refreshUI();
+ }
+
+ public void preRefreshUI() {
+ if (getDialogImpl() == null) return;
+ runOnMain(new Runnable() {
+ @Override
+ public void run() {
+ refreshUI();
+ }
+ });
+ }
+
+ @Override
+ public String dialogKey() {
+ return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
+ }
+
+ public List getMenuList() {
+ return menuList;
+ }
+
+ public BottomMenu setMenuList(List menuList) {
+ this.menuList = menuList;
+ this.menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ private boolean isSameSize(int menuListSize) {
+ if (this.menuList == null || this.menuList.size() == 0) {
+ return true;
+ }
+ return this.menuList.size() == menuListSize;
+ }
+
+ public BottomMenu setMenuStringList(List menuList) {
+ this.menuList = new ArrayList<>();
+ this.menuList.addAll(menuList);
+ this.menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setMenuList(String[] menuList) {
+ this.menuList = new ArrayList<>();
+ this.menuList.addAll(Arrays.asList(menuList));
+ this.menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setMenuList(CharSequence[] menuList) {
+ this.menuList = Arrays.asList(menuList);
+ this.menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setMenus(CharSequence... menuList) {
+ this.menuList = Arrays.asList(menuList);
+ this.menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setMenus(String... menuList) {
+ this.menuList = Arrays.asList(menuList);
+ this.menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public OnIconChangeCallBack getOnIconChangeCallBack() {
+ return onIconChangeCallBack;
+ }
+
+ public BottomMenu setOnIconChangeCallBack(OnIconChangeCallBack onIconChangeCallBack) {
+ this.onIconChangeCallBack = onIconChangeCallBack;
+ return this;
+ }
+
+ public OnBackPressedListener getOnBackPressedListener() {
+ return (OnBackPressedListener) onBackPressedListener;
+ }
+
+ public BottomMenu setOnBackPressedListener(OnBackPressedListener onBackPressedListener) {
+ this.onBackPressedListener = onBackPressedListener;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setDialogLifecycleCallback(DialogLifecycleCallback dialogLifecycleCallback) {
+ this.dialogLifecycleCallback = dialogLifecycleCallback;
+ if (isShow) dialogLifecycleCallback.onShow(me);
+ return this;
+ }
+
+ public BottomMenu setStyle(DialogXStyle style) {
+ this.style = style;
+ return this;
+ }
+
+ public BottomMenu setTheme(DialogX.THEME theme) {
+ this.theme = theme;
+ return this;
+ }
+
+ public boolean isCancelable() {
+ if (privateCancelable != null) {
+ return privateCancelable == BOOLEAN.TRUE;
+ }
+ if (overrideCancelable != null) {
+ return overrideCancelable == BOOLEAN.TRUE;
+ }
+ return cancelable;
+ }
+
+ public BottomMenu setCancelable(boolean cancelable) {
+ this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
+ preRefreshUI();
+ return this;
+ }
+
+ public DialogImpl getDialogImpl() {
+ return dialogImpl;
+ }
+
+ public CharSequence getTitle() {
+ return title;
+ }
+
+ public BottomMenu setTitle(CharSequence title) {
+ this.title = title;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setTitle(int titleResId) {
+ this.title = getString(titleResId);
+ preRefreshUI();
+ return this;
+ }
+
+ public CharSequence getMessage() {
+ return message;
+ }
+
+ public BottomMenu setMessage(CharSequence message) {
+ this.message = message;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setMessage(int messageResId) {
+ this.message = getString(messageResId);
+ preRefreshUI();
+ return this;
+ }
+
+ public CharSequence getCancelButton() {
+ return cancelText;
+ }
+
+ public BottomMenu setCancelButton(CharSequence cancelText) {
+ this.cancelText = cancelText;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setCancelButton(int cancelTextResId) {
+ this.cancelText = getString(cancelTextResId);
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setCancelButton(OnMenuButtonClickListener cancelButtonClickListener) {
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ return this;
+ }
+
+ public BottomMenu setCancelButton(CharSequence cancelText, OnMenuButtonClickListener cancelButtonClickListener) {
+ this.cancelText = cancelText;
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setCancelButton(int cancelTextResId, OnMenuButtonClickListener cancelButtonClickListener) {
+ this.cancelText = getString(cancelTextResId);
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ preRefreshUI();
+ return this;
+ }
+
+ /**
+ * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setCancelButton(OnMenuButtonClickListener )}
+ */
+ @Deprecated
+ public BottomMenu setCancelButton(OnDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ return this;
+ }
+
+ /**
+ * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setCancelButton(CharSequence cancelText, OnMenuButtonClickListener )}
+ */
+ @Deprecated
+ public BottomMenu setCancelButton(CharSequence cancelText, OnDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelText = cancelText;
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ preRefreshUI();
+ return this;
+ }
+
+ /**
+ * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setCancelButton(int cancelTextResId, OnMenuButtonClickListener )}
+ */
+ @Deprecated
+ public BottomMenu setCancelButton(int cancelTextResId, OnDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelText = getString(cancelTextResId);
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setCustomView(OnBindView onBindView) {
+ this.onBindView = onBindView;
+ preRefreshUI();
+ return this;
+ }
+
+ public View getCustomView() {
+ if (onBindView == null) return null;
+ return onBindView.getCustomView();
+ }
+
+ public BottomMenu removeCustomView() {
+ this.onBindView.clean();
+ preRefreshUI();
+ return this;
+ }
+
+ public boolean isAllowInterceptTouch() {
+ return super.isAllowInterceptTouch();
+ }
+
+ public BottomMenu setAllowInterceptTouch(boolean allowInterceptTouch) {
+ this.allowInterceptTouch = allowInterceptTouch;
+ preRefreshUI();
+ return this;
+ }
+
+ public float getBottomDialogMaxHeight() {
+ return bottomDialogMaxHeight;
+ }
+
+ public BottomMenu setBottomDialogMaxHeight(float bottomDialogMaxHeight) {
+ this.bottomDialogMaxHeight = bottomDialogMaxHeight;
+ return this;
+ }
+
+ public OnMenuItemClickListener getOnMenuItemClickListener() {
+ return onMenuItemClickListener;
+ }
+
+ public BottomMenu setOnMenuItemClickListener(OnMenuItemClickListener onMenuItemClickListener) {
+ this.onMenuItemClickListener = onMenuItemClickListener;
+ return this;
+ }
+
+ public BaseAdapter getMenuListAdapter() {
+ return menuListAdapter;
+ }
+
+ public BottomMenu setMenuListAdapter(BaseAdapter menuListAdapter) {
+ this.menuListAdapter = menuListAdapter;
+ return this;
+ }
+
+ public OnMenuButtonClickListener getBottomMenuCancelButtonClickListener() {
+ return (OnMenuButtonClickListener) cancelButtonClickListener;
+ }
+
+ public BottomMenu setCancelButtonClickListener(OnMenuButtonClickListener cancelButtonClickListener) {
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ return this;
+ }
+
+ public TextInfo getTitleTextInfo() {
+ return titleTextInfo;
+ }
+
+ public BottomMenu setTitleTextInfo(TextInfo titleTextInfo) {
+ this.titleTextInfo = titleTextInfo;
+ preRefreshUI();
+ return this;
+ }
+
+ public TextInfo getMessageTextInfo() {
+ return messageTextInfo;
+ }
+
+ public BottomMenu setMessageTextInfo(TextInfo messageTextInfo) {
+ this.messageTextInfo = messageTextInfo;
+ preRefreshUI();
+ return this;
+ }
+
+ public TextInfo getCancelTextInfo() {
+ return cancelTextInfo;
+ }
+
+ public BottomMenu setCancelTextInfo(TextInfo cancelTextInfo) {
+ this.cancelTextInfo = cancelTextInfo;
+ preRefreshUI();
+ return this;
+ }
+
+ public int getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public BottomMenu setBackgroundColor(@ColorInt int backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ preRefreshUI();
+ return this;
+ }
+
+ public int getSelection() {
+ return selectionIndex;
+ }
+
+ public ArrayList getSelectionList() {
+ return selectionItems;
+ }
+
+ public BottomMenu setSelection(int selectionIndex) {
+ this.selectMode = SELECT_MODE.SINGLE;
+ this.selectionIndex = selectionIndex;
+ this.selectionItems = null;
+ menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setSingleSelection() {
+ this.selectMode = SELECT_MODE.SINGLE;
+ this.selectionIndex = -1;
+ this.selectionItems = null;
+ menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setSelection(int[] selectionItems) {
+ this.selectMode = SELECT_MODE.MULTIPLE;
+ this.selectionIndex = -1;
+ this.selectionItems = new ArrayList<>();
+ if (selectionItems != null) {
+ for (int itemIndex : selectionItems) {
+ this.selectionItems.add(itemIndex);
+ }
+ }
+ menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setMultiSelection() {
+ this.selectMode = SELECT_MODE.MULTIPLE;
+ this.selectionIndex = -1;
+ this.selectionItems = new ArrayList<>();
+ menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setSelection(List selectionItems) {
+ this.selectMode = SELECT_MODE.MULTIPLE;
+ this.selectionIndex = -1;
+ this.selectionItems = new ArrayList<>(selectionItems);
+ menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setNoSelect() {
+ this.selectMode = SELECT_MODE.NONE;
+ this.selectionIndex = -1;
+ this.selectionItems = null;
+ menuListAdapter = null;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setBackgroundColorRes(@ColorRes int backgroundRes) {
+ this.backgroundColor = getColor(backgroundRes);
+ preRefreshUI();
+ return this;
+ }
+
+ public CharSequence getOkButton() {
+ return okText;
+ }
+
+ public BottomMenu setOkButton(CharSequence okText) {
+ this.okText = okText;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setOkButton(int OkTextResId) {
+ this.okText = getString(OkTextResId);
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setOkButton(OnMenuButtonClickListener okButtonClickListener) {
+ this.okButtonClickListener = okButtonClickListener;
+ return this;
+ }
+
+ public BottomMenu setOkButton(CharSequence okText, OnMenuButtonClickListener okButtonClickListener) {
+ this.okText = okText;
+ this.okButtonClickListener = okButtonClickListener;
+ return this;
+ }
+
+ public BottomMenu setOkButton(int okTextResId, OnMenuButtonClickListener okButtonClickListener) {
+ this.okText = getString(okTextResId);
+ this.okButtonClickListener = okButtonClickListener;
+ return this;
+ }
+
+ public BottomMenu setHapticFeedbackEnabled(boolean isHapticFeedbackEnabled) {
+ this.isHapticFeedbackEnabled = isHapticFeedbackEnabled ? 1 : 0;
+ return this;
+ }
+
+ /**
+ * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOkButton(OnMenuButtonClickListener )}
+ */
+ @Deprecated
+ public BottomMenu setOkButton(OnDialogButtonClickListener okButtonClickListener) {
+ this.okButtonClickListener = okButtonClickListener;
+ return this;
+ }
+
+ /**
+ * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOkButton(CharSequence okText, OnMenuButtonClickListener )}
+ */
+ @Deprecated
+ public BottomMenu setOkButton(CharSequence okText, OnDialogButtonClickListener okButtonClickListener) {
+ this.okText = okText;
+ this.okButtonClickListener = okButtonClickListener;
+ return this;
+ }
+
+ /**
+ * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOkButton(int okTextResId, OnMenuButtonClickListener )}
+ */
+ @Deprecated
+ public BottomMenu setOkButton(int okTextResId, OnDialogButtonClickListener okButtonClickListener) {
+ this.okText = getString(okTextResId);
+ this.okButtonClickListener = okButtonClickListener;
+ return this;
+ }
+
+ public CharSequence getOtherButton() {
+ return otherText;
+ }
+
+ public BottomMenu setOtherButton(CharSequence otherText) {
+ this.otherText = otherText;
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setOtherButton(int OtherTextResId) {
+ this.otherText = getString(OtherTextResId);
+ preRefreshUI();
+ return this;
+ }
+
+ public BottomMenu setOtherButton(OnMenuButtonClickListener otherButtonClickListener) {
+ this.otherButtonClickListener = otherButtonClickListener;
+ return this;
+ }
+
+ public BottomMenu setOtherButton(CharSequence otherText, OnMenuButtonClickListener otherButtonClickListener) {
+ this.otherText = otherText;
+ this.otherButtonClickListener = otherButtonClickListener;
+ return this;
+ }
+
+ public BottomMenu setOtherButton(int otherTextResId, OnMenuButtonClickListener otherButtonClickListener) {
+ this.otherText = getString(otherTextResId);
+ this.otherButtonClickListener = otherButtonClickListener;
+ return this;
+ }
+
+ /**
+ * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOtherButton(OnMenuButtonClickListener )}
+ */
+ @Deprecated
+ public BottomMenu setOtherButton(OnDialogButtonClickListener otherButtonClickListener) {
+ this.otherButtonClickListener = otherButtonClickListener;
+ return this;
+ }
+
+ /**
+ * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOtherButton(CharSequence otherText, OnMenuButtonClickListener )}
+ */
+ @Deprecated
+ public BottomMenu setOtherButton(CharSequence otherText, OnDialogButtonClickListener otherButtonClickListener) {
+ this.otherText = otherText;
+ this.otherButtonClickListener = otherButtonClickListener;
+ return this;
+ }
+
+ /**
+ * 建议使用 {@link com.kongzue.dialogx.dialogs.BottomMenu#setOtherButton(int otherTextResId, OnMenuButtonClickListener )}
+ */
+ @Deprecated
+ public BottomMenu setOtherButton(int otherTextResId, OnDialogButtonClickListener otherButtonClickListener) {
+ this.otherText = getString(otherTextResId);
+ this.otherButtonClickListener = otherButtonClickListener;
+ return this;
+ }
+
+ public BottomMenu setMaskColor(@ColorInt int maskColor) {
+ this.maskColor = maskColor;
+ preRefreshUI();
+ return this;
+ }
+
+ public long getEnterAnimDuration() {
+ return enterAnimDuration;
+ }
+
+ public BottomMenu setEnterAnimDuration(long enterAnimDuration) {
+ this.enterAnimDuration = enterAnimDuration;
+ return this;
+ }
+
+ public long getExitAnimDuration() {
+ return exitAnimDuration;
+ }
+
+ public BottomMenu setExitAnimDuration(long exitAnimDuration) {
+ this.exitAnimDuration = exitAnimDuration;
+ return this;
+ }
+
+ public SELECT_MODE getSelectMode() {
+ return selectMode;
+ }
+
+ @Override
+ protected void shutdown() {
+ dismiss();
+ }
+
+ public BottomMenu setMaxWidth(int maxWidth) {
+ this.maxWidth = maxWidth;
+ refreshUI();
+ return this;
+ }
+
+ public BottomMenu setMaxHeight(int maxHeight) {
+ this.maxHeight = maxHeight;
+ refreshUI();
+ return this;
+ }
+
+ public BottomMenu setMinHeight(int minHeight) {
+ this.minHeight = minHeight;
+ refreshUI();
+ return this;
+ }
+
+ public BottomMenu setMinWidth(int minWidth) {
+ this.minWidth = minWidth;
+ refreshUI();
+ return this;
+ }
+
+ public BottomMenu setDialogImplMode(DialogX.IMPL_MODE dialogImplMode) {
+ this.dialogImplMode = dialogImplMode;
+ return this;
+ }
+
+ public TextInfo getMenuTextInfo() {
+ if (menuTextInfo == null) return DialogX.menuTextInfo;
+ return menuTextInfo;
+ }
+
+ public BottomMenu setMenuTextInfo(TextInfo menuTextInfo) {
+ this.menuTextInfo = menuTextInfo;
+ return this;
+ }
+
+ public MenuItemTextInfoInterceptor getMenuItemTextInfoInterceptor() {
+ return menuItemTextInfoInterceptor;
+ }
+
+ public BottomMenu setMenuItemTextInfoInterceptor(MenuItemTextInfoInterceptor menuItemTextInfoInterceptor) {
+ this.menuItemTextInfoInterceptor = menuItemTextInfoInterceptor;
+ return this;
+ }
+
+ public boolean isBkgInterceptTouch() {
+ return bkgInterceptTouch;
+ }
+
+ public BottomMenu setBkgInterceptTouch(boolean bkgInterceptTouch) {
+ this.bkgInterceptTouch = bkgInterceptTouch;
+ return this;
+ }
+
+ public OnBackgroundMaskClickListener getOnBackgroundMaskClickListener() {
+ return onBackgroundMaskClickListener;
+ }
+
+ public BottomMenu setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener onBackgroundMaskClickListener) {
+ this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
+ return this;
+ }
+
+ public BottomMenu setRadius(float radiusPx) {
+ backgroundRadius = radiusPx;
+ refreshUI();
+ return this;
+ }
+
+ public float getRadius() {
+ return backgroundRadius;
+ }
+
+ public BottomMenu setTitleIcon(Bitmap titleIcon) {
+ this.titleIcon = new BitmapDrawable(getResources(), titleIcon);
+ refreshUI();
+ return this;
+ }
+
+ public BottomMenu setTitleIcon(int titleIconResId) {
+ this.titleIcon = getResources().getDrawable(titleIconResId);
+ refreshUI();
+ return this;
+ }
+
+ public BottomMenu setTitleIcon(Drawable titleIcon) {
+ this.titleIcon = titleIcon;
+ refreshUI();
+ return this;
+ }
+
+ public DialogXAnimInterface getDialogXAnimImpl() {
+ return dialogXAnimImpl;
+ }
+
+ public BottomMenu setDialogXAnimImpl(DialogXAnimInterface dialogXAnimImpl) {
+ this.dialogXAnimImpl = dialogXAnimImpl;
+ return this;
+ }
+
+ public BottomMenu setRootPadding(int padding) {
+ this.screenPaddings = new int[]{padding, padding, padding, padding};
+ refreshUI();
+ return this;
+ }
+
+ public BottomMenu setRootPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
+ this.screenPaddings = new int[]{paddingLeft, paddingTop, paddingRight, paddingBottom};
+ refreshUI();
+ return this;
+ }
+
+ public boolean isShowSelectedBackgroundTips() {
+ return showSelectedBackgroundTips;
+ }
+
+ public BottomMenu setShowSelectedBackgroundTips(boolean showSelectedBackgroundTips) {
+ this.showSelectedBackgroundTips = showSelectedBackgroundTips;
+ refreshUI();
+ return this;
+ }
+
+ // 返回点击的菜单索引
+ public int getSelectionIndex() {
+ return selectionIndex;
+ }
+
+ // 返回多选时,选择的菜单索引集合
+ public int[] getSelectionIndexArray() {
+ return resultArray;
+ }
+
+ // 返回多选时,选择的菜单文本集合
+ public CharSequence[] getSelectTextArray() {
+ return selectTextArray;
+ }
+
+ public MenuItemLayoutRefreshCallback getMenuMenuItemLayoutRefreshCallback() {
+ return menuMenuItemLayoutRefreshCallback;
+ }
+
+ public BottomMenu setMenuMenuItemLayoutRefreshCallback(MenuItemLayoutRefreshCallback menuMenuItemLayoutRefreshCallback) {
+ this.menuMenuItemLayoutRefreshCallback = menuMenuItemLayoutRefreshCallback;
+ return this;
+ }
+
+ public TextInfo getOkTextInfo() {
+ return okTextInfo;
+ }
+
+ public BottomMenu setOkTextInfo(TextInfo okTextInfo) {
+ this.okTextInfo = okTextInfo;
+ return this;
+ }
+
+ public TextInfo getOtherTextInfo() {
+ return otherTextInfo;
+ }
+
+ public BottomMenu setOtherTextInfo(TextInfo otherTextInfo) {
+ this.otherTextInfo = otherTextInfo;
+ return this;
+ }
+
+ public BottomMenu setScrollableWhenContentLargeThanVisibleRange(boolean scrollableWhenContentLargeThanVisibleRange) {
+ this.scrollableWhenContentLargeThanVisibleRange = scrollableWhenContentLargeThanVisibleRange;
+ return this;
+ }
+
+ public BottomMenu setData(String key, Object obj) {
+ if (data == null) data = new HashMap<>();
+ data.put(key, obj);
+ return this;
+ }
+
+ public BottomMenu onShow(DialogXRunnable dialogXRunnable) {
+ onShowRunnable = dialogXRunnable;
+ if (isShow() && onShowRunnable != null) {
+ onShowRunnable.run(this);
+ }
+ return this;
+ }
+
+ public BottomMenu onDismiss(DialogXRunnable dialogXRunnable) {
+ onDismissRunnable = dialogXRunnable;
+ return this;
+ }
+
+ public BottomMenu setEnableImmersiveMode(boolean enableImmersiveMode) {
+ this.enableImmersiveMode = enableImmersiveMode;
+ refreshUI();
+ return this;
+ }
+
+ public List getIconResIds() {
+ return iconResIds;
+ }
+
+ public int getIconResIds(int position) {
+ if (iconResIds != null && position >= 0 && position < iconResIds.size()) {
+ return iconResIds.get(position);
+ }
+ return 0;
+ }
+
+ public BottomMenu setIconResIds(List iconResIds) {
+ this.iconResIds = iconResIds;
+ refreshUI();
+ return this;
+ }
+
+ public BottomMenu setIconResIds(int... resIds) {
+ if (iconResIds == null) {
+ iconResIds = new ArrayList<>();
+ }
+ for (int id : resIds) {
+ iconResIds.add(id);
+ }
+ refreshUI();
+ return this;
+ }
+
+ public boolean isAutoTintIconInLightOrDarkMode() {
+ return autoTintIconInLightOrDarkMode;
+ }
+
+ public BottomMenu setAutoTintIconInLightOrDarkMode(boolean autoTintIconInLightOrDarkMode) {
+ this.autoTintIconInLightOrDarkMode = autoTintIconInLightOrDarkMode;
+ refreshUI();
+ return this;
+ }
+
+ public BottomMenu appendMessage(CharSequence message) {
+ this.message = TextUtils.concat(this.message, message);
+ refreshUI();
+ return this;
+ }
+
+ public BottomMenu setThisOrderIndex(int orderIndex) {
+ this.thisOrderIndex = orderIndex;
+ if (getDialogView() != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ getDialogView().setTranslationZ(orderIndex);
+ } else {
+ error("DialogX: " + dialogKey() + " 执行 .setThisOrderIndex(" + orderIndex + ") 失败:系统不支持此方法,SDK-API 版本必须大于 21(LOLLIPOP)");
+ }
+ }
+ return this;
+ }
+
+ public BottomMenu bringToFront() {
+ setThisOrderIndex(getHighestOrderIndex());
+ return this;
+ }
+
+ public BottomMenu enableMenu(int... menuIndex) {
+ for (int i : menuIndex) {
+ menuUsability.put(i, true);
+ }
+ return this;
+ }
+
+ public BottomMenu enableMenu(CharSequence... menuText) {
+ if (menuList != null && !menuList.isEmpty()) {
+ for (CharSequence c : menuText) {
+ int index = menuList.indexOf(c);
+ menuUsability.put(index, true);
+ }
+ } else {
+ error("DialogX: " + dialogKey() + " .enableMenu(" + menuText + ")执行失败,请先初始化菜单项 menuList");
+ }
+ return this;
+ }
+
+ public BottomMenu enableMenu(String... menuText) {
+ if (menuList != null && !menuList.isEmpty()) {
+ for (String c : menuText) {
+ int index = menuList.indexOf(c);
+ menuUsability.put(index, true);
+ }
+ } else {
+ error("DialogX: " + dialogKey() + " .enableMenu(" + menuText + ")执行失败,请先初始化菜单项 menuList");
+ }
+ return this;
+ }
+
+ public BottomMenu disableMenu(int... menuIndex) {
+ for (int i : menuIndex) {
+ menuUsability.put(i, false);
+ }
+ return this;
+ }
+
+ public BottomMenu disableMenu(CharSequence... menuText) {
+ if (menuList != null && !menuList.isEmpty()) {
+ for (CharSequence c : menuText) {
+ int index = menuList.indexOf(c);
+ menuUsability.put(index, false);
+ }
+ } else {
+ error("DialogX: " + dialogKey() + " .disableMenu(" + menuText + ")执行失败,请先初始化菜单项 menuList");
+ }
+ return this;
+ }
+
+ public BottomMenu disableMenu(String... menuText) {
+ if (menuList != null && !menuList.isEmpty()) {
+ for (String c : menuText) {
+ int index = menuList.indexOf(c);
+ menuUsability.put(index, false);
+ }
+ } else {
+ error("DialogX: " + dialogKey() + " .disableMenu(" + menuText + ")执行失败,请先初始化菜单项 menuList");
+ }
+ return this;
+ }
+
+ public boolean isMenuItemEnable(int index) {
+ Boolean enabled = menuUsability.get(index);
+ if (enabled == null) {
+ return true;
+ }
+ return enabled;
+ }
+
+ public BottomMenu setActionRunnable(int actionId, DialogXRunnable runnable) {
+ dialogActionRunnableMap.put(actionId, runnable);
+ return this;
+ }
+
+ public BottomMenu cleanAction(int actionId){
+ dialogActionRunnableMap.remove(actionId);
+ return this;
+ }
+
+ public BottomMenu cleanAllAction(){
+ dialogActionRunnableMap.clear();
+ return this;
+ }
+
+ // for BaseDialog use
+ protected void callDialogDismissPrivate(){
+ dismiss();
+ }
+
+ public BottomMenu bindDismissWithLifecycleOwner(LifecycleOwner owner){
+ super.bindDismissWithLifecycleOwnerPrivate(owner);
+ return this;
+ }
+
+ public BottomMenu setItemDivider(ItemDivider itemDivider) {
+ this.itemDivider = itemDivider;
+ refreshUI();
+ return this;
+ }
+}
diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java
new file mode 100644
index 0000000..b83d0c2
--- /dev/null
+++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java
@@ -0,0 +1,1226 @@
+package com.kongzue.dialogx.dialogs;
+
+import android.animation.ValueAnimator;
+import android.app.Activity;
+import android.graphics.Color;
+import android.os.Build;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.view.animation.DecelerateInterpolator;
+import android.widget.RelativeLayout;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.Nullable;
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleOwner;
+
+import com.kongzue.dialogx.DialogX;
+import com.kongzue.dialogx.R;
+import com.kongzue.dialogx.interfaces.BaseDialog;
+import com.kongzue.dialogx.interfaces.DialogConvertViewInterface;
+import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
+import com.kongzue.dialogx.interfaces.DialogXAnimInterface;
+import com.kongzue.dialogx.interfaces.DialogXRunnable;
+import com.kongzue.dialogx.interfaces.DialogXStyle;
+import com.kongzue.dialogx.interfaces.OnBackPressedListener;
+import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
+import com.kongzue.dialogx.interfaces.OnBindView;
+import com.kongzue.dialogx.util.ObjectRunnable;
+import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
+import com.kongzue.dialogx.util.views.MaxRelativeLayout;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+
+/**
+ * @author: Kongzue
+ * @github: https://github.com/kongzue/
+ * @homepage: http://kongzue.com/
+ * @mail: myzcxhh@live.cn
+ * @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;
+ public static int overrideExitAnimRes = 0;
+ public static BOOLEAN overrideCancelable;
+ protected OnBindView onBindView;
+ protected DialogLifecycleCallback dialogLifecycleCallback;
+ protected OnBackPressedListener onBackPressedListener;
+ protected CustomDialog me = this;
+ protected DialogImpl dialogImpl;
+ protected int enterAnimResId = R.anim.anim_dialogx_default_enter;
+ protected int exitAnimResId = R.anim.anim_dialogx_default_exit;
+ protected ALIGN align = ALIGN.CENTER;
+ protected int maskColor = Color.TRANSPARENT;
+ protected BOOLEAN privateCancelable;
+ protected boolean bkgInterceptTouch = true;
+ protected OnBackgroundMaskClickListener onBackgroundMaskClickListener;
+ protected DialogXAnimInterface dialogXAnimImpl;
+
+ protected WeakReference baseViewWeakReference;
+ 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,
+ TOP_CENTER,
+ TOP_LEFT,
+ TOP_RIGHT,
+ BOTTOM,
+ BOTTOM_CENTER,
+ BOTTOM_LEFT,
+ BOTTOM_RIGHT,
+ LEFT,
+ LEFT_CENTER,
+ LEFT_TOP,
+ LEFT_BOTTOM,
+ RIGHT,
+ RIGHT_CENTER,
+ RIGHT_TOP,
+ RIGHT_BOTTOM
+ }
+
+ protected CustomDialog() {
+ super();
+ }
+
+ public static CustomDialog build() {
+ return new CustomDialog();
+ }
+
+ public static CustomDialog build(OnBindView onBindView) {
+ return new CustomDialog().setCustomView(onBindView);
+ }
+
+ public CustomDialog(OnBindView onBindView) {
+ this.onBindView = onBindView;
+ }
+
+ public static CustomDialog show(OnBindView onBindView) {
+ CustomDialog customDialog = new CustomDialog(onBindView);
+ customDialog.show();
+ return customDialog;
+ }
+
+ public static CustomDialog show(OnBindView 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) {
+ getDialogView().setVisibility(View.VISIBLE);
+ getDialogImpl().getDialogXAnimImpl().doShowAnim(CustomDialog.this, getDialogImpl().boxCustom);
+ getDialogImpl().boxCustom.setVisibility(View.VISIBLE);
+ getDialogImpl().boxCustom.startAnimation(getEnterAnimation());
+ } else {
+ getDialogView().setVisibility(View.VISIBLE);
+ }
+ return this;
+ }
+ super.beforeShow();
+ if (getDialogView() == null) {
+ View dialogView = createView(R.layout.layout_dialogx_custom);
+ dialogImpl = new DialogImpl(dialogView);
+ if (dialogView != null) dialogView.setTag(me);
+ show(dialogView);
+ } else {
+ show(getDialogView());
+ }
+ return this;
+ }
+
+ public CustomDialog show(Activity activity) {
+ super.beforeShow();
+ if (getDialogView() == null) {
+ View dialogView = createView(R.layout.layout_dialogx_custom);
+ dialogImpl = new DialogImpl(dialogView);
+ if (dialogView != null) dialogView.setTag(me);
+ show(activity, dialogView);
+ } else {
+ show(activity, getDialogView());
+ }
+ return this;
+ }
+
+ private ViewTreeObserver viewTreeObserver;
+ private ViewTreeObserver.OnPreDrawListener baseViewDrawListener;
+
+ public class DialogImpl implements DialogConvertViewInterface {
+
+ public DialogXBaseRelativeLayout boxRoot;
+ public MaxRelativeLayout boxCustom;
+
+ public DialogImpl(View convertView) {
+ if (convertView == null) return;
+ setDialogView(convertView);
+ 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().getLocationInWindow(baseViewLoc);
+ baseViewLoc[2] = baseView().getWidth();
+ baseViewLoc[3] = baseView().getHeight();
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ getDialogView().setTranslationZ(getThisOrderIndex());
+ }
+
+ boxRoot.setParentDialog(me);
+ boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
+ @Override
+ public void onShow() {
+ isShow = true;
+ preShow = false;
+
+ setLifecycleState(Lifecycle.State.CREATED);
+
+ getDialogLifecycleCallback().onShow(me);
+ CustomDialog.this.onShow(me);
+ onDialogShow();
+
+ boxCustom.setVisibility(View.GONE);
+ }
+
+ @Override
+ public void onDismiss() {
+ isShow = false;
+ getDialogLifecycleCallback().onDismiss(me);
+ CustomDialog.this.onDismiss(me);
+ setLifecycleState(Lifecycle.State.DESTROYED);
+ dialogImpl = null;
+ dialogLifecycleCallback = null;
+ System.gc();
+ }
+ });
+
+ boxRoot.setOnBackPressedListener(new DialogXBaseRelativeLayout.PrivateBackPressedListener() {
+ @Override
+ public boolean onBackPressed() {
+ if (onBackPressedListener != null) {
+ if (onBackPressedListener.onBackPressed(me)) {
+ dismiss();
+ }
+ } else {
+ if (isCancelable()) {
+ dismiss();
+ }
+ }
+ return true;
+ }
+ });
+
+ boxRoot.post(new Runnable() {
+ @Override
+ public void run() {
+ if (getDialogXAnimImpl() != null) {
+ getDialogXAnimImpl().doShowAnim(CustomDialog.this, boxCustom);
+ }
+ if (getDialogImpl() != null && getDialogImpl().boxCustom != null) {
+ getDialogImpl().boxCustom.setVisibility(View.VISIBLE);
+ }
+
+ setLifecycleState(Lifecycle.State.RESUMED);
+ }
+ });
+
+ onDialogInit();
+ }
+
+ boolean initSetCustomViewLayoutListener = false;
+ ALIGN alignCache;
+
+ @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();
+ }
+
+ @Override
+ public void doDismiss(View v) {
+ if (CustomDialog.this.preDismiss(CustomDialog.this)){
+ return;
+ }
+ if (v != null) v.setEnabled(false);
+ if (!dismissAnimFlag && boxCustom != null) {
+ dismissAnimFlag = true;
+ boxCustom.post(new Runnable() {
+ @Override
+ public void run() {
+ getDialogXAnimImpl().doExitAnim(CustomDialog.this, boxCustom);
+ runOnMainDelay(new Runnable() {
+ @Override
+ public void run() {
+ if (boxRoot != null) boxRoot.setVisibility(View.GONE);
+ if (baseViewDrawListener != null) {
+ if (viewTreeObserver != null) {
+ removeDrawListener(viewTreeObserver, baseViewDrawListener);
+ } else {
+ if (boxCustom != null) {
+ removeDrawListener(boxCustom.getViewTreeObserver(), baseViewDrawListener);
+ }
+ }
+ baseViewDrawListener = null;
+ viewTreeObserver = null;
+ }
+ dismiss(getDialogView());
+ }
+ }, getExitAnimationDuration(null));
+ }
+ });
+ }
+ }
+
+ protected DialogXAnimInterface getDialogXAnimImpl() {
+ if (dialogXAnimImpl == null) {
+ dialogXAnimImpl = new DialogXAnimInterface() {
+ @Override
+ public void doShowAnim(CustomDialog customDialog, ViewGroup dialogBodyView) {
+ if (getDialogImpl() == null || getDialogImpl().boxCustom == null) {
+ return;
+ }
+ Animation enterAnim = getEnterAnimation();
+ long enterAnimationDuration = getEnterAnimationDuration(enterAnim);
+ enterAnim.setDuration(enterAnimationDuration);
+ if (boxCustom != null) {
+ boxCustom.setVisibility(View.VISIBLE);
+ boxCustom.startAnimation(enterAnim);
+ }
+
+ if (maskColor != Color.TRANSPARENT) boxRoot.setBackgroundColor(maskColor);
+
+ ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
+ bkgAlpha.setDuration(enterAnimationDuration);
+ bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ boxRoot.setBkgAlpha((Float) animation.getAnimatedValue());
+ }
+ });
+ bkgAlpha.start();
+ }
+
+ @Override
+ public void doExitAnim(CustomDialog customDialog, ViewGroup dialogBodyView) {
+ if (getDialogImpl() == null || getDialogImpl().boxCustom == null) {
+ return;
+ }
+ int exitAnimResIdTemp = R.anim.anim_dialogx_default_exit;
+ if (overrideExitAnimRes != 0) {
+ exitAnimResIdTemp = overrideExitAnimRes;
+ }
+ if (exitAnimResId != 0) {
+ exitAnimResIdTemp = exitAnimResId;
+ }
+
+ long exitAnimDurationTemp;
+ if (boxCustom != null) {
+ Animation exitAnim = AnimationUtils.loadAnimation(getOwnActivity() == null ? boxCustom.getContext() : getOwnActivity(), exitAnimResIdTemp);
+ exitAnimDurationTemp = getExitAnimationDuration(exitAnim);
+ exitAnim.setDuration(exitAnimDurationTemp);
+ boxCustom.startAnimation(exitAnim);
+ } else {
+ exitAnimDurationTemp = getExitAnimationDuration(null);
+ }
+
+ ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
+ bkgAlpha.setDuration(exitAnimDurationTemp);
+ bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ boxRoot.setBkgAlpha((Float) animation.getAnimatedValue());
+ }
+ });
+ bkgAlpha.start();
+ }
+ };
+ }
+ return dialogXAnimImpl;
+ }
+
+ public long getExitAnimationDuration(@Nullable Animation defaultExitAnim) {
+ if (defaultExitAnim == null && boxCustom.getAnimation() != null) {
+ defaultExitAnim = boxCustom.getAnimation();
+ }
+ long exitAnimDurationTemp = (defaultExitAnim == null || defaultExitAnim.getDuration() == 0) ? 300 : defaultExitAnim.getDuration();
+ if (overrideExitDuration >= 0) {
+ exitAnimDurationTemp = overrideExitDuration;
+ }
+ if (exitAnimDuration != -1) {
+ exitAnimDurationTemp = exitAnimDuration;
+ }
+ return exitAnimDurationTemp;
+ }
+
+ public long getEnterAnimationDuration(@Nullable Animation defaultEnterAnim) {
+ if (defaultEnterAnim == null && boxCustom.getAnimation() != null) {
+ defaultEnterAnim = boxCustom.getAnimation();
+ }
+ long enterAnimDurationTemp = (defaultEnterAnim == null || defaultEnterAnim.getDuration() == 0) ? 300 : defaultEnterAnim.getDuration();
+ if (overrideEnterDuration >= 0) {
+ enterAnimDurationTemp = overrideEnterDuration;
+ }
+ if (enterAnimDuration >= 0) {
+ enterAnimDurationTemp = enterAnimDuration;
+ }
+ return enterAnimDurationTemp;
+ }
+ }
+
+ private void removeDrawListener(ViewTreeObserver viewTreeObserver, ViewTreeObserver.OnPreDrawListener listener) {
+ if (viewTreeObserver == null || listener == null || !viewTreeObserver.isAlive()) {
+ return;
+ }
+ try {
+ viewTreeObserver.removeOnPreDrawListener(listener);
+ } catch (Exception e) {
+ }
+ }
+
+ private Animation getEnterAnimation() {
+ Animation enterAnim;
+ if (enterAnimResId == R.anim.anim_dialogx_default_enter &&
+ exitAnimResId == R.anim.anim_dialogx_default_exit &&
+ baseView() == null) {
+ switch (align) {
+ case TOP:
+ case TOP_CENTER:
+ case TOP_LEFT:
+ case TOP_RIGHT:
+ enterAnimResId = R.anim.anim_dialogx_top_enter;
+ exitAnimResId = R.anim.anim_dialogx_top_exit;
+ break;
+ case BOTTOM:
+ case BOTTOM_CENTER:
+ case BOTTOM_LEFT:
+ case BOTTOM_RIGHT:
+ enterAnimResId = R.anim.anim_dialogx_bottom_enter;
+ exitAnimResId = R.anim.anim_dialogx_bottom_exit;
+ break;
+ case LEFT:
+ case LEFT_CENTER:
+ case LEFT_TOP:
+ case LEFT_BOTTOM:
+ enterAnimResId = R.anim.anim_dialogx_left_enter;
+ exitAnimResId = R.anim.anim_dialogx_left_exit;
+ break;
+ case RIGHT:
+ case RIGHT_CENTER:
+ case RIGHT_TOP:
+ case RIGHT_BOTTOM:
+ enterAnimResId = R.anim.anim_dialogx_right_enter;
+ exitAnimResId = R.anim.anim_dialogx_right_exit;
+ break;
+ }
+ enterAnim = AnimationUtils.loadAnimation(getOwnActivity(), enterAnimResId);
+ enterAnim.setInterpolator(new DecelerateInterpolator(2f));
+ } else {
+ int enterAnimResIdTemp = R.anim.anim_dialogx_default_enter;
+ if (overrideEnterAnimRes != 0) {
+ enterAnimResIdTemp = overrideEnterAnimRes;
+ }
+ if (enterAnimResId != 0) {
+ enterAnimResIdTemp = enterAnimResId;
+ }
+ enterAnim = AnimationUtils.loadAnimation(getOwnActivity(), enterAnimResIdTemp);
+ }
+ long enterAnimDurationTemp = enterAnim.getDuration();
+ if (overrideEnterDuration >= 0) {
+ enterAnimDurationTemp = overrideEnterDuration;
+ }
+ if (enterAnimDuration >= 0) {
+ enterAnimDurationTemp = enterAnimDuration;
+ }
+ 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() {
+ @Override
+ public void run() {
+ if (dialogImpl != null) dialogImpl.refreshView();
+ }
+ });
+ }
+
+ public void dismiss() {
+ runOnMain(new Runnable() {
+ @Override
+ public void run() {
+ if (dialogImpl == null) return;
+ dialogImpl.doDismiss(null);
+ }
+ });
+ }
+
+ public DialogLifecycleCallback getDialogLifecycleCallback() {
+ return dialogLifecycleCallback == null ? new DialogLifecycleCallback() {
+ } : dialogLifecycleCallback;
+ }
+
+ public CustomDialog setDialogLifecycleCallback(DialogLifecycleCallback dialogLifecycleCallback) {
+ this.dialogLifecycleCallback = dialogLifecycleCallback;
+ if (isShow) dialogLifecycleCallback.onShow(me);
+ return this;
+ }
+
+ public OnBackPressedListener getOnBackPressedListener() {
+ return (OnBackPressedListener) onBackPressedListener;
+ }
+
+ public CustomDialog setOnBackPressedListener(OnBackPressedListener 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;
+ }
+ if (overrideCancelable != null) {
+ return overrideCancelable == BOOLEAN.TRUE;
+ }
+ 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 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 isEnableImmersiveMode();
+ }
+
+ /**
+ * 改为使用 .setEnableImmersiveMode(boolean) 来控制是否适配沉浸式
+ *
+ * @param autoUnsafePlacePadding 是否适配沉浸式
+ * @return CustomDialog
+ */
+ @Deprecated
+ public CustomDialog setAutoUnsafePlacePadding(boolean autoUnsafePlacePadding) {
+ setEnableImmersiveMode(autoUnsafePlacePadding);
+ return this;
+ }
+
+ /**
+ * 改为使用 .setEnableImmersiveMode(boolean) 来控制是否适配沉浸式
+ *
+ * @param fullscreen 是否适配沉浸式
+ * @return CustomDialog
+ */
+ @Deprecated
+ public CustomDialog setFullScreen(boolean fullscreen) {
+ setEnableImmersiveMode(!fullscreen);
+ 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 (getDialogView() != null) {
+ if (getDialogImpl() != null && getDialogImpl().boxCustom != null) {
+ if (baseViewDrawListener != null) {
+ if (viewTreeObserver != null) {
+ removeDrawListener(viewTreeObserver, baseViewDrawListener);
+ } else {
+ if (getDialogImpl().boxCustom != null) {
+ removeDrawListener(getDialogImpl().boxCustom.getViewTreeObserver(), baseViewDrawListener);
+ }
+ }
+ baseViewDrawListener = null;
+ viewTreeObserver = null;
+ }
+ }
+ dismiss(getDialogView());
+ isShow = false;
+ }
+ if (getDialogImpl() != null && getDialogImpl().boxCustom != null) {
+ getDialogImpl().boxCustom.removeAllViews();
+ }
+
+ enterAnimDuration = 0;
+ View dialogView = createView(R.layout.layout_dialogx_custom);
+ dialogImpl = new DialogImpl(dialogView);
+ if (dialogView != null) dialogView.setTag(me);
+ show(dialogView);
+ }
+
+ public void hide() {
+ isHide = true;
+ hideWithExitAnim = false;
+ if (getDialogView() != null) {
+ getDialogView().setVisibility(View.GONE);
+ }
+ }
+
+ protected boolean hideWithExitAnim;
+
+ public void hideWithExitAnim() {
+ hideWithExitAnim = true;
+ isHide = true;
+ if (getDialogImpl() != null) {
+ getDialogImpl().getDialogXAnimImpl().doExitAnim(CustomDialog.this, getDialogImpl().boxCustom);
+
+ runOnMainDelay(new Runnable() {
+ @Override
+ public void run() {
+ if (getDialogView() != null) {
+ getDialogView().setVisibility(View.GONE);
+ }
+ }
+ }, getDialogImpl().getExitAnimationDuration(null));
+ }
+ }
+
+ @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;
+ }
+
+ /**
+ * 判断是否有设置对应的位置关系
+ *
+ * @param gravity 位置关系
+ * @return 是否具备位置关系
+ */
+ public boolean isAlignBaseViewGravity(int gravity) {
+ return (alignViewGravity & gravity) == gravity;
+ }
+
+ public CustomDialog setAlignBaseViewGravity(View baseView, int alignGravity) {
+ this.baseView(baseView);
+ this.alignViewGravity = alignGravity;
+ baseViewLoc = new int[4];
+ baseView.getLocationInWindow(baseViewLoc);
+ setFullScreen(true);
+ return this;
+ }
+
+ public CustomDialog setAlignBaseView(View baseView) {
+ this.baseView(baseView);
+ baseViewLoc = new int[4];
+ baseView.getLocationInWindow(baseViewLoc);
+ setFullScreen(true);
+ return this;
+ }
+
+ public CustomDialog setAlignBaseViewGravity(int alignGravity) {
+ this.alignViewGravity = alignGravity;
+ if (baseView() != null) {
+ baseViewLoc = new int[4];
+ baseView().getLocationInWindow(baseViewLoc);
+ }
+ 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 宽度(单位:像素)
+ *
+ * @param width 宽度(像素)
+ * @return CustomDialog实例
+ */
+ public CustomDialog setWidth(int width) {
+ this.width = width;
+ refreshUI();
+ return this;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ /**
+ * 设置对话框 UI 高度(单位:像素)
+ *
+ * @param height 高度(像素)
+ * @return CustomDialog实例
+ */
+ public CustomDialog setHeight(int height) {
+ this.height = height;
+ refreshUI();
+ return this;
+ }
+
+ public OnBackgroundMaskClickListener getOnBackgroundMaskClickListener() {
+ return onBackgroundMaskClickListener;
+ }
+
+ public CustomDialog setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener onBackgroundMaskClickListener) {
+ this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
+ return this;
+ }
+
+ public DialogXAnimInterface getDialogXAnimImpl() {
+ return dialogXAnimImpl;
+ }
+
+ public CustomDialog setDialogXAnimImpl(DialogXAnimInterface 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 的生命周期事件
+ * 例如:
+ * new CustomDialog() {
+ *
+ * @param dialog self
+ * @Override public void onShow(CustomDialog dialog) {
+ * //...
+ * }
+ * }
+ */
+ protected void onShow(CustomDialog dialog) {
+
+ }
+
+ /**
+ * 用于使用 new 构建实例时,override 的生命周期事件
+ * 例如:
+ * new CustomDialog() {
+ *
+ * @param dialog self
+ * @Override public boolean onDismiss(CustomDialog dialog) {
+ * WaitDialog.show("Please Wait...");
+ * if (dialog.getButtonSelectResult() == BUTTON_SELECT_RESULT.BUTTON_OK) {
+ * //点击了OK的情况
+ * //...
+ * } else {
+ * //其他按钮点击、对话框dismiss的情况
+ * //...
+ * }
+ * return false;
+ * }
+ * }
+ */
+ //用于使用 new 构建实例时,override 的生命周期事件
+ protected void onDismiss(CustomDialog dialog) {
+
+ }
+
+ protected CustomDialog baseView(View view) {
+ if (view == null && baseViewWeakReference != null) {
+ baseViewWeakReference.clear();
+ baseViewWeakReference = null;
+ } else {
+ baseViewWeakReference = new WeakReference<>(view);
+ }
+ return this;
+ }
+
+ protected View baseView() {
+ return baseViewWeakReference == null ? null : baseViewWeakReference.get();
+ }
+
+ public CustomDialog setData(String key, Object obj) {
+ if (data == null) data = new HashMap<>();
+ data.put(key, obj);
+ return this;
+ }
+
+ public CustomDialog onShow(DialogXRunnable dialogXRunnable) {
+ onShowRunnable = dialogXRunnable;
+ if (isShow() && onShowRunnable != null) {
+ onShowRunnable.run(this);
+ }
+ return this;
+ }
+
+ public CustomDialog onDismiss(DialogXRunnable dialogXRunnable) {
+ onDismissRunnable = dialogXRunnable;
+ return this;
+ }
+
+ public CustomDialog setEnableImmersiveMode(boolean enableImmersiveMode) {
+ this.enableImmersiveMode = enableImmersiveMode;
+ refreshUI();
+ return this;
+ }
+
+ public CustomDialog setThisOrderIndex(int orderIndex) {
+ this.thisOrderIndex = orderIndex;
+ if (getDialogView() != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ getDialogView().setTranslationZ(orderIndex);
+ } else {
+ error("DialogX: " + dialogKey() + " 执行 .setThisOrderIndex("+orderIndex+") 失败:系统不支持此方法,SDK-API 版本必须大于 21(LOLLIPOP)");
+ }
+ }
+ return this;
+ }
+
+ public CustomDialog bringToFront() {
+ setThisOrderIndex(getHighestOrderIndex());
+ return this;
+ }
+
+ public CustomDialog setActionRunnable(int actionId, DialogXRunnable runnable) {
+ dialogActionRunnableMap.put(actionId, runnable);
+ return this;
+ }
+
+ public CustomDialog cleanAction(int actionId){
+ dialogActionRunnableMap.remove(actionId);
+ return this;
+ }
+
+ public CustomDialog cleanAllAction(){
+ dialogActionRunnableMap.clear();
+ return this;
+ }
+
+ // for BaseDialog use
+ public void callDialogDismiss(){
+ dismiss();
+ }
+
+ public CustomDialog bindDismissWithLifecycleOwner(LifecycleOwner owner){
+ super.bindDismissWithLifecycleOwnerPrivate(owner);
+ return this;
+ }
+
+ public CustomDialog setMaxWidth(int maxWidth) {
+ this.maxWidth = maxWidth;
+ refreshUI();
+ return this;
+ }
+
+ public CustomDialog setMaxHeight(int maxHeight) {
+ this.maxHeight = maxHeight;
+ refreshUI();
+ return this;
+ }
+
+ public CustomDialog setMinHeight(int minHeight) {
+ this.minHeight = minHeight;
+ refreshUI();
+ return this;
+ }
+
+ public CustomDialog setMinWidth(int minWidth) {
+ this.minWidth = minWidth;
+ refreshUI();
+ return this;
+ }
+}
diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/FullScreenDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/FullScreenDialog.java
new file mode 100644
index 0000000..a0606b7
--- /dev/null
+++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/FullScreenDialog.java
@@ -0,0 +1,1024 @@
+package com.kongzue.dialogx.dialogs;
+
+import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
+
+import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
+import android.app.Activity;
+import android.graphics.Outline;
+import android.graphics.Rect;
+import android.graphics.drawable.GradientDrawable;
+import android.os.Build;
+import android.view.RoundedCorner;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewOutlineProvider;
+import android.view.WindowInsets;
+import android.view.animation.DecelerateInterpolator;
+import android.widget.RelativeLayout;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.ColorRes;
+import androidx.lifecycle.Lifecycle;
+import androidx.lifecycle.LifecycleOwner;
+
+import com.kongzue.dialogx.DialogX;
+import com.kongzue.dialogx.R;
+import com.kongzue.dialogx.interfaces.BaseDialog;
+import com.kongzue.dialogx.interfaces.DialogConvertViewInterface;
+import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
+import com.kongzue.dialogx.interfaces.DialogXAnimInterface;
+import com.kongzue.dialogx.interfaces.DialogXBaseBottomDialog;
+import com.kongzue.dialogx.interfaces.DialogXRunnable;
+import com.kongzue.dialogx.interfaces.DialogXStyle;
+import com.kongzue.dialogx.interfaces.OnBackPressedListener;
+import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
+import com.kongzue.dialogx.interfaces.OnBindView;
+import com.kongzue.dialogx.interfaces.OnSafeInsetsChangeListener;
+import com.kongzue.dialogx.interfaces.ScrollController;
+import com.kongzue.dialogx.util.FullScreenDialogTouchEventInterceptor;
+import com.kongzue.dialogx.util.views.ActivityScreenShotImageView;
+import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
+import com.kongzue.dialogx.util.views.MaxRelativeLayout;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+
+/**
+ * @author: Kongzue
+ * @github: https://github.com/kongzue/
+ * @homepage: http://kongzue.com/
+ * @mail: myzcxhh@live.cn
+ * @createTime: 2020/10/6 15:17
+ */
+public class FullScreenDialog extends BaseDialog implements DialogXBaseBottomDialog {
+
+ public static final int ACTIVITY_CONTENT_RADIUS_KEEP = -2;
+ public static final int ACTIVITY_CONTENT_RADIUS_DEFAULT = -1;
+
+ public static int overrideEnterDuration = -1;
+ public static int overrideExitDuration = -1;
+ public static BOOLEAN overrideCancelable;
+
+ protected OnBindView onBindView;
+ protected OnBackPressedListener onBackPressedListener;
+ protected BOOLEAN privateCancelable;
+ protected boolean hideZoomBackground;
+ protected float backgroundRadius = DialogX.defaultFullScreenDialogBackgroundRadius;
+ protected float activityContentRadius = ACTIVITY_CONTENT_RADIUS_DEFAULT;
+ protected boolean allowInterceptTouch = true;
+ protected DialogXAnimInterface dialogXAnimImpl;
+ protected boolean bottomNonSafetyAreaBySelf = false;
+ protected boolean hideActivityContentView;
+ protected Integer maskColor = null;
+
+ protected DialogLifecycleCallback dialogLifecycleCallback;
+ protected OnBackgroundMaskClickListener onBackgroundMaskClickListener;
+
+ protected FullScreenDialog me = this;
+
+ protected FullScreenDialog() {
+ super();
+ }
+
+ public static FullScreenDialog build() {
+ return new FullScreenDialog();
+ }
+
+ public static FullScreenDialog build(OnBindView onBindView) {
+ return new FullScreenDialog(onBindView);
+ }
+
+ public FullScreenDialog(OnBindView onBindView) {
+ this.onBindView = onBindView;
+ }
+
+ public static FullScreenDialog show(OnBindView onBindView) {
+ FullScreenDialog FullScreenDialog = new FullScreenDialog(onBindView);
+ FullScreenDialog.show();
+ return FullScreenDialog;
+ }
+
+ public FullScreenDialog show() {
+ if (isHide && getDialogView() != null && isShow) {
+ if (hideWithExitAnim && getDialogImpl() != null) {
+ getDialogView().setVisibility(View.VISIBLE);
+ getDialogImpl().getDialogXAnimImpl().doShowAnim(me, getDialogImpl().bkg);
+ } else {
+ getDialogView().setVisibility(View.VISIBLE);
+ }
+ return this;
+ }
+ super.beforeShow();
+ if (getDialogView() == null) {
+ View dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
+ dialogImpl = new DialogImpl(dialogView);
+ if (dialogView != null) dialogView.setTag(me);
+ show(dialogView);
+ } else {
+ show(getDialogView());
+ }
+ return this;
+ }
+
+ public void show(Activity activity) {
+ super.beforeShow();
+ if (getDialogView() == null) {
+ View dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
+ dialogImpl = new DialogImpl(dialogView);
+ if (dialogView != null) dialogView.setTag(me);
+ show(activity, dialogView);
+ } else {
+ show(activity, getDialogView());
+ }
+ }
+
+ protected DialogImpl dialogImpl;
+
+ public class DialogImpl implements DialogConvertViewInterface {
+
+ private FullScreenDialogTouchEventInterceptor fullScreenDialogTouchEventInterceptor;
+
+ public ActivityScreenShotImageView imgZoomActivity;
+ public DialogXBaseRelativeLayout boxRoot;
+ public RelativeLayout boxBkg;
+ public MaxRelativeLayout bkg;
+ public RelativeLayout boxCustom;
+ public ScrollController scrollView;
+
+ public DialogImpl setScrollView(ScrollController scrollView) {
+ this.scrollView = scrollView;
+ return this;
+ }
+
+ public DialogImpl(View convertView) {
+ if (convertView == null) return;
+ setDialogView(convertView);
+ imgZoomActivity = convertView.findViewById(R.id.img_zoom_activity);
+ boxRoot = convertView.findViewById(R.id.box_root);
+ boxBkg = convertView.findViewById(R.id.box_bkg);
+ bkg = convertView.findViewById(R.id.bkg);
+ boxCustom = convertView.findViewById(R.id.box_custom);
+ imgZoomActivity.hideActivityContentView = hideActivityContentView;
+
+ imgZoomActivity.bindDialog(FullScreenDialog.this);
+
+ if (hideZoomBackground) {
+ convertView.setBackgroundResource(R.color.black20);
+ imgZoomActivity.setVisibility(View.GONE);
+ } else {
+ convertView.setBackgroundResource(R.color.black);
+ imgZoomActivity.setVisibility(View.VISIBLE);
+ }
+ init();
+ dialogImpl = this;
+ refreshView();
+ }
+
+ public float bkgEnterAimY = -1;
+ protected int enterY;
+
+ private Rect mUnsafeRect = new Rect(0, 0, 0, 0);
+
+ public float getEnterY() {
+ return Math.max(0, boxRoot.getSafeHeight() - enterY);
+ }
+
+ @Override
+ public void init() {
+ boxRoot.setParentDialog(me);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ getDialogView().setTranslationZ(getThisOrderIndex());
+ }
+
+ boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
+ @Override
+ public void onShow() {
+ isShow = true;
+ preShow = false;
+
+ setLifecycleState(Lifecycle.State.CREATED);
+ onDialogShow();
+
+ getDialogLifecycleCallback().onShow(me);
+ FullScreenDialog.this.onShow(me);
+ }
+
+ @Override
+ public void onDismiss() {
+ isShow = false;
+ getDialogLifecycleCallback().onDismiss(me);
+ FullScreenDialog.this.onDismiss(me);
+ setLifecycleState(Lifecycle.State.DESTROYED);
+ fullScreenDialogTouchEventInterceptor = null;
+ dialogImpl = null;
+ dialogLifecycleCallback = null;
+ System.gc();
+ }
+ });
+
+ boxRoot.setOnBackPressedListener(new DialogXBaseRelativeLayout.PrivateBackPressedListener() {
+ @Override
+ public boolean onBackPressed() {
+ if (onBackPressedListener != null) {
+ if (onBackPressedListener.onBackPressed(me)) {
+ dismiss();
+ }
+ } else {
+ if (isCancelable()) {
+ dismiss();
+ }
+ }
+ return true;
+ }
+ });
+
+ fullScreenDialogTouchEventInterceptor = new FullScreenDialogTouchEventInterceptor(me, dialogImpl);
+ boxRoot.setBkgAlpha(0f);
+
+ boxRoot.post(new Runnable() {
+ @Override
+ public void run() {
+ bkg.setY(boxRoot.getHeight());
+ getDialogXAnimImpl().doShowAnim(me, bkg);
+ setLifecycleState(Lifecycle.State.RESUMED);
+ }
+ });
+ boxRoot.setOnSafeInsetsChangeListener(new OnSafeInsetsChangeListener() {
+ @Override
+ public void onChange(Rect unsafeRect) {
+ mUnsafeRect.set(unsafeRect);
+ makeEnterY();
+ if (!enterAnimRunning && getEnterY() != 0) {
+ bkg.setY(getEnterY());
+ }
+ }
+ });
+
+ bkg.setOnYChanged(new MaxRelativeLayout.OnYChanged() {
+ @Override
+ public void y(float y) {
+ float realY = y + bkg.getTop();
+ float zoomScale = 1 - (boxRoot.getHeight() - realY) * 0.00002f;
+ if (zoomScale > 1) zoomScale = 1;
+ if (!hideZoomBackground) {
+ imgZoomActivity.setScale(zoomScale);
+ imgZoomActivity.setRadius(
+ getActivityZoomRadius(getDeviceRadius(), getActivityContentRadius(), ((boxRoot.getHeight() - realY) / boxRoot.getHeight()))
+ );
+ }
+ }
+ });
+
+ /**
+ * 给自定义布局增加监听,如果布局高度发生改变,则重新计算位置,位置发生变化,则再次使用动画移动布局到指定位置
+ * 目的是给自定义布局高度为wrap_content的用于纠正布局的Y轴位置
+ */
+ boxCustom.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
+ int oldHeight = oldBottom - oldTop;
+ int newHeight = bottom - top;
+ if (oldHeight != newHeight) {
+ /**
+ * 高度发生改变
+ * 这里判断是否在两种动画途中
+ */
+ if (!enterAnimRunning && !boxRoot.getFitSystemBarUtils().isInSmoothingPadding()) {
+ makeEnterY();
+ float newBkgEnterAimY = boxRoot.getSafeHeight() - mUnsafeRect.bottom - enterY - boxRoot.getUnsafePlace().top;
+ if (newBkgEnterAimY < 0) newBkgEnterAimY = 0;
+ if (newBkgEnterAimY != bkgEnterAimY && bkg.getY() != newBkgEnterAimY) {
+ float oldVal = bkgEnterAimY;
+ bkgEnterAimY = newBkgEnterAimY;
+ //需要重新定义终点
+ doShowAnimRepeat((int) oldVal, (int) newBkgEnterAimY, true);
+ } else if (bkg.getY() != newBkgEnterAimY && newBkgEnterAimY != 0) {
+ bkg.setY(newBkgEnterAimY);
+ }
+ }
+ }
+ }
+ });
+ onDialogInit();
+ }
+
+ private boolean isMatchParentHeightCustomView() {
+ if (onBindView != null && onBindView.getCustomView() != null) {
+ ViewGroup.LayoutParams lp = onBindView.getCustomView().getLayoutParams();
+ if (lp != null) {
+ return lp.height == MATCH_PARENT;
+ }
+ }
+ return false;
+ }
+
+ private void makeEnterY() {
+ int customViewHeight = boxCustom.getHeight();
+
+ if (customViewHeight == 0 || isMatchParentHeightCustomView()) {
+ customViewHeight = ((int) boxRoot.getSafeHeight());
+ }
+ enterY = customViewHeight;
+ }
+
+ @Override
+ public void refreshView() {
+ if (boxRoot == null || getOwnActivity() == null) {
+ return;
+ }
+ boxRoot.setAutoUnsafePlacePadding(isEnableImmersiveMode());
+ boxRoot.setRootPadding(screenPaddings[0], screenPaddings[1], screenPaddings[2], screenPaddings[3]);
+ if (backgroundColor != null) {
+ tintColor(bkg, backgroundColor);
+ }
+
+ bkg.setMaxWidth(getMaxWidth());
+ bkg.setMaxHeight(getMaxHeight());
+ bkg.setMinimumWidth(getMinWidth());
+ bkg.setMinimumHeight(getMinHeight());
+
+ 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);
+ }
+ if (backgroundRadius > -1) {
+ if (bkg.getBackground() instanceof GradientDrawable) {
+ GradientDrawable gradientDrawable = (GradientDrawable) bkg.getBackground();
+ if (gradientDrawable != null) gradientDrawable.setCornerRadii(new float[]{
+ backgroundRadius, backgroundRadius, backgroundRadius, backgroundRadius, 0, 0, 0, 0
+ });
+ }
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
+ bkg.setOutlineProvider(new ViewOutlineProvider() {
+ @Override
+ public void getOutline(View view, Outline outline) {
+ outline.setRoundRect(0, 0, view.getWidth(), (int) (view.getHeight() + backgroundRadius), backgroundRadius);
+ }
+ });
+ bkg.setClipToOutline(true);
+ }
+ }
+ if (maskColor != null) {
+ boxRoot.setBackgroundColor(maskColor);
+ }
+
+ if (onBindView != null) {
+ onBindView.bindParent(boxCustom, me);
+ if (onBindView.getCustomView() instanceof ScrollController) {
+ scrollView = (ScrollController) onBindView.getCustomView();
+ } else {
+ View scrollController = onBindView.getCustomView().findViewWithTag("ScrollController");
+ if (scrollController instanceof ScrollController) {
+ scrollView = (ScrollController) scrollController;
+ }
+ }
+ }
+
+ if (hideZoomBackground) {
+ getDialogView().setBackgroundResource(R.color.black20);
+ imgZoomActivity.setVisibility(View.GONE);
+ } else {
+ getDialogView().setBackgroundResource(R.color.black);
+ imgZoomActivity.setVisibility(View.VISIBLE);
+ }
+
+ fullScreenDialogTouchEventInterceptor.refresh(me, this);
+
+ onDialogRefreshUI();
+ }
+
+ @Override
+ public void doDismiss(View v) {
+ if (FullScreenDialog.this.preDismiss(FullScreenDialog.this)) {
+ return;
+ }
+ if (v != null) v.setEnabled(false);
+ if (getOwnActivity() == null) return;
+
+ if (!dismissAnimFlag && getDialogXAnimImpl() != null) {
+ dismissAnimFlag = true;
+ getDialogXAnimImpl().doExitAnim(me, bkg);
+
+ runOnMainDelay(new Runnable() {
+ @Override
+ public void run() {
+ if (boxRoot != null) {
+ boxRoot.setVisibility(View.GONE);
+ }
+ dismiss(getDialogView());
+ }
+ }, getExitAnimationDuration());
+ }
+ }
+
+ 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();
+ }
+ }
+
+ private boolean enterAnimRunning = true;
+
+ /**
+ * 弹窗显示的动画
+ * 动画执行途中实时检测终点是否改变,如果改变则中断这次动画重新设置新终点的动画并执行
+ *
+ * @param start 起点位置
+ * @param end 终点位置
+ */
+ private void doShowAnimRepeat(int start, int end, boolean isRepeat) {
+ enterAnimRunning = true;
+ long enterAnimDurationTemp = getEnterAnimationDuration();
+
+ ValueAnimator enterAnimVal = ValueAnimator.ofInt(start, end);
+ enterAnimVal.setDuration(enterAnimDurationTemp);
+ enterAnimVal.setInterpolator(new DecelerateInterpolator());
+ enterAnimVal.addUpdateListener(animation -> {
+ int thisVal = (int) animation.getAnimatedValue();
+ bkg.setY(thisVal);
+
+ makeEnterY();
+ float newBkgEnterAimY = boxRoot.getSafeHeight() - enterY;
+ if (newBkgEnterAimY < 0) newBkgEnterAimY = 0;
+ if (newBkgEnterAimY != bkgEnterAimY) {
+ bkgEnterAimY = newBkgEnterAimY;
+ //需要重新定义终点
+ animation.cancel();
+ doShowAnimRepeat(thisVal, (int) newBkgEnterAimY, true);
+ } else if (thisVal >= end) {
+ enterAnimRunning = false;
+ }
+ });
+ enterAnimVal.start();
+ bkg.setVisibility(View.VISIBLE);
+
+ if (!isRepeat) {
+ ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
+ bkgAlpha.setDuration(enterAnimDurationTemp);
+ bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ float value = (float) animation.getAnimatedValue();
+ boxRoot.setBkgAlpha(value);
+ }
+ });
+ bkgAlpha.start();
+ }
+ }
+
+ protected DialogXAnimInterface getDialogXAnimImpl() {
+ if (dialogXAnimImpl == null) {
+ dialogXAnimImpl = new DialogXAnimInterface() {
+ @Override
+ public void doShowAnim(FullScreenDialog dialog, ViewGroup dialogBodyView) {
+// long enterAnimDurationTemp = getEnterAnimationDuration();
+ makeEnterY();
+ bkgEnterAimY = boxRoot.getSafeHeight() - enterY;
+ if (bkgEnterAimY < 0) bkgEnterAimY = 0;
+ //启动带监控终点位置变化的动画
+ doShowAnimRepeat(boxRoot.getHeight(), (int) bkgEnterAimY, false);
+// ObjectAnimator enterAnim = ObjectAnimator.ofFloat(bkg, "y", boxRoot.getHeight(), bkgEnterAimY);
+// enterAnim.setDuration(enterAnimDurationTemp);
+// enterAnim.setInterpolator(new DecelerateInterpolator());
+// enterAnim.start();
+// bkg.setVisibility(View.VISIBLE);
+//
+// ValueAnimator bkgAlpha = ValueAnimator.ofFloat(0f, 1f);
+// bkgAlpha.setDuration(enterAnimDurationTemp);
+// bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+// @Override
+// public void onAnimationUpdate(ValueAnimator animation) {
+// float value = (float) animation.getAnimatedValue();
+// boxRoot.setBkgAlpha(value);
+// enterAnimRunning = !(value == 1f);
+// }
+// });
+// bkgAlpha.start();
+ }
+
+ @Override
+ public void doExitAnim(FullScreenDialog dialog, ViewGroup dialogBodyView) {
+ long exitAnimDurationTemp = getExitAnimationDuration();
+
+ ObjectAnimator exitAnim = ObjectAnimator.ofFloat(bkg, "y", bkg.getY(), boxBkg.getHeight());
+ exitAnim.setDuration(exitAnimDurationTemp);
+ exitAnim.start();
+
+ ValueAnimator bkgAlpha = ValueAnimator.ofFloat(1f, 0f);
+ bkgAlpha.setDuration(exitAnimDurationTemp);
+ bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ float value = (float) animation.getAnimatedValue();
+ boxRoot.setBkgAlpha(value);
+ enterAnimRunning = !(value == 1f);
+ }
+ });
+ bkgAlpha.start();
+ }
+ };
+ }
+ return dialogXAnimImpl;
+ }
+
+ public long getExitAnimationDuration() {
+ long exitAnimDurationTemp = 300;
+ if (overrideExitDuration >= 0) {
+ exitAnimDurationTemp = overrideExitDuration;
+ }
+ if (exitAnimDuration != -1) {
+ exitAnimDurationTemp = exitAnimDuration;
+ }
+ return exitAnimDurationTemp;
+ }
+
+ public long getEnterAnimationDuration() {
+ long enterAnimDurationTemp = 300;
+ if (overrideEnterDuration >= 0) {
+ enterAnimDurationTemp = overrideEnterDuration;
+ }
+ if (enterAnimDuration >= 0) {
+ enterAnimDurationTemp = enterAnimDuration;
+ }
+ return enterAnimDurationTemp;
+ }
+ }
+
+ @Override
+ public String dialogKey() {
+ return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
+ }
+
+ public void refreshUI() {
+ if (getDialogImpl() == null) return;
+ runOnMain(new Runnable() {
+ @Override
+ public void run() {
+ if (dialogImpl != null) dialogImpl.refreshView();
+ }
+ });
+ }
+
+ public void dismiss() {
+ runOnMain(new Runnable() {
+ @Override
+ public void run() {
+ if (dialogImpl == null) return;
+ dialogImpl.doDismiss(null);
+ }
+ });
+ }
+
+ public DialogLifecycleCallback getDialogLifecycleCallback() {
+ return dialogLifecycleCallback == null ? new DialogLifecycleCallback() {
+ } : dialogLifecycleCallback;
+ }
+
+ public FullScreenDialog setDialogLifecycleCallback(DialogLifecycleCallback dialogLifecycleCallback) {
+ this.dialogLifecycleCallback = dialogLifecycleCallback;
+ if (isShow) dialogLifecycleCallback.onShow(me);
+ return this;
+ }
+
+ public OnBackPressedListener getOnBackPressedListener() {
+ return (OnBackPressedListener) onBackPressedListener;
+ }
+
+ public FullScreenDialog setOnBackPressedListener(OnBackPressedListener onBackPressedListener) {
+ this.onBackPressedListener = onBackPressedListener;
+ refreshUI();
+ return this;
+ }
+
+ public FullScreenDialog setStyle(DialogXStyle style) {
+ this.style = style;
+ return this;
+ }
+
+ public FullScreenDialog setTheme(DialogX.THEME theme) {
+ this.theme = theme;
+ return this;
+ }
+
+ public boolean isCancelable() {
+ if (privateCancelable != null) {
+ return privateCancelable == BOOLEAN.TRUE;
+ }
+ if (overrideCancelable != null) {
+ return overrideCancelable == BOOLEAN.TRUE;
+ }
+ return cancelable;
+ }
+
+ public FullScreenDialog setCancelable(boolean cancelable) {
+ this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
+ refreshUI();
+ return this;
+ }
+
+ public DialogImpl getDialogImpl() {
+ return dialogImpl;
+ }
+
+ public FullScreenDialog setCustomView(OnBindView onBindView) {
+ this.onBindView = onBindView;
+ refreshUI();
+ return this;
+ }
+
+ public View getCustomView() {
+ if (onBindView == null) return null;
+ return onBindView.getCustomView();
+ }
+
+ public FullScreenDialog removeCustomView() {
+ this.onBindView.clean();
+ refreshUI();
+ return this;
+ }
+
+ public int getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public FullScreenDialog setBackgroundColor(@ColorInt int backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ refreshUI();
+ return this;
+ }
+
+ public FullScreenDialog setBackgroundColorRes(@ColorRes int backgroundColorRes) {
+ this.backgroundColor = getColor(backgroundColorRes);
+ refreshUI();
+ return this;
+ }
+
+ public long getEnterAnimDuration() {
+ return enterAnimDuration;
+ }
+
+ public FullScreenDialog setEnterAnimDuration(long enterAnimDuration) {
+ this.enterAnimDuration = enterAnimDuration;
+ return this;
+ }
+
+ public long getExitAnimDuration() {
+ return exitAnimDuration;
+ }
+
+ public FullScreenDialog setExitAnimDuration(long exitAnimDuration) {
+ this.exitAnimDuration = exitAnimDuration;
+ return this;
+ }
+
+ public boolean isHideZoomBackground() {
+ return hideZoomBackground;
+ }
+
+ public FullScreenDialog setHideZoomBackground(boolean hideZoomBackground) {
+ this.hideZoomBackground = hideZoomBackground;
+ refreshUI();
+ return this;
+ }
+
+ @Override
+ public void restartDialog() {
+ if (getDialogView() != null) {
+ dismiss(getDialogView());
+ isShow = false;
+ }
+ if (getDialogImpl().boxCustom != null) {
+ getDialogImpl().boxCustom.removeAllViews();
+ }
+ enterAnimDuration = 0;
+ View dialogView = createView(isLightTheme() ? R.layout.layout_dialogx_fullscreen : R.layout.layout_dialogx_fullscreen_dark);
+ dialogImpl = new DialogImpl(dialogView);
+ if (dialogView != null) dialogView.setTag(me);
+ show(dialogView);
+ }
+
+ public void hide() {
+ isHide = true;
+ hideWithExitAnim = false;
+ if (getDialogView() != null) {
+ getDialogView().setVisibility(View.GONE);
+ }
+ }
+
+ protected boolean hideWithExitAnim;
+
+ public void hideWithExitAnim() {
+ hideWithExitAnim = true;
+ isHide = true;
+ if (getDialogImpl() != null) {
+ getDialogImpl().getDialogXAnimImpl().doExitAnim(me, getDialogImpl().bkg);
+ runOnMainDelay(new Runnable() {
+ @Override
+ public void run() {
+ if (getDialogView() != null) {
+ getDialogView().setVisibility(View.GONE);
+ }
+ }
+ }, getDialogImpl().getExitAnimationDuration());
+ }
+ }
+
+ @Override
+ protected void shutdown() {
+ dismiss();
+ }
+
+ public FullScreenDialog setMaxWidth(int maxWidth) {
+ this.maxWidth = maxWidth;
+ refreshUI();
+ return this;
+ }
+
+ public FullScreenDialog setMaxHeight(int maxHeight) {
+ this.maxHeight = maxHeight;
+ refreshUI();
+ return this;
+ }
+
+ public FullScreenDialog setMinHeight(int minHeight) {
+ this.minHeight = minHeight;
+ refreshUI();
+ return this;
+ }
+
+ public FullScreenDialog setMinWidth(int minWidth) {
+ this.minWidth = minWidth;
+ refreshUI();
+ return this;
+ }
+
+ public FullScreenDialog setDialogImplMode(DialogX.IMPL_MODE dialogImplMode) {
+ this.dialogImplMode = dialogImplMode;
+ return this;
+ }
+
+ public OnBackgroundMaskClickListener getOnBackgroundMaskClickListener() {
+ return onBackgroundMaskClickListener;
+ }
+
+ public FullScreenDialog setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener onBackgroundMaskClickListener) {
+ this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
+ return this;
+ }
+
+ public FullScreenDialog setRadius(float radiusPx) {
+ backgroundRadius = radiusPx;
+ refreshUI();
+ return this;
+ }
+
+ public float getRadius() {
+ return backgroundRadius;
+ }
+
+ public boolean isAllowInterceptTouch() {
+ return allowInterceptTouch;
+ }
+
+ public FullScreenDialog setAllowInterceptTouch(boolean allowInterceptTouch) {
+ this.allowInterceptTouch = allowInterceptTouch;
+ refreshUI();
+ return this;
+ }
+
+ public DialogXAnimInterface getDialogXAnimImpl() {
+ return dialogXAnimImpl;
+ }
+
+ public FullScreenDialog setDialogXAnimImpl(DialogXAnimInterface dialogXAnimImpl) {
+ this.dialogXAnimImpl = dialogXAnimImpl;
+ return this;
+ }
+
+ public FullScreenDialog setRootPadding(int padding) {
+ this.screenPaddings = new int[]{padding, padding, padding, padding};
+ refreshUI();
+ return this;
+ }
+
+ public FullScreenDialog setRootPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
+ this.screenPaddings = new int[]{paddingLeft, paddingTop, paddingRight, paddingBottom};
+ refreshUI();
+ return this;
+ }
+
+ /**
+ * 用于使用 new 构建实例时,override 的生命周期事件
+ * 例如:
+ * new FullScreenDialog() {
+ *
+ * @param dialog self
+ * @Override public void onShow(FullScreenDialog dialog) {
+ * //...
+ * }
+ * }
+ */
+ protected void onShow(FullScreenDialog dialog) {
+
+ }
+
+ /**
+ * 用于使用 new 构建实例时,override 的生命周期事件
+ * 例如:
+ * new FullScreenDialog() {
+ *
+ * @param dialog self
+ * @Override public boolean onDismiss(FullScreenDialog dialog) {
+ * WaitDialog.show("Please Wait...");
+ * if (dialog.getButtonSelectResult() == BUTTON_SELECT_RESULT.BUTTON_OK) {
+ * //点击了OK的情况
+ * //...
+ * } else {
+ * //其他按钮点击、对话框dismiss的情况
+ * //...
+ * }
+ * return false;
+ * }
+ * }
+ */
+ //用于使用 new 构建实例时,override 的生命周期事件
+ protected void onDismiss(FullScreenDialog dialog) {
+
+ }
+
+ public boolean isBottomNonSafetyAreaBySelf() {
+ return bottomNonSafetyAreaBySelf;
+ }
+
+ public FullScreenDialog setBottomNonSafetyAreaBySelf(boolean bottomNonSafetyAreaBySelf) {
+ this.bottomNonSafetyAreaBySelf = bottomNonSafetyAreaBySelf;
+ return this;
+ }
+
+ /**
+ * 是否在显示 FullScreenDialog 时不对 activity 的界面内容进行渲染,这将提升一定的性能
+ * 只可以在使用 build 方法构建且在执行show方法之前使用
+ * 但这将引发一些问题,例如输入法弹出时 FullScreenDialog 无法上浮等
+ *
+ * @param hideActivityContentView 是否显示 activity 的界面内容
+ * @return this
+ */
+ public FullScreenDialog hideActivityContentView(boolean hideActivityContentView) {
+ this.hideActivityContentView = hideActivityContentView;
+ return this;
+ }
+
+ public FullScreenDialog setMaskColor(@ColorInt int maskColor) {
+ this.maskColor = maskColor;
+ refreshUI();
+ return this;
+ }
+
+ public float getActivityContentRadius() {
+ return activityContentRadius >= 0 ? activityContentRadius : activityContentRadius == ACTIVITY_CONTENT_RADIUS_KEEP ? getDeviceRadius() : (getRadius() >= 0 ? getRadius() : dip2px(15));
+ }
+
+ private Integer deviceRadiusCache;
+
+ public int getDeviceRadius() {
+ if (deviceRadiusCache == null) {
+ deviceRadiusCache = 0;
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
+ WindowInsets rootInsets = getRootFrameLayout() == null ? publicWindowInsets() : getRootFrameLayout().getRootWindowInsets();
+ if (rootInsets != null) {
+ RoundedCorner lT = rootInsets.getRoundedCorner(RoundedCorner.POSITION_TOP_LEFT);
+ RoundedCorner rT = rootInsets.getRoundedCorner(RoundedCorner.POSITION_TOP_RIGHT);
+ if (lT != null && rT != null) {
+ deviceRadiusCache = Math.max(lT.getRadius(), rT.getRadius());
+ }
+ }
+ }
+ if (deviceRadiusCache == 0) {
+ String manufacturer = Build.MANUFACTURER.toLowerCase();
+ if ("xiaomi".equals(manufacturer)) {
+ try {
+ Class> systemPropertiesClass = Class.forName("android.os.SystemProperties");
+ Method getIntMethod = systemPropertiesClass.getMethod("getInt", String.class, int.class);
+ deviceRadiusCache = (int) getIntMethod.invoke(null, "ro.miui.notch.radius", 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ if (deviceRadiusCache == 0) {
+ try {
+ int resourceId = me.getResources().getIdentifier("rounded_corner_radius", "dimen", "android");
+ if (resourceId > 0) {
+ deviceRadiusCache = me.getResources().getDimensionPixelSize(resourceId);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return deviceRadiusCache;
+ }
+
+ public FullScreenDialog setDeviceRadius(int deviceRadiusPx) {
+ deviceRadiusCache = deviceRadiusPx;
+ return this;
+ }
+
+ public FullScreenDialog setActivityContentRadius(float activityContentRadius) {
+ this.activityContentRadius = activityContentRadius;
+ return this;
+ }
+
+ private float getActivityZoomRadius(float startValue, float endValue, float progressValue) {
+ return startValue + progressValue * (endValue - startValue);
+ }
+
+ public FullScreenDialog setData(String key, Object obj) {
+ if (data == null) data = new HashMap<>();
+ data.put(key, obj);
+ return this;
+ }
+
+ public FullScreenDialog onShow(DialogXRunnable dialogXRunnable) {
+ onShowRunnable = dialogXRunnable;
+ if (isShow() && onShowRunnable != null) {
+ onShowRunnable.run(this);
+ }
+ return this;
+ }
+
+ public FullScreenDialog onDismiss(DialogXRunnable dialogXRunnable) {
+ onDismissRunnable = dialogXRunnable;
+ return this;
+ }
+
+ public FullScreenDialog setEnableImmersiveMode(boolean enableImmersiveMode) {
+ this.enableImmersiveMode = enableImmersiveMode;
+ refreshUI();
+ return this;
+ }
+
+ public FullScreenDialog setThisOrderIndex(int orderIndex) {
+ this.thisOrderIndex = orderIndex;
+ if (getDialogView() != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ getDialogView().setTranslationZ(orderIndex);
+ } else {
+ error("DialogX: " + dialogKey() + " 执行 .setThisOrderIndex(" + orderIndex + ") 失败:系统不支持此方法,SDK-API 版本必须大于 21(LOLLIPOP)");
+ }
+ }
+ return this;
+ }
+
+ public FullScreenDialog bringToFront() {
+ setThisOrderIndex(getHighestOrderIndex());
+ return this;
+ }
+
+ public FullScreenDialog setActionRunnable(int actionId, DialogXRunnable runnable) {
+ dialogActionRunnableMap.put(actionId, runnable);
+ return this;
+ }
+
+ public FullScreenDialog cleanAction(int actionId) {
+ dialogActionRunnableMap.remove(actionId);
+ return this;
+ }
+
+ public FullScreenDialog cleanAllAction() {
+ dialogActionRunnableMap.clear();
+ return this;
+ }
+
+ // for BaseDialog use
+ public void callDialogDismiss() {
+ dismiss();
+ }
+
+ public FullScreenDialog bindDismissWithLifecycleOwner(LifecycleOwner owner) {
+ super.bindDismissWithLifecycleOwnerPrivate(owner);
+ return this;
+ }
+}
diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/GuideDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/GuideDialog.java
new file mode 100644
index 0000000..5928d9c
--- /dev/null
+++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/GuideDialog.java
@@ -0,0 +1,852 @@
+package com.kongzue.dialogx.dialogs;
+
+import android.app.Activity;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.RelativeLayout;
+
+import androidx.annotation.ColorInt;
+import androidx.lifecycle.LifecycleOwner;
+
+import com.kongzue.dialogx.DialogX;
+import com.kongzue.dialogx.R;
+import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
+import com.kongzue.dialogx.interfaces.DialogXAnimInterface;
+import com.kongzue.dialogx.interfaces.DialogXRunnable;
+import com.kongzue.dialogx.interfaces.DialogXStyle;
+import com.kongzue.dialogx.interfaces.OnBackPressedListener;
+import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
+import com.kongzue.dialogx.interfaces.OnBindView;
+import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
+import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
+
+import java.util.Arrays;
+import java.util.HashMap;
+
+/**
+ * @author: Kongzue
+ * @github: https://github.com/kongzue/
+ * @homepage: http://kongzue.com/
+ * @mail: myzcxhh@live.cn
+ * @createTime: 2022/8/19 16:35
+ */
+public class GuideDialog extends CustomDialog {
+
+ public enum STAGE_LIGHT_TYPE {
+ RECTANGLE, //矩形
+ SQUARE_OUTSIDE, //方形(外围)
+ SQUARE_INSIDE, //方形(内围)
+ CIRCLE_OUTSIDE, //圆形(外围)
+ CIRCLE_INSIDE, //圆形(内围)
+ }
+
+ protected STAGE_LIGHT_TYPE stageLightType = STAGE_LIGHT_TYPE.CIRCLE_OUTSIDE;
+ protected Drawable tipImage;
+ protected float stageLightFilletRadius; //舞台灯光部分的圆角
+ protected Integer maskColor = null;
+ protected OnDialogButtonClickListener onStageLightPathClickListener;
+ protected int[] baseViewLocationCoordinateCompensation = new int[4];
+
+ protected GuideDialog() {
+ super();
+ enterAnimResId = R.anim.anim_dialogx_alpha_enter;
+ exitAnimResId = R.anim.anim_dialogx_default_exit;
+ this.alignViewGravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
+ }
+
+ public static GuideDialog build() {
+ return new GuideDialog();
+ }
+
+ public GuideDialog(View baseView, STAGE_LIGHT_TYPE stageLightType) {
+ this();
+ this.baseView(baseView);
+ this.stageLightType = stageLightType;
+ }
+
+ public GuideDialog(View baseView, STAGE_LIGHT_TYPE stageLightType, OnBindView onBindView, int alignBaseViewGravity) {
+ this();
+ this.baseView(baseView);
+ this.stageLightType = stageLightType;
+ this.onBindView = onBindView;
+ this.alignViewGravity = alignBaseViewGravity;
+ }
+
+ public GuideDialog(View baseView, STAGE_LIGHT_TYPE stageLightType, int tipImageResId, int alignBaseViewGravity) {
+ this();
+ this.baseView(baseView);
+ this.tipImage = getResources().getDrawable(tipImageResId);
+ this.stageLightType = stageLightType;
+ this.alignViewGravity = alignBaseViewGravity;
+ }
+
+ public GuideDialog(View baseView, STAGE_LIGHT_TYPE stageLightType, Bitmap tipImage, int alignBaseViewGravity) {
+ this();
+ this.baseView(baseView);
+ this.tipImage = new BitmapDrawable(getResources(), tipImage);
+ this.stageLightType = stageLightType;
+ this.alignViewGravity = alignBaseViewGravity;
+ }
+
+ public GuideDialog(View baseView, STAGE_LIGHT_TYPE stageLightType, Drawable tipImage, int alignBaseViewGravity) {
+ this();
+ this.baseView(baseView);
+ this.tipImage = tipImage;
+ this.stageLightType = stageLightType;
+ this.alignViewGravity = alignBaseViewGravity;
+ }
+
+ public GuideDialog(int tipImageResId) {
+ this();
+ this.tipImage = getResources().getDrawable(tipImageResId);
+ }
+
+ public GuideDialog(Bitmap tipImage) {
+ this();
+ this.tipImage = new BitmapDrawable(getResources(), tipImage);
+ }
+
+ public GuideDialog(Drawable tipImage) {
+ this();
+ this.tipImage = tipImage;
+ }
+
+ public GuideDialog(int tipImageResId, ALIGN align) {
+ this();
+ this.tipImage = getResources().getDrawable(tipImageResId);
+ this.align = align;
+ }
+
+ public GuideDialog(Bitmap tipImage, ALIGN align) {
+ this();
+ this.tipImage = new BitmapDrawable(getResources(), tipImage);
+ this.align = align;
+ }
+
+ public GuideDialog(Drawable tipImage, ALIGN align) {
+ this();
+ this.tipImage = tipImage;
+ this.align = align;
+ }
+
+ public GuideDialog(OnBindView onBindView) {
+ this();
+ this.onBindView = onBindView;
+ }
+
+ public GuideDialog(OnBindView onBindView, ALIGN align) {
+ this();
+ this.onBindView = onBindView;
+ this.align = align;
+ }
+
+ public GuideDialog(View baseView, int tipImageResId) {
+ this();
+ this.baseView(baseView);
+ this.tipImage = getResources().getDrawable(tipImageResId);
+ }
+
+ public GuideDialog(View baseView, Bitmap tipImage) {
+ this();
+ this.baseView(baseView);
+ this.tipImage = new BitmapDrawable(getResources(), tipImage);
+ }
+
+ public GuideDialog(View baseView, Drawable tipImage) {
+ this();
+ this.baseView(baseView);
+ this.tipImage = tipImage;
+ }
+
+ public GuideDialog(View baseView, STAGE_LIGHT_TYPE stageLightType, int tipImageResId) {
+ this();
+ this.baseView(baseView);
+ this.stageLightType = stageLightType;
+ this.tipImage = getResources().getDrawable(tipImageResId);
+ }
+
+ public GuideDialog(View baseView, STAGE_LIGHT_TYPE stageLightType, Bitmap tipImage) {
+ this();
+ this.baseView(baseView);
+ this.stageLightType = stageLightType;
+ this.tipImage = new BitmapDrawable(getResources(), tipImage);
+ }
+
+ public GuideDialog(View baseView, STAGE_LIGHT_TYPE stageLightType, Drawable tipImage) {
+ this();
+ this.baseView(baseView);
+ this.stageLightType = stageLightType;
+ this.tipImage = tipImage;
+ }
+
+ public GuideDialog(View baseView, int tipImageResId, int alignBaseViewGravity) {
+ this();
+ this.baseView(baseView);
+ this.alignViewGravity = alignBaseViewGravity;
+ this.tipImage = getResources().getDrawable(tipImageResId);
+ }
+
+ public GuideDialog(View baseView, Bitmap tipImage, int alignBaseViewGravity) {
+ this();
+ this.baseView(baseView);
+ this.alignViewGravity = alignBaseViewGravity;
+ this.tipImage = new BitmapDrawable(getResources(), tipImage);
+ }
+
+ public GuideDialog(View baseView, Drawable tipImage, int alignBaseViewGravity) {
+ this();
+ this.baseView(baseView);
+ this.alignViewGravity = alignBaseViewGravity;
+ this.tipImage = tipImage;
+ }
+
+ //静态方法
+ public static GuideDialog show(OnBindView onBindView) {
+ GuideDialog guideDialog = new GuideDialog(onBindView);
+ guideDialog.show();
+ return guideDialog;
+ }
+
+ public static GuideDialog show(OnBindView onBindView, ALIGN align) {
+ GuideDialog guideDialog = new GuideDialog(onBindView);
+ guideDialog.align = align;
+ guideDialog.show();
+ return guideDialog;
+ }
+
+ public static GuideDialog show(int tipImageResId) {
+ return new GuideDialog(tipImageResId).show();
+ }
+
+ public static GuideDialog show(Bitmap tipImage) {
+ return new GuideDialog(tipImage).show();
+ }
+
+ public static GuideDialog show(Drawable tipImage) {
+ return new GuideDialog(tipImage).show();
+ }
+
+ public static GuideDialog show(int tipImageResId, ALIGN align) {
+ GuideDialog guideDialog = new GuideDialog(tipImageResId, align);
+ guideDialog.align = align;
+ return guideDialog.show();
+ }
+
+ public static GuideDialog show(Bitmap tipImage, ALIGN align) {
+ GuideDialog guideDialog = new GuideDialog(tipImage, align);
+ guideDialog.align = align;
+ return guideDialog.show();
+ }
+
+ public static GuideDialog show(Drawable tipImage, ALIGN align) {
+ return new GuideDialog(tipImage, align).show();
+ }
+
+ public static GuideDialog show(View baseView, STAGE_LIGHT_TYPE stageLightType) {
+ return new GuideDialog(baseView, stageLightType).show();
+ }
+
+ public static GuideDialog show(View baseView, STAGE_LIGHT_TYPE stageLightType, OnBindView onBindView, int alignBaseViewGravity) {
+ return new GuideDialog(baseView, stageLightType, onBindView, alignBaseViewGravity).show();
+ }
+
+ public static GuideDialog show(View baseView, STAGE_LIGHT_TYPE stageLightType, int tipImageResId, int alignBaseViewGravity) {
+ return new GuideDialog(baseView, stageLightType, tipImageResId, alignBaseViewGravity).show();
+ }
+
+ public static GuideDialog show(View baseView, STAGE_LIGHT_TYPE stageLightType, Bitmap tipImage, int alignBaseViewGravity) {
+ return new GuideDialog(baseView, stageLightType, tipImage, alignBaseViewGravity).show();
+ }
+
+ public static GuideDialog show(View baseView, STAGE_LIGHT_TYPE stageLightType, Drawable tipImage, int alignBaseViewGravity) {
+ return new GuideDialog(baseView, stageLightType, tipImage, alignBaseViewGravity).show();
+ }
+
+ public static GuideDialog show(View baseView, int tipImageResId) {
+ return new GuideDialog(baseView, tipImageResId).show();
+ }
+
+ public static GuideDialog show(View baseView, Bitmap tipImage) {
+ return new GuideDialog(baseView, tipImage).show();
+ }
+
+ public static GuideDialog show(View baseView, Drawable tipImage) {
+ return new GuideDialog(baseView, tipImage).show();
+ }
+
+ public static GuideDialog show(View baseView, STAGE_LIGHT_TYPE stageLightType, int tipImageResId) {
+ return new GuideDialog(baseView, stageLightType, tipImageResId).show();
+ }
+
+ public static GuideDialog show(View baseView, STAGE_LIGHT_TYPE stageLightType, Bitmap tipImage) {
+ return new GuideDialog(baseView, stageLightType, tipImage).show();
+ }
+
+ public static GuideDialog show(View baseView, STAGE_LIGHT_TYPE stageLightType, Drawable tipImage) {
+ return new GuideDialog(baseView, stageLightType, tipImage).show();
+ }
+
+ public static GuideDialog show(View baseView, int tipImageResId, int alignBaseViewGravity) {
+ return new GuideDialog(baseView, tipImageResId, alignBaseViewGravity).show();
+ }
+
+ public static GuideDialog show(View baseView, Bitmap tipImage, int alignBaseViewGravity) {
+ return new GuideDialog(baseView, tipImage, alignBaseViewGravity).show();
+ }
+
+ public static GuideDialog show(View baseView, Drawable tipImage, int alignBaseViewGravity) {
+ return new GuideDialog(baseView, tipImage, alignBaseViewGravity).show();
+ }
+
+ //执行方法
+ public GuideDialog show() {
+ super.show();
+ return this;
+ }
+
+ public GuideDialog show(Activity activity) {
+ super.show(activity);
+ return this;
+ }
+
+ @Override
+ public String dialogKey() {
+ return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
+ }
+
+ public GuideDialog setDialogLifecycleCallback(DialogLifecycleCallback dialogLifecycleCallback) {
+ this.dialogLifecycleCallback = dialogLifecycleCallback;
+ if (isShow) dialogLifecycleCallback.onShow(me);
+ return this;
+ }
+
+ public GuideDialog setOnBackPressedListener(OnBackPressedListener onBackPressedListener) {
+ this.onBackPressedListener = onBackPressedListener;
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setStyle(DialogXStyle style) {
+ this.style = style;
+ return this;
+ }
+
+ public GuideDialog setTheme(DialogX.THEME theme) {
+ this.theme = theme;
+ return this;
+ }
+
+ public GuideDialog setCancelable(boolean cancelable) {
+ this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog.DialogImpl getDialogImpl() {
+ return dialogImpl;
+ }
+
+ public GuideDialog setCustomView(OnBindView onBindView) {
+ this.onBindView = onBindView;
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog removeCustomView() {
+ this.onBindView.clean();
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setEnterAnimResId(int enterAnimResId) {
+ this.enterAnimResId = enterAnimResId;
+ return this;
+ }
+
+ public GuideDialog setExitAnimResId(int exitAnimResId) {
+ this.exitAnimResId = exitAnimResId;
+ return this;
+ }
+
+ public GuideDialog setAnimResId(int enterAnimResId, int exitAnimResId) {
+ this.enterAnimResId = enterAnimResId;
+ this.exitAnimResId = exitAnimResId;
+ return this;
+ }
+
+ public GuideDialog setAlign(ALIGN align) {
+ this.align = align;
+ return this;
+ }
+
+ public GuideDialog setAutoUnsafePlacePadding(boolean autoUnsafePlacePadding) {
+ super.setAutoUnsafePlacePadding(autoUnsafePlacePadding);
+ return this;
+ }
+
+ public GuideDialog setFullScreen(boolean fullscreen) {
+ super.setFullScreen(fullscreen);
+ return this;
+ }
+
+ public GuideDialog setMaskColor(@ColorInt int maskColor) {
+ this.maskColor = maskColor;
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setEnterAnimDuration(long enterAnimDuration) {
+ this.enterAnimDuration = enterAnimDuration;
+ return this;
+ }
+
+ public GuideDialog setExitAnimDuration(long exitAnimDuration) {
+ this.exitAnimDuration = exitAnimDuration;
+ return this;
+ }
+
+ public GuideDialog setDialogImplMode(DialogX.IMPL_MODE dialogImplMode) {
+ this.dialogImplMode = dialogImplMode;
+ return this;
+ }
+
+ public GuideDialog setBkgInterceptTouch(boolean bkgInterceptTouch) {
+ this.bkgInterceptTouch = bkgInterceptTouch;
+ return this;
+ }
+
+ public GuideDialog setAlignBaseViewGravity(View baseView, int alignGravity) {
+ this.baseView(baseView);
+ this.alignViewGravity = alignGravity;
+ baseViewLoc = new int[4];
+ baseView.getLocationInWindow(baseViewLoc);
+ setFullScreen(true);
+ return this;
+ }
+
+ public GuideDialog setAlignBaseViewGravity(View baseView) {
+ this.baseView(baseView);
+ baseViewLoc = new int[4];
+ baseView.getLocationInWindow(baseViewLoc);
+ setFullScreen(true);
+ return this;
+ }
+
+ public GuideDialog setAlignBaseViewGravity(int alignGravity) {
+ this.alignViewGravity = alignGravity;
+ if (baseView() != null) {
+ baseViewLoc = new int[4];
+ baseView().getLocationInWindow(baseViewLoc);
+ }
+ setFullScreen(true);
+ return this;
+ }
+
+ public GuideDialog setAlignBaseViewGravity(View baseView, int alignGravity, int marginLeft,
+ int marginTop, int marginRight, int marginBottom) {
+ this.marginRelativeBaseView = new int[]{marginLeft, marginTop, marginRight, marginBottom};
+ return setAlignBaseViewGravity(baseView, alignGravity);
+ }
+
+ public GuideDialog setBaseViewMargin(int[] marginRelativeBaseView) {
+ this.marginRelativeBaseView = marginRelativeBaseView;
+ return this;
+ }
+
+ public GuideDialog setBaseViewMargin(int marginLeft, int marginTop,
+ int marginRight, int marginBottom) {
+ this.marginRelativeBaseView = new int[]{marginLeft, marginTop, marginRight, marginBottom};
+ return this;
+ }
+
+ public GuideDialog setBaseViewMarginLeft(int marginLeft) {
+ this.marginRelativeBaseView[0] = marginLeft;
+ return this;
+ }
+
+ public GuideDialog setBaseViewMarginTop(int marginTop) {
+ this.marginRelativeBaseView[1] = marginTop;
+ return this;
+ }
+
+ public GuideDialog setBaseViewMarginRight(int marginRight) {
+ this.marginRelativeBaseView[2] = marginRight;
+ return this;
+ }
+
+ public GuideDialog setBaseViewMarginBottom(int marginBottom) {
+ this.marginRelativeBaseView[3] = marginBottom;
+ return this;
+ }
+
+ /**
+ * 设置对话框 UI 宽度(单位:像素)
+ *
+ * @param width 宽度(像素)
+ * @return CustomDialog实例
+ */
+ public GuideDialog setWidth(int width) {
+ this.width = width;
+ refreshUI();
+ return this;
+ }
+
+ /**
+ * 设置对话框 UI 高度(单位:像素)
+ *
+ * @param height 高度(像素)
+ * @return CustomDialog实例
+ */
+ public GuideDialog setHeight(int height) {
+ this.height = height;
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener onBackgroundMaskClickListener) {
+ this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
+ return this;
+ }
+
+ @Override
+ protected void onDialogShow() {
+ super.onDialogShow();
+ if (baseView() == null) {
+ super.setMaskColor(maskColor == null ? getColor(R.color.black50) : maskColor);
+ }
+ }
+
+ View stageLightPathStub;
+
+ @Override
+ protected void onDialogRefreshUI() {
+ super.onDialogRefreshUI();
+ if (onBindView == null && tipImage != null) {
+ getDialogImpl().boxCustom.setFocusable(false);
+ getDialogImpl().boxCustom.setFocusableInTouchMode(false);
+ getDialogImpl().boxCustom.setOnClickListener(null);
+ getDialogImpl().boxCustom.setClickable(false);
+
+ ImageView imageView = new ImageView(getOwnActivity());
+ imageView.setImageDrawable(tipImage);
+ imageView.setAdjustViewBounds(true);
+ imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+ onBindView = new OnBindView(imageView) {
+ @Override
+ public void onBind(CustomDialog dialog, View v) {
+
+ }
+ };
+ onBindView.bindParent(getDialogImpl().boxCustom, me);
+ }
+ if (getOnStageLightPathClickListener() != null && baseView() != null) {
+ stageLightPathStub = new View(getOwnActivity());
+ stageLightPathStub.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (!getOnStageLightPathClickListener().onClick(GuideDialog.this, v)) {
+ dismiss();
+ }
+ }
+ });
+ getDialogImpl().boxRoot.addView(stageLightPathStub);
+ } else {
+ if (stageLightPathStub != null && stageLightPathStub.getParent() instanceof ViewGroup) {
+ ((ViewGroup) stageLightPathStub.getParent()).removeView(stageLightPathStub);
+ }
+ }
+ }
+
+ int[] baseViewLocCache;
+
+ @Override
+ protected void onGetBaseViewLoc(int[] baseViewLoc) {
+ if (Arrays.equals(baseViewLoc, baseViewLocCache)) {
+ return;
+ }
+ if (getDialogImpl() == null) {
+ return;
+ }
+ Bitmap bkg = Bitmap.createBitmap(getDialogImpl().boxRoot.getWidth(), getDialogImpl().boxRoot.getHeight(), Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bkg);
+
+ int x = baseViewLoc[0] + baseViewLocationCoordinateCompensation[0];
+ int y = baseViewLoc[1] + baseViewLocationCoordinateCompensation[1];
+ int w = baseViewLoc[2] + baseViewLocationCoordinateCompensation[2];
+ int h = baseViewLoc[3] + baseViewLocationCoordinateCompensation[3];
+ int hW = w / 2;
+ int hH = h / 2;
+
+ if (stageLightPathStub != null && (stageLightPathStub.getX() != x || stageLightPathStub.getY() != y)) {
+ RelativeLayout.LayoutParams rLp = (RelativeLayout.LayoutParams) stageLightPathStub.getLayoutParams();
+ if (rLp == null) {
+ rLp = new RelativeLayout.LayoutParams(w, h);
+ } else {
+ rLp.width = w;
+ rLp.height = h;
+ }
+ stageLightPathStub.setLayoutParams(rLp);
+ stageLightPathStub.setX(x);
+ stageLightPathStub.setY(y);
+ }
+
+ switch (stageLightType) {
+ case CIRCLE_OUTSIDE: {
+ int r = (int) Math.sqrt(hW * hW + hH * hH);
+ canvas.drawCircle(x + hW, y + hH, r, getStageLightPaint());
+ }
+ break;
+ case CIRCLE_INSIDE: {
+ int r = Math.min(w, h) / 2;
+ canvas.drawCircle(x + hW, y + hH, r, getStageLightPaint());
+ }
+ break;
+ case RECTANGLE: {
+ canvas.drawRoundRect(new RectF(x, y, x + w, y + h), stageLightFilletRadius, stageLightFilletRadius, getStageLightPaint());
+ }
+ break;
+ case SQUARE_INSIDE: {
+ int r = Math.min(w, h);
+ canvas.drawRoundRect(new RectF(x + hW - r / 2, y + hH - r / 2, x + hW - r / 2 + r, y + hH - r / 2 + r), stageLightFilletRadius, stageLightFilletRadius, getStageLightPaint());
+ }
+ break;
+ case SQUARE_OUTSIDE: {
+ int r = Math.max(w, h);
+ canvas.drawRoundRect(new RectF(x + hW - r / 2, y + hH - r / 2, x + hW - r / 2 + r, y + hH - r / 2 + r), stageLightFilletRadius, stageLightFilletRadius, getStageLightPaint());
+ }
+ break;
+ }
+ stageLightPaint.setXfermode(null);
+ canvas.drawColor(maskColor == null ? 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;
+
+ private Paint getStageLightPaint() {
+ if (stageLightPaint == null) {
+ stageLightPaint = new Paint();
+ stageLightPaint.setColor(Color.RED);
+ stageLightPaint.setStyle(Paint.Style.FILL);
+ stageLightPaint.setAntiAlias(true);
+ }
+ return stageLightPaint;
+ }
+
+ public STAGE_LIGHT_TYPE getStageLightType() {
+ return stageLightType;
+ }
+
+ public GuideDialog setStageLightType(STAGE_LIGHT_TYPE stageLightType) {
+ this.stageLightType = stageLightType;
+ refreshUI();
+ return this;
+ }
+
+ public Drawable getTipImage() {
+ return tipImage;
+ }
+
+ public GuideDialog setTipImage(int tipImageResId) {
+ this.tipImage = getResources().getDrawable(tipImageResId);
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setTipImage(Bitmap tipImage) {
+ this.tipImage = new BitmapDrawable(getResources(), tipImage);
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setTipImage(Drawable tipImage) {
+ this.tipImage = tipImage;
+ refreshUI();
+ return this;
+ }
+
+ public float getStageLightFilletRadius() {
+ return stageLightFilletRadius;
+ }
+
+ public GuideDialog setStageLightFilletRadius(float stageLightFilletRadius) {
+ this.stageLightFilletRadius = stageLightFilletRadius;
+ refreshUI();
+ return this;
+ }
+
+ public OnDialogButtonClickListener getOnStageLightPathClickListener() {
+ return onStageLightPathClickListener;
+ }
+
+ public GuideDialog setOnStageLightPathClickListener(OnDialogButtonClickListener onStageLightPathClickListener) {
+ this.onStageLightPathClickListener = onStageLightPathClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public DialogXAnimInterface getDialogXAnimImpl() {
+ return dialogXAnimImpl;
+ }
+
+ public GuideDialog setDialogXAnimImpl(DialogXAnimInterface dialogXAnimImpl) {
+ this.dialogXAnimImpl = dialogXAnimImpl;
+ return this;
+ }
+
+ public GuideDialog setRootPadding(int padding) {
+ this.screenPaddings = new int[]{padding, padding, padding, padding};
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setRootPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
+ this.screenPaddings = new int[]{paddingLeft, paddingTop, paddingRight, paddingBottom};
+ refreshUI();
+ return this;
+ }
+
+ public int[] getBaseViewLocationCoordinateCompensation() {
+ return baseViewLocationCoordinateCompensation;
+ }
+
+ public GuideDialog setBaseViewLocationCoordinateCompensation(int[] baseViewLocationCoordinateCompensation) {
+ this.baseViewLocationCoordinateCompensation = baseViewLocationCoordinateCompensation;
+ return this;
+ }
+
+ public GuideDialog setBaseViewLocationCoordinateCompensation(int px) {
+ this.baseViewLocationCoordinateCompensation = new int[]{px, px, px, px};
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setBaseViewLocationCoordinateCompensation(int pxX, int pxY, int pxR, int pxB) {
+ this.baseViewLocationCoordinateCompensation = new int[]{pxX, pxY, pxR, pxB};
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setBaseViewLocationCoordinateCompensationLeft(int pxX) {
+ this.baseViewLocationCoordinateCompensation[0] = pxX;
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setBaseViewLocationCoordinateCompensationTop(int pxY) {
+ this.baseViewLocationCoordinateCompensation[1] = pxY;
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setBaseViewLocationCoordinateCompensationRight(int pxR) {
+ this.baseViewLocationCoordinateCompensation[2] = pxR;
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setBaseViewLocationCoordinateCompensationBottom(int pxB) {
+ this.baseViewLocationCoordinateCompensation[3] = pxB;
+ refreshUI();
+ return this;
+ }
+
+ public int getBaseViewLocationCoordinateCompensationLeft() {
+ return baseViewLocationCoordinateCompensation[0];
+ }
+
+ public int getBaseViewLocationCoordinateCompensationTop() {
+ return baseViewLocationCoordinateCompensation[1];
+ }
+
+ public int getBaseViewLocationCoordinateCompensationRight() {
+ return baseViewLocationCoordinateCompensation[2];
+ }
+
+ public int getBaseViewLocationCoordinateCompensationBottom() {
+ return baseViewLocationCoordinateCompensation[3];
+ }
+
+ public GuideDialog setData(String key, Object obj) {
+ if (data == null) data = new HashMap<>();
+ data.put(key, obj);
+ return this;
+ }
+
+ public GuideDialog onShow(DialogXRunnable dialogXRunnable) {
+ onShowRunnable = dialogXRunnable;
+ if (isShow() && onShowRunnable != null) {
+ onShowRunnable.run(this);
+ }
+ return this;
+ }
+
+ public GuideDialog onDismiss(DialogXRunnable dialogXRunnable) {
+ onDismissRunnable = dialogXRunnable;
+ return this;
+ }
+
+ public GuideDialog setEnableImmersiveMode(boolean enableImmersiveMode) {
+ this.enableImmersiveMode = enableImmersiveMode;
+ refreshUI();
+ return this;
+ }
+
+ public GuideDialog setThisOrderIndex(int orderIndex) {
+ this.thisOrderIndex = orderIndex;
+ if (getDialogView() != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ getDialogView().setTranslationZ(orderIndex);
+ } else {
+ error("DialogX: " + dialogKey() + " 执行 .setThisOrderIndex("+orderIndex+") 失败:系统不支持此方法,SDK-API 版本必须大于 21(LOLLIPOP)");
+ }
+ }
+ return this;
+ }
+
+ public GuideDialog bringToFront() {
+ setThisOrderIndex(getHighestOrderIndex());
+ return this;
+ }
+
+ public GuideDialog setActionRunnable(int actionId, DialogXRunnable runnable) {
+ dialogActionRunnableMap.put(actionId, runnable);
+ return this;
+ }
+
+ public GuideDialog cleanAction(int actionId){
+ dialogActionRunnableMap.remove(actionId);
+ return this;
+ }
+
+ public GuideDialog cleanAllAction(){
+ dialogActionRunnableMap.clear();
+ return this;
+ }
+
+ // for BaseDialog use
+ public void callDialogDismiss(){
+ dismiss();
+ }
+
+ public GuideDialog bindDismissWithLifecycleOwner(LifecycleOwner owner){
+ super.bindDismissWithLifecycleOwnerPrivate(owner);
+ return this;
+ }
+}
diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/InputDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/InputDialog.java
new file mode 100644
index 0000000..1a492e8
--- /dev/null
+++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/InputDialog.java
@@ -0,0 +1,759 @@
+package com.kongzue.dialogx.dialogs;
+
+import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
+import android.text.TextUtils;
+import android.view.View;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.ColorRes;
+import androidx.lifecycle.LifecycleOwner;
+
+import com.kongzue.dialogx.DialogX;
+import com.kongzue.dialogx.R;
+import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
+import com.kongzue.dialogx.interfaces.DialogXAnimInterface;
+import com.kongzue.dialogx.interfaces.DialogXRunnable;
+import com.kongzue.dialogx.interfaces.DialogXStyle;
+import com.kongzue.dialogx.interfaces.OnBackPressedListener;
+import com.kongzue.dialogx.interfaces.OnBackgroundMaskClickListener;
+import com.kongzue.dialogx.interfaces.OnBindView;
+import com.kongzue.dialogx.interfaces.OnInputDialogButtonClickListener;
+import com.kongzue.dialogx.util.InputInfo;
+import com.kongzue.dialogx.util.TextInfo;
+
+import java.util.HashMap;
+
+/**
+ * @author: Kongzue
+ * @github: https://github.com/kongzue/
+ * @homepage: http://kongzue.com/
+ * @mail: myzcxhh@live.cn
+ * @createTime: 2020/9/24 13:53
+ */
+public class InputDialog extends MessageDialog {
+
+ protected InputDialog() {
+ super();
+ }
+
+ public static InputDialog build() {
+ return new InputDialog();
+ }
+
+ public static InputDialog build(DialogXStyle style) {
+ InputDialog dialog = new InputDialog();
+ dialog.setStyle(style);
+ return dialog;
+ }
+
+ public static InputDialog build(OnBindView onBindView) {
+ return new InputDialog().setCustomView(onBindView);
+ }
+
+ public InputDialog(CharSequence title, CharSequence message, CharSequence okText) {
+ cancelable = DialogX.cancelable;
+ this.title = title;
+ this.message = message;
+ this.okText = okText;
+ }
+
+ public InputDialog(int titleResId, int messageResId, int okTextResId) {
+ cancelable = DialogX.cancelable;
+ this.title = getString(titleResId);
+ this.message = getString(messageResId);
+ this.okText = getString(okTextResId);
+ }
+
+ public static InputDialog show(CharSequence title, CharSequence message, CharSequence okText) {
+ InputDialog inputDialog = new InputDialog(title, message, okText);
+ inputDialog.show();
+ return inputDialog;
+ }
+
+ public static InputDialog show(int titleResId, int messageResId, int okTextResId) {
+ InputDialog inputDialog = new InputDialog(titleResId, messageResId, okTextResId);
+ inputDialog.show();
+ return inputDialog;
+ }
+
+ public InputDialog(CharSequence title, CharSequence message, CharSequence okText, CharSequence cancelText) {
+ cancelable = DialogX.cancelable;
+ this.title = title;
+ this.message = message;
+ this.okText = okText;
+ this.cancelText = cancelText;
+ }
+
+ public InputDialog(int titleResId, int messageResId, int okTextResId, int cancelTextResId) {
+ cancelable = DialogX.cancelable;
+ this.title = getString(titleResId);
+ this.message = getString(messageResId);
+ this.okText = getString(okTextResId);
+ this.cancelText = getString(cancelTextResId);
+ }
+
+ public static InputDialog show(CharSequence title, CharSequence message, CharSequence okText, CharSequence cancelText) {
+ InputDialog inputDialog = new InputDialog(title, message, okText, cancelText);
+ inputDialog.show();
+ return inputDialog;
+ }
+
+ public static InputDialog show(int titleResId, int messageResId, int okTextResId, int cancelTextResId) {
+ InputDialog inputDialog = new InputDialog(titleResId, messageResId, okTextResId, cancelTextResId);
+ inputDialog.show();
+ return inputDialog;
+ }
+
+ public InputDialog(CharSequence title, CharSequence message, CharSequence okText, CharSequence cancelText, String inputText) {
+ cancelable = DialogX.cancelable;
+ this.title = title;
+ this.message = message;
+ this.okText = okText;
+ this.cancelText = cancelText;
+ this.inputText = inputText;
+ }
+
+ public static InputDialog show(CharSequence title, CharSequence message, CharSequence okText, CharSequence cancelText, String inputText) {
+ InputDialog inputDialog = new InputDialog(title, message, okText, cancelText, inputText);
+ inputDialog.show();
+ return inputDialog;
+ }
+
+ public InputDialog(CharSequence title, CharSequence message, CharSequence okText, CharSequence cancelText, CharSequence otherText) {
+ cancelable = DialogX.cancelable;
+ this.title = title;
+ this.message = message;
+ this.okText = okText;
+ this.cancelText = cancelText;
+ this.otherText = otherText;
+ }
+
+ public InputDialog(int titleResId, int messageResId, int okTextResId, int cancelTextResId, int otherTextResId) {
+ cancelable = DialogX.cancelable;
+ this.title = getString(titleResId);
+ this.message = getString(messageResId);
+ this.okText = getString(okTextResId);
+ this.cancelText = getString(cancelTextResId);
+ this.otherText = getString(otherTextResId);
+ }
+
+ public static InputDialog show(CharSequence title, CharSequence message, CharSequence okText, CharSequence cancelText, CharSequence otherText) {
+ InputDialog inputDialog = new InputDialog(title, message, okText, cancelText, otherText);
+ inputDialog.show();
+ return inputDialog;
+ }
+
+ public static InputDialog show(int titleResId, int messageResId, int okTextResId, int cancelTextResId, int otherTextResId) {
+ InputDialog inputDialog = new InputDialog(titleResId, messageResId, okTextResId, cancelTextResId, otherTextResId);
+ inputDialog.show();
+ return inputDialog;
+ }
+
+ public InputDialog(CharSequence title, CharSequence message, CharSequence okText, CharSequence cancelText, CharSequence otherText, String inputText) {
+ cancelable = DialogX.cancelable;
+ this.title = title;
+ this.message = message;
+ this.okText = okText;
+ this.cancelText = cancelText;
+ this.otherText = otherText;
+ this.inputText = inputText;
+ }
+
+ public InputDialog(int titleResId, int messageResId, int okTextResId, int cancelTextResId, int otherTextResId, int inputTextResId) {
+ cancelable = DialogX.cancelable;
+ this.title = getString(titleResId);
+ this.message = getString(messageResId);
+ this.okText = getString(okTextResId);
+ this.cancelText = getString(cancelTextResId);
+ this.otherText = getString(otherTextResId);
+ this.inputText = getString(inputTextResId);
+ }
+
+ public static InputDialog show(CharSequence title, CharSequence message, CharSequence okText, CharSequence cancelText, CharSequence otherText, String inputText) {
+ InputDialog inputDialog = new InputDialog(title, message, okText, cancelText, otherText, inputText);
+ inputDialog.show();
+ return inputDialog;
+ }
+
+ public static InputDialog show(int titleResId, int messageResId, int okTextResId, int cancelTextResId, int otherTextResId, int inputTextResId) {
+ InputDialog inputDialog = new InputDialog(titleResId, messageResId, okTextResId, cancelTextResId, otherTextResId, inputTextResId);
+ inputDialog.show();
+ return inputDialog;
+ }
+
+ @Override
+ public String dialogKey() {
+ return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
+ }
+
+ public CharSequence getOkButton() {
+ return okText;
+ }
+
+ public InputDialog setOkButton(CharSequence okText) {
+ this.okText = okText;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setOkButton(int okTextResId) {
+ this.okText = getString(okTextResId);
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setOkButton(OnInputDialogButtonClickListener okButtonClickListener) {
+ this.okButtonClickListener = okButtonClickListener;
+ return this;
+ }
+
+ public InputDialog setOkButton(CharSequence okText, OnInputDialogButtonClickListener okButtonClickListener) {
+ this.okText = okText;
+ this.okButtonClickListener = okButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setOkButton(int okTextResId, OnInputDialogButtonClickListener okButtonClickListener) {
+ this.okText = getString(okTextResId);
+ this.okButtonClickListener = okButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public CharSequence getCancelButton() {
+ return cancelText;
+ }
+
+ public InputDialog setCancelButton(CharSequence cancelText) {
+ this.cancelText = cancelText;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setCancelButton(int cancelTextResId) {
+ this.cancelText = getString(cancelTextResId);
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setCancelButton(OnInputDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ return this;
+ }
+
+ public InputDialog setCancelButton(CharSequence cancelText, OnInputDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelText = cancelText;
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setCancelButton(int cancelTextResId, OnInputDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelText = getString(cancelTextResId);
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public CharSequence getOtherButton() {
+ return otherText;
+ }
+
+ public InputDialog setOtherButton(CharSequence otherText) {
+ this.otherText = otherText;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setOtherButton(int otherTextResId) {
+ this.otherText = getString(otherTextResId);
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setOtherButton(OnInputDialogButtonClickListener otherButtonClickListener) {
+ this.otherButtonClickListener = otherButtonClickListener;
+ return this;
+ }
+
+ public InputDialog setOtherButton(CharSequence otherText, OnInputDialogButtonClickListener otherButtonClickListener) {
+ this.otherText = otherText;
+ this.otherButtonClickListener = otherButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setOtherButton(int otherTextResId, OnInputDialogButtonClickListener otherButtonClickListener) {
+ this.otherText = getString(otherTextResId);
+ this.otherButtonClickListener = otherButtonClickListener;
+ refreshUI();
+ return this;
+ }
+
+ public OnInputDialogButtonClickListener getInputOkButtonClickListener() {
+ return (OnInputDialogButtonClickListener) okButtonClickListener;
+ }
+
+ public InputDialog setOkButtonClickListener(OnInputDialogButtonClickListener okButtonClickListener) {
+ this.okButtonClickListener = okButtonClickListener;
+ return this;
+ }
+
+ public OnInputDialogButtonClickListener getInputCancelButtonClickListener() {
+ return (OnInputDialogButtonClickListener) cancelButtonClickListener;
+ }
+
+ public InputDialog setCancelButtonClickListener(OnInputDialogButtonClickListener cancelButtonClickListener) {
+ this.cancelButtonClickListener = cancelButtonClickListener;
+ return this;
+ }
+
+ public OnInputDialogButtonClickListener getInputOtherButtonClickListener() {
+ return (OnInputDialogButtonClickListener) otherButtonClickListener;
+ }
+
+ public InputDialog setOtherButtonClickListener(OnInputDialogButtonClickListener otherButtonClickListener) {
+ this.otherButtonClickListener = otherButtonClickListener;
+ return this;
+ }
+
+ public CharSequence getTitle() {
+ return title;
+ }
+
+ public InputDialog setTitle(CharSequence title) {
+ this.title = title;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setTitle(int titleResId) {
+ this.title = getString(titleResId);
+ refreshUI();
+ return this;
+ }
+
+ public CharSequence getMessage() {
+ return message;
+ }
+
+ public InputDialog setMessage(CharSequence message) {
+ this.message = message;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setMessage(int messageResId) {
+ this.message = getString(messageResId);
+ refreshUI();
+ return this;
+ }
+
+ public String getInputText() {
+ if (getDialogImpl() != null && getDialogImpl().txtInput != null) {
+ return getDialogImpl().txtInput.getText().toString();
+ }
+ return inputText;
+ }
+
+ public InputDialog setInputText(String inputText) {
+ this.inputText = inputText;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setInputText(int inputTextResId) {
+ this.inputText = getString(inputTextResId);
+ refreshUI();
+ return this;
+ }
+
+ public String getInputHintText() {
+ return inputHintText;
+ }
+
+ public InputDialog setInputHintText(String inputHintText) {
+ this.inputHintText = inputHintText;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setInputHintText(int inputHintTextResId) {
+ this.inputHintText = getString(inputHintTextResId);
+ refreshUI();
+ return this;
+ }
+
+ public TextInfo getTitleTextInfo() {
+ return titleTextInfo;
+ }
+
+ public InputDialog setTitleTextInfo(TextInfo titleTextInfo) {
+ this.titleTextInfo = titleTextInfo;
+ refreshUI();
+ return this;
+ }
+
+ public TextInfo getMessageTextInfo() {
+ return messageTextInfo;
+ }
+
+ public InputDialog setMessageTextInfo(TextInfo messageTextInfo) {
+ this.messageTextInfo = messageTextInfo;
+ refreshUI();
+ return this;
+ }
+
+ public TextInfo getOkTextInfo() {
+ return okTextInfo;
+ }
+
+ public InputDialog setOkTextInfo(TextInfo okTextInfo) {
+ this.okTextInfo = okTextInfo;
+ refreshUI();
+ return this;
+ }
+
+ public TextInfo getCancelTextInfo() {
+ return cancelTextInfo;
+ }
+
+ public InputDialog setCancelTextInfo(TextInfo cancelTextInfo) {
+ this.cancelTextInfo = cancelTextInfo;
+ refreshUI();
+ return this;
+ }
+
+ public TextInfo getOtherTextInfo() {
+ return otherTextInfo;
+ }
+
+ public InputDialog setOtherTextInfo(TextInfo otherTextInfo) {
+ this.otherTextInfo = otherTextInfo;
+ refreshUI();
+ return this;
+ }
+
+ public InputInfo getInputInfo() {
+ return inputInfo;
+ }
+
+ public InputDialog setInputInfo(InputInfo inputInfo) {
+ this.inputInfo = inputInfo;
+ refreshUI();
+ return this;
+ }
+
+ public int getButtonOrientation() {
+ return buttonOrientation;
+ }
+
+ public InputDialog setButtonOrientation(int buttonOrientation) {
+ this.buttonOrientation = buttonOrientation;
+ refreshUI();
+ return this;
+ }
+
+ public boolean isCancelable() {
+ if (privateCancelable != null) {
+ return privateCancelable == BOOLEAN.TRUE;
+ }
+ if (overrideCancelable != null) {
+ return overrideCancelable == BOOLEAN.TRUE;
+ }
+ return cancelable;
+ }
+
+ public InputDialog setCancelable(boolean cancelable) {
+ this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
+ refreshUI();
+ return this;
+ }
+
+ public OnBackPressedListener getOnBackPressedListener() {
+ return (OnBackPressedListener) onBackPressedListener;
+ }
+
+ public InputDialog setOnBackPressedListener(OnBackPressedListener onBackPressedListener) {
+ this.onBackPressedListener = onBackPressedListener;
+ return this;
+ }
+
+ public boolean isAutoShowInputKeyboard() {
+ return autoShowInputKeyboard;
+ }
+
+ public InputDialog setAutoShowInputKeyboard(boolean autoShowInputKeyboard) {
+ this.autoShowInputKeyboard = autoShowInputKeyboard;
+ return this;
+ }
+
+ public InputDialog setCustomView(OnBindView onBindView) {
+ this.onBindView = onBindView;
+ refreshUI();
+ return this;
+ }
+
+ public View getCustomView() {
+ if (onBindView == null) return null;
+ return onBindView.getCustomView();
+ }
+
+ public InputDialog removeCustomView() {
+ this.onBindView.clean();
+ refreshUI();
+ return this;
+ }
+
+ public int getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public InputDialog setBackgroundColor(@ColorInt int backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setBackgroundColorRes(@ColorRes int backgroundColorResId) {
+ this.backgroundColor = getColor(backgroundColorResId);
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setMaskColor(@ColorInt int maskColor) {
+ this.maskColor = maskColor;
+ refreshUI();
+ return this;
+ }
+
+ public long getEnterAnimDuration() {
+ return enterAnimDuration;
+ }
+
+ public InputDialog setEnterAnimDuration(long enterAnimDuration) {
+ this.enterAnimDuration = enterAnimDuration;
+ return this;
+ }
+
+ public long getExitAnimDuration() {
+ return exitAnimDuration;
+ }
+
+ public InputDialog setExitAnimDuration(long exitAnimDuration) {
+ this.exitAnimDuration = exitAnimDuration;
+ return this;
+ }
+
+ @Override
+ public void restartDialog() {
+ if (getDialogView() != null) {
+ dismiss(getDialogView());
+ isShow = false;
+ }
+ if (getDialogImpl().boxCustom != null) {
+ getDialogImpl().boxCustom.removeAllViews();
+ }
+ int layoutId = style.layout(isLightTheme());
+ layoutId = layoutId == 0 ? (isLightTheme() ? R.layout.layout_dialogx_material : R.layout.layout_dialogx_material_dark) : layoutId;
+
+ String inputText = getInputText();
+ enterAnimDuration = 0;
+ View dialogView = createView(layoutId);
+ dialogImpl = new DialogImpl(dialogView);
+ if (dialogView != null) dialogView.setTag(me);
+ show(dialogView);
+ setInputText(inputText);
+ }
+
+ public InputDialog setAnimResId(int enterResId, int exitResId) {
+ customEnterAnimResId = enterResId;
+ customExitAnimResId = exitResId;
+ return this;
+ }
+
+ public InputDialog setEnterAnimResId(int enterResId) {
+ customEnterAnimResId = enterResId;
+ return this;
+ }
+
+ public InputDialog setExitAnimResId(int exitResId) {
+ customExitAnimResId = exitResId;
+ return this;
+ }
+
+ public InputDialog setMaxWidth(int maxWidth) {
+ this.maxWidth = maxWidth;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setMaxHeight(int maxHeight) {
+ this.maxHeight = maxHeight;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setMinHeight(int minHeight) {
+ this.minHeight = minHeight;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setMinWidth(int minWidth) {
+ this.minWidth = minWidth;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setDialogImplMode(DialogX.IMPL_MODE dialogImplMode) {
+ this.dialogImplMode = dialogImplMode;
+ return this;
+ }
+
+ public boolean isBkgInterceptTouch() {
+ return bkgInterceptTouch;
+ }
+
+ public InputDialog setBkgInterceptTouch(boolean bkgInterceptTouch) {
+ this.bkgInterceptTouch = bkgInterceptTouch;
+ return this;
+ }
+
+ public OnBackgroundMaskClickListener getOnBackgroundMaskClickListener() {
+ return onBackgroundMaskClickListener;
+ }
+
+ public InputDialog setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener onBackgroundMaskClickListener) {
+ this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
+ return this;
+ }
+
+ public InputDialog setRadius(float radiusPx) {
+ backgroundRadius = radiusPx;
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setTitleIcon(Bitmap titleIcon) {
+ this.titleIcon = new BitmapDrawable(getResources(), titleIcon);
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setTitleIcon(int titleIconResId) {
+ this.titleIcon = getResources().getDrawable(titleIconResId);
+ refreshUI();
+ return this;
+ }
+
+ public InputDialog setTitleIcon(Drawable titleIcon) {
+ this.titleIcon = titleIcon;
+ refreshUI();
+ return this;
+ }
+
+ public DialogXAnimInterface