Skip to content

Commit

Permalink
Implemented slice popup
Browse files Browse the repository at this point in the history
  • Loading branch information
turkergoksu committed Aug 12, 2020
1 parent 1337533 commit 45cdc16
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions lib/src/main/java/com/faskn/lib/ClickablePieChart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package com.faskn.lib

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
Expand All @@ -15,10 +16,9 @@ import android.view.Gravity
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.widget.LinearLayout
import android.widget.PopupWindow
import android.widget.TextView
import android.widget.*
import androidx.core.content.ContextCompat
import androidx.core.widget.ImageViewCompat
import kotlin.math.atan2
import kotlin.math.cos
import kotlin.math.sin
Expand Down Expand Up @@ -129,14 +129,18 @@ class ClickablePieChart @JvmOverloads constructor(

private fun showInfoPopup(index: Int) {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val popupView = inflater.inflate(R.layout.layout_info, null)
val popupView = inflater.inflate(R.layout.popup_slice, null)
val width = LinearLayout.LayoutParams.WRAP_CONTENT
val height = LinearLayout.LayoutParams.WRAP_CONTENT
val popupWindow = PopupWindow(popupView, width, height, true)
var center = pointsArray[index].toList().average()
val halfRadius = rectF!!.centerX()

popupView.findViewById<TextView>(R.id.textViewInfo).text = center.toString()
popupView.findViewById<TextView>(R.id.textViewPopupText).text = "${center.toInt()} ziyaret"
ImageViewCompat.setImageTintList(
popupView.findViewById<ImageView>(R.id.imageViewPopupCircleIndicator),
ColorStateList.valueOf(ContextCompat.getColor(context, sliceColors[index]))
)

val calculatedX =
((halfRadius) * cos(Math.toRadians(center))).toInt()
Expand Down
17 changes: 8 additions & 9 deletions lib/src/main/res/layout/popup_slice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="105dp"
android:layout_height="32dp"
android:orientation="vertical">
android:layout_height="wrap_content">

<ImageView
android:id="@+id/imageViewFixedTriangle"
Expand All @@ -17,17 +16,18 @@

<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="32dp"
android:layout_below="@+id/imageViewFixedTriangle"
android:layout_alignParentBottom="true"
android:layout_marginStart="1dp"
android:layout_marginTop="-1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:elevation="10dp"
app:cardCornerRadius="5dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
android:layout_width="wrap_content"
android:layout_height="match_parent">

<ImageView
android:id="@+id/imageViewPopupCircleIndicator"
Expand All @@ -41,10 +41,9 @@
android:id="@+id/textViewPopupText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="4dp"
android:layout_marginEnd="5dp"
android:layout_marginEnd="11dp"
android:layout_toEndOf="@+id/imageViewPopupCircleIndicator"
android:ellipsize="end"
android:maxLines="1"
Expand Down

0 comments on commit 45cdc16

Please sign in to comment.