Make canvas easier to use in Kotlin 😊
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.idea
app
gradle/wrapper
kanvas
medias
.gitignore
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

Kanvas

WORK IN PROGRESS

Make canvas easier to use in Kotlin 😊

Use shapes & write less code to do more magic

arc

//create your shapes
val background = RectShape(this) { view ->
   color = Color.parseColor("#6fbf73")
   cornerRadius = 16.dpToPx(context)

   left = 100f
   width = view.width / 2f
   top = 100f
   height = view.height / 3f
}

val canvasAnimator = CanvasAnimator(this)
fun animate(){
    canvasAnimator
            .play(background.animate().right.to(this.width.toFloat()))
            .start()
}

//draw them
override fun onDraw(canvas: Canvas) {
    super.onDraw(canvas)
    canvas.draw(background)
}

Examples

arc dots slider tree

Available shapes

Shapes link
Rect
Circle
Text
Arc
Line
Triangle
Drawable
Path

Animation

Follow the example of SwitchView

Shape animations are executed by an instance of ShapeAnimator attached to your view

val canvasAnimator = CanvasAnimator(this)

All animated methods of shapes are wrapped into the method .animate()

For example, for a CircleShape, you can animate his position (centerX) using

myCircleShape.animate().centerX.to(15);

Then use your ShapeAnimator to execute this animation

shapeAnimator.play(myCircleShape.animate().centerX.to(15);)
    .setDuration(500)
    .start()

Added support methods to Canvas

drawArc(centerX, centerY, circleRadius, startAngle, sweepAngle, paint)

drawArc(center: PointF, circleRadius, startAngle, sweepAngle, paint)

drawArc(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint)

drawOval(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint)

drawLine(start: PointF, end: PointF, paint)

drawRoundRect(left, top, right, bottom, rx, ry, paint)

Added support methods to Path

addRoundRect(left, top, right, bottom, rx, ry, dir: Path.Direction)

addRoundRect(left, top, right, bottom, radiiArray, dir: Path.Direction)

arcTo(centerX, centerY, circleRadius, startAngle, sweepAngle, forceMoveTo)

arcTo(center: PointF, circleRadius, startAngle, sweepAngle, forceMoveTo)

arcTo(left, top, right, bottom, startAngle, sweepAngle, forceMoveTo)

Fiches Plateau Moto : https://www.fiches-plateau-moto.fr/