• Stars
    star
    333
  • Rank 125,855 (Top 3 %)
  • Language
    Java
  • Created over 8 years ago
  • Updated almost 7 years ago

Reviews

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

Repository Details

๐Ÿ’ yet another view animation ( a simple and elegant view animation helper library for Android)

ไธญๆ–‡่ฏดๆ˜Ž jitpack Android Arsenal

Yava

Yet Another View Animation ( a simple and elegant view animation helper library for Android)

This library helps you convert any curve into ready-to-use Interpolator or TypeEvaluator for ValueAnimator, and thirty Rovert Penner's Easing Functions are already included.

You may read the following three articles to know about the reason why I create this project, and how to implement it. They fully described the relations among ValueAnimatorใ€TypeEvaluator and TimeInterpolator, hope it helps.

When Math Meets Animation(1)
When Math Meets Animation(2)
When Math Meets Animation(3)

Screenshot

img

Usage

For example, if you want to create a BOUNCE_OUT animation, you can directly use EasingFunction.BOUNCE_OUT as Interpolator or TypeEvaluator for your ValueAnimator.

Option 1: use LinearInterpolator with EasingFunction.BOUNCE_OUT (as TypeEvaluator)

ObjectAnimator animator1 = new ObjectAnimator();
animator1.setTarget(textView1);
animator1.setPropertyName("translationY");
animator1.setFloatValues(0f, -100f);
animator1.setDuration(1000);

animator1.setInterpolator(new LinearInterpolator());
animator1.setEvaluator(EasingFunction.BOUNCE_OUT); //use `EasingFunction.BOUNCE_OUT` as `TypeEvaluator`

animator1.start();

Option 2: use EasingFunction.BOUNCE_OUT (as Interpolator) with FloatEvaluator ("Linear TypeEvaluator")

ObjectAnimator animator2 = new ObjectAnimator();
animator2.setTarget(textView2);
animator2.setPropertyName("translationY");
animator2.setFloatValues(0f, -100f);
animator2.setDuration(1000);

animator2.setInterpolator(EasingFunction.BOUNCE_OUT); //use `EasingFunction.BOUNCE_OUT` as `Interpolator`
animator2.setEvaluator(new FloatEvaluator());

animator2.start();

Want to use your customized function curve? It's simple!
Try Functions.with(IFunction youFunctionImplementation)!

Example 1: use it as TypeEvaluator

ObjectAnimator animator1 = new ObjectAnimator();
animator1.setTarget(textView1);
animator1.setPropertyName("translationY");
animator1.setFloatValues(0f, -100f);
animator1.setDuration(1000);

animator1.setInterpolator(new LinearInterpolator());
animator1.setEvaluator(Functions.with(new IFunction() { //customized TypeEvaluator
    @Override
    public float getValue(float input) {
        return input * 2 + 3;
    }
}));

animator1.start();

Or you can also use it as Interpolator:

ObjectAnimator animator2 = new ObjectAnimator();
animator2.setTarget(textView2);
animator2.setPropertyName("translationY");
animator2.setFloatValues(0f, -100f);
animator2.setDuration(1000);

animator2.setInterpolator(Functions.with(new IFunction() { //customized Interpolator
    @Override
    public float getValue(float input) {
        return input * 2 + 3;
    }
}));
animator2.setEvaluator(new FloatEvaluator());

animator2.start();

Setup

Copy those four classes into your project, then you are set!

OR

1.add this in your build.gradle file in root project

allprojects {
    repositories {
        ...
        maven { url "https://www.jitpack.io" }
    }
}

2.add the following dependency

dependencies {
    compile 'com.github.hujiaweibujidao:yava:1.0.0'
}

Documentation

There are only four core classes in library.

(1) IFunction: interface

/**
 * Function Interface: given input, get the value result
 */
public interface IFunction {
    float getValue(float input);
}

(2)AbstractFunction: abstract class

/**
 * abstract function, you can use it as `Interpolator` or `TypeEvaluator`
 */
public abstract class AbstractFunction implements IFunction, Interpolator, TypeEvaluator<Float> {

    @Override
    public float getInterpolation(float input) {
        return getValue(input);
    }

    @Override
    public Float evaluate(float fraction, Float startValue, Float endValue) {
        return startValue + getValue(fraction) * (endValue - startValue);
    }
}

(3)Functions: class

/**
 * convert any function curve to ready-to-use AbstractFunction
 */
class Functions {

    public static AbstractFunction with(final IFunction function) {
        return new AbstractFunction() {
            @Override
            public float getValue(float input) {
                return function.getValue(input);
            }
        };
    }
}

(4)EasingFunction: enum with thirty Rovert Penner's Easing Functions included

/**
 * thirty Rovert Penner's Easing Functions
 */
