PrizeDrawDialog.java
4.83 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.wd.common.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.wd.common.imageglide.ImageUtils;
import com.wd.common.viewclick.BaseClickListener;
import com.wd.fastcoding.base.R;
import com.wd.foundation.bean.response.CodeIdentifyBean;
import com.wd.foundation.wdkit.animator.MyAnimationUtils;
/**
* 抽奖弹框
* @author baozhaoxin
* @version [V1.0.0, 2023/12/7]
* @since V1.0.0
*/
public class PrizeDrawDialog {
/**
* 弹框布局
*/
private RelativeLayout dialogLayout;
/**
* 背景图
*/
private ImageView bgImg;
/**
* 跳转按钮
*/
private ImageView btnImg;
/**
* 关闭按钮
*/
private ImageView closeImg;
/**
* 上下文环境
*/
private Context context;
/**
* dialog
*/
private Dialog dialog;
/**
* 数据
*/
private CodeIdentifyBean data;
/**
* 监听
*/
private DialogClickListener clickListener;
public PrizeDrawDialog(Context context) {
this.context = context;
}
public Dialog getDialog() {
return dialog;
}
/**
* 创建布局
* @return
*/
public PrizeDrawDialog builder() {
// 获取Dialog布局
View view = LayoutInflater.from(context).inflate(R.layout.dialog_prize_draw, null);
dialogLayout = view.findViewById(R.id.layout_dialog);
bgImg = view.findViewById(R.id.img_bg);
btnImg = view.findViewById(R.id.img_btn);
closeImg = view.findViewById(R.id.img_close);
// 定义Dialog布局和参数
dialog = new Dialog(context, R.style.AlertDialogStyle);
dialog.setContentView(view);
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount = 0.5f;
// lp.y = 250;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
// 调整dialog背景大小
dialogLayout.setLayoutParams(
new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
//点击空白区域,更新状态
if(clickListener!=null){
clickListener.onClose();
}
}
});
Animation animation = MyAnimationUtils.loadAnimation(context, R.anim.scale_easter_eggs_dialog);
view.setAnimation(animation);
animation.start();
btnImg.setOnClickListener(new BaseClickListener() {
@Override
protected void onNoDoubleClick(View v) {
if(clickListener!=null){
clickListener.onJump();
}
}
});
closeImg.setOnClickListener(view1 -> {
if(clickListener!=null){
clickListener.onClose();
}
dialog.dismiss();
});
return this;
}
/**
* 设置监听
* @param clickListener
*/
public PrizeDrawDialog setClickListener(DialogClickListener clickListener){
this.clickListener = clickListener;
return this;
}
/**
* 设置数据
* @param data
* @return
*/
public PrizeDrawDialog setData(CodeIdentifyBean data){
this.data = data;
if(data != null){
String guideTopImgUrl = data.getGuideTopImgUrl();
String guideDownImgUrl = data.getGuideDownImgUrl();
ImageUtils.getInstance().
loadImage(bgImg, guideTopImgUrl, 0);
ImageUtils.getInstance().
loadImage(btnImg, guideDownImgUrl, 0);
}
return this;
}
/**
* 显示
*/
public PrizeDrawDialog show() {
if(context != null){
if(context instanceof Activity){
Activity activity = (Activity) context;
if(!activity.isDestroyed() && !activity.isFinishing()){
if(dialog!=null){
dialog.show();
}
}
}else{
if(dialog!=null){
dialog.show();
}
}
}
return this;
}
/**
* 回调监听
*/
public interface DialogClickListener {
void onJump();
void onClose();
}
}