Skip to content

Instantly share code, notes, and snippets.

@Stjin

Stjin/compose.kt Secret

Created April 9, 2022 12:46
Show Gist options
  • Save Stjin/807c430a25adebef76fae8a039cbc2b5 to your computer and use it in GitHub Desktop.
Save Stjin/807c430a25adebef76fae8a039cbc2b5 to your computer and use it in GitHub Desktop.
@Composable
fun Sample() {
val listOfDonutSection = listOf(
DonutSection(amount = 12f, color = Color.Cyan),
DonutSection(amount = 5f, color = Color.Red),
DonutSection(amount = 3f, color = Color.Green),
)
DonutProgress(
model = DonutModel(
cap = 20f,
masterProgress = 1f,
gapWidthDegrees = 0f,
gapAngleDegrees = 270f,
strokeWidth = 40f,
backgroundLineColor = Color.LightGray,
sections = listOfDonutSection.sortedBy { it.amount },
), modifier = Modifier
.height(128.dp)
.width(128.dp)
)
}
<app.futured.donut.DonutProgressView
android:id="@+id/donut_view"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:donut_bgLineColor="#1f1f1f"
app:donut_gapWidth="0"
app:donut_gapAngle="270"
app:donut_cap="20"
app:donut_strokeWidth="16dp"/>
val donut_view = findViewById<DonutProgressView>(R.id.donut_view)
val listOfDonutSection: ArrayList<DonutSection> = arrayListOf()
val section1 = DonutSection(
name = "section_1",
color = Color.parseColor("#00ffff"), // Cyan
amount = 12.0f
)
val section2 = DonutSection(
name = "section_2",
color = Color.parseColor("#ff0000"), // red
amount = 5.0f
)
val section3 = DonutSection(
name = "section_3",
color = Color.parseColor("#00ff00"), // green
amount = 3.0f
)
listOfDonutSection.add(section1)
listOfDonutSection.add(section2)
listOfDonutSection.add(section3)
donut_view.submitData(listOfDonutSection.sortedBy { it.amount })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment