@@ -10,14 +10,15 @@ import android.graphics.*
1010import android.graphics.drawable.Drawable
1111import android.support.annotation.DrawableRes
1212import android.support.annotation.IntDef
13+ import android.support.annotation.LayoutRes
1314import android.view.*
1415import android.widget.FrameLayout
1516import android.widget.ImageView
1617import com.haoge.easyandroid.EasyAndroid
1718
1819private typealias OnGuideShowListener = (Boolean ) -> Unit
19- private typealias OnGuideViewCreatedListener = (View , EasyGuideLayer .Controller ) -> Unit
20- private typealias OnDrawHighLightCallback = (canvas: Canvas , rect: RectF , paint: Paint ) -> Boolean
20+ private typealias OnGuideViewAttachedListener = (View , EasyGuideLayer .Controller ) -> Unit
21+ private typealias OnDrawHighLightCallback = (canvas: Canvas , rect: RectF , paint: Paint ) -> Unit
2122private typealias OnHighLightClickListener = (EasyGuideLayer .Controller ) -> Unit
2223private typealias OnGuideViewOffsetProvider = (Point , RectF , View ) -> Unit
2324class EasyGuideLayer private constructor(private val anchor : View ){
@@ -132,11 +133,13 @@ class EasyGuideLayer private constructor(private val anchor: View){
132133 private var layer: EasyGuideLayer ? = null
133134 private var container = mutableMapOf<RectF , GuideItem >()
134135 private val paint = Paint ()
136+ private var copyPaint: Paint
135137
136138 init {
137139 paint.isAntiAlias = true
138140 paint.xfermode = PorterDuffXfermode (PorterDuff .Mode .CLEAR )
139141 paint.maskFilter = BlurMaskFilter (10f , BlurMaskFilter .Blur .INNER )
142+ copyPaint = Paint (paint)
140143 setLayerType(View .LAYER_TYPE_SOFTWARE , null )
141144 setWillNotDraw(true )
142145 setOnClickListener(this )
@@ -159,7 +162,7 @@ class EasyGuideLayer private constructor(private val anchor: View){
159162 val child = createItemView(item)
160163 child.setTag(GuideItem .TAG_ID , item)
161164 addView(child)
162- item.getOnViewCreatedListener ()?.invoke(child, this )
165+ item.getOnViewAttachedListener ()?.invoke(child, this )
163166 }
164167 }
165168
@@ -239,12 +242,15 @@ class EasyGuideLayer private constructor(private val anchor: View){
239242 }
240243
241244 override fun onDraw (canvas : Canvas ) {
242- container.forEach {
243- if (it.value.getOnDrawHighLightListener()?.invoke(canvas, it.key, paint) == true ) return @forEach
245+ container.forEach { entry ->
246+ entry.value.getOnDrawHighLightListener()?.let {
247+ it.invoke(canvas, entry.key, copyPaint)
248+ return @forEach
249+ }
244250
245- when (it .value.getShapeType()) {
246- GuideItem .SHAPE_RECT -> canvas.drawRect(it .key, paint)
247- GuideItem .SHAPE_OVAL -> canvas.drawOval(it .key, paint)
251+ when (entry .value.getShapeType()) {
252+ GuideItem .SHAPE_RECT -> canvas.drawRect(entry .key, paint)
253+ GuideItem .SHAPE_OVAL -> canvas.drawOval(entry .key, paint)
248254 }
249255 }
250256 }
@@ -295,7 +301,7 @@ class EasyGuideLayer private constructor(private val anchor: View){
295301 * */
296302class GuideItem private constructor(val rect : RectF ? = null , val view : View ? = null , val padding : Int = 0 ){
297303 private var shapeType = SHAPE_NONE
298- private var onViewCreated : OnGuideViewCreatedListener ? = null
304+ private var onViewAttached : OnGuideViewAttachedListener ? = null
299305 private var onDrawHighLight: OnDrawHighLightCallback ? = null
300306 private var onHighLightClickListener: OnHighLightClickListener ? = null
301307 private var offsetProvider: OnGuideViewOffsetProvider ? = null
@@ -304,7 +310,7 @@ class GuideItem private constructor(val rect: RectF? = null, val view: View? = n
304310 private var gravity = Gravity .NO_GRAVITY
305311
306312 fun getShapeType () = shapeType
307- fun getOnViewCreatedListener () = onViewCreated
313+ fun getOnViewAttachedListener () = onViewAttached
308314 fun getOnDrawHighLightListener () = onDrawHighLight
309315 fun getOnHighLightClickListenter () = onHighLightClickListener
310316 fun getDrawable () = drawable
@@ -333,8 +339,8 @@ class GuideItem private constructor(val rect: RectF? = null, val view: View? = n
333339 * 1. View:被创建的引导View。
334340 * 2. Controller: 提供给上层使用的控制器。可用于进行蒙层关闭或者蒙层引导更新等操作。
335341 */
336- fun setOnViewCreatedListener ( onViewCreatedListener : OnGuideViewCreatedListener ? ): GuideItem {
337- this .onViewCreated = onViewCreatedListener
342+ fun setOnViewAttachedListener ( onViewAttachedListener : OnGuideViewAttachedListener ? ): GuideItem {
343+ this .onViewAttached = onViewAttachedListener
338344 return this
339345 }
340346
@@ -361,7 +367,7 @@ class GuideItem private constructor(val rect: RectF? = null, val view: View? = n
361367 /* *
362368 * 设置引导层View的布局id。与[setDrawable]互斥。
363369 */
364- fun setLayout (layout : Int ): GuideItem {
370+ fun setLayout (@LayoutRes layout : Int ): GuideItem {
365371 this .layout = layout
366372 this .drawable = null
367373 return this
@@ -403,8 +409,11 @@ class GuideItem private constructor(val rect: RectF? = null, val view: View? = n
403409 const val SHAPE_OVAL = 1
404410
405411 internal const val TAG_ID = 0x0F000000
412+ /* * 不指定具体的高亮绘制区域,使用默认区域Rect(0,0,0,0)*/
406413 fun newInstance () = GuideItem ()
414+ /* * 通过指定view与padding创建具体的高亮绘制区域*/
407415 fun newInstance (view : View , padding : Int = 0) = GuideItem (view = view, padding = padding)
416+ /* * 直接指定具体的高亮绘制区域*/
408417 fun newInstance (rect : RectF ) = GuideItem (rect = rect)
409418 }
410419}
0 commit comments