• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.airbnb.lottie.samples.views
2 
3 import android.annotation.SuppressLint
4 import android.content.Context
5 import android.graphics.Canvas
6 import android.graphics.Color
7 import android.graphics.Paint
8 import android.graphics.drawable.ColorDrawable
9 import androidx.annotation.ColorInt
10 import androidx.core.content.ContextCompat
11 import android.util.AttributeSet
12 import android.view.View
13 import com.airbnb.lottie.samples.R
14 
15 class BackgroundColorView @JvmOverloads constructor(
16         context: Context,
17         attrs: AttributeSet? = null,
18         defStyleInt: Int = 0
19 ) : View(context, attrs, defStyleInt) {
20 
<lambda>null21     private val paint = Paint().apply {
22         isAntiAlias = true
23     }
24 
25 
26     @SuppressLint("MissingSuperCall")
drawnull27     override fun draw(canvas: Canvas) {
28         if (background !is ColorDrawable) return
29 
30         val cx = canvas.width / 2f
31         val cy = canvas.height / 2f
32         val r = Math.min(cx, cy)
33         if (getColor() == Color.WHITE) {
34             paint.strokeWidth =
35                     resources.getDimensionPixelSize(R.dimen.background_color_view_stroke_width).toFloat()
36             paint.style = Paint.Style.STROKE
37             paint.color = ContextCompat.getColor(context, R.color.background_color1_stroke)
38         } else {
39             paint.color = getColor()
40             paint.style = Paint.Style.FILL
41         }
42         canvas.drawCircle(cx, cy, r - paint.strokeWidth, paint)
43     }
44 
getColornull45     @ColorInt fun getColor() = (background as ColorDrawable).color
46 }