-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tanishmoral11
committed
Aug 16, 2024
1 parent
df1d678
commit 25d2b13
Showing
6 changed files
with
120 additions
and
57 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
app/src/main/java/com/example/chantingapp/BeadProgressView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.example.chantingapp | ||
|
||
import android.content.Context | ||
import android.graphics.Canvas | ||
import android.graphics.Paint | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import androidx.core.content.ContextCompat | ||
import kotlin.math.cos | ||
import kotlin.math.min | ||
import kotlin.math.sin | ||
|
||
class BeadProgressView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0 | ||
) : View(context, attrs, defStyleAttr) { | ||
|
||
private val paint = Paint(Paint.ANTI_ALIAS_FLAG) | ||
private val totalBeads = 108 | ||
private var filledBeads = 0 | ||
|
||
init { | ||
paint.style = Paint.Style.FILL | ||
} | ||
|
||
fun setProgress(progress: Int) { | ||
filledBeads = progress | ||
invalidate() | ||
} | ||
|
||
override fun onDraw(canvas: Canvas) { | ||
super.onDraw(canvas) | ||
|
||
val centerX = width / 2f | ||
val centerY = height / 2f | ||
val radius = 160f // Slightly smaller to fit within the view | ||
|
||
// Draw white background circle | ||
paint.color = ContextCompat.getColor(context, android.R.color.white) | ||
canvas.drawCircle(centerX, centerY, radius, paint) | ||
|
||
// Draw border | ||
paint.style = Paint.Style.STROKE | ||
paint.color = ContextCompat.getColor(context, android.R.color.darker_gray) | ||
paint.strokeWidth = 2f | ||
canvas.drawCircle(centerX, centerY, radius, paint) | ||
|
||
paint.style = Paint.Style.FILL | ||
|
||
val angleStep = 360f / totalBeads | ||
val beadRadius = 10f // Smaller bead size | ||
|
||
for (i in 0 until totalBeads) { | ||
val angle = Math.toRadians((-90 + i * angleStep).toDouble()) // Start from 12 o'clock | ||
val x = (centerX + radius * 0.85 * cos(angle)).toFloat() // Move beads slightly inward | ||
val y = (centerY + radius * 0.85 * sin(angle)).toFloat() // Move beads slightly inward | ||
|
||
paint.color = if (i < filledBeads) { | ||
ContextCompat.getColor(context, R.color.bead_filled) | ||
} else { | ||
ContextCompat.getColor(context, R.color.bead_empty) | ||
} | ||
|
||
canvas.drawCircle(x, y, beadRadius, paint) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
<solid android:color="#FFFFFF" /> | ||
<corners android:radius="8dp" /> | ||
<stroke | ||
android:width="1dp" | ||
android:color="#CCCCCC" /> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters