From 02e25802006d0bb14132c5890d3c8a01189789d7 Mon Sep 17 00:00:00 2001 From: goksut Date: Sun, 16 Aug 2020 14:39:17 +0300 Subject: [PATCH] Added popupText attribute --- app/src/main/res/layout/activity_main.xml | 2 ++ .../java/com/faskn/lib/ClickablePieChart.kt | 19 +++++++++++++++++-- lib/src/main/res/values/attrs.xml | 6 ++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 lib/src/main/res/values/attrs.xml diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5cff641..7b85931 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -3,11 +3,13 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".MainActivity"> \ No newline at end of file diff --git a/lib/src/main/java/com/faskn/lib/ClickablePieChart.kt b/lib/src/main/java/com/faskn/lib/ClickablePieChart.kt index 3cda429..c2cac17 100644 --- a/lib/src/main/java/com/faskn/lib/ClickablePieChart.kt +++ b/lib/src/main/java/com/faskn/lib/ClickablePieChart.kt @@ -12,7 +12,6 @@ import android.graphics.Color import android.graphics.Paint import android.graphics.RectF import android.util.AttributeSet -import android.util.Log import android.view.Gravity import android.view.LayoutInflater import android.view.MotionEvent @@ -44,6 +43,9 @@ class ClickablePieChart @JvmOverloads constructor( private var clickListener: ((String, Float) -> Unit)? = null private var pointsArray = arrayListOf>() + // Attributes + private lateinit var popupText: String + init { slicePaint.isAntiAlias = true slicePaint.isDither = true @@ -51,6 +53,19 @@ class ClickablePieChart @JvmOverloads constructor( centerPaint.color = Color.WHITE centerPaint.style = Paint.Style.FILL + + initAttributes(attrs) + } + + private fun initAttributes(attrs: AttributeSet?) { + val typedArray = + context.theme.obtainStyledAttributes(attrs, R.styleable.ClickablePieChart, 0, 0) + + try { + popupText = typedArray.getString(R.styleable.ClickablePieChart_popupText)!! + } finally { + typedArray.recycle() + } } private fun scale(): FloatArray { @@ -138,7 +153,7 @@ class ClickablePieChart @JvmOverloads constructor( var center = pointsArray[index].toList().average() val halfRadius = rectF!!.centerX() - popupView.findViewById(R.id.textViewPopupText).text = "${center.toInt()} ziyaret" + popupView.findViewById(R.id.textViewPopupText).text = "${center.toInt()} $popupText" ImageViewCompat.setImageTintList( popupView.findViewById(R.id.imageViewPopupCircleIndicator), ColorStateList.valueOf(ContextCompat.getColor(context, sliceColors[index])) diff --git a/lib/src/main/res/values/attrs.xml b/lib/src/main/res/values/attrs.xml new file mode 100644 index 0000000..7d266c3 --- /dev/null +++ b/lib/src/main/res/values/attrs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file