• Stars
    star
    295
  • Rank 140,902 (Top 3 %)
  • Language
    Java
  • Created over 8 years ago
  • Updated over 8 years ago

Reviews

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

Repository Details

🐳 Wow, Android View Animation!

中文说明 Android Arsenal

wava

Wow, Android View Animation! (capital letter of each word forms WAVA)

I wanna build another fancy Android animation library, but I was still thinking how to do that. 🐈

daimajia has built an amazing library named AndroidViewAnimations, it's really really awesome.

Currently wava is just a library based on AndroidViewAnimations with many updates. Since it has changed a lot from the latest release of AndroidViewAnimations (although I tried to keep the API as same as before), I think better make another one than pulling requests.

Later I will try my best to add other fancy new features to wava, star it if you have any interest. 😜

Sample

img

Usage

It's almost the same.

YoYo.with(technique).duration(1200)
    .interpolate(new AccelerateDecelerateInterpolator())
    .listen(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationCancel(Animator animation) {
                Toast.makeText(MainActivity.this, "canceled", Toast.LENGTH_SHORT).show();
        }
    })
    .playOn(mTarget);

Setup

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:wava:1.0.0'
}

Changes

The following are main changes from AndroidViewAnimations:

1.removed deprecated NineOldAndroids.

New applications should use minSdkVersion="14" or higher which has access to the platform animation APIs.

For example, animation reset no longer needs ViewHelper

public void reset() {
    mTarget.setAlpha(1);
    mTarget.setScaleX(1);
    mTarget.setScaleY(1);
    mTarget.setTranslationX(0);
    mTarget.setTranslationY(0);
    mTarget.setRotation(0);
    mTarget.setRotationX(0);
    mTarget.setRotationY(0);
    mTarget.setPivotX(mTarget.getMeasuredWidth() / 2.0f);
    mTarget.setPivotY(mTarget.getMeasuredHeight() / 2.0f);
}

2.simplified the core YoYo class (including Builder and YoYoString) while keeping the original API.

public static class Builder {

    private static final int DEFAULT_REPEAT = 1;//动画默认只播放一次
    private static final long DEFAULT_DELAY = 0;//动画默认没有启动延时
    private static final boolean DEFAULT_RESET = false;//动画结束默认不恢复原状
    private static final long DEFAULT_DURATION = 1000;//动画时间间隔默认是1秒

    private View target;//作用的view
    private long delay = DEFAULT_DELAY;//动画启动延迟
    private long duration = DEFAULT_DURATION;//动画持续时长
    private int repeat = DEFAULT_REPEAT;//动画重复次数
    private boolean reset = DEFAULT_RESET;//动画结束之后是否恢复到原来的状态,true表示恢复
    private BaseViewAnimator animator;//animator类
    private Interpolator interpolator;//interpolator 时间插值类
    private List<Animator.AnimatorListener> listeners = new ArrayList<Animator.AnimatorListener>();//动画的监听器

    //两个构造函数都将使得animator成为一个非空对象
    private Builder(Techniques technique) {
        this.animator = technique.getAnimator();
    }

    private Builder(BaseViewAnimator animator) {
        this.animator = animator;
    }

    public Builder duration(long duration) {
        this.duration = duration;
        return this;
    }

    public Builder delay(long delay) {
        this.delay = delay;
        return this;
    }

    public Builder interpolate(Interpolator interpolator) {
        this.interpolator = interpolator;
        return this;
    }

    public Builder listen(AnimatorListenerAdapter listener) {
        this.listeners.add(listener);
        return this;
    }

    public Builder reset(boolean reset) {
        this.reset = reset;
        return this;
    }

    public Builder repeat(int count) {
        this.repeat = count;
        return this;
    }

    //调用play表示动画正式开始,返回结果是可以控制动画的对象YoYoString
    public YoYoString playOn(View target) {
        this.target = target;
        start();
        return new YoYoString(this.animator);
    }

    //builder内部的start方法,将animatorset启动
    private void start() {
        animator.setTarget(target).setDuration(duration).setInterpolator(interpolator)
                .setStartDelay(delay).setRest(reset).setRepeat(repeat);

        if (listeners.size() > 0) {
            animator.addAllListeners(listeners);
        }

        animator.start();
    }
}

3.added supports to animation replay and animation reset after animation ends.

public void start() {
    reset();
    prepare();
    if (mRepeat != 0) {
        for (Animator animator : mAnimatorSet.getChildAnimations()) {
            ((ValueAnimator) animator).setRepeatCount(mRepeat > 0 ? mRepeat - 1 : mRepeat);//区别无穷次
            //((ValueAnimator) animator).setRepeatMode(ValueAnimator.REVERSE);
        }
    }
    if (mRest) {
        mAnimatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                reset();
            }
        });
    }
    mAnimatorSet.start();
}

4.replaced the original dependency AndroidEasingFunctions with my another library yava.

public class LandingAnimator extends BaseViewAnimator {
    @Override
    protected void prepare() {
      //before
//        mAnimatorSet.playTogether(
//                Glider.glide(Skill.QuintEaseOut, mAnimatorSet.getDuration(), ObjectAnimator.ofFloat(mTarget, "scaleX", 1.5f, 1f)),
//                Glider.glide(Skill.QuintEaseOut, mAnimatorSet.getDuration(), ObjectAnimator.ofFloat(mTarget, "scaleY", 1.5f, 1f)),
//                Glider.glide(Skill.QuintEaseOut, mAnimatorSet.getDuration(), ObjectAnimator.ofFloat(mTarget, "alpha", 0, 1f))
//        );

        //after
        ObjectAnimator animator1 = ObjectAnimator.ofFloat(mTarget, "scaleX", 1.5f, 1f);
        animator1.setInterpolator(EasingFunction.QUINT_OUT);
        ObjectAnimator animator2 = ObjectAnimator.ofFloat(mTarget, "scaleY", 1.5f, 1f);
        animator2.setInterpolator(EasingFunction.QUINT_OUT);
        ObjectAnimator animator3 = ObjectAnimator.ofFloat(mTarget, "alpha", 0, 1f);
        animator3.setInterpolator(EasingFunction.QUINT_OUT);
        mAnimatorSet.playTogether(animator1, animator2, animator3);
    }
}

5.simplified all the ViewAnimator with easy access way to mAnimatorSet and mTarget.

public class BounceAnimator extends BaseViewAnimator {
    @Override
    public void prepare() {
        mAnimatorSet.playTogether(
                ObjectAnimator.ofFloat(mTarget, "translationY", 0, 0, -30, 0, -15, 0, 0)
        );
    }
}

6.modified the effect visualization code while keeping it same as before.

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

yava

🐒 yet another view animation ( a simple and elegant view animation helper library for Android)
Java
333
star
5

Gank-for-Mac

💎 The missing Mac OS X application for gank.io (Swift)
Swift
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