|
@@ -14,6 +14,7 @@ import android.view.animation.DecelerateInterpolator;
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
|
|
import androidx.annotation.ColorInt;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
import androidx.lifecycle.Lifecycle;
|
|
|
|
|
|
import com.kongzue.dialogx.DialogX;
|
|
@@ -38,7 +39,7 @@ import com.kongzue.dialogx.util.views.MaxRelativeLayout;
|
|
|
* @createTime: 2020/10/20 11:59
|
|
|
*/
|
|
|
public class CustomDialog extends BaseDialog {
|
|
|
-
|
|
|
+
|
|
|
public static int overrideEnterDuration = -1;
|
|
|
public static int overrideExitDuration = -1;
|
|
|
public static int overrideEnterAnimRes = 0;
|
|
@@ -59,14 +60,14 @@ public class CustomDialog extends BaseDialog {
|
|
|
protected boolean bkgInterceptTouch = true;
|
|
|
protected OnBackgroundMaskClickListener<CustomDialog> onBackgroundMaskClickListener;
|
|
|
protected DialogXAnimInterface<CustomDialog> dialogXAnimImpl;
|
|
|
-
|
|
|
+
|
|
|
protected View baseView;
|
|
|
protected int alignViewGravity = -1; //指定菜单相对 baseView 的位置
|
|
|
protected int width = -1; //指定菜单宽度
|
|
|
protected int height = -1; //指定菜单高度
|
|
|
protected int[] baseViewLoc;
|
|
|
protected int[] marginRelativeBaseView = new int[4];
|
|
|
-
|
|
|
+
|
|
|
public enum ALIGN {
|
|
|
CENTER,
|
|
|
TOP,
|
|
@@ -86,47 +87,41 @@ public class CustomDialog extends BaseDialog {
|
|
|
RIGHT_TOP,
|
|
|
RIGHT_BOTTOM
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected CustomDialog() {
|
|
|
super();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static CustomDialog build() {
|
|
|
return new CustomDialog();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static CustomDialog build(OnBindView<CustomDialog> onBindView) {
|
|
|
return new CustomDialog().setCustomView(onBindView);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog(OnBindView<CustomDialog> onBindView) {
|
|
|
this.onBindView = onBindView;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static CustomDialog show(OnBindView<CustomDialog> onBindView) {
|
|
|
CustomDialog customDialog = new CustomDialog(onBindView);
|
|
|
customDialog.show();
|
|
|
return customDialog;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static CustomDialog show(OnBindView<CustomDialog> onBindView, ALIGN align) {
|
|
|
CustomDialog customDialog = new CustomDialog(onBindView);
|
|
|
customDialog.align = align;
|
|
|
customDialog.show();
|
|
|
return customDialog;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog show() {
|
|
|
if (isHide && getDialogView() != null && isShow) {
|
|
|
if (hideWithExitAnim && getDialogImpl() != null && getDialogImpl().boxCustom != null) {
|
|
|
getDialogView().setVisibility(View.VISIBLE);
|
|
|
- getDialogImpl().getDialogXAnimImpl().doShowAnim(CustomDialog.this, new ObjectRunnable<Float>() {
|
|
|
- @Override
|
|
|
- public void run(Float animProgress) {
|
|
|
- float value = animProgress;
|
|
|
- getDialogImpl().boxRoot.setBkgAlpha(value);
|
|
|
- }
|
|
|
- });
|
|
|
+ getDialogImpl().getDialogXAnimImpl().doShowAnim(CustomDialog.this, getDialogImpl().boxCustom);
|
|
|
getDialogImpl().boxCustom.setVisibility(View.VISIBLE);
|
|
|
getDialogImpl().boxCustom.startAnimation(getEnterAnimation());
|
|
|
} else {
|
|
@@ -143,7 +138,7 @@ public class CustomDialog extends BaseDialog {
|
|
|
show(dialogView);
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog show(Activity activity) {
|
|
|
super.beforeShow();
|
|
|
if (getDialogView() == null) {
|
|
@@ -154,25 +149,25 @@ public class CustomDialog extends BaseDialog {
|
|
|
show(activity, dialogView);
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private ViewTreeObserver viewTreeObserver;
|
|
|
private ViewTreeObserver.OnDrawListener baseViewDrawListener;
|
|
|
-
|
|
|
+
|
|
|
public class DialogImpl implements DialogConvertViewInterface {
|
|
|
-
|
|
|
+
|
|
|
public DialogXBaseRelativeLayout boxRoot;
|
|
|
public MaxRelativeLayout boxCustom;
|
|
|
-
|
|
|
+
|
|
|
public DialogImpl(View convertView) {
|
|
|
if (convertView == null) return;
|
|
|
boxRoot = convertView.findViewById(R.id.box_root);
|
|
|
boxCustom = convertView.findViewById(R.id.box_custom);
|
|
|
-
|
|
|
+
|
|
|
init();
|
|
|
dialogImpl = this;
|
|
|
refreshView();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void init() {
|
|
|
if (baseViewLoc == null && baseView != null) {
|
|
@@ -187,16 +182,16 @@ public class CustomDialog extends BaseDialog {
|
|
|
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;
|
|
@@ -208,7 +203,7 @@ public class CustomDialog extends BaseDialog {
|
|
|
System.gc();
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
boxRoot.setOnBackPressedListener(new DialogXBaseRelativeLayout.PrivateBackPressedListener() {
|
|
|
@Override
|
|
|
public boolean onBackPressed() {
|
|
@@ -224,33 +219,25 @@ public class CustomDialog extends BaseDialog {
|
|
|
return true;
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
boxRoot.post(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- getDialogXAnimImpl().doShowAnim(CustomDialog.this, new ObjectRunnable<Float>() {
|
|
|
- @Override
|
|
|
- public void run(Float animProgress) {
|
|
|
- float value = animProgress;
|
|
|
- if (boxRoot != null) {
|
|
|
- boxRoot.setBkgAlpha(value);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ getDialogXAnimImpl().doShowAnim(CustomDialog.this, boxCustom);
|
|
|
if (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) {
|
|
@@ -264,7 +251,7 @@ public class CustomDialog extends BaseDialog {
|
|
|
rlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
boxCustom.setLayoutParams(rlp);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Runnable onLayoutChangeRunnable = new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
@@ -282,7 +269,7 @@ public class CustomDialog extends BaseDialog {
|
|
|
calX = (baseViewLeft + baseView.getMeasuredWidth() / 2 - boxCustom.getWidth() / 2);
|
|
|
calY = (baseViewTop + baseView.getMeasuredHeight() / 2 - boxCustom.getHeight() / 2);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (isAlignBaseViewGravity(Gravity.TOP)) {
|
|
|
calY = baseViewTop - boxCustom.getHeight() - marginRelativeBaseView[3];
|
|
|
}
|
|
@@ -299,15 +286,15 @@ public class CustomDialog extends BaseDialog {
|
|
|
int heightCache = height == 0 ? baseView.getHeight() : height;
|
|
|
baseViewLoc[2] = widthCache > 0 ? widthCache : baseViewLoc[2];
|
|
|
baseViewLoc[3] = heightCache > 0 ? heightCache : baseViewLoc[3];
|
|
|
-
|
|
|
+
|
|
|
if (calX != 0 && calX != boxCustom.getX()) boxCustom.setX(calX);
|
|
|
if (calY != 0 && calY != boxCustom.getY()) boxCustom.setY(calY);
|
|
|
-
|
|
|
+
|
|
|
onGetBaseViewLoc(baseViewLoc);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
viewTreeObserver = boxCustom.getViewTreeObserver();
|
|
|
viewTreeObserver.addOnDrawListener(baseViewDrawListener = new ViewTreeObserver.OnDrawListener() {
|
|
|
@Override
|
|
@@ -394,7 +381,7 @@ public class CustomDialog extends BaseDialog {
|
|
|
boxCustom.setLayoutParams(rlp);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
boxRoot.setAutoUnsafePlacePadding(autoUnsafePlacePadding);
|
|
|
if (bkgInterceptTouch) {
|
|
|
if (isCancelable()) {
|
|
@@ -412,30 +399,28 @@ public class CustomDialog extends BaseDialog {
|
|
|
} else {
|
|
|
boxRoot.setClickable(false);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (onBindView != null && onBindView.getCustomView() != null && boxCustom != null) {
|
|
|
onBindView.bindParent(boxCustom, me);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (boxCustom != null) {
|
|
|
if (width != -1) {
|
|
|
boxCustom.setMaxWidth(width);
|
|
|
boxCustom.setMinimumWidth(width);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (height != -1) {
|
|
|
boxCustom.setMaxHeight(height);
|
|
|
boxCustom.setMinimumHeight(height);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
boxRoot.setBackgroundColor(getMaskColor());
|
|
|
-
|
|
|
+
|
|
|
onDialogRefreshUI();
|
|
|
}
|
|
|
-
|
|
|
- long exitAnimDurationTemp = -1;
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void doDismiss(View v) {
|
|
|
if (v != null) v.setEnabled(false);
|
|
@@ -444,65 +429,61 @@ public class CustomDialog extends BaseDialog {
|
|
|
boxCustom.post(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- getDialogXAnimImpl().doExitAnim(CustomDialog.this, new ObjectRunnable<Float>() {
|
|
|
-
|
|
|
+ getDialogXAnimImpl().doExitAnim(CustomDialog.this, boxCustom);
|
|
|
+ runOnMainDelay(new Runnable() {
|
|
|
@Override
|
|
|
- public void run(Float animProgress) {
|
|
|
- float value = animProgress;
|
|
|
- if (boxRoot != null) {
|
|
|
- boxRoot.setBkgAlpha(value);
|
|
|
- }
|
|
|
- if (value == 0) {
|
|
|
- if (boxRoot != null) boxRoot.setVisibility(View.GONE);
|
|
|
- if (baseViewDrawListener != null) {
|
|
|
- if (viewTreeObserver != null) {
|
|
|
- removeDrawListener(viewTreeObserver, baseViewDrawListener);
|
|
|
- } else {
|
|
|
- if (boxCustom != null) {
|
|
|
- removeDrawListener(boxCustom.getViewTreeObserver(), baseViewDrawListener);
|
|
|
- }
|
|
|
+ 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(dialogView);
|
|
|
+ baseViewDrawListener = null;
|
|
|
+ viewTreeObserver = null;
|
|
|
}
|
|
|
+ dismiss(dialogView);
|
|
|
}
|
|
|
- });
|
|
|
+ }, getExitAnimationDuration(null));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected DialogXAnimInterface<CustomDialog> getDialogXAnimImpl() {
|
|
|
if (dialogXAnimImpl == null) {
|
|
|
dialogXAnimImpl = new DialogXAnimInterface<CustomDialog>() {
|
|
|
@Override
|
|
|
- public void doShowAnim(CustomDialog customDialog, ObjectRunnable<Float> animProgress) {
|
|
|
+ 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(enterAnim.getDuration());
|
|
|
+ bkgAlpha.setDuration(enterAnimationDuration);
|
|
|
bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
|
@Override
|
|
|
public void onAnimationUpdate(ValueAnimator animation) {
|
|
|
- animProgress.run((Float) animation.getAnimatedValue());
|
|
|
+ boxRoot.setBkgAlpha((Float) animation.getAnimatedValue());
|
|
|
}
|
|
|
});
|
|
|
bkgAlpha.start();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
- public void doExitAnim(CustomDialog customDialog, ObjectRunnable<Float> animProgress) {
|
|
|
+ public void doExitAnim(CustomDialog customDialog, ViewGroup dialogBodyView) {
|
|
|
if (getDialogImpl() == null || getDialogImpl().boxCustom == null) {
|
|
|
return;
|
|
|
}
|
|
@@ -513,26 +494,23 @@ public class CustomDialog extends BaseDialog {
|
|
|
if (exitAnimResId != 0) {
|
|
|
exitAnimResIdTemp = exitAnimResId;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ long exitAnimDurationTemp;
|
|
|
if (boxCustom != null) {
|
|
|
Animation exitAnim = AnimationUtils.loadAnimation(getOwnActivity() == null ? boxCustom.getContext() : getOwnActivity(), exitAnimResIdTemp);
|
|
|
- exitAnimDurationTemp = exitAnim.getDuration();
|
|
|
- if (overrideExitDuration >= 0) {
|
|
|
- exitAnimDurationTemp = overrideExitDuration;
|
|
|
- }
|
|
|
- if (exitAnimDuration >= 0) {
|
|
|
- exitAnimDurationTemp = exitAnimDuration;
|
|
|
- }
|
|
|
+ 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) {
|
|
|
- animProgress.run((Float) animation.getAnimatedValue());
|
|
|
+ boxRoot.setBkgAlpha((Float) animation.getAnimatedValue());
|
|
|
}
|
|
|
});
|
|
|
bkgAlpha.start();
|
|
@@ -541,8 +519,36 @@ public class CustomDialog extends BaseDialog {
|
|
|
}
|
|
|
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.OnDrawListener listener) {
|
|
|
if (viewTreeObserver == null || listener == null || !viewTreeObserver.isAlive()) {
|
|
|
return;
|
|
@@ -552,7 +558,7 @@ public class CustomDialog extends BaseDialog {
|
|
|
} catch (Exception e) {
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private Animation getEnterAnimation() {
|
|
|
Animation enterAnim;
|
|
|
if (enterAnimResId == R.anim.anim_dialogx_default_enter &&
|
|
@@ -610,15 +616,15 @@ public class CustomDialog extends BaseDialog {
|
|
|
enterAnim.setDuration(enterAnimDurationTemp);
|
|
|
return enterAnim;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected void onGetBaseViewLoc(int[] baseViewLoc) {
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public String dialogKey() {
|
|
|
return getClass().getSimpleName() + "(" + Integer.toHexString(hashCode()) + ")";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void refreshUI() {
|
|
|
if (getDialogImpl() == null) return;
|
|
|
runOnMain(new Runnable() {
|
|
@@ -628,7 +634,7 @@ public class CustomDialog extends BaseDialog {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void dismiss() {
|
|
|
runOnMain(new Runnable() {
|
|
|
@Override
|
|
@@ -638,38 +644,38 @@ public class CustomDialog extends BaseDialog {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public DialogLifecycleCallback<CustomDialog> getDialogLifecycleCallback() {
|
|
|
return dialogLifecycleCallback == null ? new DialogLifecycleCallback<CustomDialog>() {
|
|
|
} : dialogLifecycleCallback;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setDialogLifecycleCallback(DialogLifecycleCallback<CustomDialog> dialogLifecycleCallback) {
|
|
|
this.dialogLifecycleCallback = dialogLifecycleCallback;
|
|
|
if (isShow) dialogLifecycleCallback.onShow(me);
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public OnBackPressedListener<CustomDialog> getOnBackPressedListener() {
|
|
|
return (OnBackPressedListener<CustomDialog>) onBackPressedListener;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setOnBackPressedListener(OnBackPressedListener<CustomDialog> onBackPressedListener) {
|
|
|
this.onBackPressedListener = onBackPressedListener;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setStyle(DialogXStyle style) {
|
|
|
this.style = style;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setTheme(DialogX.THEME theme) {
|
|
|
this.theme = theme;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public boolean isCancelable() {
|
|
|
if (privateCancelable != null) {
|
|
|
return privateCancelable == BOOLEAN.TRUE;
|
|
@@ -679,112 +685,112 @@ public class CustomDialog extends BaseDialog {
|
|
|
}
|
|
|
return cancelable;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setCancelable(boolean cancelable) {
|
|
|
this.privateCancelable = cancelable ? BOOLEAN.TRUE : BOOLEAN.FALSE;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog.DialogImpl getDialogImpl() {
|
|
|
return dialogImpl;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setCustomView(OnBindView<CustomDialog> onBindView) {
|
|
|
this.onBindView = onBindView;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public View getCustomView() {
|
|
|
if (onBindView == null) return null;
|
|
|
return onBindView.getCustomView();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog removeCustomView() {
|
|
|
this.onBindView.clean();
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int getEnterAnimResId() {
|
|
|
return enterAnimResId;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setEnterAnimResId(int enterAnimResId) {
|
|
|
this.enterAnimResId = enterAnimResId;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int getExitAnimResId() {
|
|
|
return exitAnimResId;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setExitAnimResId(int exitAnimResId) {
|
|
|
this.exitAnimResId = exitAnimResId;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setAnimResId(int enterAnimResId, int exitAnimResId) {
|
|
|
this.enterAnimResId = enterAnimResId;
|
|
|
this.exitAnimResId = exitAnimResId;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public ALIGN getAlign() {
|
|
|
return align;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setAlign(ALIGN align) {
|
|
|
this.align = align;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public boolean isAutoUnsafePlacePadding() {
|
|
|
return autoUnsafePlacePadding;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setAutoUnsafePlacePadding(boolean autoUnsafePlacePadding) {
|
|
|
this.autoUnsafePlacePadding = autoUnsafePlacePadding;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setFullScreen(boolean fullscreen) {
|
|
|
this.autoUnsafePlacePadding = !autoUnsafePlacePadding;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setMaskColor(@ColorInt int maskColor) {
|
|
|
this.maskColor = maskColor;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int getMaskColor() {
|
|
|
return maskColor;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public long getEnterAnimDuration() {
|
|
|
return enterAnimDuration;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setEnterAnimDuration(long enterAnimDuration) {
|
|
|
this.enterAnimDuration = enterAnimDuration;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public long getExitAnimDuration() {
|
|
|
return exitAnimDuration;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setExitAnimDuration(long exitAnimDuration) {
|
|
|
this.exitAnimDuration = exitAnimDuration;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void restartDialog() {
|
|
|
if (dialogView != null) {
|
|
@@ -807,16 +813,16 @@ public class CustomDialog extends BaseDialog {
|
|
|
if (getDialogImpl() != null && getDialogImpl().boxCustom != null) {
|
|
|
getDialogImpl().boxCustom.removeAllViews();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
enterAnimDuration = 0;
|
|
|
dialogView = createView(R.layout.layout_dialogx_custom);
|
|
|
dialogImpl = new DialogImpl(dialogView);
|
|
|
if (dialogView != null) dialogView.setTag(me);
|
|
|
show(dialogView);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private boolean isHide;
|
|
|
-
|
|
|
+
|
|
|
public void hide() {
|
|
|
isHide = true;
|
|
|
hideWithExitAnim = false;
|
|
@@ -824,54 +830,50 @@ public class CustomDialog extends BaseDialog {
|
|
|
getDialogView().setVisibility(View.GONE);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected boolean hideWithExitAnim;
|
|
|
-
|
|
|
+
|
|
|
public void hideWithExitAnim() {
|
|
|
hideWithExitAnim = true;
|
|
|
isHide = true;
|
|
|
if (getDialogImpl() != null) {
|
|
|
- getDialogImpl().getDialogXAnimImpl().doExitAnim(CustomDialog.this, new ObjectRunnable<Float>() {
|
|
|
+ getDialogImpl().getDialogXAnimImpl().doExitAnim(CustomDialog.this, getDialogImpl().boxCustom);
|
|
|
+
|
|
|
+ runOnMainDelay(new Runnable() {
|
|
|
@Override
|
|
|
- public void run(Float animProgress) {
|
|
|
- float value = animProgress;
|
|
|
- if (getDialogImpl().boxRoot != null) {
|
|
|
- getDialogImpl().boxRoot.setBkgAlpha(value);
|
|
|
- }
|
|
|
- if (value == 0) {
|
|
|
- if (getDialogView() != null) {
|
|
|
- getDialogView().setVisibility(View.GONE);
|
|
|
- }
|
|
|
+ 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;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 判断是否有设置对应的位置关系
|
|
|
*
|
|
@@ -881,7 +883,7 @@ public class CustomDialog extends BaseDialog {
|
|
|
public boolean isAlignBaseViewGravity(int gravity) {
|
|
|
return (alignViewGravity & gravity) == gravity;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setAlignBaseViewGravity(View baseView, int alignGravity) {
|
|
|
this.baseView = baseView;
|
|
|
this.alignViewGravity = alignGravity;
|
|
@@ -890,7 +892,7 @@ public class CustomDialog extends BaseDialog {
|
|
|
setFullScreen(true);
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setAlignBaseView(View baseView) {
|
|
|
this.baseView = baseView;
|
|
|
baseViewLoc = new int[4];
|
|
@@ -898,7 +900,7 @@ public class CustomDialog extends BaseDialog {
|
|
|
setFullScreen(true);
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setAlignBaseViewGravity(int alignGravity) {
|
|
|
this.alignViewGravity = alignGravity;
|
|
|
if (baseView != null) {
|
|
@@ -908,79 +910,79 @@ public class CustomDialog extends BaseDialog {
|
|
|
setFullScreen(true);
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setAlignBaseViewGravity(View baseView, int alignGravity, int marginLeft,
|
|
|
int marginTop, int marginRight, int marginBottom) {
|
|
|
this.marginRelativeBaseView = new int[]{marginLeft, marginTop, marginRight, marginBottom};
|
|
|
refreshUI();
|
|
|
return setAlignBaseViewGravity(baseView, alignGravity);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int[] getBaseViewMargin() {
|
|
|
return marginRelativeBaseView;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setBaseViewMargin(int[] marginRelativeBaseView) {
|
|
|
this.marginRelativeBaseView = marginRelativeBaseView;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setBaseViewMargin(int marginLeft, int marginTop,
|
|
|
int marginRight, int marginBottom) {
|
|
|
this.marginRelativeBaseView = new int[]{marginLeft, marginTop, marginRight, marginBottom};
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setBaseViewMarginLeft(int marginLeft) {
|
|
|
this.marginRelativeBaseView[0] = marginLeft;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setBaseViewMarginTop(int marginTop) {
|
|
|
this.marginRelativeBaseView[1] = marginTop;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setBaseViewMarginRight(int marginRight) {
|
|
|
this.marginRelativeBaseView[2] = marginRight;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setBaseViewMarginBottom(int marginBottom) {
|
|
|
this.marginRelativeBaseView[3] = marginBottom;
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int getBaseViewMarginLeft(int marginLeft) {
|
|
|
return this.marginRelativeBaseView[0];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int getBaseViewMarginTop(int marginLeft) {
|
|
|
return this.marginRelativeBaseView[1];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int getBaseViewMarginRight(int marginLeft) {
|
|
|
return this.marginRelativeBaseView[2];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int getBaseViewMarginBottom(int marginLeft) {
|
|
|
return this.marginRelativeBaseView[3];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public View getBaseView() {
|
|
|
return baseView;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int getWidth() {
|
|
|
return width;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 设置对话框 UI 宽度(单位:像素)
|
|
|
*
|
|
@@ -992,11 +994,11 @@ public class CustomDialog extends BaseDialog {
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int getHeight() {
|
|
|
return height;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 设置对话框 UI 高度(单位:像素)
|
|
|
*
|
|
@@ -1008,37 +1010,37 @@ public class CustomDialog extends BaseDialog {
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public OnBackgroundMaskClickListener<CustomDialog> getOnBackgroundMaskClickListener() {
|
|
|
return onBackgroundMaskClickListener;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setOnBackgroundMaskClickListener(OnBackgroundMaskClickListener<CustomDialog> onBackgroundMaskClickListener) {
|
|
|
this.onBackgroundMaskClickListener = onBackgroundMaskClickListener;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public DialogXAnimInterface<CustomDialog> getDialogXAnimImpl() {
|
|
|
return dialogXAnimImpl;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setDialogXAnimImpl(DialogXAnimInterface<CustomDialog> dialogXAnimImpl) {
|
|
|
this.dialogXAnimImpl = dialogXAnimImpl;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setRootPadding(int padding) {
|
|
|
this.screenPaddings = new int[]{padding, padding, padding, padding};
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public CustomDialog setRootPadding(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
|
|
|
this.screenPaddings = new int[]{paddingLeft, paddingTop, paddingRight, paddingBottom};
|
|
|
refreshUI();
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 用于使用 new 构建实例时,override 的生命周期事件
|
|
|
* 例如:
|
|
@@ -1051,9 +1053,9 @@ public class CustomDialog extends BaseDialog {
|
|
|
* }
|
|
|
*/
|
|
|
public void onShow(CustomDialog dialog) {
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 用于使用 new 构建实例时,override 的生命周期事件
|
|
|
* 例如:
|
|
@@ -1075,6 +1077,6 @@ public class CustomDialog extends BaseDialog {
|
|
|
*/
|
|
|
//用于使用 new 构建实例时,override 的生命周期事件
|
|
|
public void onDismiss(CustomDialog dialog) {
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|