float
.
18 | */
19 | public abstract void setValue(T object, float value);
20 |
21 | @Override
22 | final public void set(T object, Float value) {
23 | setValue(object, value);
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/animator/IntProperty.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.animator;
2 |
3 | import android.util.Property;
4 |
5 | /**
6 | * Created by simon on 17-6-2.
7 | */
8 |
9 | public abstract class IntPropertyint
.
18 | */
19 | public abstract void setValue(T object, int value);
20 |
21 | @Override
22 | final public void set(T object, Integer value) {
23 | setValue(object, value.intValue());
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/animator/ViewAnimatorBuilder.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.animator;
2 |
3 | import android.support.annotation.FloatRange;
4 | import android.util.Property;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by simon liu.
9 | */
10 | public class ViewAnimatorBuilder extends AnimatorBuilder {
11 |
12 | public ViewAnimatorBuilder(View target) {
13 | super(target);
14 | }
15 |
16 | public static final Property
40 | * The {@link Path} must not have gaps in the x direction and must not
41 | * loop back on itself such that there can be two points sharing the same x coordinate.
42 | *
43 | * @param path the {@link Path} to use to make the line representing the {@link Interpolator}
44 | * @return the {@link Interpolator} representing the {@link Path}
45 | */
46 | @SuppressWarnings("unused")
47 | public static Interpolator create(Path path) {
48 | if (Build.VERSION.SDK_INT >= 21) {
49 | return PathInterpolatorCompatApi21.create(path);
50 | }
51 | return PathInterpolatorCompatBase.create(path);
52 | }
53 |
54 | /**
55 | * Create an {@link Interpolator} for a quadratic Bezier curve. The end points
56 | * {@code (0, 0)} and {@code (1, 1)} are assumed.
57 | *
58 | * @param controlX the x coordinate of the quadratic Bezier control point
59 | * @param controlY the y coordinate of the quadratic Bezier control point
60 | * @return the {@link Interpolator} representing the quadratic Bezier curve
61 | */
62 | @SuppressWarnings("unused")
63 | public static Interpolator create(float controlX, float controlY) {
64 | if (Build.VERSION.SDK_INT >= 21) {
65 | return PathInterpolatorCompatApi21.create(controlX, controlY);
66 | }
67 | return PathInterpolatorCompatBase.create(controlX, controlY);
68 | }
69 |
70 | /**
71 | * Create an {@link Interpolator} for a cubic Bezier curve. The end points
72 | * {@code (0, 0)} and {@code (1, 1)} are assumed.
73 | *
74 | * @param controlX1 the x coordinate of the first control point of the cubic Bezier
75 | * @param controlY1 the y coordinate of the first control point of the cubic Bezier
76 | * @param controlX2 the x coordinate of the second control point of the cubic Bezier
77 | * @param controlY2 the y coordinate of the second control point of the cubic Bezier
78 | * @return the {@link Interpolator} representing the cubic Bezier curve
79 | */
80 | public static Interpolator create(float controlX1, float controlY1,
81 | float controlX2, float controlY2) {
82 | if (Build.VERSION.SDK_INT >= 21) {
83 | return PathInterpolatorCompatApi21.create(controlX1, controlY1, controlX2, controlY2);
84 | }
85 | return PathInterpolatorCompatBase.create(controlX1, controlY1, controlX2, controlY2);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/animator/interpolator/PathInterpolatorCompatApi21.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.simon.core.animationtools.animator.interpolator;
18 |
19 | import android.annotation.TargetApi;
20 | import android.graphics.Path;
21 | import android.os.Build;
22 | import android.view.animation.Interpolator;
23 | import android.view.animation.PathInterpolator;
24 |
25 | /**
26 | * API 21+ implementation for path interpolator compatibility.
27 | */
28 | class PathInterpolatorCompatApi21 {
29 |
30 | private PathInterpolatorCompatApi21() {
31 | // prevent instantiation
32 | }
33 |
34 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
35 | public static Interpolator create(Path path) {
36 | return new PathInterpolator(path);
37 | }
38 |
39 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
40 | public static Interpolator create(float controlX, float controlY) {
41 | return new PathInterpolator(controlX, controlY);
42 | }
43 |
44 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
45 | public static Interpolator create(float controlX1, float controlY1,
46 | float controlX2, float controlY2) {
47 | return new PathInterpolator(controlX1, controlY1, controlX2, controlY2);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/animator/interpolator/PathInterpolatorCompatBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.simon.core.animationtools.animator.interpolator;
18 |
19 | import android.graphics.Path;
20 | import android.view.animation.Interpolator;
21 |
22 | /**
23 | * Base implementation for path interpolator compatibility.
24 | */
25 | class PathInterpolatorCompatBase {
26 |
27 | private PathInterpolatorCompatBase() {
28 | // prevent instantiation
29 | }
30 |
31 | public static Interpolator create(Path path) {
32 | return new PathInterpolatorDonut(path);
33 | }
34 |
35 | public static Interpolator create(float controlX, float controlY) {
36 | return new PathInterpolatorDonut(controlX, controlY);
37 | }
38 |
39 | public static Interpolator create(float controlX1, float controlY1,
40 | float controlX2, float controlY2) {
41 | return new PathInterpolatorDonut(controlX1, controlY1, controlX2, controlY2);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/animator/interpolator/PathInterpolatorDonut.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.simon.core.animationtools.animator.interpolator;
17 |
18 | import android.graphics.Path;
19 | import android.graphics.PathMeasure;
20 | import android.view.animation.Interpolator;
21 |
22 | /**
23 | * A path interpolator implementation compatible with API 4+.
24 | */
25 | class PathInterpolatorDonut implements Interpolator {
26 |
27 | /**
28 | * Governs the accuracy of the approximation of the {@link Path}.
29 | */
30 | private static final float PRECISION = 0.002f;
31 |
32 | private final float[] mX;
33 | private final float[] mY;
34 |
35 | public PathInterpolatorDonut(Path path) {
36 | final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */);
37 |
38 | final float pathLength = pathMeasure.getLength();
39 | final int numPoints = (int) (pathLength / PRECISION) + 1;
40 |
41 | mX = new float[numPoints];
42 | mY = new float[numPoints];
43 |
44 | final float[] position = new float[2];
45 | for (int i = 0; i < numPoints; ++i) {
46 | final float distance = (i * pathLength) / (numPoints - 1);
47 | pathMeasure.getPosTan(distance, position, null /* tangent */);
48 |
49 | mX[i] = position[0];
50 | mY[i] = position[1];
51 | }
52 | }
53 |
54 | public PathInterpolatorDonut(float controlX, float controlY) {
55 | this(createQuad(controlX, controlY));
56 | }
57 |
58 | public PathInterpolatorDonut(float controlX1, float controlY1,
59 | float controlX2, float controlY2) {
60 | this(createCubic(controlX1, controlY1, controlX2, controlY2));
61 | }
62 |
63 | @Override
64 | public float getInterpolation(float t) {
65 | if (t <= 0.0f) {
66 | return 0.0f;
67 | } else if (t >= 1.0f) {
68 | return 1.0f;
69 | }
70 |
71 | // Do a binary search for the correct x to interpolate between.
72 | int startIndex = 0;
73 | int endIndex = mX.length - 1;
74 | while (endIndex - startIndex > 1) {
75 | int midIndex = (startIndex + endIndex) / 2;
76 | if (t < mX[midIndex]) {
77 | endIndex = midIndex;
78 | } else {
79 | startIndex = midIndex;
80 | }
81 | }
82 |
83 | final float xRange = mX[endIndex] - mX[startIndex];
84 | if (xRange == 0) {
85 | return mY[startIndex];
86 | }
87 |
88 | final float tInRange = t - mX[startIndex];
89 | final float fraction = tInRange / xRange;
90 |
91 | final float startY = mY[startIndex];
92 | final float endY = mY[endIndex];
93 |
94 | return startY + (fraction * (endY - startY));
95 | }
96 |
97 | private static Path createQuad(float controlX, float controlY) {
98 | final Path path = new Path();
99 | path.moveTo(0.0f, 0.0f);
100 | path.quadTo(controlX, controlY, 1.0f, 1.0f);
101 | return path;
102 | }
103 |
104 | private static Path createCubic(float controlX1, float controlY1,
105 | float controlX2, float controlY2) {
106 | final Path path = new Path();
107 | path.moveTo(0.0f, 0.0f);
108 | path.cubicTo(controlX1, controlY1, controlX2, controlY2, 1.0f, 1.0f);
109 | return path;
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/AnimDrawableContainer.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Canvas;
5 | import android.graphics.ColorFilter;
6 | import android.graphics.Paint;
7 | import android.graphics.PixelFormat;
8 | import android.graphics.Rect;
9 | import android.graphics.drawable.Drawable;
10 | import android.support.annotation.ColorInt;
11 | import android.support.annotation.IntRange;
12 | import android.support.annotation.NonNull;
13 | import android.support.annotation.Nullable;
14 |
15 | import com.simon.core.animationtools.animator.AnimUtils;
16 |
17 | /**
18 | *
19 | * Created by simon on 17-6-7.
20 | */
21 |
22 | public abstract class AnimDrawableContainer extends AnimationDrawable{
23 |
24 | protected final @NonNull Drawable[] children;
25 |
26 | private Paint bgPaint;
27 |
28 | private @ColorInt int bgColor = -1;
29 |
30 | public AnimDrawableContainer() {
31 | children = createChildren();
32 | bgPaint = new Paint();
33 | bgPaint.setAntiAlias(true);
34 | initCallback();
35 | }
36 |
37 | public abstract @NonNull Drawable[] createChildren();
38 |
39 | private void initCallback() {
40 | for (Drawable child : children) {
41 | child.setCallback(this);
42 | }
43 | }
44 |
45 | @Override
46 | public void invalidateDrawable(@NonNull Drawable who) {
47 | invalidateSelf();
48 | }
49 |
50 | @Override
51 | public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {
52 |
53 | }
54 |
55 | @Override
56 | public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {
57 |
58 | }
59 |
60 | @Override
61 | public void draw(@NonNull Canvas canvas) {
62 | super.draw(canvas);
63 | drawChildren(canvas);
64 | }
65 |
66 | @Override
67 | protected void drawSelf(@NonNull Canvas canvas) {
68 | if(bgColor != -1) {
69 | int count = canvas.save();
70 | bgPaint.setColor(bgColor);
71 | canvas.drawRect(getBounds(), bgPaint);
72 | canvas.restoreToCount(count);
73 | }
74 | }
75 |
76 | protected void drawChildren(@NonNull Canvas canvas) {
77 | for (Drawable child : children) {
78 | int count = canvas.save();
79 | child.draw(canvas);
80 | canvas.restoreToCount(count);
81 | }
82 | }
83 |
84 | @Override
85 | public ValueAnimator createAnimator() {
86 | return null;
87 | }
88 |
89 | @Override
90 | protected void onBoundsChange(Rect bounds) {
91 | super.onBoundsChange(bounds);
92 | for (Drawable child : children) {
93 | child.setBounds(bounds);
94 | }
95 | }
96 |
97 | public int getChildCount() {
98 | return children.length;
99 | }
100 |
101 | public Drawable getChildAt(int index) {
102 | return children[index];
103 | }
104 |
105 | @Override
106 | public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {
107 | for (Drawable child : children) {
108 | child.setAlpha(alpha);
109 | }
110 | }
111 |
112 | @Override
113 | public void setColorFilter(@Nullable ColorFilter colorFilter) {
114 |
115 | }
116 |
117 | public void setBgColor(int bgColor) {
118 | this.bgColor = bgColor;
119 | }
120 |
121 | @Override
122 | public int getOpacity() {
123 | return PixelFormat.TRANSLUCENT;
124 | }
125 |
126 | @Override
127 | public void start() {
128 | super.start();
129 | AnimUtils.start(children);
130 | }
131 |
132 | @Override
133 | public void stop() {
134 | super.stop();
135 | AnimUtils.stop(children);
136 | }
137 |
138 | @Override
139 | public boolean isRunning() {
140 | return AnimUtils.isRunning(children);
141 | }
142 |
143 |
144 | }
145 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/AnimationDrawable.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Camera;
5 | import android.graphics.Canvas;
6 | import android.graphics.ColorFilter;
7 | import android.graphics.Matrix;
8 | import android.graphics.PixelFormat;
9 | import android.graphics.Rect;
10 | import android.graphics.drawable.Animatable;
11 | import android.graphics.drawable.Drawable;
12 | import android.support.annotation.IntRange;
13 | import android.support.annotation.NonNull;
14 | import android.support.annotation.Nullable;
15 |
16 | import com.simon.core.animationtools.animator.AnimUtils;
17 |
18 | /**
19 | *
20 | * Created by simon on 17-6-5.
21 | */
22 |
23 | public abstract class AnimationDrawable extends Drawable implements
24 | ValueAnimator.AnimatorUpdateListener,
25 | Animatable, Drawable.Callback {
26 |
27 | private static final Rect ZERO_BOUNDS_RECT = new Rect();
28 |
29 | private ValueAnimator animator;
30 |
31 | private Camera mCamera;
32 |
33 | private Matrix mMatrix;
34 |
35 | private float scale = 1;
36 | private float scaleX = 1;
37 | private float scaleY = 1;
38 | private float pivotX;
39 | private float pivotY;
40 | private int animationDelay;
41 | private float rotationX;
42 | private float rotationY;
43 | private float translationX;
44 | private float translationY;
45 | private float rotation;
46 | private float translationXPercentage;
47 | private float translationYPercentage;
48 | private @IntRange(from = 0, to = 255) int alpha = 255;
49 | protected Rect drawBounds = ZERO_BOUNDS_RECT;
50 |
51 |
52 | @Override
53 | public int getAlpha() {
54 | return alpha;
55 | }
56 |
57 | public AnimationDrawable() {
58 | mCamera = new Camera();
59 | mMatrix = new Matrix();
60 | }
61 |
62 | public abstract ValueAnimator createAnimator();
63 |
64 | protected abstract void drawSelf(@NonNull Canvas canvas);
65 |
66 | @Override
67 | public void draw(@NonNull Canvas canvas) {
68 | float tx = getTranslationX();
69 | tx = tx == 0 ? (int) (getBounds().width() * getTranslationXPercentage()) : tx;
70 | float ty = getTranslationY();
71 | ty = ty == 0 ? (int) (getBounds().height() * getTranslationYPercentage()) : ty;
72 | canvas.translate(tx, ty);
73 | canvas.scale(getScaleX(), getScaleY(), getPivotX(), getPivotY());
74 | canvas.rotate(getRotation(), getPivotX(), getPivotY());
75 |
76 | if (getRotationX() != 0 || getRotationY() != 0) {
77 | mCamera.save();
78 | mCamera.rotateX(getRotationX());
79 | mCamera.rotateY(getRotationY());
80 | mCamera.getMatrix(mMatrix);
81 | mMatrix.preTranslate(-getPivotX(), -getPivotY());
82 | mMatrix.postTranslate(getPivotX(), getPivotY());
83 | mCamera.restore();
84 | canvas.concat(mMatrix);
85 | }
86 | drawSelf(canvas);
87 | }
88 |
89 | @Override
90 | public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {
91 | this.alpha = alpha;
92 | }
93 |
94 | @Override
95 | public void setColorFilter(@Nullable ColorFilter colorFilter) {
96 | //do nothing
97 | }
98 |
99 | @Override
100 | public int getOpacity() {
101 | return PixelFormat.TRANSLUCENT;
102 | }
103 |
104 | @Override
105 | public void invalidateDrawable(@NonNull Drawable who) {
106 | invalidateSelf();
107 | }
108 |
109 | @Override
110 | public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {
111 | scheduleSelf(what,when);
112 | }
113 |
114 | @Override
115 | public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {
116 | unscheduleSelf(what);
117 | }
118 |
119 | @Override
120 | public void onAnimationUpdate(ValueAnimator animation) {
121 | final Callback callback = getCallback();
122 | if (callback != null) {
123 | callback.invalidateDrawable(this);
124 | }
125 | }
126 |
127 | public void reset() {
128 | scale = 1;
129 | rotationX = 0;
130 | rotationY = 0;
131 | translationX = 0;
132 | translationY = 0;
133 | rotation = 0;
134 | translationXPercentage = 0f;
135 | translationYPercentage = 0f;
136 | }
137 |
138 | @Override
139 | public void start() {
140 | animator = createAnimator();
141 | if(animator != null) {
142 | animator.addUpdateListener(this);
143 | animator.setStartDelay(getAnimationDelay());
144 | AnimUtils.start(animator);
145 | }
146 | }
147 |
148 | @Override
149 | public void stop() {
150 | AnimUtils.stop(animator);
151 | reset();
152 | if(animator != null) {
153 | animator.removeUpdateListener(this);
154 | animator = null;
155 | }
156 | }
157 |
158 | @Override
159 | public boolean isRunning() {
160 | return AnimUtils.isRunning(animator);
161 | }
162 |
163 | //getters and setters
164 |
165 |
166 | public float getScale() {
167 | return scale;
168 | }
169 |
170 | public void setScale(float scale) {
171 | this.scale = scale;
172 | }
173 |
174 | public float getScaleX() {
175 | return scaleX;
176 | }
177 |
178 | public void setScaleX(float scaleX) {
179 | this.scaleX = scaleX;
180 | }
181 |
182 | public float getScaleY() {
183 | return scaleY;
184 | }
185 |
186 | public void setScaleY(float scaleY) {
187 | this.scaleY = scaleY;
188 | }
189 |
190 | public float getPivotX() {
191 | return pivotX;
192 | }
193 |
194 | public float getPivotY() {
195 | return pivotY;
196 | }
197 |
198 | public int getAnimationDelay() {
199 | return animationDelay;
200 | }
201 |
202 | public void setAnimationDelay(int animationDelay) {
203 | this.animationDelay = animationDelay;
204 | }
205 |
206 | public float getRotationX() {
207 | return rotationX;
208 | }
209 |
210 | public void setRotationX(float rotationX) {
211 | this.rotationX = rotationX;
212 | }
213 |
214 | public float getRotationY() {
215 | return rotationY;
216 | }
217 |
218 | public void setRotationY(float rotateY) {
219 | this.rotationY = rotateY;
220 | }
221 |
222 | public float getTranslationX() {
223 | return translationX;
224 | }
225 |
226 | public void setTranslationX(float translationX) {
227 | this.translationX = translationX;
228 | }
229 |
230 | public float getTranslationY() {
231 | return translationY;
232 | }
233 |
234 | public void setTranslationY(float translationY) {
235 | this.translationY = translationY;
236 | }
237 |
238 | public float getRotation() {
239 | return rotation;
240 | }
241 |
242 | public void setRotation(float rotate) {
243 | this.rotation = rotate;
244 | }
245 |
246 | public float getTranslationXPercentage() {
247 | return translationXPercentage;
248 | }
249 |
250 | public void setTranslationXPercentage(float translationXPercentage) {
251 | this.translationXPercentage = translationXPercentage;
252 | }
253 |
254 | public float getTranslationYPercentage() {
255 | return translationYPercentage;
256 | }
257 |
258 | public void setTranslationYPercentage(float translationYPercentage) {
259 | this.translationYPercentage = translationYPercentage;
260 | }
261 |
262 | public void setPivotX(float pivotX) {
263 | this.pivotX = pivotX;
264 | }
265 |
266 | public void setPivotY(float pivotY) {
267 | this.pivotY = pivotY;
268 | }
269 |
270 | public Rect getDrawBounds() {
271 | return drawBounds;
272 | }
273 |
274 | @Override
275 | protected void onBoundsChange(Rect bounds) {
276 | super.onBoundsChange(bounds);
277 | this.setDrawBounds(bounds);
278 | }
279 |
280 | public void setDrawBounds(@NonNull Rect drawBounds) {
281 | setDrawBounds(drawBounds.left, drawBounds.top, drawBounds.right, drawBounds.bottom);
282 | }
283 |
284 | public void setDrawBounds(int left, int top, int right, int bottom) {
285 | this.drawBounds = new Rect(left, top, right, bottom);
286 | pivotX = drawBounds.centerX();
287 | pivotY = drawBounds.centerY();
288 | }
289 |
290 | }
291 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/container/ChasingDots.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.container;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Rect;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Build;
7 | import android.support.annotation.NonNull;
8 | import android.view.animation.LinearInterpolator;
9 |
10 | import com.simon.core.animationtools.drawable.AnimDrawableContainer;
11 | import com.simon.core.animationtools.drawable.AnimationDrawable;
12 | import com.simon.core.animationtools.drawable.shape.CircleAnimDrawable;
13 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
14 |
15 | import static com.simon.core.animationtools.utils.ShapeUtils.clipSquare;
16 |
17 | /**
18 | * ChasingDots
19 | * Created by simon on 17-6-8.
20 | */
21 |
22 | public class ChasingDots extends AnimDrawableContainer {
23 |
24 | @NonNull
25 | @Override
26 | public Drawable[] createChildren() {
27 | Dot[] dots = {
28 | new Dot(),
29 | new Dot()
30 | };
31 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
32 | dots[1].setAnimationDelay(1000);
33 | } else {
34 | dots[1].setAnimationDelay(-1000);
35 | }
36 | return dots;
37 | }
38 |
39 | @Override
40 | public ValueAnimator createAnimator() {
41 | float fractions[] = new float[]{0f, 1f};
42 | return new DrawableAnimatorBuilder(this).
43 | rotate(fractions, 0f, 360f).
44 | duration(2000).
45 | interpolator(new LinearInterpolator()).
46 | build();
47 | }
48 |
49 | @Override
50 | protected void onBoundsChange(Rect bounds) {
51 | super.onBoundsChange(bounds);
52 | bounds = clipSquare(bounds);
53 | int drawW = (int) (bounds.width() * 0.6f);
54 | ((AnimationDrawable) getChildAt(0)).setDrawBounds(
55 | bounds.right - drawW,
56 | bounds.top,
57 | bounds.right
58 | , bounds.top + drawW
59 | );
60 | ((AnimationDrawable) getChildAt(1)).setDrawBounds(
61 | bounds.right - drawW,
62 | bounds.bottom - drawW,
63 | bounds.right,
64 | bounds.bottom
65 | );
66 | }
67 |
68 | private class Dot extends CircleAnimDrawable {
69 |
70 | Dot() {
71 | setScale(0f);
72 | setAlpha(170);
73 | }
74 |
75 | @Override
76 | public ValueAnimator createAnimator() {
77 | float fractions[] = new float[]{0f, 0.5f, 1f};
78 | return new DrawableAnimatorBuilder(this).
79 | scale(fractions, 0f, 1f, 0f).
80 | duration(2000).
81 | easeInOut(fractions)
82 | .build();
83 | }
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/container/CubeGrid.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.container;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Rect;
5 | import android.graphics.drawable.Drawable;
6 | import android.support.annotation.NonNull;
7 |
8 | import com.simon.core.animationtools.drawable.AnimDrawableContainer;
9 | import com.simon.core.animationtools.drawable.shape.RectAnimDrawable;
10 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
11 |
12 | import static com.simon.core.animationtools.utils.ShapeUtils.clipSquare;
13 |
14 |
15 | /**
16 | * Created by simon on 17-6-8.
17 | */
18 |
19 | public class CubeGrid extends AnimDrawableContainer {
20 |
21 | @NonNull
22 | @Override
23 | public Drawable[] createChildren() {
24 | int delays[] = new int[]{
25 | 200, 300, 400
26 | , 100, 200, 300
27 | , 0, 100, 200
28 | };
29 | GridItem[] gridItems = new GridItem[9];
30 | for (int i = 0; i < gridItems.length; i++) {
31 | gridItems[i] = new GridItem();
32 | gridItems[i].setAnimationDelay(delays[i]);
33 | }
34 | return gridItems;
35 | }
36 |
37 | @Override
38 | public GridItem getChildAt(int index) {
39 | return ((GridItem) super.getChildAt(index));
40 | }
41 |
42 | @Override
43 | protected void onBoundsChange(Rect bounds) {
44 | super.onBoundsChange(bounds);
45 | bounds = clipSquare(bounds);
46 | int width = (int) (bounds.width() * 0.33f);
47 | int height = (int) (bounds.height() * 0.33f);
48 | for (int i = 0; i < getChildCount(); i++) {
49 | int x = i % 3;
50 | int y = i / 3;
51 | int l = bounds.left + x * width;
52 | int t = bounds.top + y * height;
53 | GridItem sprite = getChildAt(i);
54 | sprite.setDrawBounds(l, t, l + width, t + height);
55 | }
56 | }
57 |
58 | private class GridItem extends RectAnimDrawable {
59 | @Override
60 | public ValueAnimator createAnimator() {
61 | float fractions[] = new float[]{0f, 0.35f, 0.7f, 1f};
62 | return new DrawableAnimatorBuilder(this).
63 | scale(fractions, 1f, 0f, 1f, 1f).
64 | duration(1300).
65 | easeInOut(fractions)
66 | .build();
67 | }
68 | }
69 |
70 |
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/container/DoubleCircleBounce.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.container;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Color;
5 | import android.support.annotation.NonNull;
6 |
7 | import com.simon.core.animationtools.drawable.AnimDrawableContainer;
8 | import com.simon.core.animationtools.drawable.AnimationDrawable;
9 | import com.simon.core.animationtools.drawable.shape.CircleAnimDrawable;
10 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
11 |
12 | /**
13 | * DoubleCircleBounce
14 | * Created by simon on 17-6-7.
15 | */
16 |
17 | public class DoubleCircleBounce extends AnimDrawableContainer {
18 |
19 | @NonNull
20 | @Override
21 | public AnimationDrawable[] createChildren() {
22 | AnimationDrawable[] children = new AnimationDrawable[]{new Bounce(Color.WHITE), new Bounce(Color.WHITE)};
23 | children[1].setAnimationDelay(-1000);
24 | return children;
25 | }
26 |
27 | private static class Bounce extends CircleAnimDrawable {
28 |
29 | private Bounce(int color) {
30 | setAlpha(153);
31 | setScale(0f);
32 | setColor(color);
33 | }
34 |
35 | @Override
36 | public ValueAnimator createAnimator() {
37 | float fractions[] = new float[]{0f, 0.5f, 1f};
38 | return new DrawableAnimatorBuilder(this).scale(fractions, 0f, 1f, 0f).
39 | duration(2000).
40 | easeInOut(fractions)
41 | .build();
42 | }
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/container/FoldingCube.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.container;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Canvas;
5 | import android.graphics.Rect;
6 | import android.graphics.drawable.Drawable;
7 | import android.os.Build;
8 | import android.support.annotation.NonNull;
9 | import android.view.animation.LinearInterpolator;
10 |
11 | import com.simon.core.animationtools.drawable.AnimDrawableContainer;
12 | import com.simon.core.animationtools.drawable.shape.RectAnimDrawable;
13 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
14 |
15 | import static com.simon.core.animationtools.utils.ShapeUtils.clipSquare;
16 |
17 | /**
18 | * FoldingCube
19 | * Created by simon on 17-6-8.
20 | */
21 |
22 | public class FoldingCube extends AnimDrawableContainer {
23 |
24 | @NonNull
25 | @Override
26 | public Drawable[] createChildren() {
27 | Cube[] cubes
28 | = new Cube[4];
29 | for (int i = 0; i < cubes.length; i++) {
30 | cubes[i] = new Cube();
31 |
32 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
33 | cubes[i].setAnimationDelay(300 * i);
34 | } else {
35 | cubes[i].setAnimationDelay(300 * i - 1200);
36 | }
37 | }
38 | return cubes;
39 | }
40 |
41 | @Override
42 | protected void onBoundsChange(Rect bounds) {
43 | super.onBoundsChange(bounds);
44 | bounds = clipSquare(bounds);
45 | int size = Math.min(bounds.width(), bounds.height());
46 | size = (int) Math.sqrt(
47 | (size
48 | * size) / 2);
49 | int oW = (bounds.width() - size) / 2;
50 | int oH = (bounds.height() - size) / 2;
51 | bounds = new Rect(
52 | bounds.left + oW,
53 | bounds.top + oH,
54 | bounds.right - oW,
55 | bounds.bottom - oH
56 | );
57 | int px = bounds.left + size / 2 + 1;
58 | int py = bounds.top + size / 2 + 1;
59 | for (int i = 0; i < getChildCount(); i++) {
60 | Cube cube = getChildAt(i);
61 | cube.setDrawBounds(
62 | bounds.left,
63 | bounds.top,
64 | px,
65 | py
66 | );
67 | cube.setPivotX(cube.getDrawBounds().right);
68 | cube.setPivotY(cube.getDrawBounds().bottom);
69 | }
70 | }
71 |
72 | @Override
73 | public Cube getChildAt(int index) {
74 | return ((Cube) super.getChildAt(index));
75 | }
76 |
77 | @Override
78 | public void drawChildren(@NonNull Canvas canvas) {
79 |
80 | Rect bounds = clipSquare(getBounds());
81 | for (int i = 0; i < getChildCount(); i++) {
82 | int count = canvas.save();
83 | canvas.rotate(45 + i * 90, bounds.centerX(), bounds.centerY());
84 | Cube cube = getChildAt(i);
85 | cube.draw(canvas);
86 | canvas.restoreToCount(count);
87 | }
88 | }
89 |
90 | private class Cube extends RectAnimDrawable {
91 |
92 | Cube() {
93 | setAlpha(0);
94 | setRotationX(-180);
95 | }
96 |
97 | @Override
98 | public ValueAnimator createAnimator() {
99 | float fractions[] = new float[]{0f, 0.1f, 0.25f, 0.75f, 0.9f, 1f};
100 | return new DrawableAnimatorBuilder(this)
101 | .alpha(fractions, 0f, 0f, 1f, 1f, 0f, 0f)
102 | .rotateX(fractions, -180f, -180f, 0f, 0f, 0f, 0f)
103 | .rotateY(fractions, 0f, 0f, 0f, 0f, 180f, 180f)
104 | .duration(2400)
105 | .interpolator(new LinearInterpolator())
106 | .build();
107 | }
108 | }
109 |
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/container/MultiplePulse.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.container;
2 |
3 | import android.graphics.drawable.Drawable;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.simon.core.animationtools.drawable.AnimDrawableContainer;
7 | import com.simon.core.animationtools.drawable.shape.Pulse;
8 |
9 | /**
10 | * MultiplePulse
11 | * Created by simon on 17-6-8.
12 | */
13 |
14 | public class MultiplePulse extends AnimDrawableContainer {
15 |
16 | @NonNull
17 | @Override
18 | public Drawable[] createChildren() {
19 | Pulse[] children = {
20 | new Pulse(),
21 | new Pulse(),
22 | new Pulse(),
23 | };
24 | for (int i = 0; i < children.length; i++) {
25 | children[i].setAnimationDelay(200 * (i + 1));
26 | }
27 | return children;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/container/RotatingDots.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.container;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Canvas;
5 | import android.graphics.Rect;
6 | import android.graphics.drawable.Drawable;
7 | import android.os.Build;
8 | import android.support.annotation.NonNull;
9 |
10 | import com.simon.core.animationtools.drawable.AnimDrawableContainer;
11 | import com.simon.core.animationtools.drawable.shape.CircleAnimDrawable;
12 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
13 |
14 | import static com.simon.core.animationtools.utils.ShapeUtils.clipSquare;
15 |
16 | /**
17 | * RotatingDots
18 | * Created by simon on 17-6-8.
19 | */
20 |
21 | public class RotatingDots extends AnimDrawableContainer {
22 |
23 |
24 | @Override
25 | public void drawChildren(@NonNull Canvas canvas) {
26 | for (int i = 0; i < getChildCount(); i++) {
27 | Dot dot = getChildAt(i);
28 | int count = canvas.save();
29 | canvas.rotate(i * 360 / getChildCount(),
30 | getBounds().centerX(),
31 | getBounds().centerY());
32 | dot.draw(canvas);
33 | canvas.restoreToCount(count);
34 | }
35 | }
36 |
37 | @Override
38 | protected void onBoundsChange(Rect bounds) {
39 | super.onBoundsChange(bounds);
40 | bounds = clipSquare(bounds);
41 | int radius = (int) (bounds.width() * Math.PI / 3f / getChildCount());
42 | int left = bounds.centerX() - radius;
43 | int right = bounds.centerX() + radius;
44 | for (int i = 0; i < getChildCount(); i++) {
45 | Dot dot = getChildAt(i);
46 | dot.setDrawBounds(left, bounds.top, right, bounds.top + radius * 2);
47 | }
48 | }
49 |
50 | @Override
51 | public Dot getChildAt(int index) {
52 | return ((Dot) super.getChildAt(index));
53 | }
54 |
55 | @NonNull
56 | @Override
57 | public Drawable[] createChildren() {
58 | Dot[] dots = new Dot[12];
59 | for (int i = 0; i < dots.length; i++) {
60 | dots[i] = new Dot();
61 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
62 | dots[i].setAnimationDelay(1200 / 12 * i);
63 | } else {
64 | dots[i].setAnimationDelay(1200 / 12 * i + -1200);
65 | }
66 | }
67 | return dots;
68 | }
69 |
70 |
71 | private class Dot extends CircleAnimDrawable {
72 |
73 | Dot() {
74 | setScale(0f);
75 | }
76 |
77 | @Override
78 | public ValueAnimator createAnimator() {
79 | float fractions[] = new float[]{0f, 0.5f, 1f};
80 | return new DrawableAnimatorBuilder(this).
81 | scale(fractions, 0f, 1f, 0f).
82 | duration(1200).
83 | easeInOut(fractions)
84 | .build();
85 | }
86 | }
87 |
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/container/RotatingDots2.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.container;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Canvas;
5 | import android.graphics.Rect;
6 | import android.graphics.drawable.Drawable;
7 | import android.os.Build;
8 | import android.support.annotation.NonNull;
9 |
10 | import com.simon.core.animationtools.drawable.AnimDrawableContainer;
11 | import com.simon.core.animationtools.drawable.shape.CircleAnimDrawable;
12 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
13 |
14 | import static com.simon.core.animationtools.utils.ShapeUtils.clipSquare;
15 |
16 | /**
17 | *
18 | * Created by simon on 17-6-8.
19 | */
20 |
21 | public class RotatingDots2 extends AnimDrawableContainer {
22 |
23 |
24 | @Override
25 | public void drawChildren(@NonNull Canvas canvas) {
26 | for (int i = 0; i < getChildCount(); i++) {
27 | Dot dot = getChildAt(i);
28 | int count = canvas.save();
29 | canvas.rotate(i * 360 / getChildCount(),
30 | getBounds().centerX(),
31 | getBounds().centerY());
32 | dot.draw(canvas);
33 | canvas.restoreToCount(count);
34 | }
35 | }
36 |
37 | @Override
38 | protected void onBoundsChange(Rect bounds) {
39 | super.onBoundsChange(bounds);
40 | bounds = clipSquare(bounds);
41 | int radius = (int) (bounds.width() * Math.PI / 3f / getChildCount());
42 | int left = bounds.centerX() - radius;
43 | int right = bounds.centerX() + radius;
44 | for (int i = 0; i < getChildCount(); i++) {
45 | Dot dot = getChildAt(i);
46 | dot.setDrawBounds(left, bounds.top, right, bounds.top + radius * 2);
47 | }
48 | }
49 |
50 | @Override
51 | public Dot getChildAt(int index) {
52 | return ((Dot) super.getChildAt(index));
53 | }
54 |
55 | @NonNull
56 | @Override
57 | public Drawable[] createChildren() {
58 | Dot[] dots = new Dot[12];
59 | for (int i = 0; i < dots.length; i++) {
60 | dots[i] = new Dot();
61 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
62 | dots[i].setAnimationDelay(1200 / 12 * i);
63 | } else {
64 | dots[i].setAnimationDelay(1200 / 12 * i + -1200);
65 | }
66 | }
67 | return dots;
68 | }
69 |
70 |
71 | private class Dot extends CircleAnimDrawable {
72 |
73 | Dot() {
74 | setAlpha(0);
75 | }
76 |
77 | @Override
78 | public ValueAnimator createAnimator() {
79 | float fractions[] = new float[]{0f, 0.39f, 0.4f, 1f};
80 | return new DrawableAnimatorBuilder(this)
81 | .alpha(fractions, 0f, 0f, 1f, 0f)
82 | .duration(1200)
83 | .easeInOut(fractions)
84 | .build();
85 | }
86 | }
87 |
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/container/ThreeBounce.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.container;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Rect;
5 | import android.graphics.drawable.Drawable;
6 | import android.support.annotation.NonNull;
7 |
8 | import com.simon.core.animationtools.drawable.AnimDrawableContainer;
9 | import com.simon.core.animationtools.drawable.shape.CircleAnimDrawable;
10 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
11 |
12 | import static com.simon.core.animationtools.utils.ShapeUtils.clipSquare;
13 |
14 | /**
15 | * ThreeBounce
16 | * Created by simon on 17-6-8.
17 | */
18 |
19 | public class ThreeBounce extends AnimDrawableContainer{
20 |
21 | @NonNull
22 | @Override
23 | public Drawable[] createChildren() {
24 | Bounce[] bounces = {
25 | new Bounce(),
26 | new Bounce(),
27 | new Bounce()
28 | };
29 | bounces[1].setAnimationDelay(160);
30 | bounces[2].setAnimationDelay(320);
31 | return bounces;
32 | }
33 |
34 | @Override
35 | public Bounce getChildAt(int index) {
36 | return ((Bounce) super.getChildAt(index));
37 | }
38 |
39 | @Override
40 | protected void onBoundsChange(Rect bounds) {
41 | super.onBoundsChange(bounds);
42 | bounds = clipSquare(bounds);
43 | int radius = bounds.width() / 6;
44 | int top = bounds.centerY() - radius;
45 | int bottom = bounds.centerY() + radius;
46 |
47 | for (int i = 0; i < getChildCount(); i++) {
48 | int center = bounds.width() * (i + 1) / 4
49 | + bounds.left;
50 | getChildAt(i).setDrawBounds(
51 | center - radius, top, center + radius, bottom
52 | );
53 | }
54 | }
55 |
56 | private class Bounce extends CircleAnimDrawable {
57 |
58 | Bounce() {
59 | setScale(0f);
60 | }
61 |
62 | @Override
63 | public ValueAnimator createAnimator() {
64 | float fractions[] = new float[]{0f, 0.4f, 0.8f, 1f};
65 | return new DrawableAnimatorBuilder(this).scale(fractions, 0f, 1f, 0f, 0f).
66 | duration(1400).
67 | easeInOut(fractions)
68 | .build();
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/container/WanderingCubes.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.container;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Color;
5 | import android.graphics.Rect;
6 | import android.graphics.drawable.Drawable;
7 | import android.support.annotation.NonNull;
8 |
9 | import com.simon.core.animationtools.drawable.AnimDrawableContainer;
10 | import com.simon.core.animationtools.drawable.AnimationDrawable;
11 | import com.simon.core.animationtools.drawable.shape.RectAnimDrawable;
12 | import com.simon.core.animationtools.animator.AnimatorBuilder;
13 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
14 |
15 | import static com.simon.core.animationtools.utils.ShapeUtils.clipSquare;
16 |
17 | /**
18 | * Wandering cubes
19 | * Created by simon on 17-6-8.
20 | */
21 |
22 | public class WanderingCubes extends AnimDrawableContainer {
23 |
24 |
25 | @NonNull
26 | @Override
27 | public Drawable[] createChildren() {
28 | return new AnimationDrawable[]{
29 | new Cube(0, Color.RED),
30 | new Cube(3,Color.BLUE)
31 | };
32 | }
33 |
34 | @Override
35 | protected void onBoundsChange(Rect bounds) {
36 | super.onBoundsChange(bounds);
37 | bounds = clipSquare(bounds);
38 | for (int i = 0; i < getChildCount(); i++) {
39 | Drawable child = getChildAt(i);
40 | ((AnimationDrawable) child).setDrawBounds(
41 | bounds.left,
42 | bounds.top,
43 | bounds.left + bounds.width() / 4,
44 | bounds.top + bounds.height() / 4
45 | );
46 | }
47 | }
48 |
49 | private class Cube extends RectAnimDrawable {
50 | int startFrame;
51 |
52 | public Cube(int startFrame, int color) {
53 | super();
54 | this.startFrame = startFrame;
55 | setColor(color);
56 | }
57 |
58 | @Override
59 | public ValueAnimator createAnimator() {
60 | float fractions[] = new float[]{0f, 0.25f, 0.5f, 0.51f, 0.75f, 1f};
61 | AnimatorBuilder builder = new DrawableAnimatorBuilder(this)
62 | .rotate(fractions, 0f, -90f, -179f, -180f, -270f, -360f)
63 | .translateXPercentage(fractions, 0f, 0.75f, 0.75f, 0.75f, 0f, 0f)
64 | .translateYPercentage(fractions, 0f, 0f, 0.75f, 0.75f, 0.75f, 0f)
65 | .scale(fractions, 1f, 0.5f, 1f, 1f, 0.5f, 1f)
66 | .duration(1800)
67 | .easeInOut(fractions)
68 | .startFrame(startFrame);
69 | return builder.build();
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/container/WavingBars.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.container;
2 |
3 |
4 | import android.animation.ValueAnimator;
5 | import android.graphics.Rect;
6 | import android.graphics.drawable.Drawable;
7 | import android.os.Build;
8 | import android.support.annotation.NonNull;
9 |
10 | import com.simon.core.animationtools.drawable.AnimDrawableContainer;
11 | import com.simon.core.animationtools.drawable.AnimationDrawable;
12 | import com.simon.core.animationtools.drawable.shape.RectAnimDrawable;
13 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
14 | import com.simon.core.animationtools.utils.ShapeUtils;
15 |
16 | import static com.simon.core.animationtools.utils.ShapeUtils.clipSquare;
17 |
18 | /**
19 | * wandering bars
20 | * Created by simon on 17-6-8.
21 | */
22 |
23 | public class WavingBars extends AnimDrawableContainer {
24 |
25 | @NonNull
26 | @Override
27 | public AnimationDrawable[] createChildren() {
28 | AnimationDrawable[] children = ShapeUtils.createShapeArray(WavingItem.class, 5);
29 | for (int i = 0; i < children.length; i++) {
30 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
31 | children[i].setAnimationDelay(600 + i * 100);
32 | } else {
33 | children[i].setAnimationDelay(-1200 + i * 100);
34 | }
35 | }
36 | return children;
37 | }
38 |
39 | @Override
40 | protected void onBoundsChange(Rect bounds) {
41 | super.onBoundsChange(bounds);
42 | bounds = clipSquare(bounds);
43 | int rw = bounds.width() / getChildCount();
44 | int width = bounds.width() / 5 * 3 / 5;
45 | for (int i = 0; i < getChildCount(); i++) {
46 | Drawable child = getChildAt(i);
47 | int l = bounds.left + i * rw + rw / 5;
48 | int r = l + width;
49 | ((AnimationDrawable) child).setDrawBounds(l, bounds.top, r, bounds.bottom);
50 | }
51 | }
52 |
53 | public static class WavingItem extends RectAnimDrawable {
54 |
55 | WavingItem() {
56 | setScaleY(0.4f);
57 | }
58 |
59 | @Override
60 | public ValueAnimator createAnimator() {
61 | float fractions[] = new float[]{0f, 0.2f, 0.4f, 1f};
62 | return new DrawableAnimatorBuilder(this).scaleY(fractions, 0.4f, 1f, 0.4f, 0.4f)
63 | .duration(1200)
64 | .easeInOut(fractions)
65 | .build();
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/shape/CircleAnimDrawable.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.shape;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 |
7 | /**
8 | * CircleAnimDrawable
9 | * Created by simon on 17-6-7.
10 | */
11 |
12 | public abstract class CircleAnimDrawable extends ShapeAnimDrawable {
13 |
14 | @Override
15 | public void drawShape(Canvas canvas, Paint paint) {
16 | Rect drawBounds = getDrawBounds();
17 | int radius = Math.min(drawBounds.width() / 2, drawBounds.height()) / 2;
18 | canvas.drawCircle(drawBounds.centerX(),
19 | drawBounds.centerY(),
20 | radius, paint);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/shape/Pulse.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.shape;
2 |
3 | import android.animation.ValueAnimator;
4 |
5 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
6 |
7 | /**
8 | * Created by simon on 17-6-7.
9 | */
10 |
11 | public class Pulse extends CircleAnimDrawable {
12 |
13 | public Pulse() {
14 | setScale(0f);
15 | }
16 |
17 | @Override
18 | public ValueAnimator createAnimator() {
19 | float fractions[] = new float[]{0f, 1f};
20 | return new DrawableAnimatorBuilder(this)
21 | .scale(fractions, 0f, 1f)
22 | .alpha(fractions, 1f, 0f)
23 | .duration(1000)
24 | .easeInOut(fractions)
25 | .build();
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/shape/RectAnimDrawable.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.shape;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Paint;
5 |
6 | /**
7 | * abstract class ofRect animation drawable
8 | * Created by simon on 17-6-6.
9 | */
10 |
11 | public abstract class RectAnimDrawable extends ShapeAnimDrawable {
12 | @Override
13 | public void drawShape(Canvas canvas, Paint paint) {
14 | canvas.drawRect(getDrawBounds(),paint);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/shape/RotatingPlane.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.shape;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.graphics.Rect;
5 |
6 | import com.simon.core.animationtools.animator.DrawableAnimatorBuilder;
7 |
8 | import static com.simon.core.animationtools.utils.ShapeUtils.clipSquare;
9 |
10 | public class RotatingPlane extends RectAnimDrawable {
11 |
12 | @Override
13 | protected void onBoundsChange(Rect bounds) {
14 | setDrawBounds(clipSquare(bounds));
15 | }
16 |
17 | @Override
18 | public ValueAnimator createAnimator() {
19 | float fractions[] = new float[]{0f, 0.5f, 1f};
20 | return new DrawableAnimatorBuilder(this).
21 | rotateX(fractions, 0f, -180f, -180f).
22 | rotateY(fractions, 0f, 0f, -180f).
23 | duration(1200).
24 | easeInOut(fractions)
25 | .build();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/drawable/shape/ShapeAnimDrawable.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.drawable.shape;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Color;
5 | import android.graphics.ColorFilter;
6 | import android.graphics.Paint;
7 |
8 | import com.simon.core.animationtools.drawable.AnimationDrawable;
9 |
10 | /**
11 | *
12 | * Created by simon on 17-6-6.
13 | */
14 |
15 | public abstract class ShapeAnimDrawable extends AnimationDrawable {
16 |
17 | private Paint mPaint;
18 | private int mUseColor;
19 | private int mBaseColor;
20 |
21 | public ShapeAnimDrawable() {
22 | super();
23 | setColor(Color.WHITE);
24 | mPaint = new Paint();
25 | mPaint.setAntiAlias(true);
26 | mPaint.setColor(mUseColor);
27 | }
28 |
29 | public void setColor(int color) {
30 | mBaseColor = color;
31 | updateUseColor();
32 | }
33 |
34 | public int getColor() {
35 | return mBaseColor;
36 | }
37 |
38 | @SuppressWarnings("unused")
39 | public int getUseColor() {
40 | return mUseColor;
41 | }
42 |
43 | @Override
44 | public void setAlpha(int alpha) {
45 | super.setAlpha(alpha);
46 | updateUseColor();
47 | }
48 |
49 |
50 | private void updateUseColor() {
51 | int alpha = getAlpha();
52 | alpha += alpha >> 7;
53 | final int baseAlpha = mBaseColor >>> 24;
54 | final int useAlpha = baseAlpha * alpha >> 8;
55 | mUseColor = (mBaseColor << 8 >>> 8) | (useAlpha << 24);
56 | }
57 |
58 | @Override
59 | public void setColorFilter(ColorFilter colorFilter) {
60 | mPaint.setColorFilter(colorFilter);
61 | }
62 |
63 | @Override
64 | protected final void drawSelf(Canvas canvas) {
65 | mPaint.setColor(mUseColor);
66 | drawShape(canvas, mPaint);
67 | }
68 |
69 | public abstract void drawShape(Canvas canvas, Paint paint);
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/utils/ShapeUtils.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.utils;
2 |
3 | import android.graphics.Rect;
4 |
5 | import com.simon.core.animationtools.drawable.AnimationDrawable;
6 | import com.simon.core.animationtools.drawable.shape.ShapeAnimDrawable;
7 |
8 | import java.lang.reflect.Constructor;
9 | import java.lang.reflect.InvocationTargetException;
10 |
11 | /**
12 | * utils of shapes
13 | * Created by simon on 17-6-8.
14 | */
15 |
16 | public class ShapeUtils {
17 |
18 | public static AnimationDrawable[] createShapeArray(Class extends ShapeAnimDrawable> clazz, int count) {
19 | AnimationDrawable[] array = new AnimationDrawable[count];
20 | try {
21 | Constructor extends ShapeAnimDrawable> constructor = clazz.getConstructor();
22 | for (int i = 0; i < array.length; i++) {
23 | array[i] = constructor.newInstance();
24 | }
25 | return array;
26 | } catch (NoSuchMethodException e) {
27 | e.printStackTrace();
28 | } catch (IllegalAccessException e) {
29 | e.printStackTrace();
30 | } catch (InstantiationException e) {
31 | e.printStackTrace();
32 | } catch (InvocationTargetException e) {
33 | e.printStackTrace();
34 | }
35 | throw new IllegalStateException("class " + clazz.getName() + " cannot new instance");
36 | }
37 |
38 | public static Rect clipSquare(Rect rect) {
39 | int w = rect.width();
40 | int h = rect.height();
41 | int min = Math.min(w, h);
42 | int cx = rect.centerX();
43 | int cy = rect.centerY();
44 | int r = min / 2;
45 | return new Rect(
46 | cx - r,
47 | cy - r,
48 | cx + r,
49 | cy + r
50 | );
51 | }
52 |
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/library/src/main/java/com/simon/core/animationtools/view/InterpolatorCanvas.java:
--------------------------------------------------------------------------------
1 | package com.simon.core.animationtools.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.support.annotation.Nullable;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 | import android.view.animation.Interpolator;
11 |
12 | /**
13 | * Created by simon on 17-5-12.
14 | */
15 |
16 | public class InterpolatorCanvas extends View {
17 |
18 | private Interpolator interpolator;
19 |
20 | private Paint paint;
21 |
22 | public InterpolatorCanvas(Context context) {
23 | super(context);
24 | init();
25 | }
26 |
27 | public InterpolatorCanvas(Context context, @Nullable AttributeSet attrs) {
28 | super(context, attrs);
29 | init();
30 | }
31 |
32 | public InterpolatorCanvas(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 | init();
35 | }
36 |
37 | public void setInterpolator(Interpolator interpolator) {
38 | this.interpolator = interpolator;
39 | }
40 |
41 | private void init() {
42 | paint = new Paint();
43 | paint.setAntiAlias(true);
44 |
45 | paint.setStrokeWidth(2);
46 | paint.setStyle(Paint.Style.FILL);
47 | }
48 |
49 | @Override
50 | protected void onDraw(Canvas canvas) {
51 | super.onDraw(canvas);
52 | int width = getWidth();
53 | int height = getHeight();
54 | paint.setColor(Color.GRAY);
55 | canvas.drawRect(0, 0, width, height, paint);
56 | if (interpolator == null) return;
57 | paint.setColor(Color.BLUE);
58 | for (int i = 0; i < width; i++) {
59 | float x = (((float) i) / width);
60 | float y = interpolator.getInterpolation(x);
61 | canvas.drawPoint(x * width, (1 - y) * height, paint);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |