|
@@ -1,6 +1,7 @@
|
|
|
package com.kongzue.dialogx.dialogs;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
import android.content.res.Configuration;
|
|
|
import android.graphics.Color;
|
|
|
import android.view.View;
|
|
@@ -31,6 +32,12 @@ import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
|
|
|
*/
|
|
|
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 int overrideMaskEnterAnimRes = R.anim.anim_dialogx_default_alpha_enter;
|
|
|
+ public static int overrideMaskExitAnimRes = R.anim.anim_dialogx_default_exit;
|
|
|
public static BOOLEAN overrideCancelable;
|
|
|
protected OnBindView<CustomDialog> onBindView;
|
|
|
protected DialogLifecycleCallback<CustomDialog> dialogLifecycleCallback;
|
|
@@ -138,38 +145,10 @@ public class CustomDialog extends BaseDialog {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- RelativeLayout.LayoutParams rlp;
|
|
|
- rlp = ((RelativeLayout.LayoutParams) boxCustom.getLayoutParams());
|
|
|
- switch (align) {
|
|
|
- case TOP:
|
|
|
- rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
- rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
|
- break;
|
|
|
- case BOTTOM:
|
|
|
- rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
- rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
|
|
- break;
|
|
|
- case CENTER:
|
|
|
- rlp.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
|
- rlp.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
|
|
- rlp.addRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
- break;
|
|
|
- case LEFT:
|
|
|
- rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
- rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
|
- rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
|
|
|
- break;
|
|
|
- case RIGHT:
|
|
|
- rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
- rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
|
- rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
|
|
- break;
|
|
|
- }
|
|
|
- boxCustom.setLayoutParams(rlp);
|
|
|
-
|
|
|
boxRoot.post(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
+ Animation enterAnim;
|
|
|
if (enterAnimResId == R.anim.anim_dialogx_default_enter && exitAnimResId == R.anim.anim_dialogx_default_exit) {
|
|
|
switch (align) {
|
|
|
case TOP:
|
|
@@ -189,25 +168,71 @@ public class CustomDialog extends BaseDialog {
|
|
|
exitAnimResId = R.anim.anim_dialogx_right_exit;
|
|
|
break;
|
|
|
}
|
|
|
- }
|
|
|
- Animation enterAnim;
|
|
|
- if (enterAnimResId == R.anim.anim_dialogx_default_enter) {
|
|
|
- enterAnim = AnimationUtils.loadAnimation(getContext(), R.anim.anim_dialogx_default_enter);
|
|
|
+ enterAnim = AnimationUtils.loadAnimation(getContext(), enterAnimResId);
|
|
|
enterAnim.setInterpolator(new DecelerateInterpolator(2f));
|
|
|
} else {
|
|
|
- enterAnim = AnimationUtils.loadAnimation(getContext(), enterAnimResId);
|
|
|
+ int enterAnimResIdTemp = R.anim.anim_dialogx_default_enter;
|
|
|
+ if (overrideEnterAnimRes != 0) {
|
|
|
+ enterAnimResIdTemp = overrideEnterAnimRes;
|
|
|
+ }
|
|
|
+ if (enterAnimResId != 0) {
|
|
|
+ enterAnimResIdTemp = enterAnimResId;
|
|
|
+ }
|
|
|
+ enterAnim = AnimationUtils.loadAnimation(getContext(), enterAnimResIdTemp);
|
|
|
}
|
|
|
- if (enterAnimDuration != -1) {
|
|
|
- enterAnim.setDuration(enterAnimDuration);
|
|
|
+ long enterAnimDurationTemp = enterAnim.getDuration();
|
|
|
+ if (overrideEnterDuration >= 0) {
|
|
|
+ enterAnimDurationTemp = overrideEnterDuration;
|
|
|
}
|
|
|
+ if (enterAnimDuration >= 0) {
|
|
|
+ enterAnimDurationTemp = enterAnimDuration;
|
|
|
+ }
|
|
|
+ enterAnim.setDuration(enterAnimDurationTemp);
|
|
|
boxCustom.setVisibility(View.VISIBLE);
|
|
|
boxCustom.startAnimation(enterAnim);
|
|
|
+
|
|
|
+ boxRoot.setBackgroundColor(maskColor);
|
|
|
+ if (overrideMaskEnterAnimRes != 0) {
|
|
|
+ Animation maskEnterAnim = AnimationUtils.loadAnimation(getContext(), overrideMaskEnterAnimRes);
|
|
|
+ maskEnterAnim.setInterpolator(new DecelerateInterpolator(2f));
|
|
|
+ maskEnterAnim.setDuration(enterAnimDurationTemp);
|
|
|
+ boxRoot.startAnimation(maskEnterAnim);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void refreshView() {
|
|
|
+ RelativeLayout.LayoutParams rlp;
|
|
|
+ rlp = ((RelativeLayout.LayoutParams) boxCustom.getLayoutParams());
|
|
|
+ switch (align) {
|
|
|
+ case TOP:
|
|
|
+ rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
+ rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
|
+ break;
|
|
|
+ case BOTTOM:
|
|
|
+ rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
+ rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
|
|
+ break;
|
|
|
+ case CENTER:
|
|
|
+ rlp.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
|
+ rlp.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
|
|
+ rlp.addRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
+ break;
|
|
|
+ case LEFT:
|
|
|
+ rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
+ rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
|
+ rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
|
|
|
+ break;
|
|
|
+ case RIGHT:
|
|
|
+ rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
+ rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
|
+ rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ boxCustom.setLayoutParams(rlp);
|
|
|
+
|
|
|
boxRoot.setAutoUnsafePlacePadding(autoUnsafePlacePadding);
|
|
|
if (isCancelable()) {
|
|
|
boxRoot.setOnClickListener(new View.OnClickListener() {
|
|
@@ -220,8 +245,6 @@ public class CustomDialog extends BaseDialog {
|
|
|
boxRoot.setOnClickListener(null);
|
|
|
}
|
|
|
|
|
|
- boxRoot.setBackgroundColor(maskColor);
|
|
|
-
|
|
|
if (onBindView != null && onBindView.getCustomView() != null) {
|
|
|
onBindView.bindParent(boxCustom, me);
|
|
|
}
|
|
@@ -231,11 +254,23 @@ public class CustomDialog extends BaseDialog {
|
|
|
public void doDismiss(View v) {
|
|
|
if (v != null) v.setEnabled(false);
|
|
|
|
|
|
- Animation exitAnim = AnimationUtils.loadAnimation(getContext(), exitAnimResId);
|
|
|
- if (exitAnimDuration != -1) {
|
|
|
- exitAnim.setDuration(exitAnimDuration);
|
|
|
+ int exitAnimResIdTemp = R.anim.anim_dialogx_default_exit;
|
|
|
+ if (overrideExitAnimRes != 0) {
|
|
|
+ exitAnimResIdTemp = overrideExitAnimRes;
|
|
|
}
|
|
|
- boxCustom.startAnimation(exitAnim);
|
|
|
+ if (exitAnimResId != 0) {
|
|
|
+ exitAnimResIdTemp = exitAnimResId;
|
|
|
+ }
|
|
|
+ Animation exitAnim = AnimationUtils.loadAnimation(getContext(), exitAnimResIdTemp);
|
|
|
+
|
|
|
+ long exitAnimDurationTemp = exitAnim.getDuration();
|
|
|
+ if (overrideExitDuration >= 0) {
|
|
|
+ exitAnimDurationTemp = overrideExitDuration;
|
|
|
+ }
|
|
|
+ if (exitAnimDuration >= 0) {
|
|
|
+ exitAnimDurationTemp = exitAnimDuration;
|
|
|
+ }
|
|
|
+ exitAnim.setDuration(exitAnimDurationTemp);
|
|
|
exitAnim.setAnimationListener(new Animation.AnimationListener() {
|
|
|
@Override
|
|
|
public void onAnimationStart(Animation animation) {
|
|
@@ -252,6 +287,14 @@ public class CustomDialog extends BaseDialog {
|
|
|
|
|
|
}
|
|
|
});
|
|
|
+ boxCustom.startAnimation(exitAnim);
|
|
|
+
|
|
|
+ if (overrideMaskExitAnimRes != 0) {
|
|
|
+ Animation maskExitAnim = AnimationUtils.loadAnimation(getContext(), overrideMaskExitAnimRes);
|
|
|
+ maskExitAnim.setDuration(exitAnimDurationTemp);
|
|
|
+ maskExitAnim.setInterpolator(new DecelerateInterpolator(2f));
|
|
|
+ boxRoot.startAnimation(maskExitAnim);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|