@@ -19,10 +19,14 @@ import android.view.View
1919import android.view.animation.LinearInterpolator
2020import android.widget.LinearLayout
2121import android.widget.PopupWindow
22+ import android.widget.RelativeLayout
2223import android.widget.TextView
2324import androidx.core.content.ContextCompat
2425import androidx.core.view.doOnPreDraw
2526import androidx.core.widget.ImageViewCompat
27+ import androidx.recyclerview.widget.LinearLayoutManager
28+ import androidx.recyclerview.widget.RecyclerView
29+ import com.faskn.lib.legend.LegendAdapter
2630import kotlin.math.atan2
2731import kotlin.math.cos
2832import kotlin.math.sin
@@ -33,7 +37,11 @@ class ClickablePieChart @JvmOverloads constructor(
3337 defStyleAttr : Int = 0
3438) : View(context, attrs, defStyleAttr) {
3539
36- private var slicePaint: Paint = Paint ()
40+ private var slicePaint: Paint = Paint ().apply {
41+ isAntiAlias = true
42+ isDither = true
43+ style = Paint .Style .FILL
44+ }
3745 private var centerPaint: Paint = Paint (Paint .ANTI_ALIAS_FLAG ).apply {
3846 color = Color .WHITE
3947 style = Paint .Style .FILL
@@ -59,10 +67,6 @@ class ClickablePieChart @JvmOverloads constructor(
5967 }
6068
6169 private fun init () {
62- slicePaint.isAntiAlias = true
63- slicePaint.isDither = true
64- slicePaint.style = Paint .Style .FILL
65-
6670 initSlices()
6771 startAnimation()
6872 }
@@ -161,7 +165,6 @@ class ClickablePieChart @JvmOverloads constructor(
161165 radius - width,
162166 centerPaint
163167 )
164-
165168 }
166169 }
167170
@@ -271,6 +274,18 @@ class ClickablePieChart @JvmOverloads constructor(
271274 showPopup = show
272275 }
273276
277+ fun showLegend (rootLayout : RelativeLayout ) {
278+ val recyclerView = RecyclerView (context)
279+ val linearLayoutManager = LinearLayoutManager (context, LinearLayoutManager .VERTICAL , false )
280+ recyclerView.layoutManager = linearLayoutManager
281+ val adapter = LegendAdapter ()
282+ slices?.toMutableList()?.let { adapter.setup(it) }
283+ recyclerView.adapter = adapter
284+ recyclerView.overScrollMode = OVER_SCROLL_NEVER
285+ rootLayout.addView(recyclerView)
286+ invalidateAndRequestLayout()
287+ }
288+
274289 private fun invalidateAndRequestLayout () {
275290 invalidate()
276291 requestLayout()
0 commit comments