forked from razerdp/BasePopup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentPopup.java
More file actions
171 lines (140 loc) · 5.49 KB
/
CommentPopup.java
File metadata and controls
171 lines (140 loc) · 5.49 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package razerdp.demo.popup;
import android.content.Context;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import razerdp.basepopup.BasePopupWindow;
import razerdp.basepopup.R;
/**
* Created by 大灯泡 on 2016/1/16.
* 微信朋友圈评论弹窗
*/
public class CommentPopup extends BasePopupWindow implements View.OnClickListener {
private ImageView mLikeAnimaView;
private TextView mLikeText;
private View mLikeClikcLayout;
private View mCommentClickLayout;
private OnCommentPopupClickListener mOnCommentPopupClickListener;
private Handler mHandler;
public CommentPopup(Context context) {
super(context);
mHandler = new Handler();
mLikeAnimaView = (ImageView) findViewById(R.id.iv_like);
mLikeText = (TextView) findViewById(R.id.tv_like);
mLikeClikcLayout = findViewById(R.id.item_like);
mCommentClickLayout = findViewById(R.id.item_comment);
mLikeClikcLayout.setOnClickListener(this);
mCommentClickLayout.setOnClickListener(this);
buildAnima();
setBackground(0);
setOutSideDismiss(true);
setKeepSize(true);
setPopupGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
setBlurBackgroundEnable(true);
}
private AnimationSet mAnimationSet;
private void buildAnima() {
ScaleAnimation mScaleAnimation = new ScaleAnimation(1f, 2f, 1f, 2f, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
mScaleAnimation.setDuration(200);
mScaleAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
mScaleAnimation.setFillAfter(false);
AlphaAnimation mAlphaAnimation = new AlphaAnimation(1, .2f);
mAlphaAnimation.setDuration(400);
mAlphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
mAlphaAnimation.setFillAfter(false);
mAnimationSet = new AnimationSet(false);
mAnimationSet.setDuration(400);
mAnimationSet.addAnimation(mScaleAnimation);
mAnimationSet.addAnimation(mAlphaAnimation);
mAnimationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
dismiss();
}
}, 150);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
@Override
protected Animation onCreateShowAnimation() {
Animation showAnima = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,
1f,
Animation.RELATIVE_TO_PARENT,
0,
Animation.RELATIVE_TO_PARENT,
0,
Animation.RELATIVE_TO_PARENT,
0);
showAnima.setInterpolator(new DecelerateInterpolator());
showAnima.setDuration(350);
return showAnima;
}
@Override
protected Animation onCreateDismissAnimation() {
Animation exitAnima = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,
0f,
Animation.RELATIVE_TO_PARENT,
1f,
Animation.RELATIVE_TO_PARENT,
0,
Animation.RELATIVE_TO_PARENT,
0);
exitAnima.setInterpolator(new DecelerateInterpolator());
exitAnima.setDuration(350);
return exitAnima;
}
@Override
public View onCreateContentView() {
return createPopupById(R.layout.popup_comment);
}
//=============================================================Getter/Setter
public OnCommentPopupClickListener getOnCommentPopupClickListener() {
return mOnCommentPopupClickListener;
}
public void setOnCommentPopupClickListener(OnCommentPopupClickListener onCommentPopupClickListener) {
mOnCommentPopupClickListener = onCommentPopupClickListener;
}
//=============================================================clickEvent
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.item_like:
if (mOnCommentPopupClickListener != null) {
mOnCommentPopupClickListener.onLikeClick(v, mLikeText);
mLikeAnimaView.clearAnimation();
mLikeAnimaView.startAnimation(mAnimationSet);
}
break;
case R.id.item_comment:
if (mOnCommentPopupClickListener != null) {
mOnCommentPopupClickListener.onCommentClick(v);
dismiss();
}
break;
}
}
//=============================================================InterFace
public interface OnCommentPopupClickListener {
void onLikeClick(View v, TextView likeText);
void onCommentClick(View v);
}
}