-
Notifications
You must be signed in to change notification settings - Fork 26
/
EditDialog.java
209 lines (193 loc) · 5.6 KB
/
EditDialog.java
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package com.siberiadante.customdialoglib;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
* @Created SiberiaDante
* @Describe: 带EditText的确认or取消弹窗
* @Time: 2017/6/19
* @Email: 994537867@qq.com
* @GitHub: https://github.com/SiberiaDante
*/
public class EditDialog {
private Context context;
private Dialog dialog;
private LinearLayout mLinear_layout;
private TextView mTvTitle;
private EditText mEdtContent;
private Button btn_neg;
private Button btn_pos;
private ImageView img_line;
private Display display;
public EditDialog(Context context) {
this.context = context;
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
display = windowManager.getDefaultDisplay();
}
public EditDialog builder() {
View view = LayoutInflater.from(context).inflate(R.layout.dialog_alert_edit, null);
mLinear_layout = (LinearLayout) view.findViewById(R.id.linear_alert_dialog_bg);
mTvTitle = (TextView) view.findViewById(R.id.tv_alert_dialog_title);
mEdtContent = (EditText) view.findViewById(R.id.edt_alert_dialog_content);
btn_neg = (Button) view.findViewById(R.id.btn_alert_dialog_cancel);
btn_pos = (Button) view.findViewById(R.id.btn_alert_dialog_sure);
img_line = (ImageView) view.findViewById(R.id.img_alert_dialog_line);
dialog = new Dialog(context, R.style.ActionGeneralDialog);
dialog.setContentView(view);
mLinear_layout.setLayoutParams(new FrameLayout.LayoutParams((int) (display.getWidth() * 0.85), LinearLayout.LayoutParams.WRAP_CONTENT));
return this;
}
/**
* @param title
* @return
*/
public EditDialog setTitle(String title) {
if ("".equals(title)) {
mTvTitle.setText("标题");
} else {
mTvTitle.setText(title);
}
return this;
}
/**
* @param title
* @param color
* @param textSize
* @return
*/
public EditDialog setTitle(String title, int color, float textSize) {
if ("".equals(title)) {
mTvTitle.setText("标题");
} else {
mTvTitle.setText(title);
}
mTvTitle.setTextColor(color);
mTvTitle.setTextSize(textSize);
return this;
}
/**
* @return
*/
public String getMsg() {
return mEdtContent.getText().toString();
}
/**
* @param cancelable
* @return
*/
public EditDialog setCancelable(boolean cancelable) {
dialog.setCancelable(cancelable);
return this;
}
/**
* @param text
* @param listener
* @return
*/
public EditDialog setPositiveButton(String text, final View.OnClickListener listener) {
if ("".equals(text)) {
btn_pos.setText("确定");
} else {
btn_pos.setText(text);
}
btn_pos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onClick(v);
dialog.dismiss();
}
});
return this;
}
/**
* @param text
* @param color
* @param textSize
* @param listener
* @return
*/
public EditDialog setPositiveButton(String text, int color, float textSize, final View.OnClickListener listener) {
if ("".equals(text)) {
btn_pos.setText("确定");
} else {
btn_pos.setText(text);
}
btn_pos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onClick(v);
dialog.dismiss();
}
});
btn_pos.setTextColor(color);
btn_pos.setTextSize(textSize);
return this;
}
/**
* @param text
* @param listener
* @return
*/
public EditDialog setNegativeButton(String text,
final View.OnClickListener listener) {
if ("".equals(text)) {
btn_neg.setText("取消");
} else {
btn_neg.setText(text);
}
btn_neg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onClick(v);
dialog.dismiss();
}
});
return this;
}
/**
* @param text
* @param color
* @param textSize
* @param listener
* @return
*/
public EditDialog setNegativeButton(String text, int color, float textSize,
final View.OnClickListener listener) {
if ("".equals(text)) {
btn_neg.setText("取消");
} else {
btn_neg.setText(text);
}
btn_neg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onClick(v);
dialog.dismiss();
}
});
btn_neg.setTextColor(color);
btn_neg.setTextSize(textSize);
return this;
}
/**
*
*/
public void dismiss() {
dialog.dismiss();
}
/**
*
*/
public void show() {
dialog.show();
}
}