Skip to content

Commit

Permalink
use drawArc
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoniecz committed Jul 13, 2022
1 parent f81533c commit 2330117
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.graphics.Canvas
import android.graphics.ColorFilter
import android.graphics.Paint
import android.graphics.PixelFormat
import android.graphics.RectF
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.View
Expand Down Expand Up @@ -192,22 +193,31 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
}

val decorationSegmentImageWidth = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth
val decorationSegmentImageHeight = laurelLeafOnStalk.intrinsicHeight

val regularSegmentCount = 11f

val circleCenterX = canvasWidth / 2f
val shownSegments = ((regularSegmentCount - 1) * percentageOfGrowth / 100).toInt()
val locationBetweenCenterAndEdge = 0.78f
for (i in 0..shownSegments) {
for (i in 1..shownSegments) {
// https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1)

var bitmap = laurelLeafOnStalk.bitmap
if (i == shownSegments) {
bitmap = horizontalEndingLeaf.bitmap
} else if (i == 0 ) {
bitmap = laurelStalk.bitmap
}

val stalkPaint = Paint()
stalkPaint.isAntiAlias = true
stalkPaint.setARGB(255, 0, 106, 0)
stalkPaint.style = Paint.Style.STROKE
stalkPaint.strokeWidth = 3f
val stalkCircleSize = circleRadius * locationBetweenCenterAndEdge * 1.1f // 1.03 too low
val frame = RectF(canvasWidth.toFloat() / 2 - stalkCircleSize, canvasHeight.toFloat() / 2 - stalkCircleSize, canvasWidth.toFloat() / 2 + stalkCircleSize, canvasHeight.toFloat() / 2 + stalkCircleSize)
val stalkLengthInDegrees = 180f * percentageOfGrowth / 100f - 10f
canvas.drawArc(frame, 90f, stalkLengthInDegrees, false, stalkPaint )
val upperLimitOfRightStalk = (90f - stalkLengthInDegrees + 360) % 360
canvas.drawArc(frame, upperLimitOfRightStalk, stalkLengthInDegrees, false, stalkPaint )
// left side
canvas.withRotation(i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) {
// drawBitmap takes corner of the bitmap, we care about centering segments
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/res/drawable/ic_laurel_leaf_rotated.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,4 @@
android:fillColor="#006a00"
android:strokeColor="#00000000"
android:strokeLineCap="butt"/>
<path
android:pathData="M2.976,12.355h10.748v0.048h-10.748z"
android:strokeWidth="0.713252"
android:fillColor="#000000"
android:strokeColor="#065006"
android:fillType="evenOdd"
android:fillAlpha="0.244816"/>
</vector>
27 changes: 6 additions & 21 deletions res/graphics/laurel_wreath/laurel_leaf_rotated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 0 additions & 25 deletions res/graphics/laurel_wreath/laurel_leaf_stalk.svg

This file was deleted.

0 comments on commit 2330117

Please sign in to comment.