{"id":18339594,"url":"https://github.com/javayhu/yava","last_synced_at":"2025-04-07T05:12:38.256Z","repository":{"id":147670242,"uuid":"59666181","full_name":"javayhu/yava","owner":"javayhu","description":":monkey: yet another view animation ( a simple and elegant view animation helper library for Android)","archived":false,"fork":false,"pushed_at":"2024-03-21T11:02:27.000Z","size":529,"stargazers_count":333,"open_issues_count":0,"forks_count":22,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-30T21:14:15.622Z","etag":null,"topics":["android","animation"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/javayhu.png","metadata":{"files":{"readme":"README-CN.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-05-25T13:38:50.000Z","updated_at":"2024-11-13T10:18:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"f0ac9ce2-24dc-47d1-82e8-7754b3304243","html_url":"https://github.com/javayhu/yava","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javayhu%2Fyava","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javayhu%2Fyava/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javayhu%2Fyava/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javayhu%2Fyava/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/javayhu","download_url":"https://codeload.github.com/javayhu/yava/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595335,"owners_count":20963943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","animation"],"created_at":"2024-11-05T20:18:31.677Z","updated_at":"2025-04-07T05:12:38.229Z","avatar_url":"https://github.com/javayhu.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![jitpack](https://www.jitpack.io/v/hujiaweibujidao/yava.svg)](https://www.jitpack.io/#hujiaweibujidao/yava)  [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-yava-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3639) \u003ca href=\"http://www.methodscount.com/?lib=com.github.hujiaweibujidao%3Ayava%3A1.0.0\"\u003e\u003cimg src=\"https://img.shields.io/badge/Methods and size-core: 129 | deps: 15167 | 37 KB-e91e63.svg\"/\u003e\u003c/a\u003e   \n\n## Yava\n\n\u003e Yet Another View Animation ( a simple and elegant view animation helper library for Android)    \n\nThis 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.\n\n关于本项目的创建缘由以及实现思路，欢迎阅读我写的这三篇文章，详细介绍了Android动画中的三个重要类：`ValueAnimator`、`TypeEvaluator`和`TimeInterpolator`，我保证您会有所收获的 😜\n\n[当数学遇上动画：讲述`ValueAnimator`、`TypeEvaluator`和`TimeInterpolator`之间的恩恩怨怨(1)](http://hujiaweibujidao.github.io/blog/2016/05/26/when-math-meets-android-animation/)    \n[当数学遇上动画：讲述`ValueAnimator`、`TypeEvaluator`和`TimeInterpolator`之间的恩恩怨怨(2)](http://hujiaweibujidao.github.io/blog/2016/05/27/When-Math-meets-Android-Animation-2/)     \n[当数学遇上动画：讲述`ValueAnimator`、`TypeEvaluator`和`TimeInterpolator`之间的恩恩怨怨(3)](http://hujiaweibujidao.github.io/blog/2016/05/27/When-Math-meets-Android-Animation-3/)     \n\n该项目实现的功能就是将抽象的函数曲线轻松转换成立即可用的`Interpolator`和`TypeEvaluator`，然后应用在Android动画中。这个项目还提供了常见的30个缓动函数(Easing Functions)的实现，它们既可以当做`Interpolator`来用，又可以当做`TypeEvaluator`来用，真的非常方便。\n\n## Screenshot\n\n![img](yava.gif)\n\n## Usage\n\n举个例子，以弹跳动画效果为例，可以直接使用`EasingFunction.BOUNCE_OUT`作为`Interpolator`或者`TypeEvaluator`来使用：\n\n第一种方式：使用线性插值器和自定义的TypeEvaluator\n\n```java\nObjectAnimator animator1 = new ObjectAnimator();\nanimator1.setTarget(textView1);\nanimator1.setPropertyName(\"translationY\");\nanimator1.setFloatValues(0f, -100f);\nanimator1.setDuration(1000);\nanimator1.setInterpolator(new LinearInterpolator());\nanimator1.setEvaluator(EasingFunction.BOUNCE_OUT); //这里将EasingFunction.BOUNCE_OUT作为TypeEvaluator来使用\nanimator1.start();\n```\n\n第二种方式：使用自定义的Interpolator和\"线性估值器\"\n\n```java\nObjectAnimator animator2 = new ObjectAnimator();\nanimator2.setTarget(textView2);\nanimator2.setPropertyName(\"translationY\");\nanimator2.setFloatValues(0f, -100f);\nanimator2.setDuration(1000);\nanimator2.setInterpolator(EasingFunction.BOUNCE_OUT); //这里将EasingFunction.BOUNCE_OUT作为Interpolator来使用\nanimator2.setEvaluator(new FloatEvaluator());\nanimator2.start();\n```\n\n如果你想使用自己定义的函数来制作动画，可以使用`Functions`的`with`方法，传入一个实现了`IFunction`接口的类就行，返回值你既可以当做`Interpolator`，也可以当做`TypeEvaluator`来使用\n\n代码示例：\n\n```java\nObjectAnimator animator1 = new ObjectAnimator();\nanimator1.setTarget(textView1);\nanimator1.setPropertyName(\"translationY\");\nanimator1.setFloatValues(0f, -100f);\nanimator1.setDuration(1000);\nanimator1.setInterpolator(new LinearInterpolator());\nanimator1.setEvaluator(Functions.with(new IFunction() { //自定义为TypeEvaluator\n    @Override\n    public float getValue(float input) {\n        return input * 2 + 3;\n    }\n}));\nanimator1.start();\n```\n\n或者这样：\n\n\n```java\nObjectAnimator animator2 = new ObjectAnimator();\nanimator2.setTarget(textView2);\nanimator2.setPropertyName(\"translationY\");\nanimator2.setFloatValues(0f, -100f);\nanimator2.setDuration(1000);\nanimator2.setInterpolator(Functions.with(new IFunction() { //自定义为Interpolator\n    @Override\n    public float getValue(float input) {\n        return input * 2 + 3;\n    }\n}));\nanimator2.setEvaluator(new FloatEvaluator());\nanimator2.start();\n```\n\n## Setup\n\n你只需要拷贝`library`中的4个重要类到你的项目中就行了！\n\n或者\n\n1.在项目根目录的`build.gradle`文件中加入\n\n```\nallprojects {\n    repositories {\n        ...\n        maven { url \"https://www.jitpack.io\" }\n    }\n}\n```\n\n2.然后在需要的`build.gradle`文件中加入依赖\n\n```\ndependencies {\n    compile 'com.github.hujiaweibujidao:yava:1.0.0'\n}\n```\n\n## Documentation\n\n项目只有4个核心类，放在`library`中\n\n(1) `IFunction`接口\n\n```java\n/**\n * 函数接口：给定输入，得到输出\n */\npublic interface IFunction {\n    float getValue(float input);\n}\n```\n\n(2)`AbstractFunction`抽象类\n\n```java\n/**\n * 抽象函数实现，既可以当做简单函数使用，也可以当做Interpolator或者TypeEvaluator去用于制作动画\n */\npublic abstract class AbstractFunction implements IFunction, Interpolator, TypeEvaluator\u003cFloat\u003e {\n\n    @Override\n    public float getInterpolation(float input) {\n        return getValue(input);\n    }\n\n    @Override\n    public Float evaluate(float fraction, Float startValue, Float endValue) {\n        return startValue + getValue(fraction) * (endValue - startValue);\n    }\n}\n```\n\n(3)`Functions`类\n\n```java\n/**\n * 工具类，将自定义的函数快速封装成AbstractFunction\n */\nclass Functions {\n\n    public static AbstractFunction with(final IFunction function) {\n        return new AbstractFunction() {\n            @Override\n            public float getValue(float input) {\n                return function.getValue(input);\n            }\n        };\n    }\n}\n```\n\n(4)`EasingFunction`枚举：包含了30个常见的缓动函数\n\n```java\n/**\n * 常见的30个缓动函数的实现\n */\npublic enum EasingFunction implements IFunction, Interpolator, TypeEvaluator\u003cFloat\u003e {\n\n    /* ------------------------------------------------------------------------------------------- */\n    /* BACK\n    /* ------------------------------------------------------------------------------------------- */\n    BACK_IN {\n        @Override\n        public float getValue(float input) {\n            return input * input * ((1.70158f + 1) * input - 1.70158f);\n        }\n    },\n    BACK_OUT {\n        @Override\n        public float getValue(float input) {\n            return ((input = input - 1) * input * ((1.70158f + 1) * input + 1.70158f) + 1);\n        }\n    },\n    BACK_INOUT {\n        @Override\n        public float getValue(float input) {\n            float s = 1.70158f;\n            if ((input *= 2) \u003c 1) {\n                return 0.5f * (input * input * (((s *= (1.525f)) + 1) * input - s));\n            }\n            return 0.5f * ((input -= 2) * input * (((s *= (1.525f)) + 1) * input + s) + 2);\n        }\n    },\n\n    //other easing functions ......\n\n    //如果这个function在求值的时候需要duration作为参数的话，那么可以通过setDuration来设置，否则使用默认值\n    private float duration = 1000f;\n\n    public float getDuration() {\n        return duration;\n    }\n\n    public EasingFunction setDuration(float duration) {\n        this.duration = duration;\n        return this;\n    }\n\n    //将Function当做Interpolator使用，默认的实现，不需要枚举元素去重新实现\n    @Override\n    public float getInterpolation(float input) {\n        return getValue(input);\n    }\n\n    //将Function当做TypeEvaluator使用，默认的实现，不需要枚举元素去重新实现\n    @Override\n    public Float evaluate(float fraction, Float startValue, Float endValue) {\n        return startValue + getValue(fraction) * (endValue - startValue);\n    }\n\n    //几个数学常量\n    public static final float PI = (float) Math.PI;\n    public static float TWO_PI = PI * 2.0f;\n    public static float HALF_PI = PI * 0.5f;\n}\n```\n\n## Reference\n\n本项目主要参考了以下项目和内容    \n1.[EaseInterpolator](https://github.com/cimi-chen/EaseInterpolator)    \n2.[AnimationEasingFunctions](https://github.com/daimajia/AnimationEasingFunctions)       \n3.[easings.net](http://easings.net/)     \n\n## License\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2016 Hujiawei\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavayhu%2Fyava","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjavayhu%2Fyava","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavayhu%2Fyava/lists"}