public enum EasingFunction implements IFunction, Interpolator, TypeEvaluator<Float> {

    /* ------------------------------------------------------------------------------------------- */
    /* BACK
    /* ------------------------------------------------------------------------------------------- */
    BACK_IN {
        @Override
        public float getValue(float input) {
            return input * input * ((1.70158f + 1) * input - 1.70158f);
        }
    },
    BACK_OUT {
        @Override
        public float getValue(float input) {
            return ((input = input - 1) * input * ((1.70158f + 1) * input + 1.70158f) + 1);
        }
    },
    BACK_INOUT {
        @Override
        public float getValue(float input) {
            float s = 1.70158f;
            if ((input *= 2) < 1) {
                return 0.5f * (input * input * (((s *= (1.525f)) + 1) * input - s));
            }
            return 0.5f * ((input -= 2) * input * (((s *= (1.525f)) + 1) * input + s) + 2);
        }
    },

    //other easing functions ......

    private float duration = 1000f;

    public float getDuration() {
        return duration;
    }

    public EasingFunction setDuration(float duration) {
        this.duration = duration;
        return this;
    }

    @Override
    public float getInterpolation(float input) {
        return getValue(input);
    }

    @Override
    public Float evaluate(float fraction, Float startValue, Float endValue) {
        return startValue + getValue(fraction) * (endValue - startValue);
    }

    //Math constants
    public static final float PI = (float) Math.PI;
    public static float TWO_PI = PI * 2.0f;
    public static float HALF_PI = PI * 0.5f;
}

References

1.EaseInterpolator
2.AnimationEasingFunctions
3.easings.net

wava

Currently I'm planning to build another fancy animation library named wava for Android, follow that project or my Github if you have any interest in it. ๐Ÿ˜„

License

The MIT License (MIT)

Copyright (c) 2016 Hujiawei

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

More Repositories

1

FabDialogMorph

๐Ÿ  Fab and Dialog Morphing Animation on Android
Java
738
star
2

AndroidInterviews

๐Ÿ‚ Helpful materials for Android Interviews
501
star
3

poetry

china ancient poetry project data
368
star
4

Gank-for-Mac

๐Ÿ’Ž The missing Mac OS X application for gank.io (Swift)
Swift
295
star
5

wava

๐Ÿณ Wow, Android View Animation!
Java
295
star
6

Gank-Alfred-Workflow

๐Ÿบ An Alfred Workflow for searching ganks(ๅนฒ่ดง) in gank.io
Python
188
star
7

TinyWeibo

๐Ÿˆ [DEPRECATED]An Android application for Sina Weibo
Java
99
star
8

WeChat4j

[DEPRECATED]An Open Source Java SDK for WeChat Open Platform
Java
45
star
9

IconFontApp

Demo application for using IconFont on Android platform.
Java
44
star
10

XFace

A Face Recognition Application running on Android Platform
Java
40
star
11

Ganks-for-gank.io

A data fetcher and parser for daily issues created by gank.io
Java
26
star
12

ProgressView

ProgressView on Android
Java
12
star
13

customlint

custom lint rules
Java
10
star
14

NumberTextView

A simple view which switchs numbers with translation animation
Java
8
star
15

daoism-motionlayout

Daoism-MotionLayout is a simple android application showing MotionLayout animation
Kotlin
8
star
16

kiss-monitor

Simple performance monitor tool for Android application.
Java
7
star
17

XingShan

ไฝฟๅพ’่กŒๅ–„๏ผŒ่ฎฉ่กŒๅ–„ๆˆไธบไธ€็งไน ๆƒฏ
Java
5
star
18

hujiaweibujidao.github.io

https://hujiaweibujidao.github.io
HTML
5
star
19

AnnotationView

AnnotationView on Android
Java
4
star
20

Ganks-for-andoirdweekly.net

๐Ÿš A data crawler and parser for weekly issues created by androidweekly.net
Java
4
star
21

flac

An Android Recorder which supports flac format.
C
4
star
22

kiss-utils

Simple util classes for Android.
Java
4
star
23

GankHub-site

๐Ÿ˜ The hub for technical ganks(ๅนฒ่ดง) with powerful search ability.
Java
4
star
24

android-ocr-demo

a demo application forked from android-ocr with some files modified to make it run.
Java
3
star
25

javafx2-doc-cn

Chinese translation for the official documentation of JavaFx 2.
3
star
26

LearnKotlin

head first learning kotlin
Kotlin
2
star
27

javayhu.github.io.hugo

hugo blog files
CSS
2
star
28

plugin

Simple Android Plugin Framework for study.
Java
1
star
29

arouter

activity router
Java
1
star
30

XSolutions

OJ Solutions including BestCoders, CodeForces, LeetCode OJ, Google Code Jam, HOJ, POJ, etc
Java
1
star