├── .gitignore
├── LICENSE
├── README.md
├── actions
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── dtx12
│ │ └── android_animations_actions
│ │ └── actions
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── dtx12
│ │ └── android_animations_actions
│ │ └── actions
│ │ ├── ActionType.java
│ │ ├── Actions.java
│ │ ├── ArgbEvaluator.java
│ │ ├── Interpolations.java
│ │ ├── RepeatAction.java
│ │ ├── TypedAction.java
│ │ └── listeners
│ │ ├── AlphaUpdateListener.java
│ │ ├── BaseUpdateListener.java
│ │ ├── ColorUpdateListener.java
│ │ ├── MoveUpdateListener.java
│ │ ├── RotationUpdateListener.java
│ │ └── ScaleUpdateListener.java
│ └── res
│ └── values
│ └── strings.xml
├── build.gradle
├── demo
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── dtx12
│ │ └── android_animations_actions
│ │ └── demo
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── dtx12
│ │ └── android_animations_actions
│ │ └── demo
│ │ └── MainActivity.java
│ └── res
│ ├── drawable
│ ├── circle.xml
│ └── square.xml
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.gitignore.io
2 |
3 | ### Android ###
4 | # Built application files
5 | *.apk
6 | *.ap_
7 |
8 | # Files for the Dalvik VM
9 | *.dex
10 |
11 | # Java class files
12 | *.class
13 |
14 | # Generated files
15 | bin/
16 | gen/
17 |
18 | # Gradle files
19 | .gradle/
20 | build/
21 | /*/build/
22 |
23 | # Local configuration file (sdk path, etc)
24 | local.properties
25 |
26 | # Proguard folder generated by Eclipse
27 | proguard/
28 |
29 | # Log Files
30 | *.log
31 |
32 | ### Android Patch ###
33 | gen-external-apklibs
34 |
35 |
36 | ### Intellij ###
37 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
38 |
39 | *.iml
40 |
41 | ## Directory-based project format:
42 | .idea/
43 | # if you remove the above rule, at least ignore the following:
44 |
45 | # User-specific stuff:
46 | # .idea/workspace.xml
47 | # .idea/tasks.xml
48 | # .idea/dictionaries
49 |
50 | # Sensitive or high-churn files:
51 | # .idea/dataSources.ids
52 | # .idea/dataSources.xml
53 | # .idea/sqlDataSources.xml
54 | # .idea/dynamic.xml
55 | # .idea/uiDesigner.xml
56 |
57 | # Gradle:
58 | # .idea/gradle.xml
59 | # .idea/libraries
60 |
61 | # Mongo Explorer plugin:
62 | # .idea/mongoSettings.xml
63 |
64 | ## File-based project format:
65 | *.ipr
66 | *.iws
67 |
68 | ## Plugin-specific files:
69 |
70 | # IntelliJ
71 | out/
72 |
73 | # mpeltonen/sbt-idea plugin
74 | .idea_modules/
75 |
76 | # JIRA plugin
77 | atlassian-ide-plugin.xml
78 |
79 | # Crashlytics plugin (for Android Studio and IntelliJ)
80 | com_crashlytics_export_strings.xml
81 | crashlytics.properties
82 | crashlytics-build.properties
83 |
84 | ### OSX ###
85 | .DS_Store
86 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 dtx12
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](http://www.android-gems.com/lib/dtx12/AndroidAnimationsActions)
2 |
3 | # Android Animations Actions
4 | Actions for android animations. Inspired by libgdx scene2d actions.
5 |
6 | The main goal of this project is making creating of complex animations easier.
7 | You may create animations like in demo with just a couple lines of code.
8 |
9 | ##Actions
10 | `sequence` - executes actions sequentially
11 | `delay` - inserts pause into sequence
12 | `run` - will run target runnable, useful in sequences
13 | `parallel` - executes actions at the same time
14 | `color` - color animation for view
15 | `scaleTo` - scales view to defined values
16 | `scaleBy` - scales view by defined values
17 | `alpha` - alpha animation
18 | `fadeIn` - fades alpha to 1
19 | `fadeOut` - fades alpha to 0
20 | `rotateTo` - rotates view to defined degree
21 | `rotateBy` - rotates view by defined degree
22 | `moveTo` - moves view to defined x, y
23 | `moveBy` - moves view by defined x, y
24 | `repeat` - repeats action using defined number of times
25 | `forever` - repeats action infinite
26 |
27 | `play` - plays specified action on specified view
28 |
29 | ##Interpolations
30 | Library contains class `Interpolations` with different predefined interpolations which may be useful for animations.
31 |
32 | ## Demo
33 | For better quality please check package demo in the project.
34 | 
35 |
36 | ## Gradle
37 | ```java
38 | repositories {
39 | jcenter()
40 | }
41 |
42 | dependencies {
43 | compile 'com.dtx12:actions:0.1.4'
44 | }
45 | ```
46 |
--------------------------------------------------------------------------------
/actions/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/actions/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:1.1.1'
7 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
8 | classpath 'com.github.dcendents:android-maven-plugin:1.2'
9 | }
10 | }
11 | apply plugin: 'com.android.library'
12 | apply plugin: 'com.jfrog.bintray'
13 | apply plugin: 'com.github.dcendents.android-maven'
14 |
15 | repositories {
16 | jcenter()
17 | }
18 |
19 | version = "0.1.4"
20 | group = "com.dtx12"
21 |
22 | android {
23 | compileSdkVersion 23
24 | buildToolsVersion "23.0.1"
25 |
26 | defaultConfig {
27 | minSdkVersion 14
28 | targetSdkVersion 23
29 | versionCode 1
30 | versionName "1.0"
31 | }
32 | buildTypes {
33 | release {
34 | minifyEnabled false
35 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
36 | }
37 | }
38 | }
39 |
40 | bintray {
41 | user = System.getenv('BINTRAY_USER')
42 | key = System.getenv('BINTRAY_KEY')
43 | configurations = ['archives']
44 | pkg {
45 | repo = 'maven'
46 | name = 'animations-actions'
47 | desc = 'Actions for android animations. Inspired by libgdx scene2d actions.'
48 | licenses = ['MIT']
49 | vcsUrl = 'https://github.com/dtx12/AndroidAnimationsActions.git'
50 | issueTrackerUrl = 'https://github.com/dtx12/AndroidAnimationsActions/issues'
51 | labels = ['android', 'animations', 'actions']
52 | publicDownloadNumbers = true
53 | publish = true
54 | }
55 | }
56 |
57 | dependencies {
58 | compile fileTree(dir: 'libs', include: ['*.jar'])
59 | compile 'com.android.support:appcompat-v7:23.0.1'
60 | }
61 |
62 | install {
63 | repositories.mavenInstaller {
64 | pom {
65 | project {
66 | packaging 'aar'
67 | groupId 'com.dtx12'
68 | artifactId 'actions'
69 | name "Android Animations as Actions"
70 | description 'Actions for android animations. Inspired by libgdx scene2d actions.'
71 | url 'https://github.com/dtx12/AndroidAnimationsActions'
72 |
73 | developers {
74 | developer {
75 | id 'dtx12'
76 | name 'Bogdan Kiselev'
77 | email 'dtx1212@gmail.com'
78 | }
79 | }
80 |
81 | licenses {
82 | license {
83 | name 'MIT'
84 | url 'http://opensource.org/licenses/mit-license.php'
85 | }
86 | }
87 |
88 | scm {
89 | url 'https://github.com/dtx12/AndroidAnimationsActions'
90 | connection 'https://github.com/dtx12/AndroidAnimationsActions.git'
91 | developerConnection 'https://github.com/dtx12/AndroidAnimationsActions.git'
92 | }
93 | }
94 | }
95 | }
96 | }
97 |
98 | task sourcesJar(type: Jar) {
99 | from android.sourceSets.main.java.srcDirs
100 | classifier = 'sources'
101 | }
102 |
103 | task javadoc(type: Javadoc) {
104 | source = android.sourceSets.main.java.srcDirs
105 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
106 | }
107 |
108 | task javadocJar(type: Jar, dependsOn: javadoc) {
109 | classifier = 'javadoc'
110 | from javadoc.destinationDir
111 | }
112 |
113 | artifacts {
114 | archives javadocJar
115 | archives sourcesJar
116 | }
--------------------------------------------------------------------------------
/actions/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:/Program Files (x86)/Android/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/actions/src/androidTest/java/com/dtx12/android_animations_actions/actions/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.dtx12.android_animations_actions.actions;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/actions/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/ActionType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2015 dtx12
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dtx12.android_animations_actions.actions;
26 |
27 | enum ActionType {
28 | ALPHA, SCALE_TO, SCALE_BY, SIZE_TO, SIZE_BY, ROTATE_TO, ROTATE_BY, COLOR, MOVE_TO, MOVE_BY
29 | }
30 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/Actions.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2015 dtx12
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dtx12.android_animations_actions.actions;
26 |
27 | import android.animation.Animator;
28 | import android.animation.AnimatorListenerAdapter;
29 | import android.animation.AnimatorSet;
30 | import android.animation.ValueAnimator;
31 | import android.support.annotation.NonNull;
32 | import android.support.annotation.Nullable;
33 | import android.view.View;
34 | import android.view.animation.Interpolator;
35 |
36 | public final class Actions {
37 |
38 | private static void setPropertiesForAnimator(@NonNull Animator animator, float duration, @Nullable Interpolator interpolator) {
39 | if (duration < 0) {
40 | throw new IllegalStateException("Duration cannot be negative");
41 | }
42 | animator.setDuration((long) (duration * 1000));
43 | if (interpolator != null) {
44 | animator.setInterpolator(interpolator);
45 | }
46 | }
47 |
48 | /**
49 | * Repeats action forever
50 | *
51 | * @param animator action to repeat
52 | */
53 | @NonNull
54 | public static Animator forever(@NonNull Animator animator) {
55 | return repeat(-1, animator);
56 | }
57 |
58 | /**
59 | * Repeats action specified count of times
60 | *
61 | * @param count how many times action should be repeated
62 | * @param animator action to repeat
63 | */
64 | @NonNull
65 | public static Animator repeat(final int count, @NonNull Animator animator) {
66 | if (count <= 1 && count != -1)
67 | return animator;
68 |
69 | return new RepeatAction(count, animator);
70 | }
71 |
72 | /**
73 | * Makes instant transition from start color to end
74 | *
75 | * @param from start color in ARGB
76 | * @param to end color in ARGB
77 | */
78 | @NonNull
79 | public static Animator color(int from, int to) {
80 | return color(from, to, 0);
81 | }
82 |
83 | /**
84 | * Animates transition between specified colors
85 | *
86 | * @param from start color in ARGB
87 | * @param to end color in ARGB
88 | * @param duration animation duration in seconds
89 | */
90 | @NonNull
91 | public static Animator color(int from, int to, float duration) {
92 | return color(from, to, duration, null);
93 | }
94 |
95 | /**
96 | * Animates transition between specified colors
97 | *
98 | * @param from start color in ARGB
99 | * @param to end color in ARGB
100 | * @param duration animation duration in seconds
101 | * @param interpolator interpolator which will be used for this animation. See also {@link Interpolations}
102 | */
103 | @NonNull
104 | public static Animator color(int from, int to, float duration, @Nullable Interpolator interpolator) {
105 | TypedAction action = new TypedAction();
106 | setPropertiesForAnimator(action, duration, interpolator);
107 | action.setType(ActionType.COLOR);
108 | action.setIntTargets(from, to);
109 | return action;
110 | }
111 |
112 | /**
113 | * Runs specified runnable
114 | *
115 | * @param runnable runnable to run
116 | */
117 | @NonNull
118 | public static Animator run(@NonNull final Runnable runnable) {
119 | ValueAnimator animator = new ValueAnimator();
120 | animator.setIntValues(1);
121 | animator.addListener(new AnimatorListenerAdapter() {
122 | @Override
123 | public void onAnimationEnd(Animator animation) {
124 | runnable.run();
125 | }
126 | });
127 | return animator;
128 | }
129 |
130 | /**
131 | * Rotates view by specified degree instantly
132 | *
133 | * @param rotation rotation in degrees
134 | */
135 | @NonNull
136 | public static Animator rotateBy(float rotation) {
137 | return rotateBy(rotation, 0);
138 | }
139 |
140 | /**
141 | * Animates view rotating by specified degree
142 | *
143 | * @param rotation rotation in degrees
144 | * @param duration animation duration
145 | */
146 | @NonNull
147 | public static Animator rotateBy(float rotation, float duration) {
148 | return rotateBy(rotation, duration, null);
149 | }
150 |
151 | /**
152 | * Animates view rotating by specified degree
153 | *
154 | * @param rotation rotation in degrees
155 | * @param duration animation duration
156 | * @param interpolator interpolator which will be used for this animation. See also {@link Interpolations}
157 | */
158 | @NonNull
159 | public static Animator rotateBy(float rotation, float duration, @Nullable Interpolator interpolator) {
160 | return rotate(rotation, duration, interpolator, ActionType.ROTATE_BY);
161 | }
162 |
163 | /**
164 | * Rotates view to specified degree instantly
165 | *
166 | * @param rotation rotation in degrees
167 | */
168 | @NonNull
169 | public static Animator rotateTo(float rotation) {
170 | return rotateTo(rotation, 0);
171 | }
172 |
173 | /**
174 | * Animates view rotating to specified degree
175 | *
176 | * @param rotation rotation in degrees
177 | * @param duration animation duration
178 | */
179 | @NonNull
180 | public static Animator rotateTo(float rotation, float duration) {
181 | return rotateTo(rotation, duration, null);
182 | }
183 |
184 | /**
185 | * Animates view rotating to specified degree
186 | *
187 | * @param rotation rotation rotation in degrees
188 | * @param duration duration animation duration
189 | * @param interpolator interpolator which will be used for this animation. See also {@link Interpolations}
190 | */
191 | @NonNull
192 | public static Animator rotateTo(float rotation, float duration, @Nullable Interpolator interpolator) {
193 | return rotate(rotation, duration, interpolator, ActionType.ROTATE_TO);
194 | }
195 |
196 | @NonNull
197 | private static Animator rotate(float rotation, float duration, @Nullable Interpolator interpolator, ActionType type) {
198 | TypedAction action = new TypedAction();
199 | setPropertiesForAnimator(action, duration, interpolator);
200 | action.setType(type);
201 | action.setFloatTargets(rotation);
202 | return action;
203 | }
204 |
205 | /**
206 | * Moves view by specified x, y instantly
207 | *
208 | * @param x x
209 | * @param y y
210 | */
211 | @NonNull
212 | public static Animator moveBy(float x, float y) {
213 | return moveBy(x, y, 0);
214 | }
215 |
216 | /**
217 | * Moves view with animation by specified x, y
218 | *
219 | * @param x x
220 | * @param y y
221 | * @param duration animation duration
222 | */
223 | @NonNull
224 | public static Animator moveBy(float x, float y, float duration) {
225 | return moveBy(x, y, duration, null);
226 | }
227 |
228 | /**
229 | * Moves view with animation by specified x, y
230 | *
231 | * @param x x
232 | * @param y y
233 | * @param duration animation duration
234 | * @param interpolator interpolator which will be used for this animation. See also {@link Interpolations}
235 | */
236 | @NonNull
237 | public static Animator moveBy(float x, float y, float duration, @Nullable Interpolator interpolator) {
238 | return move(x, y, duration, interpolator, ActionType.MOVE_BY);
239 | }
240 |
241 | /**
242 | * Moves view to specified x, y instantly
243 | *
244 | * @param x x
245 | * @param y y
246 | */
247 | @NonNull
248 | public static Animator moveTo(float x, float y) {
249 | return moveTo(x, y, 0);
250 | }
251 |
252 | /**
253 | * Moves view with animation to specified x, y
254 | *
255 | * @param x x
256 | * @param y y
257 | * @param duration animation duration
258 | */
259 | @NonNull
260 | public static Animator moveTo(float x, float y, float duration) {
261 | return moveTo(x, y, duration, null);
262 | }
263 |
264 | /**
265 | * Moves view with animation to specified x, y
266 | *
267 | * @param x x
268 | * @param y y
269 | * @param duration animation duration
270 | * @param interpolator interpolator which will be used for this animation. See also {@link Interpolations}
271 | */
272 | @NonNull
273 | public static Animator moveTo(float x, float y, float duration, @Nullable Interpolator interpolator) {
274 | return move(x, y, duration, interpolator, ActionType.MOVE_TO);
275 | }
276 |
277 | @NonNull
278 | private static Animator move(float x, float y, float duration, @Nullable Interpolator interpolator, @NonNull ActionType type) {
279 | TypedAction action = new TypedAction();
280 | setPropertiesForAnimator(action, duration, interpolator);
281 | action.setFloatTargets(x, y);
282 | action.setType(type);
283 | return action;
284 | }
285 |
286 | /**
287 | * Scales view to specified scaleX, scaleY instantly
288 | *
289 | * @param scaleX scaleX
290 | * @param scaleY scaleY
291 | */
292 | @NonNull
293 | public static Animator scaleTo(float scaleX, float scaleY) {
294 | return scaleTo(scaleX, scaleY, 0);
295 | }
296 |
297 | /**
298 | * Scales view to specified scaleX, scaleY with animation
299 | *
300 | * @param scaleX scaleX
301 | * @param scaleY scaleY
302 | * @param duration animation duration
303 | */
304 | @NonNull
305 | public static Animator scaleTo(float scaleX, float scaleY, float duration) {
306 | return scaleTo(scaleX, scaleY, duration, null);
307 | }
308 |
309 | /**
310 | * Scales view to specified scaleX, scaleY with animation
311 | *
312 | * @param scaleX scaleX
313 | * @param scaleY scaleY
314 | * @param duration animation duration
315 | * @param interpolator interpolator which will be used for this animation. See also {@link Interpolations}
316 | */
317 | @NonNull
318 | public static Animator scaleTo(float scaleX, float scaleY, float duration, @Nullable Interpolator interpolator) {
319 | return scale(scaleX, scaleY, duration, interpolator, ActionType.SCALE_TO);
320 | }
321 |
322 | /**
323 | * Scales view by specified scaleX, scaleY instantly
324 | *
325 | * @param scaleX scaleX
326 | * @param scaleY scaleY
327 | */
328 | @NonNull
329 | public static Animator scaleBy(float scaleX, float scaleY) {
330 | return scaleBy(scaleX, scaleY, 0);
331 | }
332 |
333 | /**
334 | * Scales view by specified scaleX, scaleY with animation
335 | *
336 | * @param scaleX scaleX
337 | * @param scaleY scaleY
338 | * @param duration animation duration
339 | */
340 | public static Animator scaleBy(float scaleX, float scaleY, float duration) {
341 | return scaleBy(scaleX, scaleY, duration, null);
342 | }
343 |
344 | /**
345 | * Scales view by specified scaleX, scaleY with animation
346 | *
347 | * @param scaleX scaleX
348 | * @param scaleY scaleY
349 | * @param duration animation duration
350 | * @param interpolator interpolator which will be used for this animation. See also {@link Interpolations}
351 | */
352 | @NonNull
353 | public static Animator scaleBy(float scaleX, float scaleY, float duration, @Nullable Interpolator interpolator) {
354 | return scale(scaleX, scaleY, duration, interpolator, ActionType.SCALE_BY);
355 | }
356 |
357 | @NonNull
358 | private static Animator scale(float scaleX, float scaleY, float duration, @Nullable Interpolator interpolator, @NonNull ActionType type) {
359 | TypedAction action = new TypedAction();
360 | setPropertiesForAnimator(action, duration, interpolator);
361 | action.setFloatTargets(scaleX, scaleY);
362 | action.setType(type);
363 | return action;
364 | }
365 |
366 | /**
367 | * Fades view alpha to 0 instantly
368 | */
369 | @NonNull
370 | public static Animator fadeOut() {
371 | return alpha(0);
372 | }
373 |
374 | /**
375 | * Fades view alpha to 0 with animation
376 | *
377 | * @param duration animation duration
378 | */
379 | @NonNull
380 | public static Animator fadeOut(float duration) {
381 | return alpha(0, duration);
382 | }
383 |
384 | /**
385 | * Fades view alpha to 0 with animation
386 | *
387 | * @param duration animation duration
388 | * @param interpolator interpolator which will be used for this animation. See also {@link Interpolations}
389 | */
390 | @NonNull
391 | public static Animator fadeOut(float duration, @Nullable Interpolator interpolator) {
392 | return alpha(0, duration, interpolator);
393 | }
394 |
395 | /**
396 | * Fades view alpha to 1 instantly
397 | */
398 | @NonNull
399 | public static Animator fadeIn() {
400 | return alpha(1);
401 | }
402 |
403 | /**
404 | * Fades view alpha to 1 with animation
405 | *
406 | * @param duration animation duration
407 | */
408 | @NonNull
409 | public static Animator fadeIn(float duration) {
410 | return alpha(1, duration);
411 | }
412 |
413 | /**
414 | * Fades view alpha to 1 with animation
415 | *
416 | * @param duration animation duration
417 | * @param interpolator interpolator which will be used for this animation. See also {@link Interpolations}
418 | */
419 | @NonNull
420 | public static Animator fadeIn(float duration, @Nullable Interpolator interpolator) {
421 | return alpha(1, duration, interpolator);
422 | }
423 |
424 | /**
425 | * Sets view alpha to specified value instantly
426 | *
427 | * @param alpha alpha to set
428 | */
429 | @NonNull
430 | public static Animator alpha(float alpha) {
431 | return alpha(alpha, 0);
432 | }
433 |
434 | /**
435 | * Animates transition between current view alpha to target alpha
436 | *
437 | * @param alpha alpha to set
438 | * @param duration animation duration
439 | */
440 | @NonNull
441 | public static Animator alpha(float alpha, float duration) {
442 | return alpha(alpha, duration, null);
443 | }
444 |
445 | /**
446 | * Animates transition between current view alpha to target alpha
447 | *
448 | * @param alpha alpha to set
449 | * @param duration animation duration
450 | * @param interpolator interpolator which will be used for this animation. See also {@link Interpolations}
451 | */
452 | @NonNull
453 | public static Animator alpha(float alpha, float duration, @Nullable Interpolator interpolator) {
454 | TypedAction action = new TypedAction();
455 | setPropertiesForAnimator(action, duration, interpolator);
456 | action.setFloatTargets(alpha);
457 | action.setType(ActionType.ALPHA);
458 | return action;
459 | }
460 |
461 | /**
462 | * Inserts pause to sequence with specified duration
463 | *
464 | * @param duration duration in seconds
465 | */
466 | @NonNull
467 | public static Animator delay(float duration) {
468 | ValueAnimator animator = new ValueAnimator();
469 | setPropertiesForAnimator(animator, duration, null);
470 | animator.setIntValues(1);
471 | return animator;
472 | }
473 |
474 | /**
475 | * Runs actions in parallel
476 | *
477 | * @param animators actions to run
478 | */
479 | @NonNull
480 | public static Animator parallel(@NonNull Animator... animators) {
481 | AnimatorSet set = new AnimatorSet();
482 | set.playTogether(animators);
483 | return set;
484 | }
485 |
486 | /**
487 | * Runs actions sequence
488 | *
489 | * @param animators actions to run
490 | */
491 | @NonNull
492 | public static Animator sequence(@NonNull Animator... animators) {
493 | AnimatorSet set = new AnimatorSet();
494 | set.playSequentially(animators);
495 | return set;
496 | }
497 |
498 | /**
499 | * Plays actions on view
500 | *
501 | * @param animator action to play
502 | * @param view view where action should be played
503 | */
504 | public static void play(@NonNull final Animator animator, @NonNull final View view) {
505 | prepareActions(animator, view);
506 | animator.start();
507 | }
508 |
509 | private static void prepareActions(@NonNull Animator animator, @NonNull View view) {
510 | if (animator instanceof AnimatorSet) {
511 | AnimatorSet set = ((AnimatorSet) animator);
512 | for (Animator child : set.getChildAnimations()) {
513 | prepareActions(child, view);
514 | }
515 | } else {
516 | animator.setTarget(view);
517 | }
518 | }
519 | }
520 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/ArgbEvaluator.java:
--------------------------------------------------------------------------------
1 | package com.dtx12.android_animations_actions.actions;
2 |
3 | import android.animation.TypeEvaluator;
4 | import android.animation.ValueAnimator;
5 |
6 | /**
7 | * This evaluator can be used to perform type interpolation between integer
8 | * values that represent ARGB colors.
9 | */
10 | class ArgbEvaluator implements TypeEvaluator {
11 | private static final ArgbEvaluator sInstance = new ArgbEvaluator();
12 |
13 | /**
14 | * Returns an instance of ArgbEvaluator
that may be used in
15 | * {@link ValueAnimator#setEvaluator(TypeEvaluator)}. The same instance may
16 | * be used in multiple Animator
s because it holds no state.
17 | *
18 | * @return An instance of ArgbEvalutor
.
19 | * @hide
20 | */
21 | public static ArgbEvaluator getInstance() {
22 | return sInstance;
23 | }
24 |
25 | /**
26 | * This function returns the calculated in-between value for a color
27 | * given integers that represent the start and end values in the four
28 | * bytes of the 32-bit int. Each channel is separately linearly interpolated
29 | * and the resulting calculated values are recombined into the return value.
30 | *
31 | * @param fraction The fraction from the starting to the ending values
32 | * @param startValue A 32-bit int value representing colors in the
33 | * separate bytes of the parameter
34 | * @param endValue A 32-bit int value representing colors in the
35 | * separate bytes of the parameter
36 | * @return A value that is calculated to be the linearly interpolated
37 | * result, derived by separating the start and end values into separate
38 | * color channels and interpolating each one separately, recombining the
39 | * resulting values in the same way.
40 | */
41 | public Object evaluate(float fraction, Object startValue, Object endValue) {
42 | int startInt = (Integer) startValue;
43 | int startA = (startInt >> 24) & 0xff;
44 | int startR = (startInt >> 16) & 0xff;
45 | int startG = (startInt >> 8) & 0xff;
46 | int startB = startInt & 0xff;
47 |
48 | int endInt = (Integer) endValue;
49 | int endA = (endInt >> 24) & 0xff;
50 | int endR = (endInt >> 16) & 0xff;
51 | int endG = (endInt >> 8) & 0xff;
52 | int endB = endInt & 0xff;
53 |
54 | return (int) ((startA + (int) (fraction * (endA - startA))) << 24) |
55 | (int) ((startR + (int) (fraction * (endR - startR))) << 16) |
56 | (int) ((startG + (int) (fraction * (endG - startG))) << 8) |
57 | (int) ((startB + (int) (fraction * (endB - startB))));
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/Interpolations.java:
--------------------------------------------------------------------------------
1 | package com.dtx12.android_animations_actions.actions;
2 |
3 | import android.view.animation.Interpolator;
4 |
5 | import static java.lang.Math.*;
6 |
7 | /*
8 | * Timing functions. Based on https://github.com/raywenderlich/SKTUtils/blob/master/SKTUtils/SKTTimingFunctions.swift
9 | *
10 | * Copyright (c) 2013-2014 Razeware LLC
11 | *
12 | * Permission is hereby granted, free of charge, to any person obtaining a copy
13 | * of this software and associated documentation files (the "Software"), to deal
14 | * in the Software without restriction, including without limitation the rights
15 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 | * copies of the Software, and to permit persons to whom the Software is
17 | * furnished to do so, subject to the following conditions:
18 | *
19 | * The above copyright notice and this permission notice shall be included in
20 | * all copies or substantial portions of the Software.
21 | *
22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 | * THE SOFTWARE.
29 | */
30 | public final class Interpolations {
31 |
32 | public static final Interpolator QuadraticEaseIn = new Interpolator() {
33 | @Override
34 | public float getInterpolation(float t) {
35 | return t * t;
36 | }
37 | };
38 |
39 | public static final Interpolator QuadraticEaseOut = new Interpolator() {
40 | @Override
41 | public float getInterpolation(float t) {
42 | return t * (2.0f - t);
43 | }
44 | };
45 |
46 | public static final Interpolator QuadraticEaseInOut = new Interpolator() {
47 | @Override
48 | public float getInterpolation(float t) {
49 | if (t < 0.5) {
50 | return 2.0f * t * t;
51 | } else {
52 | float f = t - 1.0f;
53 | return 1.0f - 2.0f * f * f;
54 | }
55 | }
56 | };
57 |
58 | public static final Interpolator CubicEaseIn = new Interpolator() {
59 | @Override
60 | public float getInterpolation(float t) {
61 | return t * t * t;
62 | }
63 | };
64 |
65 | public static final Interpolator CubicEaseOut = new Interpolator() {
66 | @Override
67 | public float getInterpolation(float t) {
68 | float f = t - 1.0f;
69 | return 1.0f + f * f * f;
70 | }
71 | };
72 |
73 | public static final Interpolator CubicEaseInOut = new Interpolator() {
74 | @Override
75 | public float getInterpolation(float t) {
76 | if (t < 0.5) {
77 | return 4.0f * t * t * t;
78 | } else {
79 | float f = t - 1.0f;
80 | return 1.0f + 4.0f * f * f * f;
81 | }
82 | }
83 | };
84 |
85 | public static final Interpolator QuarticEaseIn = new Interpolator() {
86 | @Override
87 | public float getInterpolation(float t) {
88 | return t * t * t * t;
89 | }
90 | };
91 |
92 | public static final Interpolator QuarticEaseOut = new Interpolator() {
93 | @Override
94 | public float getInterpolation(float t) {
95 | float f = t - 1.0f;
96 | return 1.0f - f * f * f * f;
97 | }
98 | };
99 |
100 | public static final Interpolator QuarticEaseInOut = new Interpolator() {
101 | @Override
102 | public float getInterpolation(float t) {
103 | if (t < 0.5) {
104 | return 8.0f * t * t * t * t;
105 | } else {
106 | float f = t - 1.0f;
107 | return 1.0f - 8.0f * f * f * f * f;
108 | }
109 | }
110 | };
111 |
112 | public static final Interpolator FunctionQuinticEaseIn = new Interpolator() {
113 | @Override
114 | public float getInterpolation(float t) {
115 | return t * t * t * t * t;
116 | }
117 | };
118 |
119 | public static final Interpolator QuinticEaseOut = new Interpolator() {
120 | @Override
121 | public float getInterpolation(float t) {
122 | float f = t - 1.0f;
123 | return 1.0f + f * f * f * f * f;
124 | }
125 | };
126 |
127 | public static final Interpolator QuinticEaseInOut = new Interpolator() {
128 | @Override
129 | public float getInterpolation(float t) {
130 | if (t < 0.5) {
131 | return 16.0f * t * t * t * t * t;
132 | } else {
133 | float f = t - 1.0f;
134 | return 1.0f + 16.0f * f * f * f * f * f;
135 | }
136 | }
137 | };
138 |
139 | public static final Interpolator SineEaseIn = new Interpolator() {
140 | @Override
141 | public float getInterpolation(float t) {
142 | return (float) (sin((t - 1.0f) * PI / 2) + 1.0f);
143 | }
144 | };
145 |
146 | public static final Interpolator SineEaseOut = new Interpolator() {
147 | @Override
148 | public float getInterpolation(float t) {
149 | return (float) sin(t * PI / 2);
150 | }
151 | };
152 |
153 | public static final Interpolator SineEaseInOut = new Interpolator() {
154 | @Override
155 | public float getInterpolation(float t) {
156 | return (float) (0.5f * (1.0f - cos(t * PI)));
157 | }
158 | };
159 |
160 | public static final Interpolator CircularEaseIn = new Interpolator() {
161 | @Override
162 | public float getInterpolation(float t) {
163 | return (float) (1.0f - sqrt(1.0 - t * t));
164 | }
165 | };
166 |
167 | public static final Interpolator CircularEaseOut = new Interpolator() {
168 | @Override
169 | public float getInterpolation(float t) {
170 | return (float) sqrt((2.0f - t) * t);
171 | }
172 | };
173 |
174 | public static final Interpolator CircularEaseInOut = new Interpolator() {
175 | @Override
176 | public float getInterpolation(float t) {
177 | if (t < 0.5) {
178 | return (float) (0.5 * (1.0 - sqrt(1.0 - 4.0 * t * t)));
179 | } else {
180 | return (float) (0.5 * sqrt(-4.0 * t * t + 8.0 * t - 3.0) + 0.5);
181 | }
182 | }
183 | };
184 |
185 | public static final Interpolator ExponentialEaseIn = new Interpolator() {
186 | @Override
187 | public float getInterpolation(float t) {
188 | return (t == 0.0) ? t : (float) pow(2.0, 10.0 * (t - 1.0));
189 | }
190 | };
191 |
192 | public static final Interpolator ExponentialEaseOut = new Interpolator() {
193 | @Override
194 | public float getInterpolation(float t) {
195 | return (t == 1.0) ? t : (float) (1.0 - pow(2.0, -10.0 * t));
196 | }
197 | };
198 |
199 | public static final Interpolator ExponentialEaseInOut = new Interpolator() {
200 | @Override
201 | public float getInterpolation(float t) {
202 | if (t == 0.0 || t == 1.0) {
203 | return t;
204 | } else if (t < 0.5) {
205 | return (float) (0.5 * pow(2.0, 20.0 * t - 10.0));
206 | } else {
207 | return (float) (1.0 - 0.5 * pow(2.0, -20.0 * t + 10.0));
208 | }
209 | }
210 | };
211 |
212 | public static final Interpolator ElasticEaseIn = new Interpolator() {
213 | @Override
214 | public float getInterpolation(float t) {
215 | return (float) (sin(13.0 * PI / 2 * t) * pow(2.0, 10.0 * (t - 1.0)));
216 | }
217 | };
218 |
219 | public static final Interpolator ElasticEaseOut = new Interpolator() {
220 | @Override
221 | public float getInterpolation(float t) {
222 | return (float) (sin(-13.0 * PI / 2 * (t + 1.0)) * pow(2.0, -10.0 * t) + 1.0);
223 | }
224 | };
225 |
226 | public static final Interpolator ElasticEaseInOut = new Interpolator() {
227 | @Override
228 | public float getInterpolation(float t) {
229 | if (t < 0.5) {
230 | return (float) (0.5 * sin(13.0 * PI * t) * pow(2.0, 20.0 * t - 10.0));
231 | } else {
232 | return (float) (0.5 * sin(-13.0 * PI * t) * pow(2.0, -20.0 * t + 10.0) + 1.0);
233 | }
234 | }
235 | };
236 |
237 | public static final Interpolator BackEaseIn = new Interpolator() {
238 | @Override
239 | public float getInterpolation(float t) {
240 | float s = 1.70158f;
241 | return ((s + 1.0f) * t - s) * t * t;
242 | }
243 | };
244 |
245 | public static final Interpolator BackEaseOut = new Interpolator() {
246 | @Override
247 | public float getInterpolation(float t) {
248 | float s = 1.70158f;
249 | float f = 1.0f - t;
250 | return 1.0f - ((s + 1.0f) * f - s) * f * f;
251 | }
252 | };
253 |
254 | public static final Interpolator BackEaseInOut = new Interpolator() {
255 | @Override
256 | public float getInterpolation(float t) {
257 | float s = 1.70158f;
258 | if (t < 0.5) {
259 | float f = 2.0f * t;
260 | return 0.5f * ((s + 1.0f) * f - s) * f * f;
261 | } else {
262 | float f = 2.0f * (1.0f - t);
263 | return 1.0f - 0.5f * ((s + 1.0f) * f - s) * f * f;
264 | }
265 | }
266 | };
267 |
268 | public static final Interpolator ExtremeBackEaseIn = new Interpolator() {
269 | @Override
270 | public float getInterpolation(float t) {
271 | return (float) ((t * t - sin(t * PI)) * t);
272 | }
273 | };
274 |
275 | public static final Interpolator ExtremeBackEaseOut = new Interpolator() {
276 | @Override
277 | public float getInterpolation(float t) {
278 | float f = 1.0f - t;
279 | return (float) (1.0 - (f * f - sin(f * PI)) * f);
280 | }
281 | };
282 |
283 | public static final Interpolator ExtremeBackEaseInOut = new Interpolator() {
284 | @Override
285 | public float getInterpolation(float t) {
286 | if (t < 0.5) {
287 | float f = 2.0f * t;
288 | return (float) (0.5 * (f * f - sin(f * PI)) * f);
289 | } else {
290 | float f = 2.0f * (1.0f - t);
291 | return (float) (1.0 - 0.5 * (f * f - sin(f * PI)) * f);
292 | }
293 | }
294 | };
295 | public static final Interpolator BounceEaseOut = new Interpolator() {
296 | @Override
297 | public float getInterpolation(float t) {
298 | if (t < 1.0 / 2.75) {
299 | return 7.5625f * t * t;
300 | } else if (t < 2.0 / 2.75) {
301 | float f = t - 1.5f / 2.75f;
302 | return 7.5625f * f * f + 0.75f;
303 | } else if (t < 2.5 / 2.75) {
304 | float f = t - 2.25f / 2.75f;
305 | return 7.5625f * f * f + 0.9375f;
306 | } else {
307 | float f = t - 2.625f / 2.75f;
308 | return 7.5625f * f * f + 0.984375f;
309 | }
310 | }
311 | };
312 | public static final Interpolator BounceEaseIn = new Interpolator() {
313 | @Override
314 | public float getInterpolation(float t) {
315 | return 1.0f - BounceEaseOut.getInterpolation(1.0f - t);
316 | }
317 | };
318 | public static final Interpolator BounceEaseInOut = new Interpolator() {
319 | @Override
320 | public float getInterpolation(float t) {
321 | if (t < 0.5) {
322 | return 0.5f * BounceEaseIn.getInterpolation(t * 2.0f);
323 | } else {
324 | return 0.5f * BounceEaseOut.getInterpolation(t * 2.0f - 1.0f) + 0.5f;
325 | }
326 | }
327 | };
328 |
329 | public static final Interpolator SmoothStep = new Interpolator() {
330 | @Override
331 | public float getInterpolation(float t) {
332 | return t * t * (3 - 2 * t);
333 | }
334 | };
335 | }
336 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/RepeatAction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2015 dtx12
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 |
26 | package com.dtx12.android_animations_actions.actions;
27 |
28 | import android.animation.Animator;
29 | import android.animation.AnimatorListenerAdapter;
30 | import android.animation.AnimatorSet;
31 | import android.animation.ValueAnimator;
32 |
33 | class RepeatAction extends ValueAnimator {
34 | private final Animator animator;
35 |
36 | RepeatAction(int repeatCount, Animator animator) {
37 | this.animator = animator;
38 | long duration = countDuration(animator);
39 | setDuration(duration);
40 | setFloatValues(0, 1);
41 | setRepeatCount(Math.max(-1, repeatCount - 1));
42 | addListener(new AnimatorListenerAdapter() {
43 | @Override
44 | public void onAnimationRepeat(Animator animation) {
45 | RepeatAction.this.animator.start();
46 | }
47 | });
48 | }
49 |
50 | @Override
51 | public void start() {
52 | super.start();
53 | animator.start();
54 | }
55 |
56 | private long countDuration(Animator animator) {
57 | long duration = 0;
58 | if (animator instanceof AnimatorSet) {
59 | for (Animator child : ((AnimatorSet) animator).getChildAnimations()) {
60 | duration += countDuration(child);
61 | }
62 | } else if (animator instanceof RepeatAction) {
63 | duration += countDuration(((RepeatAction) animator).animator);
64 | } else {
65 | duration += animator.getDuration();
66 | }
67 | return Math.max(duration, 0);
68 | }
69 |
70 | @Override
71 | public void setTarget(Object target) {
72 | animator.setTarget(target);
73 | setTargetInternal(target, animator);
74 | }
75 |
76 | private void setTargetInternal(Object target, Animator animator) {
77 | if (animator instanceof AnimatorSet) {
78 | AnimatorSet set = ((AnimatorSet) animator);
79 | for (Animator child : set.getChildAnimations()) {
80 | setTargetInternal(target, child);
81 | }
82 | } else {
83 | animator.setTarget(target);
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/TypedAction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2015 dtx12
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dtx12.android_animations_actions.actions;
26 |
27 | import android.animation.PropertyValuesHolder;
28 | import android.animation.ValueAnimator;
29 | import android.view.View;
30 | import com.dtx12.android_animations_actions.actions.listeners.*;
31 |
32 | class TypedAction extends ValueAnimator {
33 | private ActionType type;
34 | private float[] floatTargets;
35 | private int[] intTargets;
36 | private View view;
37 |
38 | public void setFloatTargets(float... floatTargets) {
39 | this.floatTargets = floatTargets;
40 | }
41 |
42 | public void setIntTargets(int... intTargets) {
43 | this.intTargets = intTargets;
44 | }
45 |
46 | public void setType(ActionType type) {
47 | this.type = type;
48 | }
49 |
50 | @Override
51 | public void setTarget(Object target) {
52 | if (target instanceof View) {
53 | this.view = ((View) target);
54 | }
55 | }
56 |
57 | @Override
58 | public void start() {
59 | updateValues();
60 | super.start();
61 | }
62 |
63 | private void updateValues() {
64 | if (type == null) {
65 | throw new IllegalStateException("type is not specified!");
66 | }
67 | if (view == null) {
68 | throw new IllegalStateException("target is not specified!");
69 | }
70 | switch (type) {
71 |
72 | case ALPHA:
73 | prepareAlphaAnimation();
74 | break;
75 | case SCALE_TO:
76 | prepareScaleAnimation(false);
77 | break;
78 | case SCALE_BY:
79 | prepareScaleAnimation(true);
80 | break;
81 | case SIZE_TO:
82 | break;
83 | case SIZE_BY:
84 | break;
85 | case ROTATE_TO:
86 | prepareRotateAnimation(false);
87 | break;
88 | case ROTATE_BY:
89 | prepareRotateAnimation(true);
90 | break;
91 | case COLOR:
92 | prepareColorAnimation();
93 | break;
94 | case MOVE_TO:
95 | prepareMoveAnimation(false);
96 | break;
97 | case MOVE_BY:
98 | prepareMoveAnimation(true);
99 | break;
100 | }
101 | }
102 |
103 | private void prepareColorAnimation() {
104 | setIntValues(intTargets);
105 | setEvaluator(ArgbEvaluator.getInstance());
106 | addUpdateListener(new ColorUpdateListener(view));
107 | }
108 |
109 | private void prepareRotateAnimation(boolean rotateBy) {
110 | float rotationOffset = rotateBy ? view.getRotation() : 0;
111 | setFloatValues(view.getRotation(), rotationOffset + floatTargets[0]);
112 | addUpdateListener(new RotationUpdateListener(view));
113 | }
114 |
115 | private void prepareMoveAnimation(boolean moveBy) {
116 | float moveXOffset = moveBy ? view.getX() : 0;
117 | float moveYOffset = moveBy ? view.getY() : 0;
118 | PropertyValuesHolder x = PropertyValuesHolder.ofFloat("x", view.getX(), moveXOffset + floatTargets[0]);
119 | PropertyValuesHolder y = PropertyValuesHolder.ofFloat("y", view.getY(), moveYOffset + floatTargets[1]);
120 | setValues(x, y);
121 | addUpdateListener(new MoveUpdateListener(view));
122 | }
123 |
124 | private void prepareScaleAnimation(boolean scaleBy) {
125 | float scaleXOffset = scaleBy ? view.getScaleX() : 0;
126 | float scaleYOffset = scaleBy ? view.getScaleY() : 0;
127 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", view.getScaleX(), scaleXOffset + floatTargets[0]);
128 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", view.getScaleY(), scaleYOffset + floatTargets[1]);
129 | setValues(scaleX, scaleY);
130 | addUpdateListener(new ScaleUpdateListener(view));
131 | }
132 |
133 | private void prepareAlphaAnimation() {
134 | setFloatValues(view.getAlpha(), floatTargets[0]);
135 | addUpdateListener(new AlphaUpdateListener(view));
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/listeners/AlphaUpdateListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2015 dtx12
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dtx12.android_animations_actions.actions.listeners;
26 |
27 | import android.animation.ValueAnimator;
28 | import android.view.View;
29 |
30 | public class AlphaUpdateListener extends BaseUpdateListener {
31 | public AlphaUpdateListener(View view) {
32 | super(view);
33 | }
34 |
35 | @Override
36 | void onAnimationUpdate(View view, ValueAnimator animation) {
37 | float alpha = (float) animation.getAnimatedValue();
38 | view.setAlpha(alpha);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/listeners/BaseUpdateListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2015 dtx12
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dtx12.android_animations_actions.actions.listeners;
26 |
27 | import android.animation.ValueAnimator;
28 | import android.view.View;
29 |
30 | abstract class BaseUpdateListener implements ValueAnimator.AnimatorUpdateListener {
31 | private final View view;
32 |
33 | public BaseUpdateListener(View view) {
34 | this.view = view;
35 | }
36 |
37 | @Override
38 | public final void onAnimationUpdate(ValueAnimator animation) {
39 | onAnimationUpdate(view, animation);
40 | }
41 |
42 | abstract void onAnimationUpdate(View view, ValueAnimator animation);
43 | }
44 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/listeners/ColorUpdateListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2015 dtx12
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dtx12.android_animations_actions.actions.listeners;
26 |
27 | import android.animation.ValueAnimator;
28 | import android.graphics.Paint;
29 | import android.graphics.PorterDuff;
30 | import android.graphics.PorterDuffColorFilter;
31 | import android.view.View;
32 |
33 | public class ColorUpdateListener extends BaseUpdateListener {
34 |
35 | private Paint paint;
36 |
37 | public ColorUpdateListener(View view) {
38 | super(view);
39 | paint = new Paint();
40 | view.setLayerType(View.LAYER_TYPE_SOFTWARE, paint);
41 | }
42 |
43 | @Override
44 | void onAnimationUpdate(View view, ValueAnimator animation) {
45 | int currentColor = (int) animation.getAnimatedValue();
46 | paint.setColorFilter(new PorterDuffColorFilter(currentColor, PorterDuff.Mode.MULTIPLY));
47 | view.invalidate();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/listeners/MoveUpdateListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2015 dtx12
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dtx12.android_animations_actions.actions.listeners;
26 |
27 | import android.animation.ValueAnimator;
28 | import android.view.View;
29 |
30 | public class MoveUpdateListener extends BaseUpdateListener {
31 | public MoveUpdateListener(View view) {
32 | super(view);
33 | }
34 |
35 | @Override
36 | void onAnimationUpdate(View view, ValueAnimator animation) {
37 | float x = (float) animation.getAnimatedValue("x");
38 | float y = (float) animation.getAnimatedValue("y");
39 | view.setX(x);
40 | view.setY(y);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/listeners/RotationUpdateListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2015 dtx12
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dtx12.android_animations_actions.actions.listeners;
26 |
27 | import android.animation.ValueAnimator;
28 | import android.view.View;
29 |
30 | public class RotationUpdateListener extends BaseUpdateListener {
31 | public RotationUpdateListener(View view) {
32 | super(view);
33 | }
34 |
35 | @Override
36 | void onAnimationUpdate(View view, ValueAnimator animation) {
37 | view.setRotation((float) animation.getAnimatedValue());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/actions/src/main/java/com/dtx12/android_animations_actions/actions/listeners/ScaleUpdateListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2015 dtx12
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dtx12.android_animations_actions.actions.listeners;
26 |
27 | import android.animation.ValueAnimator;
28 | import android.view.View;
29 |
30 | public class ScaleUpdateListener extends BaseUpdateListener {
31 | public ScaleUpdateListener(View view) {
32 | super(view);
33 | }
34 |
35 | @Override
36 | void onAnimationUpdate(View view, ValueAnimator animation) {
37 | float scaleX = (float) animation.getAnimatedValue("scaleX");
38 | float scaleY = (float) animation.getAnimatedValue("scaleY");
39 | view.setScaleX(scaleX);
40 | view.setScaleY(scaleY);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/actions/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.1.1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/demo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/demo/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:1.1.1'
7 | }
8 | }
9 | apply plugin: 'com.android.application'
10 |
11 | repositories {
12 | jcenter()
13 | }
14 |
15 | android {
16 | compileSdkVersion 23
17 | buildToolsVersion "23.0.1"
18 |
19 | defaultConfig {
20 | applicationId "com.dtx12.android_animations_actions.demo"
21 | minSdkVersion 14
22 | targetSdkVersion 23
23 | versionCode 1
24 | versionName "1.0"
25 | }
26 | buildTypes {
27 | release {
28 | minifyEnabled false
29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
30 | }
31 | }
32 | }
33 |
34 | dependencies {
35 | compile fileTree(dir: 'libs', include: ['*.jar'])
36 | compile 'com.android.support:appcompat-v7:23.0.1'
37 | compile 'com.jakewharton:butterknife:7.0.1'
38 | compile project(':actions')
39 | }
40 |
--------------------------------------------------------------------------------
/demo/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:/Program Files (x86)/Android/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/demo/src/androidTest/java/com/dtx12/android_animations_actions/demo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.dtx12.android_animations_actions.demo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/demo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/dtx12/android_animations_actions/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dtx12.android_animations_actions.demo;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.Point;
5 | import android.os.Bundle;
6 | import android.support.v4.content.ContextCompat;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.Gravity;
9 | import android.widget.FrameLayout;
10 | import android.widget.ImageView;
11 | import android.widget.LinearLayout;
12 | import butterknife.Bind;
13 | import butterknife.ButterKnife;
14 | import butterknife.OnClick;
15 | import com.dtx12.android_animations_actions.actions.Interpolations;
16 |
17 | import java.util.Random;
18 |
19 | import static com.dtx12.android_animations_actions.actions.Actions.*;
20 |
21 |
22 | public class MainActivity extends AppCompatActivity {
23 |
24 | @Bind(R.id.firstAnimContainer)
25 | protected LinearLayout firstAnimContainer;
26 | @Bind(R.id.secondAnimContainer)
27 | protected FrameLayout secondAnimContainer;
28 | private Random random = new Random();
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 | ButterKnife.bind(this);
35 | }
36 |
37 | @OnClick(R.id.playSecondAnim)
38 | protected void playSecondAnim() {
39 | firstAnimContainer.removeAllViews();
40 | secondAnimContainer.removeAllViews();
41 | Point center = new Point(secondAnimContainer.getMeasuredWidth() / 2, secondAnimContainer.getMeasuredHeight() / 2);
42 | int size = getResources().getDimensionPixelSize(R.dimen.circle_size);
43 | float delay = 0;
44 | for (int i = 0; i < 6; i++) {
45 | FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(size, size);
46 | final ImageView view = new ImageView(this);
47 | view.setLayoutParams(params);
48 | view.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.square));
49 | Point newPos = new Point();
50 | switch (i) {
51 | case 0:
52 | newPos.set(0, 0);
53 | break;
54 |
55 | case 1:
56 | newPos.set(0, center.y);
57 | break;
58 |
59 | case 2:
60 | newPos.set(0, center.y * 2 - size);
61 | break;
62 |
63 | case 3:
64 | newPos.set(center.x * 2 - size, 0);
65 | break;
66 |
67 | case 4:
68 | newPos.set(center.x * 2 - size, center.y);
69 | break;
70 |
71 | case 5:
72 | newPos.set(center.x * 2 - size, center.y * 2 - size);
73 | break;
74 | }
75 | play(sequence(parallel(fadeOut(), color(-1, Color.BLUE)), moveTo(center.x, center.y),
76 | fadeIn(.5f), parallel(moveTo(newPos.x, newPos.y, 1, Interpolations.ExponentialEaseOut)), run(new Runnable() {
77 | @Override
78 | public void run() {
79 | play(sequence(color(Color.BLUE, Color.GREEN, .1f), forever(sequence(color(Color.GREEN, Color.RED, 1), color(Color.GREEN, Color.RED, 1)))), view);
80 | }
81 | }),
82 | parallel(rotateBy(720, 2, Interpolations.BackEaseOut), sequence(scaleTo(.5f, .5f, 1, Interpolations.BackEaseOut),
83 | scaleTo(1, 1, 1, Interpolations.ElasticEaseOut))), sequence(delay(delay), parallel(fadeOut(.5f, Interpolations.ExponentialEaseOut),
84 | scaleTo(0, 1, .5f, Interpolations.ExponentialEaseOut)))), view);
85 | delay += 1f;
86 | secondAnimContainer.addView(view);
87 | }
88 | }
89 |
90 | @OnClick(R.id.playFirstAnim)
91 | protected void playFirstAnimation() {
92 | firstAnimContainer.removeAllViews();
93 | secondAnimContainer.removeAllViews();
94 | for (int i = 0; i < 6; i++) {
95 | int size = getResources().getDimensionPixelSize(R.dimen.circle_size);
96 | int margin = getResources().getDimensionPixelSize(R.dimen.circle_margin);
97 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(size, size);
98 | params.leftMargin = margin;
99 | params.rightMargin = margin;
100 | params.gravity = Gravity.CENTER;
101 | ImageView view = new ImageView(this);
102 | view.setLayoutParams(params);
103 | view.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.circle));
104 | float delay = random.nextFloat();
105 | float targetY = random.nextInt((int) (firstAnimContainer.getBottom() / 4f));
106 | play(sequence(fadeOut(), scaleTo(1.5f, 1.5f), fadeIn(2), delay(delay),
107 | parallel(moveBy(0, targetY, 2, Interpolations.ElasticEaseOut), sequence(color(-1, Color.GREEN, 1), color(Color.GREEN, Color.RED, 1)),
108 | scaleTo(1, 1, 2, Interpolations.ElasticEaseOut))), view);
109 | firstAnimContainer.addView(view);
110 | }
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/circle.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/square.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
20 |
21 |
29 |
30 |
37 |
38 |
44 |
45 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dtx12/AndroidAnimationsActions/d3a5325a9171bbfc2d5aed2c92d12cfc24f7fc1d/demo/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dtx12/AndroidAnimationsActions/d3a5325a9171bbfc2d5aed2c92d12cfc24f7fc1d/demo/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dtx12/AndroidAnimationsActions/d3a5325a9171bbfc2d5aed2c92d12cfc24f7fc1d/demo/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dtx12/AndroidAnimationsActions/d3a5325a9171bbfc2d5aed2c92d12cfc24f7fc1d/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 32dp
6 | 12dp
7 |
8 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android Animations Actions
3 |
4 | Hello world!
5 | Settings
6 | First animation
7 | Second animation
8 |
9 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dtx12/AndroidAnimationsActions/d3a5325a9171bbfc2d5aed2c92d12cfc24f7fc1d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':demo', ':actions'
2 |
--------------------------------------------------------------------------------