• Stars
    star
    1,067
  • Rank 42,298 (Top 0.9 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ€ Animated Vector Drawables on steroids ๐Ÿ€

Kyrie

Build status Download

Kyrie is a superset of Android's VectorDrawable and AnimatedVectorDrawable classes: it can do everything they can do and more.

Screen capture of tool

Motivation

VectorDrawables are great because they provide density independenceโ€”they can be scaled arbitrarily on any device without loss of quality. AnimatedVectorDrawables make them even more awesome, allowing us to animate specific properties of a VectorDrawable in a variety of ways.

However, these two classes have three main limitations:

  1. They can't be paused, resumed, or seeked.
  2. They can't be dynamically created at runtime (they must be inflated from a drawable resource).
  3. They only support a small subset of features that SVGs provide on the web.

Kyrie was created in order to address these problems.

Getting started

To create an animation using Kyrie, you first need to build a KyrieDrawable. There are two ways to do this:

Option #1: from an existing VD/AVD resource

With Kyrie, you can convert an existing VectorDrawable or AnimatedVectorDrawable resource into a KyrieDrawable with a single line:

val drawable = KyrieDrawable.create(context, R.drawable.my_vd_or_avd);

Option #2: programatically using a KyrieDrawable.Builder

You can also build KyrieDrawables at runtime using the builder pattern. KyrieDrawables are similar to SVGs and VectorDrawables in that they are tree-like structures built of Nodes. As you build the tree, you can optionally assign Animations to the properties of each Node to create an animatable KyrieDrawable.

Here is a snippet of code from the sample app that builds a material design circular progress indicator:

val drawable =
    kyrieDrawable {
        viewport = size(48f, 48f)
        tint = Color.RED
        group {
            translateX(24f)
            translateY(24f)
            rotation(
                Animation.ofFloat(0f, 720f)
                    .duration(4444)
                    .repeatCount(Animation.INFINITE)
            )
            path {
                strokeColor(Color.WHITE)
                strokeWidth(4f)
                trimPathStart(
                    Animation.ofFloat(0f, 0.75f)
                        .duration(1333)
                        .repeatCount(Animation.INFINITE)
                        .interpolator("M 0 0 h .5 C .7 0 .6 1 1 1".asPathInterpolator())
                )
                trimPathEnd(
                    Animation.ofFloat(0.03f, 0.78f)
                        .duration(1333)
                        .repeatCount(Animation.INFINITE)
                        .interpolator("M 0 0 c .2 0 .1 1 .5 1 C 1 1 1 1 1 1".asPathInterpolator())
                )
                trimPathOffset(
                    Animation.ofFloat(0f, 0.25f)
                        .duration(1333)
                        .repeatCount(Animation.INFINITE)
                )
                strokeLineCap(StrokeLineCap.SQUARE)
                pathData("M 0 -18 a 18 18 0 1 1 0 36 18 18 0 1 1 0 -36")
            }
        }
    }

Features

Kyrie supports 100% of the features that VectorDrawables and AnimatedVectorDrawables provide. It also extends the functionality of VectorDrawables and AnimatedVectorDrawables in a number of ways, making it possible to create even more powerful and elaborate scalable assets and animations.

VectorDrawable features

In addition to the features supported by VectorDrawable, Kyrie provides the following:

<path> features

  • CircleNode. Equivalent to the <circle> node in SVG.
  • EllipseNode. Equivalent to the <ellipse> node in SVG.
  • LineNode. Equivalent to the <line> node in SVG.
  • RectangleNode. Equivalent to the <rect> node in SVG.
  • strokeDashArray (FloatArray). Equivalent to the stroke-dasharray attribute in SVG.
  • strokeDashOffset (Float). Equivalent to the stroke-dashoffset attribute in SVG.
  • isScalingStroke (Boolean). Equivalent to vector-effect="non-scaling-stroke" in SVG. Defines whether a path's stroke width will be affected by scaling transformations.
  • The strokeMiterLimit attribute is animatable.

<clip-path> features

  • FillType (either NON_ZERO or EVEN_ODD). Equivalent to the clip-rule attribute in SVG.
  • ClipType (either INTERSECT or DIFFERENCE). Defines whether the clipping region is additive or subtractive.

<group> features

  • Transformations (pivot, scale, rotation, and translation) can be set on any Node, not just GroupNodes.

AnimatedVectorDrawable features

In addition to the features supported by AnimatedVectorDrawable, Kyrie provides the following:

Further reading

  • Check out this blog post for more on the motivation behind the library.
  • Check out the sample app for example usages in both Java and Kotlin.
  • Check out the documentation for a complete listing of all supported Animations and Nodes that can be used when constructing KyrieDrawables programatically.

Dependency

Add this to your root build.gradle file (not your module's build.gradle file):

allprojects {
    repositories {
        // ...
        jcenter()
    }
}

Then add the library to your module's build.gradle file:

dependencies {
    // ...
    implementation 'com.github.alexjlockwood:kyrie:0.2.1'
}

Compatibility

  • Minimum Android SDK: Kyrie requires a minimum API level of 14.
  • Compile Android SDK: Kyrie requires you to compile against API 28 or later.

More Repositories

1

ShapeShifter

SVG icon animation tool for Android, iOS, and the web
TypeScript
3,895
star
2

avocado

๐Ÿฅ‘ Vector Drawable optimization tool ๐Ÿฅ‘
TypeScript
1,287
star
3

adp-delightful-details

This sample app accompanies a blog post I wrote on icon animations
Java
1,044
star
4

adp-activity-transitions

This sample app accompanies a series of blog posts I wrote on transitions in Android
Java
540
star
5

bees-and-bombs-compose

Implementing some cool animations using Jetpack Compose
Kotlin
380
star
6

android-2048-compose

2048 implemented using Jetpack Compose
Kotlin
333
star
7

adp-applistloader

Tutorial: AppListLoader (part 4)
Java
238
star
8

adp-path-morph-submission-status

Submission status path morphing example
Java
210
star
9

adp-worker-fragments

Handling Configuration Changes with Fragments
Java
206
star
10

gcm

Google Cloud Messaging for application servers implemented using the Go programming language.
Go
176
star
11

android-lint-checks-demo

A demo project that shows how to setup and write some basic custom lint checks.
Kotlin
150
star
12

adp-nested-scrolling

Sample app for the Android Design Patterns blog post on nested scrolling.
Java
136
star
13

AndroidDesignPatterns

Android Design Patterns
JavaScript
134
star
14

custom-lollipop-transitions

Java
65
star
15

svg2vd

SVG to VectorDrawable command line tool
TypeScript
47
star
16

floating-camera

Basic implementation of a floating camera view that can draw on top of other applications. Uses the same APIs that Facebook uses to implement Chatheads.
Java
46
star
17

adp-leaky-threads

Activitys, Threads, & Memory Leaks
Java
33
star
18

android-2048-strings

A repository containing all of the strings for the 2048++ application.
24
star
19

adp-contextcompat-getcolor

Java
16
star
20

godesignpatterns

Go Design Patterns
CSS
15
star
21

adp-contact-list-compose

A simple animatable contact list implemented with 100% Jetpack Compose. Written for a blog post that maybe I will finish some day...
Kotlin
13
star
22

adp-theming-buttons-with-themeoverlays

Java
9
star
23

lost-temple-analyzer

TypeScript
9
star
24

roll-off-club

Source code for the Roll Off Club site
HTML
6
star
25

arch-component-sample

Java
6
star
26

WindowInsetsPlayground

In which I figure out how window insets and status bars work on Android
Kotlin
5
star
27

15440-project3

Distributed multiplayer air hockey! Includes an Android client application (written in Java) and a distributed server (written in Go).
Java
3
star
28

network-buffer

An Android project for my networks practicum class (15-446) at CMU.
Java
2
star
29

scouting-manager-2012

Scouting Manager Android Application (as of March, 2012)
Java
2
star
30

droidcon-2017

TypeScript
1
star
31

scouting-manager-2013

Java
1
star