-
Notifications
You must be signed in to change notification settings - Fork 12
/
MainActivity.kt
375 lines (343 loc) · 14.2 KB
/
MainActivity.kt
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
package com.maple.demo
import android.app.Activity
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import com.maple.demo.custom.CustomActionSheetRecyclerDialogActivity
import com.maple.demo.custom.CustomAlertDialogActivity
import com.maple.demo.custom.CustomMultipleSelectedDialog
import com.maple.msdialog.*
import com.maple.msdialog.utils.DensityUtils.dp2px
import com.maple.msdialog.utils.DialogUtil.setScaleWidth
import java.util.*
/**
* Custom Dialog Demo
*
* @author maple
* @time 2017/3/28
*/
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
// ------------------------------------ Alert Dialog -------------------------------------------
fun adOne(view: View?) {
val config = AlertDialog.Config(this).apply {
scaleWidth = 0.78
rightBtnColor = Color.RED
// titlePaddingTop = 20f.dp2px(context)
// messagePaddingTop = 15f.dp2px(context)
// messagePaddingBottom = 20f.dp2px(context)
}
AlertDialog(this, config)
.setDialogTitle("退出当前账号")
.setHtmlMessage("再连续登陆<font color=\"#ff0000\">15</font>天,就可变身为QQ达人。退出QQ可能会使你现有记录归零,确定退出?")
.setLeftButton("取消")
.setRightButton("确认退出") { showToast("exit") }
.show()
}
fun adTwo(view: View?) {
AlertDialog(this).apply {
setCancelable(true)
setScaleWidth(0.75) // 设置宽度,占屏幕宽度百分比
// getMessageView().setPadding(15f.dp2px(context), 24f.dp2px(context), 15f.dp2px(context), 24f.dp2px(context))
setMessage("你现在无法接收到新消息提醒。请到系统-设置-通知中开启消息提醒")
// setBottomViewHeightDp(48f)
setRightButton("确定") { showToast("OK") }
}.show()
}
fun adThree(view: View?) {
startActivity(Intent(this, CustomAlertDialogActivity::class.java))
// AlertDialog(this)
// .setTitle("确认删除:XXXX?", isBold = false)
// .setMessage("1.必须确保空间下不存在任何文件、文件夹或图片样式,否则无法删除;\n2.存储空间删除后不可恢复且可能会影响正在使用该空间的其他用户。",
// spSize = 14f, gravity = Gravity.START)
// .setRightButton("确定") { showToast("OK") }
// .show()
}
// -------------------------------- Action Sheet Dialog ----------------------------------------
private val onItemClickListener = OnSheetItemClickListener { item, position ->
showToast("item ${item.getShowName()}")
}
fun asMessage(view: View?) {
ActionSheetDialog(this).apply {
setCancelable(false)
setCanceledOnTouchOutside(false)
setTitle("清空消息列表后,聊天记录依然保留,确定要清空消息列表?")
addSheetItem("清空消息列表", Color.parseColor(DEF_BLUE)) { item, position ->
showToast("clear msg list")
}
setCancelText("取 消")
}.show()
}
fun asImage(view: View?) {
ActionSheetDialog(this).apply {
// setCancelable(false)
// setCanceledOnTouchOutside(false)
addSheetItem("发送给好友", Color.parseColor(DEF_BLUE), onItemClickListener)
addSheetItem("转载到空间相册", Color.parseColor(DEF_BLUE), onItemClickListener)
// addSheetItem("上传到群相册")
// addSheetItem("保存到手机")
// addSheetItem("收藏")
// addSheetItem("查看聊天图片")
setCancelText("取消哦", Color.parseColor(DEF_BLUE))
}.show()
}
fun asList(view: View?) {
ActionSheetDialog(this, ActionSheetDialog.Config(this).apply {
paddingBottom = 15f.dp2px(context)
showCancel = true
cancelText = "Config Cancel"
}).apply {
setTitle("请选择操作")
setCancelable(false)
setCanceledOnTouchOutside(false)
addSheetItem("条目一", Color.parseColor(DEF_RED), onItemClickListener)
addSheetItem("条目二", onItemClickListener)
addSheetItem("条目三", Color.BLUE, onItemClickListener)
addSheetItem("条目四", Color.CYAN, onItemClickListener)
addSheetItem("条目五", onItemClickListener)
addSheetItem("条目六", onItemClickListener)
addSheetItem("条目七", onItemClickListener)
addSheetItem("条目八", onItemClickListener)
addSheetItem(SheetItem("条目九").apply { itemClickListener = onItemClickListener })
addSheetItem(SheetItem("条目十", Color.CYAN, onItemClickListener))
}.show()
}
// -------------------------------- Action Sheet Recycler List Dialog ----------------------------------------
var ar1: ActionSheetRecyclerSingleSelectedDialog? = null
fun asrList(view: View?) {
if (ar1 == null) {
val items = arrayListOf(
User("001", "张三", "男", 23),
User("002", "李四", "女", 8),
User("004", "王五", "男", 11),
User("007", "赵六六", "女", 123)
)
ar1 = ActionSheetRecyclerSingleSelectedDialog(this).apply {
setTitle("选择条目")
setCloseVisibility(false)
setTopLineVisibility(true)
isShowItemMark(true)
setMinScaleHeight(0.3)
setDataBottomPadding(12f)// 默认底部留白:20dp
addSheetItems(items)
addSheetItemClickListener { item, position ->
if (item is User) {
Log.e("okhttp", "item: ${item.toString()}")
showToast("${item.name} 性别:${item.sex} 年龄:${item.age}岁")
} else {
showToast("$position ${item.getShowName()}")
}
}
// isShowItemMark(false)// 不显示item 选中对勾
// setSelectedIndex(1)// 选中第二个
}
}
ar1?.show()
}
var ar2: ActionSheetRecyclerSingleSelectedDialog? = null
fun asrBigDataList(view: View?) {
if (ar2 == null) {
val items = getSheetItemTestData(20)
ar2 = ActionSheetRecyclerSingleSelectedDialog(this, ActionSheetRecyclerDialog.Config(this).apply {
titleTextSizeSp = 18f
// closeDraw = ContextCompat.getDrawable(context, android.R.drawable.ic_delete)
isShowMark = true
// selectMark = ContextCompat.getDrawable(context, R.drawable.ms_svg_round_check)
itemTextSelectedColor = Color.RED
}).apply {
setTitle("选择条目")
addSheetItems(items)
setCancelable(false)
setCanceledOnTouchOutside(false)
setMaxScaleHeight(0.65)
addSheetItemClickListener { item, position ->
// showToast("$position ${item.getShowName()}")
}
}
}
ar2?.show()
}
fun customACR(view: View?) {
startActivity(Intent(this, CustomActionSheetRecyclerDialogActivity::class.java))
}
// -------------------------------- Action Sheet Recycler List Dialog ----------------------------------------
var arm1: ActionSheetRecyclerMultipleSelectedDialog? = null
fun multipleList1(view: View?) {
if (arm1 == null) {
val items = getSheetItemTestData(3)
arm1 = ActionSheetRecyclerMultipleSelectedDialog(this, ActionSheetRecyclerDialog.Config(this).apply {
titleTextSizeSp = 18f
isShowMark = true
itemTextSelectedColor = Color.RED
}).apply {
setTitle("多选条目")
addSheetItems(items)
setCancelable(false)
setCanceledOnTouchOutside(false)
setDataBottomPadding(0f)
setMinScaleHeight(0.45) // 设置最小高度
addSheetItemClickListener { item, position ->
// showToast("$position ${item.getShowName()}")
}
addSheetItemSelectedConfirmListener { list ->
showToast("选中了 ${list.size} 个")
}
}
}
arm1?.show()
}
var arm2: ActionSheetRecyclerMultipleSelectedDialog? = null
fun multipleList2(view: View?) {
if (arm2 == null) {
val items = getSheetItemTestData(20)
arm2 = ActionSheetRecyclerMultipleSelectedDialog(this, ActionSheetRecyclerDialog.Config(this).apply {
titleTextSizeSp = 18f
isShowMark = true
itemTextSelectedColor = Color.RED
}).apply {
setTitle("多选条目")
addSheetItems(items)
setCancelable(false)
setCanceledOnTouchOutside(false)
setDataBottomPadding(0f)
setMinScaleHeight(0.45) // 设置最小高度
setMaxScaleHeight(1.0) // 设置最大高度
addSheetItemClickListener { item, position ->
// showToast("$position ${item.getShowName()}")
}
addSheetItemSelectedConfirmListener { list ->
showToast("选中了 ${list.size} 个")
}
}
}
arm2?.show()
}
var arm3: CustomMultipleSelectedDialog? = null
fun customMultipleACR(view: View?) {
if (arm3 == null) {
arm3 = CustomMultipleSelectedDialog(this, ActionSheetRecyclerDialog.Config(this).apply {
titleTextSizeSp = 18f
isShowMark = true
itemTextSelectedColor = Color.RED
}).apply {
addSheetItemSelectedConfirmListener { list ->
showToast("选中了 ${list.size} 个")
}
}
}
arm3?.show()
}
// -------------------------------- Action Sheet List Dialog ----------------------------------------
var asl1: ActionSheetListDialog? = null
fun aslList(view: View?) {
if (asl1 == null) {
asl1 = ActionSheetListDialog(this).apply {
addSheetItems(getSheetItemTestData(2)) { item, position ->
showToast(item.getShowName())
}
setCancelText("取消")
}
}
asl1?.show()
}
var asl2: ActionSheetListDialog? = null
fun aslListNoCancel(view: View?) {
if (asl2 == null) {
asl2 = ActionSheetListDialog(this).apply {
setTitle("标题")
addSheetItems(getSheetItemTestData(10)) { item, position ->
showToast(item.getShowName())
}
setSelectedIndex(3)
}
}
asl2?.show()
}
var asl3: ActionSheetListDialog? = null
fun aslListTitle(view: View?) {
if (asl3 == null) {
asl3 = ActionSheetListDialog(this).apply {
setTitle("标题")
setCancelText("取消")
addSheetItems(getSheetItemTestData(20)) { item, position ->
showToast(item.getShowName())
}
}
}
asl3?.show()
}
// --------------------------------- Alert Edit Dialog -----------------------------------------
fun aeOne(view: View?) {
AlertEditDialog(this).apply {
setTitle("姓名")
setMessage("请输入您的真实姓名。")
setLeftButton("取消")
setRightButton("确定", OnEditTextCallListener {
showToast(it)
})
}.show()
}
fun aeTwo(view: View?) {
AlertEditDialog(this).apply {
setMessage("给自己起一个好听的名字吧")
setRightButton("确定", OnEditTextCallListener {
showToast(it)
})
}.show()
}
// --------------------------------- Number Picker Dialog -----------------------------------------
var index = 0
var defValue: String? = null
fun npOne(view: View?) {
val numbers = arrayOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")
defValue = numbers[index]
AlertNumberPickerDialog(this).apply {
setTitle("Number")
setNumberValues(numbers, index) { picker, oldVal, newVal ->
defValue = numbers[newVal]
}
setLeftButton("Cancel")
setRightButton("OK") {
showToast(defValue)
}
}.show()
}
fun npTwo(view: View?) {
val numbers = arrayOf("北京", "上海", "天津", "杭州", "苏州", "深圳")
defValue = numbers[index]
AlertNumberPickerDialog(this).apply {
setScaleWidth(0.8)
setCancelable(false)
setTitle("选择城市")
setNumberValues(numbers, index) { picker, oldVal, newVal ->
defValue = numbers[newVal]
}
setNumberValueSuffix("市")
setLeftButton("取消")
setRightButton("确定") { showToast(defValue) }
}.show()
}
// ----------------------------------- other methods -------------------------------------------
private fun showToast(msg: String?) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}
companion object {
const val DEF_BLUE = "#4762FE"
const val DEF_RED = "#FD4A2E"
}
// 获取测试数据
private fun getSheetItemTestData(count: Int): ArrayList<SheetItem> {
val testData = arrayListOf<SheetItem>()
for (index in 1..count) {
val mColor = -0x1000000 or Random().nextInt(0xffffff)
testData.add(SheetItem("custom sheet view $index", mColor))
}
return testData
}
}