BottomTopBaseDialog.java
3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.xdy.ui.dialog;
import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
public abstract class BottomTopBaseDialog extends BaseDialog {
protected View animateView;
private BaseAnimatorSet windowInAs;
private BaseAnimatorSet windowOutAs;
protected Animation innerShowAnim;
protected Animation innerDismissAnim;
protected long innerAnimDuration = 350;
protected boolean isInnerShowAnim;
protected boolean isInnerDismissAnim;
protected int left, top, right, bottom;
public BottomTopBaseDialog(Context context) {
super(context);
}
/**
* set duration for inner animation of animateView(设置animateView内置动画时长)
* @param innerAnimDuration
*/
public void innerAnimDuration(long innerAnimDuration) {
this.innerAnimDuration = innerAnimDuration;
}
public void padding(int left, int top, int right, int bottom) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
/**
* show dialog and animateView with inner show animation(设置dialog和animateView显示动画)
*/
protected void showWithAnim() {
if (innerShowAnim != null) {
innerShowAnim.setDuration(innerAnimDuration);
innerShowAnim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
isInnerShowAnim = true;
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
isInnerShowAnim = false;
}
});
ll_control_height.startAnimation(innerShowAnim);
}
if (animateView != null) {
if (getWindowInAs() != null) {
windowInAs = getWindowInAs();
}
windowInAs.duration(innerAnimDuration).playOn(animateView);
}
}
/**
* dimiss dialog and animateView with inner dismiss animation(设置dialog和animateView消失动画)
*/
protected void dismissWithAnim() {
if (innerDismissAnim != null) {
innerDismissAnim.setDuration(innerAnimDuration);
innerDismissAnim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
isInnerDismissAnim = true;
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
isInnerDismissAnim = false;
superDismiss();
}
});
ll_control_height.startAnimation(innerDismissAnim);
} else {
superDismiss();
}
if (animateView != null) {
if (getWindowOutAs() != null) {
windowOutAs = getWindowOutAs();
}
windowOutAs.duration(innerAnimDuration).playOn(animateView);
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (isInnerDismissAnim || isInnerShowAnim) {
return true;
}
return super.dispatchTouchEvent(ev);
}
@Override
public void onBackPressed() {
if (isInnerDismissAnim || isInnerShowAnim) {
return;
}
super.onBackPressed();
}
protected abstract BaseAnimatorSet getWindowInAs();
protected abstract BaseAnimatorSet getWindowOutAs();
}