-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathEasyGuideLayerActivity.kt
More file actions
122 lines (103 loc) · 4.67 KB
/
EasyGuideLayerActivity.kt
File metadata and controls
122 lines (103 loc) · 4.67 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
package com.haoge.sample.easyandroid.activities
import android.annotation.SuppressLint
import android.view.Gravity
import android.view.View
import android.widget.TextView
import butterknife.OnClick
import com.haoge.easyandroid.easy.EasyGuideLayer
import com.haoge.easyandroid.easy.EasyToast
import com.haoge.easyandroid.easy.GuideItem
import com.haoge.sample.easyandroid.BaseActivity
import com.haoge.sample.easyandroid.R
/**
* @author haoge on 2018/10/31
*/
class EasyGuideLayerActivity: BaseActivity() {
private val anchor by lazy { findViewById<View>(R.id.layer_layout) }
private val guideShownCallback = { shown:Boolean ->
EasyToast.DEFAULT.show("蒙层已${if (shown) "展示" else "消失"}")
}
override fun getLayoutId(): Int = R.layout.activity_guide_layer
@OnClick(R.id.show_simple_guide)
fun showSimpleGuide() {
createDefaultGuide().show()
}
@SuppressLint("RtlHardcoded")
private val gravities = listOf(
Gravity.LEFT or Gravity.TOP to "左上",
Gravity.TOP to "顶部",
Gravity.RIGHT or Gravity.TOP to "右上",
Gravity.LEFT to "左边",
Gravity.RIGHT to "右边",
Gravity.LEFT or Gravity.BOTTOM to "左下",
Gravity.BOTTOM to "底部",
Gravity.BOTTOM or Gravity.RIGHT to "右下"
)
@OnClick(R.id.show_with_activity)
fun showWithActivity() {
val item = GuideItem.newInstance(findViewById<View>(R.id.layer_layout))
.setGravity(Gravity.BOTTOM)
.setLayout(R.layout.guide_text_layout)
.setHighLightShape(GuideItem.SHAPE_OVAL)
item.setOnViewAttachedListener { view, controller ->
(view as TextView).text = "此处展示下方的各种蒙层展示效果"
}
EasyGuideLayer.with(this).addItem(item)
.setDismissOnClickOutside(true)
.show()
}
@OnClick(R.id.show_with_gravities)
fun showWithGravity() {
var index = 0
val item = GuideItem.newInstance(findViewById<View>(R.id.anchor_center))
item.setGravity(gravities[index].first).setLayout(R.layout.guide_text_layout)
item.setOnViewAttachedListener { view, controller ->
(view as TextView).text = gravities[index].second
view.setOnClickListener {
// 点击后重置gravity信息并重新展示
try {
index++
item.setGravity(gravities[index].first)
controller.getGuideLayer().show()
} catch (e:IndexOutOfBoundsException) {
controller.dismiss()
}
}
}
createDefaultGuide()
.addItem(item)
.show()
}
@OnClick(R.id.show_with_multiple_highlight)
fun showWithHighlights() {
val layer = createDefaultGuide()
layer.setBackgroundColor(0x66000000) // 背景色调深点便于查看高亮块
val topItem = GuideItem.newInstance(findViewById<View>(R.id.anchor_top))
.setHighLightShape(GuideItem.SHAPE_OVAL)
.setOnHighLightClickListener { EasyToast.DEFAULT.show("顶部高亮区域被点击") }
val centerItem = GuideItem.newInstance(findViewById<View>(R.id.anchor_center))
.setHighLightShape(GuideItem.SHAPE_RECT)
.setOnHighLightClickListener { EasyToast.DEFAULT.show("中央高亮区域被点击") }
val bottomItem = GuideItem.newInstance(findViewById<View>(R.id.anchor_bottom))
.setOnDrawHighLightCallback { canvas, rect, paint ->
canvas.drawRoundRect(rect, 30f, 30f, paint)
}.setOnHighLightClickListener { EasyToast.DEFAULT.show("底部高亮区域被点击") }
layer.addItem(topItem).addItem(centerItem).addItem(bottomItem).show()
}
@OnClick(R.id.show_with_offset)
fun showWithOffset() {
val item = GuideItem.newInstance(findViewById<View>(R.id.anchor_center))
.setLayout(R.layout.guide_text_layout)
.setOnViewAttachedListener { view, controller ->
(view as TextView).text = "中央展示hehehehe "
}.setOffsetProvider { point, rectF, view ->
// 在此根据具体尺寸计算出中央位置
point.offset(((rectF.width() - view.width) / 2).toInt(), 0)
}.setGravity(Gravity.TOP)
createDefaultGuide().addItem(item).show()
}
private fun createDefaultGuide() = EasyGuideLayer.with(anchor)
.setBackgroundColor(0x33000000)
.setOnGuideShownListener(guideShownCallback)
.setDismissOnClickOutside(true)
}