From c7121ff86a8e3fd3e2dc1b84ea8efcec043828a1 Mon Sep 17 00:00:00 2001 From: csshuai Date: Wed, 7 Dec 2016 14:05:19 +0800 Subject: [PATCH 1/2] Update SpinKitView.java Fixed: when the power off/on then sprite not start --- .../main/java/com/github/ybq/android/spinkit/SpinKitView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/src/main/java/com/github/ybq/android/spinkit/SpinKitView.java b/library/src/main/java/com/github/ybq/android/spinkit/SpinKitView.java index 2f13c62..6c30568 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/SpinKitView.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/SpinKitView.java @@ -108,6 +108,10 @@ public void onScreenStateChanged(int screenState) { if (mSprite != null) { mSprite.stop(); } + } else { + if (mSprite != null) { + mSprite.start(); + } } } From 6e0acd14432e494cb88bbf127df858f68f11fac0 Mon Sep 17 00:00:00 2001 From: william Date: Wed, 11 Jul 2018 10:57:10 +0800 Subject: [PATCH 2/2] 1. update library 2. bugs fixed 3. add horizontal sprite --- build.gradle | 28 +- gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle | 12 +- .../ybq/android/spinkit/SpinKitView.java | 134 +--- .../ybq/android/spinkit/SpriteFactory.java | 108 +-- .../com/github/ybq/android/spinkit/Style.java | 41 +- .../spinkit/animation/AnimationUtils.java | 59 +- .../spinkit/animation/FloatProperty.java | 24 +- .../spinkit/animation/IntProperty.java | 24 +- .../animation/SpriteAnimatorBuilder.java | 350 ++++----- .../spinkit/animation/interpolator/Ease.java | 6 +- .../interpolator/KeyFrameInterpolator.java | 82 +- .../interpolator/PathInterpolatorCompat.java | 102 +-- .../PathInterpolatorCompatApi21.java | 32 +- .../PathInterpolatorCompatBase.java | 26 +- .../interpolator/PathInterpolatorDonut.java | 140 ++-- .../spinkit/sprite/CircleLayoutContainer.java | 44 +- .../android/spinkit/sprite/CircleSprite.java | 22 +- .../android/spinkit/sprite/RectSprite.java | 18 +- .../android/spinkit/sprite/RingSprite.java | 27 +- .../android/spinkit/sprite/ShapeSprite.java | 88 +-- .../ybq/android/spinkit/sprite/Sprite.java | 740 +++++++++--------- .../spinkit/sprite/SpriteContainer.java | 159 ++-- .../android/spinkit/style/ChasingDots.java | 112 ++- .../ybq/android/spinkit/style/Circle.java | 53 +- .../ybq/android/spinkit/style/CubeGrid.java | 73 +- .../android/spinkit/style/DoubleBounce.java | 57 +- .../android/spinkit/style/FadingCircle.java | 52 +- .../android/spinkit/style/FoldingCube.java | 145 ++-- .../ybq/android/spinkit/style/Horizontal.java | 45 ++ .../android/spinkit/style/MultiplePulse.java | 26 +- .../spinkit/style/MultiplePulseRing.java | 26 +- .../ybq/android/spinkit/style/Pulse.java | 27 +- .../ybq/android/spinkit/style/PulseRing.java | 27 +- .../android/spinkit/style/RotatingCircle.java | 21 +- .../android/spinkit/style/RotatingPlane.java | 29 +- .../android/spinkit/style/ThreeBounce.java | 82 +- .../android/spinkit/style/WanderingCubes.java | 95 ++- .../ybq/android/spinkit/style/Wave.java | 76 +- library/src/main/res/values/attrs.xml | 45 +- library/src/main/res/values/styles.xml | 411 +++++----- sample/build.gradle | 38 +- sample/src/main/AndroidManifest.xml | 40 +- .../ybq/android/loading/ArgbEvaluator.java | 86 +- .../github/ybq/android/loading/Colors.java | 20 +- .../ybq/android/loading/DetailActivity.java | 113 ++- .../ybq/android/loading/MainActivity.java | 75 +- .../ybq/android/loading/Page1Fragment.java | 120 ++- .../ybq/android/loading/Page2Fragment.java | 123 +-- .../android/loading/SquareFrameLayout.java | 38 +- .../src/main/res/layout/activity_detail.xml | 17 +- sample/src/main/res/layout/activity_main.xml | 23 +- sample/src/main/res/layout/fragment_page1.xml | 13 +- sample/src/main/res/layout/fragment_page2.xml | 252 +++--- sample/src/main/res/layout/item_list.xml | 20 +- sample/src/main/res/layout/item_pager.xml | 39 +- sample/src/main/res/values-v21/styles.xml | 12 +- sample/src/main/res/values/colors.xml | 6 +- sample/src/main/res/values/dimens.xml | 8 +- sample/src/main/res/values/strings.xml | 2 +- sample/src/main/res/values/styles.xml | 28 +- 61 files changed, 2353 insertions(+), 2390 deletions(-) create mode 100644 library/src/main/java/com/github/ybq/android/spinkit/style/Horizontal.java diff --git a/build.gradle b/build.gradle index 09b5979..32e376a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,24 +1,26 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' // Add this line + repositories { + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } } allprojects { - repositories { - jcenter() - } + repositories { + google() + jcenter() + } } task clean(type: Delete) { - delete rootProject.buildDir + delete rootProject.buildDir } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fb3f4d1..f9d9da0 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/library/build.gradle b/library/build.gradle index ca00f75..432df2e 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -3,10 +3,10 @@ apply plugin: 'com.github.dcendents.android-maven' group = 'com.github.ybq' version = '1.0' android { - compileSdkVersion 24 - buildToolsVersion "24.0.2" - defaultConfig { - minSdkVersion 14 - targetSdkVersion 24 - } + compileSdkVersion 27 + buildToolsVersion "27.0.3" + defaultConfig { + minSdkVersion 14 + targetSdkVersion 27 + } } \ No newline at end of file diff --git a/library/src/main/java/com/github/ybq/android/spinkit/SpinKitView.java b/library/src/main/java/com/github/ybq/android/spinkit/SpinKitView.java index 6c30568..f74a8fe 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/SpinKitView.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/SpinKitView.java @@ -4,115 +4,41 @@ import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; -import android.graphics.drawable.Drawable; import android.os.Build; import android.util.AttributeSet; -import android.view.View; import android.widget.ProgressBar; - import com.github.ybq.android.spinkit.sprite.Sprite; -/** - * Created by ybq. - */ public class SpinKitView extends ProgressBar { - private Style mStyle; - private int mColor; - private Sprite mSprite; - - public SpinKitView(Context context) { - this(context, null); - } - - public SpinKitView(Context context, AttributeSet attrs) { - this(context, attrs, R.attr.SpinKitViewStyle); - } - - public SpinKitView(Context context, AttributeSet attrs, int defStyleAttr) { - this(context, attrs, defStyleAttr, R.style.SpinKitView); - } - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public SpinKitView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpinKitView, defStyleAttr, - defStyleRes); - mStyle = Style.values()[a.getInt(R.styleable.SpinKitView_SpinKit_Style, 0)]; - mColor = a.getColor(R.styleable.SpinKitView_SpinKit_Color, Color.WHITE); - a.recycle(); - init(); - setIndeterminate(true); - } - - private void init() { - Sprite sprite = SpriteFactory.create(mStyle); - setIndeterminateDrawable(sprite); - } - - @Override - public void setIndeterminateDrawable(Drawable d) { - if (!(d instanceof Sprite)) { - throw new IllegalArgumentException("this d must be instanceof Sprite"); - } - setIndeterminateDrawable((Sprite) d); - } - - public void setIndeterminateDrawable(Sprite d) { - super.setIndeterminateDrawable(d); - mSprite = d; - if (mSprite.getColor() == 0) { - mSprite.setColor(mColor); - } - onSizeChanged(getWidth(), getHeight(), getWidth(), getHeight()); - if (getVisibility() == VISIBLE) { - mSprite.start(); - } - } - - @Override - public Sprite getIndeterminateDrawable() { - return mSprite; - } - - public void setColor(int color) { - this.mColor = color; - if (mSprite != null) { - mSprite.setColor(color); - } - invalidate(); - } - - @Override - public void unscheduleDrawable(Drawable who) { - super.unscheduleDrawable(who); - if (who instanceof Sprite) { - ((Sprite) who).stop(); - } - } - - @Override - public void onWindowFocusChanged(boolean hasWindowFocus) { - super.onWindowFocusChanged(hasWindowFocus); - if (hasWindowFocus) { - if (mSprite != null && getVisibility() == VISIBLE) { - mSprite.start(); - } - } - } - - @Override - public void onScreenStateChanged(int screenState) { - super.onScreenStateChanged(screenState); - if (screenState == View.SCREEN_STATE_OFF) { - if (mSprite != null) { - mSprite.stop(); - } - } else { - if (mSprite != null) { - mSprite.start(); - } - } - } - + private Style mStyle; + private int mColor; + + public SpinKitView(Context context) { + this(context, null); + } + + public SpinKitView(Context context, AttributeSet attrs) { + this(context, attrs, R.attr.SpinKitViewStyle); + } + + public SpinKitView(Context context, AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, R.style.SpinKitView); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public SpinKitView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpinKitView, defStyleAttr, defStyleRes); + mStyle = Style.values()[a.getInt(R.styleable.SpinKitView_SpinKit_Style, 0)]; + mColor = a.getColor(R.styleable.SpinKitView_SpinKit_Color, Color.WHITE); + a.recycle(); + init(); + } + + private void init() { + Sprite sprite = SpriteFactory.create(mStyle); + sprite.setColor(mColor); + setIndeterminateDrawable(sprite); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/SpriteFactory.java b/library/src/main/java/com/github/ybq/android/spinkit/SpriteFactory.java index 73ebef5..71bcbd9 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/SpriteFactory.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/SpriteFactory.java @@ -7,6 +7,7 @@ import com.github.ybq.android.spinkit.style.DoubleBounce; import com.github.ybq.android.spinkit.style.FadingCircle; import com.github.ybq.android.spinkit.style.FoldingCube; +import com.github.ybq.android.spinkit.style.Horizontal; import com.github.ybq.android.spinkit.style.MultiplePulse; import com.github.ybq.android.spinkit.style.MultiplePulseRing; import com.github.ybq.android.spinkit.style.Pulse; @@ -22,57 +23,60 @@ */ public class SpriteFactory { - public static Sprite create(Style style) { - Sprite sprite = null; - switch (style) { - case ROTATING_PLANE: - sprite = new RotatingPlane(); - break; - case DOUBLE_BOUNCE: - sprite = new DoubleBounce(); - break; - case WAVE: - sprite = new Wave(); - break; - case WANDERING_CUBES: - sprite = new WanderingCubes(); - break; - case PULSE: - sprite = new Pulse(); - break; - case CHASING_DOTS: - sprite = new ChasingDots(); - break; - case THREE_BOUNCE: - sprite = new ThreeBounce(); - break; - case CIRCLE: - sprite = new Circle(); - break; - case CUBE_GRID: - sprite = new CubeGrid(); - break; - case FADING_CIRCLE: - sprite = new FadingCircle(); - break; - case FOLDING_CUBE: - sprite = new FoldingCube(); - break; - case ROTATING_CIRCLE: - sprite = new RotatingCircle(); - break; - case MULTIPLE_PULSE: - sprite = new MultiplePulse(); - break; - case PULSE_RING: - sprite = new PulseRing(); - break; - case MULTIPLE_PULSE_RING: - sprite = new MultiplePulseRing(); - break; - default: - break; - } - return sprite; + public static Sprite create(Style style) { + Sprite sprite = null; + switch (style) { + case ROTATING_PLANE: + sprite = new RotatingPlane(); + break; + case DOUBLE_BOUNCE: + sprite = new DoubleBounce(); + break; + case WAVE: + sprite = new Wave(); + break; + case WANDERING_CUBES: + sprite = new WanderingCubes(); + break; + case PULSE: + sprite = new Pulse(); + break; + case CHASING_DOTS: + sprite = new ChasingDots(); + break; + case THREE_BOUNCE: + sprite = new ThreeBounce(); + break; + case CIRCLE: + sprite = new Circle(); + break; + case CUBE_GRID: + sprite = new CubeGrid(); + break; + case FADING_CIRCLE: + sprite = new FadingCircle(); + break; + case FOLDING_CUBE: + sprite = new FoldingCube(); + break; + case ROTATING_CIRCLE: + sprite = new RotatingCircle(); + break; + case MULTIPLE_PULSE: + sprite = new MultiplePulse(); + break; + case PULSE_RING: + sprite = new PulseRing(); + break; + case MULTIPLE_PULSE_RING: + sprite = new MultiplePulseRing(); + break; + case Horizontal: + sprite = new Horizontal(); + break; + default: + break; } + return sprite; + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/Style.java b/library/src/main/java/com/github/ybq/android/spinkit/Style.java index a1ebb1d..589a777 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/Style.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/Style.java @@ -5,26 +5,27 @@ */ public enum Style { - ROTATING_PLANE(0), - DOUBLE_BOUNCE(1), - WAVE(2), - WANDERING_CUBES(3), - PULSE(4), - CHASING_DOTS(5), - THREE_BOUNCE(6), - CIRCLE(7), - CUBE_GRID(8), - FADING_CIRCLE(9), - FOLDING_CUBE(10), - ROTATING_CIRCLE(11), - MULTIPLE_PULSE(12), - PULSE_RING(13), - MULTIPLE_PULSE_RING(14); + ROTATING_PLANE(0), + DOUBLE_BOUNCE(1), + WAVE(2), + WANDERING_CUBES(3), + PULSE(4), + CHASING_DOTS(5), + THREE_BOUNCE(6), + CIRCLE(7), + CUBE_GRID(8), + FADING_CIRCLE(9), + FOLDING_CUBE(10), + ROTATING_CIRCLE(11), + MULTIPLE_PULSE(12), + PULSE_RING(13), + MULTIPLE_PULSE_RING(14), + Horizontal(15); - @SuppressWarnings({"FieldCanBeLocal", "unused"}) - private int value; + @SuppressWarnings({ "FieldCanBeLocal", "unused" }) + private int value; - Style(int value) { - this.value = value; - } + Style(int value) { + this.value = value; + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/animation/AnimationUtils.java b/library/src/main/java/com/github/ybq/android/spinkit/animation/AnimationUtils.java index 18c4c46..c6711a6 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/animation/AnimationUtils.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/animation/AnimationUtils.java @@ -2,7 +2,6 @@ import android.animation.Animator; import android.animation.ValueAnimator; - import com.github.ybq.android.spinkit.sprite.Sprite; /** @@ -10,44 +9,44 @@ */ public class AnimationUtils { - public static void start(Animator animator) { - if (animator != null && !animator.isStarted()) { - animator.start(); - } + public static void start(Animator animator) { + if (animator != null && !animator.isStarted()) { + animator.start(); } + } - public static void stop(Animator animator) { - if (animator != null && !animator.isRunning()) { - animator.end(); - } + public static void stop(Animator animator) { + if (animator != null && !animator.isRunning()) { + animator.end(); } + } - public static void start(Sprite... sprites) { - for (Sprite sprite : sprites) { - sprite.start(); - } + public static void start(Sprite... sprites) { + for (Sprite sprite : sprites) { + sprite.start(); } + } - public static void stop(Sprite... sprites) { - for (Sprite sprite : sprites) { - sprite.stop(); - } + public static void stop(Sprite... sprites) { + for (Sprite sprite : sprites) { + sprite.stop(); } + } - public static boolean isRunning(Sprite... sprites) { - for (Sprite sprite : sprites) { - if (sprite.isRunning()) { - return true; - } - } - return false; + public static boolean isRunning(Sprite... sprites) { + for (Sprite sprite : sprites) { + if (sprite.isRunning()) { + return true; + } } + return false; + } - public static boolean isRunning(ValueAnimator animator) { - return animator != null && animator.isRunning(); - } + public static boolean isRunning(ValueAnimator animator) { + return animator != null && animator.isRunning(); + } - public static boolean isStarted(ValueAnimator animator) { - return animator != null && animator.isStarted(); - } + public static boolean isStarted(ValueAnimator animator) { + return animator != null && animator.isStarted(); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/animation/FloatProperty.java b/library/src/main/java/com/github/ybq/android/spinkit/animation/FloatProperty.java index 4b3e4ee..64d42b1 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/animation/FloatProperty.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/animation/FloatProperty.java @@ -28,19 +28,17 @@ */ public abstract class FloatProperty extends Property { - public FloatProperty(String name) { - super(Float.class, name); - } + public FloatProperty(String name) { + super(Float.class, name); + } - /** - * A type-specific override of the {@link #set(Object, Float)} that is faster when dealing - * with fields of type float. - */ - public abstract void setValue(T object, float value); - - @Override - final public void set(T object, Float value) { - setValue(object, value); - } + /** + * A type-specific override of the {@link #set(Object, Float)} that is faster when dealing + * with fields of type float. + */ + public abstract void setValue(T object, float value); + @Override final public void set(T object, Float value) { + setValue(object, value); + } } \ No newline at end of file diff --git a/library/src/main/java/com/github/ybq/android/spinkit/animation/IntProperty.java b/library/src/main/java/com/github/ybq/android/spinkit/animation/IntProperty.java index b777068..1582e6c 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/animation/IntProperty.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/animation/IntProperty.java @@ -28,19 +28,17 @@ */ public abstract class IntProperty extends Property { - public IntProperty(String name) { - super(Integer.class, name); - } + public IntProperty(String name) { + super(Integer.class, name); + } - /** - * A type-specific override of the {@link #set(Object, Integer)} that is faster when dealing - * with fields of type int. - */ - public abstract void setValue(T object, int value); - - @Override - final public void set(T object, Integer value) { - setValue(object, value); - } + /** + * A type-specific override of the {@link #set(Object, Integer)} that is faster when dealing + * with fields of type int. + */ + public abstract void setValue(T object, int value); + @Override final public void set(T object, Integer value) { + setValue(object, value); + } } \ No newline at end of file diff --git a/library/src/main/java/com/github/ybq/android/spinkit/animation/SpriteAnimatorBuilder.java b/library/src/main/java/com/github/ybq/android/spinkit/animation/SpriteAnimatorBuilder.java index 457b502..04f3c83 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/animation/SpriteAnimatorBuilder.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/animation/SpriteAnimatorBuilder.java @@ -7,11 +7,8 @@ import android.util.Property; import android.view.animation.Animation; import android.view.animation.Interpolator; - - import com.github.ybq.android.spinkit.animation.interpolator.KeyFrameInterpolator; import com.github.ybq.android.spinkit.sprite.Sprite; - import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -21,195 +18,186 @@ */ public class SpriteAnimatorBuilder { - private static final String TAG = "SpriteAnimatorBuilder"; - private Sprite sprite; - private Interpolator interpolator; - private int repeatCount = Animation.INFINITE; - private long duration = 2000; - private int startFrame = 0; - private Map fds = new HashMap<>(); - - - class FrameData { - public FrameData(float[] fractions, Property property, T[] values) { - this.fractions = fractions; - this.property = property; - this.values = values; - } - - float[] fractions; - Property property; - T[] values; - } - - class IntFrameData extends FrameData { - - public IntFrameData(float[] fractions, Property property, Integer[] values) { - super(fractions, property, values); + private static final String TAG = "SpriteAnimatorBuilder"; + private Sprite sprite; + private Interpolator interpolator; + private int repeatCount = Animation.INFINITE; + private long duration = 2000; + private int startFrame = 0; + private Map fds = new HashMap<>(); + + public SpriteAnimatorBuilder(Sprite sprite) { + this.sprite = sprite; + } + + public SpriteAnimatorBuilder scale(float fractions[], Float... scale) { + holder(fractions, Sprite.SCALE, scale); + return this; + } + + public SpriteAnimatorBuilder alpha(float fractions[], Integer... alpha) { + holder(fractions, Sprite.ALPHA, alpha); + return this; + } + + @SuppressWarnings("unused") + public SpriteAnimatorBuilder scaleX(float fractions[], Float... scaleX) { + holder(fractions, Sprite.SCALE_X, scaleX); + return this; + } + + public SpriteAnimatorBuilder scaleY(float fractions[], Float... scaleY) { + holder(fractions, Sprite.SCALE_Y, scaleY); + return this; + } + + public SpriteAnimatorBuilder rotateX(float fractions[], Integer... rotateX) { + holder(fractions, Sprite.ROTATE_X, rotateX); + return this; + } + + public SpriteAnimatorBuilder rotateY(float fractions[], Integer... rotateY) { + holder(fractions, Sprite.ROTATE_Y, rotateY); + return this; + } + + @SuppressWarnings("unused") + public SpriteAnimatorBuilder translateX(float fractions[], Integer... translateX) { + holder(fractions, Sprite.TRANSLATE_X, translateX); + return this; + } + + @SuppressWarnings("unused") + public SpriteAnimatorBuilder translateY(float fractions[], Integer... translateY) { + holder(fractions, Sprite.TRANSLATE_Y, translateY); + return this; + } + + public SpriteAnimatorBuilder rotate(float fractions[], Integer... rotate) { + holder(fractions, Sprite.ROTATE, rotate); + return this; + } + + public SpriteAnimatorBuilder translateXPercentage(float fractions[], Float... translateXPercentage) { + holder(fractions, Sprite.TRANSLATE_X_PERCENTAGE, translateXPercentage); + return this; + } + + public SpriteAnimatorBuilder translateYPercentage(float[] fractions, Float... translateYPercentage) { + holder(fractions, Sprite.TRANSLATE_Y_PERCENTAGE, translateYPercentage); + return this; + } + + private void holder(float[] fractions, Property property, Float[] values) { + ensurePair(fractions.length, values.length); + fds.put(property.getName(), new FloatFrameData(fractions, property, values)); + } + + private void holder(float[] fractions, Property property, Integer[] values) { + ensurePair(fractions.length, values.length); + fds.put(property.getName(), new IntFrameData(fractions, property, values)); + } + + private void ensurePair(int fractionsLength, int valuesLength) { + if (fractionsLength != valuesLength) { + throw new IllegalStateException(String.format( + Locale.getDefault(), + "The fractions.length must equal values.length, " + + "fraction.length[%d], values.length[%d]", + fractionsLength, + valuesLength)); + } + } + + public SpriteAnimatorBuilder interpolator(Interpolator interpolator) { + this.interpolator = interpolator; + return this; + } + + public SpriteAnimatorBuilder easeInOut(float... fractions) { + interpolator(KeyFrameInterpolator.easeInOut( + fractions + )); + return this; + } + + public SpriteAnimatorBuilder duration(long duration) { + this.duration = duration; + return this; + } + + @SuppressWarnings("unused") + public SpriteAnimatorBuilder repeatCount(int repeatCount) { + this.repeatCount = repeatCount; + return this; + } + + public SpriteAnimatorBuilder startFrame(int startFrame) { + if (startFrame < 0) { + Log.w(TAG, "startFrame should always be non-negative"); + startFrame = 0; + } + this.startFrame = startFrame; + return this; + } + + public ObjectAnimator build() { + PropertyValuesHolder[] holders = new PropertyValuesHolder[fds.size()]; + int i = 0; + for (Map.Entry fd : fds.entrySet()) { + FrameData data = fd.getValue(); + Keyframe[] keyframes = new Keyframe[data.fractions.length]; + float[] fractions = data.fractions; + float startF = fractions[startFrame]; + for (int j = startFrame; j < (startFrame + data.values.length); j++) { + int key = j - startFrame; + int vk = j % data.values.length; + float fraction = fractions[vk] - startF; + if (fraction < 0) { + fraction = fractions[fractions.length - 1] + fraction; } - } - - class FloatFrameData extends FrameData { - - public FloatFrameData(float[] fractions, Property property, Float[] values) { - super(fractions, property, values); + if (data instanceof IntFrameData) { + keyframes[key] = Keyframe.ofInt(fraction, (Integer) data.values[vk]); + } else if (data instanceof FloatFrameData) { + keyframes[key] = Keyframe.ofFloat(fraction, (Float) data.values[vk]); + } else { + keyframes[key] = Keyframe.ofObject(fraction, data.values[vk]); } + } + holders[i] = PropertyValuesHolder.ofKeyframe(data.property, keyframes); + i++; } - public SpriteAnimatorBuilder(Sprite sprite) { - this.sprite = sprite; - } - - public SpriteAnimatorBuilder scale(float fractions[], Float... scale) { - holder(fractions, Sprite.SCALE, scale); - return this; - } - - public SpriteAnimatorBuilder alpha(float fractions[], Integer... alpha) { - holder(fractions, Sprite.ALPHA, alpha); - return this; - } - - @SuppressWarnings("unused") - public SpriteAnimatorBuilder scaleX(float fractions[], Float... scaleX) { - holder(fractions, Sprite.SCALE, scaleX); - return this; - } - - public SpriteAnimatorBuilder scaleY(float fractions[], Float... scaleY) { - holder(fractions, Sprite.SCALE_Y, scaleY); - return this; - } - - public SpriteAnimatorBuilder rotateX(float fractions[], Integer... rotateX) { - holder(fractions, Sprite.ROTATE_X, rotateX); - return this; - } + ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(sprite, holders); + animator.setDuration(duration); + animator.setRepeatCount(repeatCount); + animator.setInterpolator(interpolator); + return animator; + } - public SpriteAnimatorBuilder rotateY(float fractions[], Integer... rotateY) { - holder(fractions, Sprite.ROTATE_Y, rotateY); - return this; - } + class FrameData { + float[] fractions; + Property property; + T[] values; - @SuppressWarnings("unused") - public SpriteAnimatorBuilder translateX(float fractions[], Integer... translateX) { - holder(fractions, Sprite.TRANSLATE_X, translateX); - return this; + public FrameData(float[] fractions, Property property, T[] values) { + this.fractions = fractions; + this.property = property; + this.values = values; } + } + class IntFrameData extends FrameData { - @SuppressWarnings("unused") - public SpriteAnimatorBuilder translateY(float fractions[], Integer... translateY) { - holder(fractions, Sprite.TRANSLATE_Y, translateY); - return this; + public IntFrameData(float[] fractions, Property property, Integer[] values) { + super(fractions, property, values); } + } + class FloatFrameData extends FrameData { - public SpriteAnimatorBuilder rotate(float fractions[], Integer... rotate) { - holder(fractions, Sprite.ROTATE, rotate); - return this; + public FloatFrameData(float[] fractions, Property property, Float[] values) { + super(fractions, property, values); } - - public SpriteAnimatorBuilder translateXPercentage(float fractions[], Float... translateXPercentage) { - holder(fractions, Sprite.TRANSLATE_X_PERCENTAGE, translateXPercentage); - return this; - } - - public SpriteAnimatorBuilder translateYPercentage(float[] fractions, Float... translateYPercentage) { - holder(fractions, Sprite.TRANSLATE_Y_PERCENTAGE, translateYPercentage); - return this; - } - - private void holder(float[] fractions, Property property, Float[] values) { - ensurePair(fractions.length, values.length); - fds.put(property.getName(), new FloatFrameData(fractions, property, values)); - } - - - private void holder(float[] fractions, Property property, Integer[] values) { - ensurePair(fractions.length, values.length); - fds.put(property.getName(), new IntFrameData(fractions, property, values)); - } - - private void ensurePair(int fractionsLength, int valuesLength) { - if (fractionsLength != valuesLength) { - throw new IllegalStateException(String.format( - Locale.getDefault(), - "The fractions.length must equal values.length, " + - "fraction.length[%d], values.length[%d]", - fractionsLength, - valuesLength)); - } - } - - - public SpriteAnimatorBuilder interpolator(Interpolator interpolator) { - this.interpolator = interpolator; - return this; - } - - public SpriteAnimatorBuilder easeInOut(float... fractions) { - interpolator(KeyFrameInterpolator.easeInOut( - fractions - )); - return this; - } - - - public SpriteAnimatorBuilder duration(long duration) { - this.duration = duration; - return this; - } - - @SuppressWarnings("unused") - public SpriteAnimatorBuilder repeatCount(int repeatCount) { - this.repeatCount = repeatCount; - return this; - } - - public SpriteAnimatorBuilder startFrame(int startFrame) { - if (startFrame < 0) { - Log.w(TAG, "startFrame should always be non-negative"); - startFrame = 0; - } - this.startFrame = startFrame; - return this; - } - - public ObjectAnimator build() { - - PropertyValuesHolder[] holders = new PropertyValuesHolder[fds.size()]; - int i = 0; - for (Map.Entry fd : fds.entrySet()) { - FrameData data = fd.getValue(); - Keyframe[] keyframes = new Keyframe[data.fractions.length]; - float[] fractions = data.fractions; - float startF = fractions[startFrame]; - for (int j = startFrame; j < (startFrame + data.values.length); j++) { - int key = j - startFrame; - int vk = j % data.values.length; - float fraction = fractions[vk] - startF; - if (fraction < 0) { - fraction = fractions[fractions.length - 1] + fraction; - } - if (data instanceof IntFrameData) { - keyframes[key] = Keyframe.ofInt(fraction, (Integer) data.values[vk]); - } else if (data instanceof FloatFrameData) { - keyframes[key] = Keyframe.ofFloat(fraction, (Float) data.values[vk]); - } else { - keyframes[key] = Keyframe.ofObject(fraction, data.values[vk]); - } - } - holders[i] = PropertyValuesHolder.ofKeyframe(data.property, keyframes); - i++; - } - - ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(sprite, - holders); - animator.setDuration(duration); - animator.setRepeatCount(repeatCount); - animator.setInterpolator(interpolator); - return animator; - } - + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/Ease.java b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/Ease.java index 916ca6f..799487b 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/Ease.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/Ease.java @@ -6,7 +6,7 @@ * Created by ybq. */ public class Ease { - public static Interpolator inOut() { - return PathInterpolatorCompat.create(0.42f, 0f, 0.58f, 1f); - } + public static Interpolator inOut() { + return PathInterpolatorCompat.create(0.42f, 0f, 0.58f, 1f); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/KeyFrameInterpolator.java b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/KeyFrameInterpolator.java index 361f9d1..87342ac 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/KeyFrameInterpolator.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/KeyFrameInterpolator.java @@ -8,47 +8,47 @@ */ public class KeyFrameInterpolator implements Interpolator { - private TimeInterpolator interpolator; - private float[] fractions; - - - public static KeyFrameInterpolator easeInOut(float... fractions) { - KeyFrameInterpolator interpolator = new KeyFrameInterpolator(Ease.inOut()); - interpolator.setFractions(fractions); - return interpolator; - } - - public static KeyFrameInterpolator pathInterpolator(float controlX1, float controlY1, - float controlX2, float controlY2, - float... fractions) { - KeyFrameInterpolator interpolator = new KeyFrameInterpolator(PathInterpolatorCompat.create(controlX1, controlY1, controlX2, controlY2)); - interpolator.setFractions(fractions); - return interpolator; - } - - public KeyFrameInterpolator(TimeInterpolator interpolator, float... fractions) { - this.interpolator = interpolator; - this.fractions = fractions; - } - - public void setFractions(float... fractions) { - this.fractions = fractions; - } - - @Override - public synchronized float getInterpolation(float input) { - if (fractions.length > 1) { - for (int i = 0; i < fractions.length - 1; i++) { - float start = fractions[i]; - float end = fractions[i + 1]; - float duration = end - start; - if (input >= start && input <= end) { - input = (input - start) / duration; - return start + (interpolator.getInterpolation(input) - * duration); - } - } + private TimeInterpolator interpolator; + private float[] fractions; + + public KeyFrameInterpolator(TimeInterpolator interpolator, float... fractions) { + this.interpolator = interpolator; + this.fractions = fractions; + } + + public static KeyFrameInterpolator easeInOut(float... fractions) { + KeyFrameInterpolator interpolator = new KeyFrameInterpolator(Ease.inOut()); + interpolator.setFractions(fractions); + return interpolator; + } + + public static KeyFrameInterpolator pathInterpolator(float controlX1, float controlY1, + float controlX2, float controlY2, + float... fractions) { + KeyFrameInterpolator interpolator = + new KeyFrameInterpolator(PathInterpolatorCompat.create(controlX1, controlY1, controlX2, controlY2)); + interpolator.setFractions(fractions); + return interpolator; + } + + public void setFractions(float... fractions) { + this.fractions = fractions; + } + + @Override + public synchronized float getInterpolation(float input) { + if (fractions.length > 1) { + for (int i = 0; i < fractions.length - 1; i++) { + float start = fractions[i]; + float end = fractions[i + 1]; + float duration = end - start; + if (input >= start && input <= end) { + input = (input - start) / duration; + return start + (interpolator.getInterpolation(input) + * duration); } - return interpolator.getInterpolation(input); + } } + return interpolator.getInterpolation(input); + } } \ No newline at end of file diff --git a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompat.java b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompat.java index f1e618d..ad9d606 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompat.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompat.java @@ -27,61 +27,61 @@ */ public class PathInterpolatorCompat { - private PathInterpolatorCompat() { - // prevent instantiation - } + private PathInterpolatorCompat() { + // prevent instantiation + } - /** - * Create an {@link Interpolator} for an arbitrary {@link Path}. The {@link Path} - * must begin at {@code (0, 0)} and end at {@code (1, 1)}. The x-coordinate along the - * {@link Path} is the input value and the output is the y coordinate of the line at that - * point. This means that the Path must conform to a function {@code y = f(x)}. - *

- * The {@link Path} must not have gaps in the x direction and must not - * loop back on itself such that there can be two points sharing the same x coordinate. - * - * @param path the {@link Path} to use to make the line representing the {@link Interpolator} - * @return the {@link Interpolator} representing the {@link Path} - */ - @SuppressWarnings("unused") - public static Interpolator create(Path path) { - if (Build.VERSION.SDK_INT >= 21) { - return PathInterpolatorCompatApi21.create(path); - } - return PathInterpolatorCompatBase.create(path); + /** + * Create an {@link Interpolator} for an arbitrary {@link Path}. The {@link Path} + * must begin at {@code (0, 0)} and end at {@code (1, 1)}. The x-coordinate along the + * {@link Path} is the input value and the output is the y coordinate of the line at that + * point. This means that the Path must conform to a function {@code y = f(x)}. + *

+ * The {@link Path} must not have gaps in the x direction and must not + * loop back on itself such that there can be two points sharing the same x coordinate. + * + * @param path the {@link Path} to use to make the line representing the {@link Interpolator} + * @return the {@link Interpolator} representing the {@link Path} + */ + @SuppressWarnings("unused") + public static Interpolator create(Path path) { + if (Build.VERSION.SDK_INT >= 21) { + return PathInterpolatorCompatApi21.create(path); } + return PathInterpolatorCompatBase.create(path); + } - /** - * Create an {@link Interpolator} for a quadratic Bezier curve. The end points - * {@code (0, 0)} and {@code (1, 1)} are assumed. - * - * @param controlX the x coordinate of the quadratic Bezier control point - * @param controlY the y coordinate of the quadratic Bezier control point - * @return the {@link Interpolator} representing the quadratic Bezier curve - */ - @SuppressWarnings("unused") - public static Interpolator create(float controlX, float controlY) { - if (Build.VERSION.SDK_INT >= 21) { - return PathInterpolatorCompatApi21.create(controlX, controlY); - } - return PathInterpolatorCompatBase.create(controlX, controlY); + /** + * Create an {@link Interpolator} for a quadratic Bezier curve. The end points + * {@code (0, 0)} and {@code (1, 1)} are assumed. + * + * @param controlX the x coordinate of the quadratic Bezier control point + * @param controlY the y coordinate of the quadratic Bezier control point + * @return the {@link Interpolator} representing the quadratic Bezier curve + */ + @SuppressWarnings("unused") + public static Interpolator create(float controlX, float controlY) { + if (Build.VERSION.SDK_INT >= 21) { + return PathInterpolatorCompatApi21.create(controlX, controlY); } + return PathInterpolatorCompatBase.create(controlX, controlY); + } - /** - * Create an {@link Interpolator} for a cubic Bezier curve. The end points - * {@code (0, 0)} and {@code (1, 1)} are assumed. - * - * @param controlX1 the x coordinate of the first control point of the cubic Bezier - * @param controlY1 the y coordinate of the first control point of the cubic Bezier - * @param controlX2 the x coordinate of the second control point of the cubic Bezier - * @param controlY2 the y coordinate of the second control point of the cubic Bezier - * @return the {@link Interpolator} representing the cubic Bezier curve - */ - public static Interpolator create(float controlX1, float controlY1, - float controlX2, float controlY2) { - if (Build.VERSION.SDK_INT >= 21) { - return PathInterpolatorCompatApi21.create(controlX1, controlY1, controlX2, controlY2); - } - return PathInterpolatorCompatBase.create(controlX1, controlY1, controlX2, controlY2); + /** + * Create an {@link Interpolator} for a cubic Bezier curve. The end points + * {@code (0, 0)} and {@code (1, 1)} are assumed. + * + * @param controlX1 the x coordinate of the first control point of the cubic Bezier + * @param controlY1 the y coordinate of the first control point of the cubic Bezier + * @param controlX2 the x coordinate of the second control point of the cubic Bezier + * @param controlY2 the y coordinate of the second control point of the cubic Bezier + * @return the {@link Interpolator} representing the cubic Bezier curve + */ + public static Interpolator create(float controlX1, float controlY1, + float controlX2, float controlY2) { + if (Build.VERSION.SDK_INT >= 21) { + return PathInterpolatorCompatApi21.create(controlX1, controlY1, controlX2, controlY2); } + return PathInterpolatorCompatBase.create(controlX1, controlY1, controlX2, controlY2); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompatApi21.java b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompatApi21.java index 01e488a..4018558 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompatApi21.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompatApi21.java @@ -27,23 +27,23 @@ */ class PathInterpolatorCompatApi21 { - private PathInterpolatorCompatApi21() { - // prevent instantiation - } + private PathInterpolatorCompatApi21() { + // prevent instantiation + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public static Interpolator create(Path path) { - return new PathInterpolator(path); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static Interpolator create(Path path) { + return new PathInterpolator(path); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public static Interpolator create(float controlX, float controlY) { - return new PathInterpolator(controlX, controlY); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static Interpolator create(float controlX, float controlY) { + return new PathInterpolator(controlX, controlY); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public static Interpolator create(float controlX1, float controlY1, - float controlX2, float controlY2) { - return new PathInterpolator(controlX1, controlY1, controlX2, controlY2); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static Interpolator create(float controlX1, float controlY1, + float controlX2, float controlY2) { + return new PathInterpolator(controlX1, controlY1, controlX2, controlY2); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompatBase.java b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompatBase.java index 093ff70..a91a8aa 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompatBase.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorCompatBase.java @@ -24,20 +24,20 @@ */ class PathInterpolatorCompatBase { - private PathInterpolatorCompatBase() { - // prevent instantiation - } + private PathInterpolatorCompatBase() { + // prevent instantiation + } - public static Interpolator create(Path path) { - return new PathInterpolatorDonut(path); - } + public static Interpolator create(Path path) { + return new PathInterpolatorDonut(path); + } - public static Interpolator create(float controlX, float controlY) { - return new PathInterpolatorDonut(controlX, controlY); - } + public static Interpolator create(float controlX, float controlY) { + return new PathInterpolatorDonut(controlX, controlY); + } - public static Interpolator create(float controlX1, float controlY1, - float controlX2, float controlY2) { - return new PathInterpolatorDonut(controlX1, controlY1, controlX2, controlY2); - } + public static Interpolator create(float controlX1, float controlY1, + float controlX2, float controlY2) { + return new PathInterpolatorDonut(controlX1, controlY1, controlX2, controlY2); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorDonut.java b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorDonut.java index 01358df..815ca9c 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorDonut.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/animation/interpolator/PathInterpolatorDonut.java @@ -24,88 +24,88 @@ */ class PathInterpolatorDonut implements Interpolator { - /** - * Governs the accuracy of the approximation of the {@link Path}. - */ - private static final float PRECISION = 0.002f; + /** + * Governs the accuracy of the approximation of the {@link Path}. + */ + private static final float PRECISION = 0.002f; - private final float[] mX; - private final float[] mY; + private final float[] mX; + private final float[] mY; - public PathInterpolatorDonut(Path path) { - final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */); + public PathInterpolatorDonut(Path path) { + final PathMeasure pathMeasure = new PathMeasure(path, false /* forceClosed */); - final float pathLength = pathMeasure.getLength(); - final int numPoints = (int) (pathLength / PRECISION) + 1; + final float pathLength = pathMeasure.getLength(); + final int numPoints = (int) (pathLength / PRECISION) + 1; - mX = new float[numPoints]; - mY = new float[numPoints]; + mX = new float[numPoints]; + mY = new float[numPoints]; - final float[] position = new float[2]; - for (int i = 0; i < numPoints; ++i) { - final float distance = (i * pathLength) / (numPoints - 1); - pathMeasure.getPosTan(distance, position, null /* tangent */); + final float[] position = new float[2]; + for (int i = 0; i < numPoints; ++i) { + final float distance = (i * pathLength) / (numPoints - 1); + pathMeasure.getPosTan(distance, position, null /* tangent */); - mX[i] = position[0]; - mY[i] = position[1]; - } + mX[i] = position[0]; + mY[i] = position[1]; } - - public PathInterpolatorDonut(float controlX, float controlY) { - this(createQuad(controlX, controlY)); + } + + public PathInterpolatorDonut(float controlX, float controlY) { + this(createQuad(controlX, controlY)); + } + + public PathInterpolatorDonut(float controlX1, float controlY1, + float controlX2, float controlY2) { + this(createCubic(controlX1, controlY1, controlX2, controlY2)); + } + + private static Path createQuad(float controlX, float controlY) { + final Path path = new Path(); + path.moveTo(0.0f, 0.0f); + path.quadTo(controlX, controlY, 1.0f, 1.0f); + return path; + } + + private static Path createCubic(float controlX1, float controlY1, + float controlX2, float controlY2) { + final Path path = new Path(); + path.moveTo(0.0f, 0.0f); + path.cubicTo(controlX1, controlY1, controlX2, controlY2, 1.0f, 1.0f); + return path; + } + + @Override + public float getInterpolation(float t) { + if (t <= 0.0f) { + return 0.0f; + } else if (t >= 1.0f) { + return 1.0f; } - public PathInterpolatorDonut(float controlX1, float controlY1, - float controlX2, float controlY2) { - this(createCubic(controlX1, controlY1, controlX2, controlY2)); + // Do a binary search for the correct x to interpolate between. + int startIndex = 0; + int endIndex = mX.length - 1; + while (endIndex - startIndex > 1) { + int midIndex = (startIndex + endIndex) / 2; + if (t < mX[midIndex]) { + endIndex = midIndex; + } else { + startIndex = midIndex; + } } - @Override - public float getInterpolation(float t) { - if (t <= 0.0f) { - return 0.0f; - } else if (t >= 1.0f) { - return 1.0f; - } - - // Do a binary search for the correct x to interpolate between. - int startIndex = 0; - int endIndex = mX.length - 1; - while (endIndex - startIndex > 1) { - int midIndex = (startIndex + endIndex) / 2; - if (t < mX[midIndex]) { - endIndex = midIndex; - } else { - startIndex = midIndex; - } - } - - final float xRange = mX[endIndex] - mX[startIndex]; - if (xRange == 0) { - return mY[startIndex]; - } - - final float tInRange = t - mX[startIndex]; - final float fraction = tInRange / xRange; - - final float startY = mY[startIndex]; - final float endY = mY[endIndex]; - - return startY + (fraction * (endY - startY)); + final float xRange = mX[endIndex] - mX[startIndex]; + if (xRange == 0) { + return mY[startIndex]; } - private static Path createQuad(float controlX, float controlY) { - final Path path = new Path(); - path.moveTo(0.0f, 0.0f); - path.quadTo(controlX, controlY, 1.0f, 1.0f); - return path; - } + final float tInRange = t - mX[startIndex]; + final float fraction = tInRange / xRange; - private static Path createCubic(float controlX1, float controlY1, - float controlX2, float controlY2) { - final Path path = new Path(); - path.moveTo(0.0f, 0.0f); - path.cubicTo(controlX1, controlY1, controlX2, controlY2, 1.0f, 1.0f); - return path; - } + final float startY = mY[startIndex]; + final float endY = mY[endIndex]; + + return startY + (fraction * (endY - startY)); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/sprite/CircleLayoutContainer.java b/library/src/main/java/com/github/ybq/android/spinkit/sprite/CircleLayoutContainer.java index 7d89612..0ca09f5 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/sprite/CircleLayoutContainer.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/sprite/CircleLayoutContainer.java @@ -8,29 +8,29 @@ */ public abstract class CircleLayoutContainer extends SpriteContainer { - @Override - public void drawChild(Canvas canvas) { - for (int i = 0; i < getChildCount(); i++) { - Sprite sprite = getChildAt(i); - int count = canvas.save(); - canvas.rotate(i * 360 / getChildCount(), - getBounds().centerX(), - getBounds().centerY()); - sprite.draw(canvas); - canvas.restoreToCount(count); - } + @Override + public void drawChild(Canvas canvas) { + for (int i = 0; i < getChildCount(); i++) { + Sprite sprite = getChildAt(i); + int count = canvas.save(); + canvas.rotate(i * 360 / getChildCount(), + getBounds().centerX(), + getBounds().centerY()); + sprite.draw(canvas); + canvas.restoreToCount(count); } + } - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - bounds = clipSquare(bounds); - int radius = (int) (bounds.width() * Math.PI / 3.6f / getChildCount()); - int left = bounds.centerX() - radius; - int right = bounds.centerX() + radius; - for (int i = 0; i < getChildCount(); i++) { - Sprite sprite = getChildAt(i); - sprite.setDrawBounds(left, bounds.top, right, bounds.top + radius * 2); - } + @Override + protected void onBoundsChange(Rect bounds) { + super.onBoundsChange(bounds); + bounds = clipSquare(bounds); + int radius = (int) (bounds.width() * Math.PI / 3.6f / getChildCount()); + int left = bounds.centerX() - radius; + int right = bounds.centerX() + radius; + for (int i = 0; i < getChildCount(); i++) { + Sprite sprite = getChildAt(i); + sprite.setDrawBounds(left, bounds.top, right, bounds.top + radius * 2); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/sprite/CircleSprite.java b/library/src/main/java/com/github/ybq/android/spinkit/sprite/CircleSprite.java index 3cb6219..f51cd2c 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/sprite/CircleSprite.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/sprite/CircleSprite.java @@ -9,18 +9,16 @@ */ public class CircleSprite extends ShapeSprite { - @Override - public ValueAnimator onCreateAnimation() { - return null; - } + @Override + public ValueAnimator onCreateAnimation() { + return null; + } - @Override - public void drawShape(Canvas canvas, Paint paint) { - if (getDrawBounds() != null) { - int radius = Math.min(getDrawBounds().width(), getDrawBounds().height()) / 2; - canvas.drawCircle(getDrawBounds().centerX(), - getDrawBounds().centerY(), - radius, paint); - } + @Override + public void drawShape(Canvas canvas, Paint paint) { + if (getDrawBounds() != null) { + int radius = Math.min(getDrawBounds().width(), getDrawBounds().height()) / 2; + canvas.drawCircle(getDrawBounds().centerX(), getDrawBounds().centerY(), radius, paint); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/sprite/RectSprite.java b/library/src/main/java/com/github/ybq/android/spinkit/sprite/RectSprite.java index a19f31c..0c9bc83 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/sprite/RectSprite.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/sprite/RectSprite.java @@ -8,15 +8,15 @@ * Created by ybq. */ public class RectSprite extends ShapeSprite { - @Override - public ValueAnimator onCreateAnimation() { - return null; - } + @Override + public ValueAnimator onCreateAnimation() { + return null; + } - @Override - public void drawShape(Canvas canvas, Paint paint) { - if (getDrawBounds() != null) { - canvas.drawRect(getDrawBounds(), paint); - } + @Override + public void drawShape(Canvas canvas, Paint paint) { + if (getDrawBounds() != null) { + canvas.drawRect(getDrawBounds(), paint); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/sprite/RingSprite.java b/library/src/main/java/com/github/ybq/android/spinkit/sprite/RingSprite.java index 70f5f0f..fb8935b 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/sprite/RingSprite.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/sprite/RingSprite.java @@ -9,21 +9,18 @@ */ public class RingSprite extends ShapeSprite { - - @Override - public void drawShape(Canvas canvas, Paint paint) { - if (getDrawBounds() != null) { - paint.setStyle(Paint.Style.STROKE); - int radius = Math.min(getDrawBounds().width(), getDrawBounds().height()) / 2; - paint.setStrokeWidth(radius / 12); - canvas.drawCircle(getDrawBounds().centerX(), - getDrawBounds().centerY(), - radius, paint); - } + @Override + public void drawShape(Canvas canvas, Paint paint) { + if (getDrawBounds() != null) { + paint.setStyle(Paint.Style.STROKE); + int radius = Math.min(getDrawBounds().width(), getDrawBounds().height()) / 2; + paint.setStrokeWidth(radius / 12); + canvas.drawCircle(getDrawBounds().centerX(), getDrawBounds().centerY(), radius, paint); } + } - @Override - public ValueAnimator onCreateAnimation() { - return null; - } + @Override + public ValueAnimator onCreateAnimation() { + return null; + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/sprite/ShapeSprite.java b/library/src/main/java/com/github/ybq/android/spinkit/sprite/ShapeSprite.java index 0251426..a48647c 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/sprite/ShapeSprite.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/sprite/ShapeSprite.java @@ -10,57 +10,57 @@ */ public abstract class ShapeSprite extends Sprite { - private Paint mPaint; - private int mUseColor; - private int mBaseColor; + private Paint mPaint; + private int mUseColor; + private int mBaseColor; - public ShapeSprite() { - setColor(Color.WHITE); - mPaint = new Paint(); - mPaint.setAntiAlias(true); - mPaint.setColor(mUseColor); - } + public ShapeSprite() { + setColor(Color.WHITE); + mPaint = new Paint(); + mPaint.setAntiAlias(true); + mPaint.setColor(mUseColor); + } - @Override - public void setColor(int color) { - mBaseColor = color; - updateUseColor(); - } + @Override + public int getColor() { + return mBaseColor; + } - @Override - public int getColor() { - return mBaseColor; - } + @Override + public void setColor(int color) { + mBaseColor = color; + updateUseColor(); + } - @SuppressWarnings("unused") - public int getUseColor() { - return mUseColor; - } + @SuppressWarnings("unused") + public int getUseColor() { + return mUseColor; + } - @Override - public void setAlpha(int alpha) { - super.setAlpha(alpha); - updateUseColor(); - } + @Override + public void setAlpha(int alpha) { + super.setAlpha(alpha); + updateUseColor(); + } - private void updateUseColor() { - int alpha = getAlpha(); - alpha += alpha >> 7; - final int baseAlpha = mBaseColor >>> 24; - final int useAlpha = baseAlpha * alpha >> 8; - mUseColor = (mBaseColor << 8 >>> 8) | (useAlpha << 24); - } + private void updateUseColor() { + int alpha = getAlpha(); + alpha += alpha >> 7; + final int baseAlpha = mBaseColor >>> 24; + final int useAlpha = baseAlpha * alpha >> 8; + mUseColor = (mBaseColor << 8 >>> 8) | (useAlpha << 24); + } - @Override - public void setColorFilter(ColorFilter colorFilter) { - mPaint.setColorFilter(colorFilter); - } + @Override + public void setColorFilter(ColorFilter colorFilter) { + mPaint.setColorFilter(colorFilter); + } - @Override - protected final void drawSelf(Canvas canvas) { - mPaint.setColor(mUseColor); - drawShape(canvas, mPaint); - } + @Override + protected final void drawSelf(Canvas canvas) { + mPaint.setColor(mUseColor); + drawShape(canvas, mPaint); + } - public abstract void drawShape(Canvas canvas, Paint paint); + public abstract void drawShape(Canvas canvas, Paint paint); } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/sprite/Sprite.java b/library/src/main/java/com/github/ybq/android/spinkit/sprite/Sprite.java index b7fbf60..4406416 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/sprite/Sprite.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/sprite/Sprite.java @@ -10,7 +10,6 @@ import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; import android.util.Property; - import com.github.ybq.android.spinkit.animation.AnimationUtils; import com.github.ybq.android.spinkit.animation.FloatProperty; import com.github.ybq.android.spinkit.animation.IntProperty; @@ -19,437 +18,428 @@ * Created by ybq. */ @SuppressWarnings("WeakerAccess") -public abstract class Sprite extends Drawable implements - ValueAnimator.AnimatorUpdateListener - , Animatable - , Drawable.Callback { - - private float scale = 1; - private float scaleX = 1; - private float scaleY = 1; - private float pivotX; - private float pivotY; - private int animationDelay; - private int rotateX; - private int rotateY; - private int translateX; - private int translateY; - private int rotate; - private float translateXPercentage; - private float translateYPercentage; - private ValueAnimator animator; - private int alpha = 255; - private static final Rect ZERO_BOUNDS_RECT = new Rect(); - protected Rect drawBounds = ZERO_BOUNDS_RECT; - private Camera mCamera; - private Matrix mMatrix; - - public Sprite() { - mCamera = new Camera(); - mMatrix = new Matrix(); - } - - public abstract int getColor(); - - public abstract void setColor(int color); +public abstract class Sprite extends Drawable implements ValueAnimator.AnimatorUpdateListener, Animatable, Drawable.Callback { + public static final Property ROTATE_X = new IntProperty("rotateX") { @Override - public void setAlpha(int alpha) { - this.alpha = alpha; + public void setValue(Sprite object, int value) { + object.setRotateX(value); } @Override - public int getAlpha() { - return alpha; + public Integer get(Sprite object) { + return object.getRotateX(); } - + }; + public static final Property ROTATE = new IntProperty("rotate") { @Override - public int getOpacity() { - return PixelFormat.RGBA_8888; - } - - public float getTranslateXPercentage() { - return translateXPercentage; - } - - public void setTranslateXPercentage(float translateXPercentage) { - this.translateXPercentage = translateXPercentage; - } - - public float getTranslateYPercentage() { - return translateYPercentage; - } - - public void setTranslateYPercentage(float translateYPercentage) { - this.translateYPercentage = translateYPercentage; - } - - public int getTranslateX() { - return translateX; - } - - public void setTranslateX(int translateX) { - this.translateX = translateX; - } - - public int getTranslateY() { - return translateY; + public void setValue(Sprite object, int value) { + object.setRotate(value); } - public void setTranslateY(int translateY) { - this.translateY = translateY; - } - - public int getRotate() { - return rotate; + @Override + public Integer get(Sprite object) { + return object.getRotate(); } - - public void setRotate(int rotate) { - this.rotate = rotate; + }; + public static final Property ROTATE_Y = new IntProperty("rotateY") { + @Override + public void setValue(Sprite object, int value) { + object.setRotateY(value); } - public float getScale() { - return scale; + @Override + public Integer get(Sprite object) { + return object.getRotateY(); } - - public void setScale(float scale) { - this.scale = scale; - setScaleX(scale); - setScaleY(scale); + }; + @SuppressWarnings("unused") + public static final Property TRANSLATE_X = new IntProperty("translateX") { + @Override + public void setValue(Sprite object, int value) { + object.setTranslateX(value); } - public float getScaleX() { - return scaleX; + @Override + public Integer get(Sprite object) { + return object.getTranslateX(); } - - public void setScaleX(float scaleX) { - this.scaleX = scaleX; + }; + @SuppressWarnings("unused") + public static final Property TRANSLATE_Y = new IntProperty("translateY") { + @Override + public void setValue(Sprite object, int value) { + object.setTranslateY(value); } - public float getScaleY() { - return scaleY; + @Override + public Integer get(Sprite object) { + return object.getTranslateY(); } - - public void setScaleY(float scaleY) { - this.scaleY = scaleY; + }; + public static final Property TRANSLATE_X_PERCENTAGE = new FloatProperty("translateXPercentage") { + @Override + public void setValue(Sprite object, float value) { + object.setTranslateXPercentage(value); } - public int getRotateX() { - return rotateX; + @Override + public Float get(Sprite object) { + return object.getTranslateXPercentage(); } - - public void setRotateX(int rotateX) { - this.rotateX = rotateX; + }; + public static final Property TRANSLATE_Y_PERCENTAGE = new FloatProperty("translateYPercentage") { + @Override + public void setValue(Sprite object, float value) { + object.setTranslateYPercentage(value); } - public int getRotateY() { - return rotateY; + @Override + public Float get(Sprite object) { + return object.getTranslateYPercentage(); } - - public void setRotateY(int rotateY) { - this.rotateY = rotateY; + }; + @SuppressWarnings("unused") + public static final Property SCALE_X = new FloatProperty("scaleX") { + @Override + public void setValue(Sprite object, float value) { + object.setScaleX(value); } - public float getPivotX() { - return pivotX; + @Override + public Float get(Sprite object) { + return object.getScaleX(); } - - public void setPivotX(float pivotX) { - this.pivotX = pivotX; + }; + public static final Property SCALE_Y = new FloatProperty("scaleY") { + @Override + public void setValue(Sprite object, float value) { + object.setScaleY(value); } - public float getPivotY() { - return pivotY; + @Override + public Float get(Sprite object) { + return object.getScaleY(); } - - public void setPivotY(float pivotY) { - this.pivotY = pivotY; + }; + public static final Property SCALE = new FloatProperty("scale") { + @Override + public void setValue(Sprite object, float value) { + object.setScale(value); } - @SuppressWarnings("unused") - public int getAnimationDelay() { - return animationDelay; + @Override + public Float get(Sprite object) { + return object.getScale(); } - - public Sprite setAnimationDelay(int animationDelay) { - this.animationDelay = animationDelay; - return this; + }; + public static final Property ALPHA = new IntProperty("alpha") { + @Override + public void setValue(Sprite object, int value) { + object.setAlpha(value); } @Override - public void setColorFilter(ColorFilter colorFilter) { + public Integer get(Sprite object) { + return object.getAlpha(); + } + }; + private static final Rect ZERO_BOUNDS_RECT = new Rect(); + protected Rect drawBounds = ZERO_BOUNDS_RECT; + private float scale = 1; + private float scaleX = 1; + private float scaleY = 1; + private float pivotX; + private float pivotY; + private int animationDelay; + private int rotateX; + private int rotateY; + private int translateX; + private int translateY; + private int rotate; + private float translateXPercentage; + private float translateYPercentage; + private ValueAnimator animator; + private int alpha = 255; + private Camera mCamera; + private Matrix mMatrix; + + public Sprite() { + mCamera = new Camera(); + mMatrix = new Matrix(); + } + + public abstract int getColor(); + + public abstract void setColor(int color); + + @Override + public int getAlpha() { + return alpha; + } + + @Override + public void setAlpha(int alpha) { + this.alpha = alpha; + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } + + public float getTranslateXPercentage() { + return translateXPercentage; + } + + public void setTranslateXPercentage(float translateXPercentage) { + this.translateXPercentage = translateXPercentage; + } + + public float getTranslateYPercentage() { + return translateYPercentage; + } + + public void setTranslateYPercentage(float translateYPercentage) { + this.translateYPercentage = translateYPercentage; + } + + public int getTranslateX() { + return translateX; + } + + public void setTranslateX(int translateX) { + this.translateX = translateX; + } + + public int getTranslateY() { + return translateY; + } + + public void setTranslateY(int translateY) { + this.translateY = translateY; + } + + public int getRotate() { + return rotate; + } + + public void setRotate(int rotate) { + this.rotate = rotate; + } + + public float getScale() { + return scale; + } + + public void setScale(float scale) { + this.scale = scale; + setScaleX(scale); + setScaleY(scale); + } + + public float getScaleX() { + return scaleX; + } + + public void setScaleX(float scaleX) { + this.scaleX = scaleX; + } - } + public float getScaleY() { + return scaleY; + } - public abstract ValueAnimator onCreateAnimation(); + public void setScaleY(float scaleY) { + this.scaleY = scaleY; + } - @Override - public void start() { - if (AnimationUtils.isStarted(animator)) { - return; - } - - animator = obtainAnimation(); - if (animator == null) { - return; - } - - AnimationUtils.start(animator); - invalidateSelf(); - } + public int getRotateX() { + return rotateX; + } - public ValueAnimator obtainAnimation() { - if (animator == null) { - animator = onCreateAnimation(); - } - if (animator != null) { - animator.addUpdateListener(this); - animator.setStartDelay(animationDelay); - } - return animator; - } - - @Override - public void stop() { - if (AnimationUtils.isStarted(animator)) { - animator.removeAllUpdateListeners(); - animator.end(); - reset(); - } - } + public void setRotateX(int rotateX) { + this.rotateX = rotateX; + } - protected abstract void drawSelf(Canvas canvas); - - public void reset() { - scale = 1; - rotateX = 0; - rotateY = 0; - translateX = 0; - translateY = 0; - rotate = 0; - translateXPercentage = 0f; - translateYPercentage = 0f; - } + public int getRotateY() { + return rotateY; + } - @Override - public boolean isRunning() { - return AnimationUtils.isRunning(animator); - } + public void setRotateY(int rotateY) { + this.rotateY = rotateY; + } - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - setDrawBounds(bounds); - } + public float getPivotX() { + return pivotX; + } - public void setDrawBounds(Rect drawBounds) { - setDrawBounds(drawBounds.left, drawBounds.top, drawBounds.right, drawBounds.bottom); - } + public void setPivotX(float pivotX) { + this.pivotX = pivotX; + } - public void setDrawBounds(int left, int top, int right, int bottom) { - this.drawBounds = new Rect(left, top, right, bottom); - setPivotX(getDrawBounds().centerX()); - setPivotY(getDrawBounds().centerY()); - } + public float getPivotY() { + return pivotY; + } - @Override - public void invalidateDrawable(Drawable who) { - invalidateSelf(); - } + public void setPivotY(float pivotY) { + this.pivotY = pivotY; + } - @Override - public void scheduleDrawable(Drawable who, Runnable what, long when) { + @SuppressWarnings("unused") + public int getAnimationDelay() { + return animationDelay; + } - } + public Sprite setAnimationDelay(int animationDelay) { + this.animationDelay = animationDelay; + return this; + } - @Override - public void unscheduleDrawable(Drawable who, Runnable what) { + @Override + public void setColorFilter(ColorFilter colorFilter) { - } + } - @Override - public void onAnimationUpdate(ValueAnimator animation) { - final Callback callback = getCallback(); - if (callback != null) { - callback.invalidateDrawable(this); - } - } + public abstract ValueAnimator onCreateAnimation(); - public Rect getDrawBounds() { - return drawBounds; + @Override + public void start() { + if (AnimationUtils.isStarted(animator)) { + return; } - @Override - public void draw(Canvas canvas) { - int tx = getTranslateX(); - tx = tx == 0 ? (int) (getBounds().width() * getTranslateXPercentage()) : tx; - int ty = getTranslateY(); - ty = ty == 0 ? (int) (getBounds().height() * getTranslateYPercentage()) : ty; - canvas.translate(tx, ty); - canvas.scale(getScaleX(), getScaleY(), getPivotX(), getPivotY()); - canvas.rotate(getRotate(), getPivotX(), getPivotY()); - - if (getRotateX() != 0 || getRotateY() != 0) { - mCamera.save(); - mCamera.rotateX(getRotateX()); - mCamera.rotateY(getRotateY()); - mCamera.getMatrix(mMatrix); - mMatrix.preTranslate(-getPivotX(), -getPivotY()); - mMatrix.postTranslate(getPivotX(), getPivotY()); - mCamera.restore(); - canvas.concat(mMatrix); - } - drawSelf(canvas); + animator = obtainAnimation(); + if (animator == null) { + return; } - public Rect clipSquare(Rect rect) { - int w = rect.width(); - int h = rect.height(); - int min = Math.min(w, h); - int cx = rect.centerX(); - int cy = rect.centerY(); - int r = min / 2; - return new Rect( - cx - r, - cy - r, - cx + r, - cy + r - ); - } + onPreStart(); - public static final Property ROTATE_X = new IntProperty("rotateX") { - @Override - public void setValue(Sprite object, int value) { - object.setRotateX(value); - } - - @Override - public Integer get(Sprite object) { - return object.getRotateX(); - } - }; - - public static final Property ROTATE = new IntProperty("rotate") { - @Override - public void setValue(Sprite object, int value) { - object.setRotate(value); - } - - @Override - public Integer get(Sprite object) { - return object.getRotate(); - } - }; - - public static final Property ROTATE_Y = new IntProperty("rotateY") { - @Override - public void setValue(Sprite object, int value) { - object.setRotateY(value); - } - - @Override - public Integer get(Sprite object) { - return object.getRotateY(); - } - }; - - @SuppressWarnings("unused") - public static final Property TRANSLATE_X = new IntProperty("translateX") { - @Override - public void setValue(Sprite object, int value) { - object.setTranslateX(value); - } - - @Override - public Integer get(Sprite object) { - return object.getTranslateX(); - } - }; - - @SuppressWarnings("unused") - public static final Property TRANSLATE_Y = new IntProperty("translateY") { - @Override - public void setValue(Sprite object, int value) { - object.setTranslateY(value); - } - - @Override - public Integer get(Sprite object) { - return object.getTranslateY(); - } - }; - - public static final Property TRANSLATE_X_PERCENTAGE = new FloatProperty("translateXPercentage") { - @Override - public void setValue(Sprite object, float value) { - object.setTranslateXPercentage(value); - } - - @Override - public Float get(Sprite object) { - return object.getTranslateXPercentage(); - } - }; - - public static final Property TRANSLATE_Y_PERCENTAGE = new FloatProperty("translateYPercentage") { - @Override - public void setValue(Sprite object, float value) { - object.setTranslateYPercentage(value); - } - - @Override - public Float get(Sprite object) { - return object.getTranslateYPercentage(); - } - }; - - @SuppressWarnings("unused") - public static final Property SCALE_X = new FloatProperty("scaleX") { - @Override - public void setValue(Sprite object, float value) { - object.setScaleX(value); - } - - @Override - public Float get(Sprite object) { - return object.getScaleX(); - } - }; - - public static final Property SCALE_Y = new FloatProperty("scaleY") { - @Override - public void setValue(Sprite object, float value) { - object.setScaleY(value); - } - - @Override - public Float get(Sprite object) { - return object.getScaleY(); - } - }; - - public static final Property SCALE = new FloatProperty("scale") { - @Override - public void setValue(Sprite object, float value) { - object.setScale(value); - } - - @Override - public Float get(Sprite object) { - return object.getScale(); - } - }; - - public static final Property ALPHA = new IntProperty("alpha") { - @Override - public void setValue(Sprite object, int value) { - object.setAlpha(value); - } - - @Override - public Integer get(Sprite object) { - return object.getAlpha(); - } - }; + AnimationUtils.start(animator); + invalidateSelf(); + } + public void onPreStart() { + + } + + public ValueAnimator obtainAnimation() { + if (animator == null) { + animator = onCreateAnimation(); + } + if (animator != null) { + animator.addUpdateListener(this); + animator.setStartDelay(animationDelay); + } + return animator; + } + + @Override + public void stop() { + if (AnimationUtils.isStarted(animator)) { + animator.removeAllUpdateListeners(); + animator.end(); + reset(); + } + } + + protected abstract void drawSelf(Canvas canvas); + + public void reset() { + scale = 1; + rotateX = 0; + rotateY = 0; + translateX = 0; + translateY = 0; + rotate = 0; + translateXPercentage = 0f; + translateYPercentage = 0f; + } + + @Override + public boolean isRunning() { + return AnimationUtils.isRunning(animator); + } + + @Override + protected void onBoundsChange(Rect bounds) { + super.onBoundsChange(bounds); + setDrawBounds(bounds); + } + + public void setDrawBounds(int left, int top, int right, int bottom) { + drawBounds = new Rect(left, top, right, bottom); + setPivotX(getDrawBounds().centerX()); + setPivotY(getDrawBounds().centerY()); + } + + @Override + public void invalidateDrawable(Drawable who) { + invalidateSelf(); + } + + @Override + public void scheduleDrawable(Drawable who, Runnable what, long when) { + + } + + @Override + public void unscheduleDrawable(Drawable who, Runnable what) { + + } + + @Override + public void onAnimationUpdate(ValueAnimator animation) { + final Callback callback = getCallback(); + if (callback != null) { + callback.invalidateDrawable(this); + } + } + + public Rect getDrawBounds() { + return drawBounds; + } + + public void setDrawBounds(Rect drawBounds) { + setDrawBounds(drawBounds.left, drawBounds.top, drawBounds.right, drawBounds.bottom); + } + + @Override + public void draw(Canvas canvas) { + int tx = getTranslateX(); + tx = tx == 0 ? (int) (getBounds().width() * getTranslateXPercentage()) : tx; + int ty = getTranslateY(); + ty = ty == 0 ? (int) (getBounds().height() * getTranslateYPercentage()) : ty; + canvas.translate(tx, ty); + canvas.scale(getScaleX(), getScaleY(), getPivotX(), getPivotY()); + canvas.rotate(getRotate(), getPivotX(), getPivotY()); + + if (getRotateX() != 0 || getRotateY() != 0) { + mCamera.save(); + mCamera.rotateX(getRotateX()); + mCamera.rotateY(getRotateY()); + mCamera.getMatrix(mMatrix); + mMatrix.preTranslate(-getPivotX(), -getPivotY()); + mMatrix.postTranslate(getPivotX(), getPivotY()); + mCamera.restore(); + canvas.concat(mMatrix); + } + drawSelf(canvas); + } + + public Rect clipSquare(Rect rect) { + int w = rect.width(); + int h = rect.height(); + int min = Math.min(w, h); + int cx = rect.centerX(); + int cy = rect.centerY(); + int r = min / 2; + return new Rect( + cx - r, + cy - r, + cx + r, + cy + r + ); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/sprite/SpriteContainer.java b/library/src/main/java/com/github/ybq/android/spinkit/sprite/SpriteContainer.java index 7c98da5..8b786cc 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/sprite/SpriteContainer.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/sprite/SpriteContainer.java @@ -3,7 +3,6 @@ import android.animation.ValueAnimator; import android.graphics.Canvas; import android.graphics.Rect; - import com.github.ybq.android.spinkit.animation.AnimationUtils; /** @@ -12,98 +11,98 @@ @SuppressWarnings("WeakerAccess") public abstract class SpriteContainer extends Sprite { - private Sprite[] sprites; - - private int color; + private Sprite[] sprites; - public SpriteContainer() { - sprites = onCreateChild(); - initCallBack(); - onChildCreated(sprites); - } - - private void initCallBack() { - if (sprites != null) { - for (Sprite sprite : sprites) { - sprite.setCallback(this); - } - } - } + private int color; - public void onChildCreated(Sprite... sprites) { + public SpriteContainer() { + sprites = onCreateChild(); + initCallBack(); + onChildCreated(sprites); + } + private void initCallBack() { + if (sprites != null) { + for (Sprite sprite : sprites) { + sprite.setCallback(this); + } } + } - public int getChildCount() { - return sprites == null ? 0 : sprites.length; - } + public void onChildCreated(Sprite... sprites) { - public Sprite getChildAt(int index) { - return sprites == null ? null : sprites[index]; - } + } - @Override - public void setColor(int color) { - this.color = color; - for (int i = 0; i < getChildCount(); i++) { - getChildAt(i).setColor(color); - } - } + public int getChildCount() { + return sprites == null ? 0 : sprites.length; + } - @Override - public int getColor() { - return color; - } + public Sprite getChildAt(int index) { + return sprites == null ? null : sprites[index]; + } - @Override - public void draw(Canvas canvas) { - super.draw(canvas); - drawChild(canvas); - } + @Override + public int getColor() { + return color; + } - public void drawChild(Canvas canvas) { - if (sprites != null) { - for (Sprite sprite : sprites) { - int count = canvas.save(); - sprite.draw(canvas); - canvas.restoreToCount(count); - } - } + @Override + public void setColor(int color) { + this.color = color; + for (int i = 0; i < getChildCount(); i++) { + getChildAt(i).setColor(color); } - - @Override - protected void drawSelf(Canvas canvas) { - } - - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - for (Sprite sprite : sprites) { - sprite.setBounds(bounds); - } - } - - @Override - public void start() { - super.start(); - AnimationUtils.start(sprites); - } - - @Override - public void stop() { - super.stop(); - AnimationUtils.stop(sprites); - } - - @Override - public boolean isRunning() { - return AnimationUtils.isRunning(sprites) || super.isRunning(); + } + + @Override + public void draw(Canvas canvas) { + super.draw(canvas); + drawChild(canvas); + } + + public void drawChild(Canvas canvas) { + if (sprites != null) { + for (Sprite sprite : sprites) { + int count = canvas.save(); + sprite.draw(canvas); + canvas.restoreToCount(count); + } } + } - public abstract Sprite[] onCreateChild(); + @Override + protected void drawSelf(Canvas canvas) { + } - @Override - public ValueAnimator onCreateAnimation() { - return null; + @Override + protected void onBoundsChange(Rect bounds) { + super.onBoundsChange(bounds); + for (Sprite sprite : sprites) { + sprite.setBounds(bounds); } + } + + @Override + public void start() { + super.start(); + AnimationUtils.start(sprites); + } + + @Override + public void stop() { + super.stop(); + AnimationUtils.stop(sprites); + } + + @Override + public boolean isRunning() { + return AnimationUtils.isRunning(sprites) || super.isRunning(); + } + + public abstract Sprite[] onCreateChild(); + + @Override + public ValueAnimator onCreateAnimation() { + return null; + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/ChasingDots.java b/library/src/main/java/com/github/ybq/android/spinkit/style/ChasingDots.java index a69ad64..81694ff 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/ChasingDots.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/ChasingDots.java @@ -4,7 +4,6 @@ import android.graphics.Rect; import android.os.Build; import android.view.animation.LinearInterpolator; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.sprite.CircleSprite; import com.github.ybq.android.spinkit.sprite.Sprite; @@ -15,68 +14,67 @@ */ public class ChasingDots extends SpriteContainer { - @Override - public Sprite[] onCreateChild() { - return new Sprite[]{ - new Dot(), - new Dot() - }; - } + @Override + public Sprite[] onCreateChild() { + return new Sprite[] { + new Dot(), + new Dot() + }; + } - @Override - public void onChildCreated(Sprite... sprites) { - super.onChildCreated(sprites); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - sprites[1].setAnimationDelay(1000); - } else { - sprites[1].setAnimationDelay(-1000); - } + @Override + public void onChildCreated(Sprite... sprites) { + super.onChildCreated(sprites); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + sprites[1].setAnimationDelay(1000); + } else { + sprites[1].setAnimationDelay(-1000); } + } - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 1f}; - return new SpriteAnimatorBuilder(this). - rotate(fractions, 0, 360). - duration(2000). - interpolator(new LinearInterpolator()). - build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 1f }; + return new SpriteAnimatorBuilder(this). + rotate(fractions, 0, 360). + duration(2000). + interpolator(new LinearInterpolator()). + build(); + } - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - bounds = clipSquare(bounds); - int drawW = (int) (bounds.width() * 0.6f); - getChildAt(0).setDrawBounds( - bounds.right - drawW, - bounds.top, - bounds.right - , bounds.top + drawW - ); - getChildAt(1).setDrawBounds( - bounds.right - drawW, - bounds.bottom - drawW, - bounds.right, - bounds.bottom - ); - } - - private class Dot extends CircleSprite { + @Override + protected void onBoundsChange(Rect bounds) { + super.onBoundsChange(bounds); + bounds = clipSquare(bounds); + int drawW = (int) (bounds.width() * 0.6f); + getChildAt(0).setDrawBounds( + bounds.right - drawW, + bounds.top, + bounds.right + , bounds.top + drawW + ); + getChildAt(1).setDrawBounds( + bounds.right - drawW, + bounds.bottom - drawW, + bounds.right, + bounds.bottom + ); + } - Dot() { - setScale(0f); - } + private class Dot extends CircleSprite { - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.5f, 1f}; - return new SpriteAnimatorBuilder(this). - scale(fractions, 0f, 1f, 0f). - duration(2000). - easeInOut(fractions) - .build(); - } + Dot() { + setScale(0f); } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.5f, 1f }; + return new SpriteAnimatorBuilder(this) + .scale(fractions, 0f, 1f, 0f) + .duration(2000) + .easeInOut(fractions) + .build(); + } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/Circle.java b/library/src/main/java/com/github/ybq/android/spinkit/style/Circle.java index a37452c..f67f307 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/Circle.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/Circle.java @@ -2,10 +2,9 @@ import android.animation.ValueAnimator; import android.os.Build; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; -import com.github.ybq.android.spinkit.sprite.CircleSprite; import com.github.ybq.android.spinkit.sprite.CircleLayoutContainer; +import com.github.ybq.android.spinkit.sprite.CircleSprite; import com.github.ybq.android.spinkit.sprite.Sprite; /** @@ -13,34 +12,34 @@ */ public class Circle extends CircleLayoutContainer { - @Override - public Sprite[] onCreateChild() { - Dot[] dots = new Dot[12]; - for (int i = 0; i < dots.length; i++) { - dots[i] = new Dot(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - dots[i].setAnimationDelay(1200 / 12 * i); - } else { - dots[i].setAnimationDelay(1200 / 12 * i + -1200); - } - } - return dots; + @Override + public Sprite[] onCreateChild() { + Dot[] dots = new Dot[12]; + for (int i = 0; i < dots.length; i++) { + dots[i] = new Dot(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + dots[i].setAnimationDelay(1200 / 12 * i); + } else { + dots[i].setAnimationDelay(1200 / 12 * i + -1200); + } } + return dots; + } - private class Dot extends CircleSprite { + private class Dot extends CircleSprite { - Dot() { - setScale(0f); - } + Dot() { + setScale(0f); + } - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.5f, 1f}; - return new SpriteAnimatorBuilder(this). - scale(fractions, 0f, 1f, 0f). - duration(1200). - easeInOut(fractions) - .build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.5f, 1f }; + return new SpriteAnimatorBuilder(this) + .scale(fractions, 0f, 1f, 0f) + .duration(1200) + .easeInOut(fractions) + .build(); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/CubeGrid.java b/library/src/main/java/com/github/ybq/android/spinkit/style/CubeGrid.java index 52d67a9..6eb8517 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/CubeGrid.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/CubeGrid.java @@ -2,7 +2,6 @@ import android.animation.ValueAnimator; import android.graphics.Rect; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.sprite.RectSprite; import com.github.ybq.android.spinkit.sprite.Sprite; @@ -13,46 +12,44 @@ */ public class CubeGrid extends SpriteContainer { - @Override - public Sprite[] onCreateChild() { - int delays[] = new int[]{ - 200, 300, 400 - , 100, 200, 300 - , 0, 100, 200 - }; - GridItem[] gridItems = new GridItem[9]; - for (int i = 0; i < gridItems.length; i++) { - gridItems[i] = new GridItem(); - gridItems[i].setAnimationDelay(delays[i]); - } - return gridItems; + @Override + public Sprite[] onCreateChild() { + int delays[] = new int[] { + 200, 300, 400, 100, 200, 300, 0, 100, 200 + }; + GridItem[] gridItems = new GridItem[9]; + for (int i = 0; i < gridItems.length; i++) { + gridItems[i] = new GridItem(); + gridItems[i].setAnimationDelay(delays[i]); } + return gridItems; + } - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - bounds = clipSquare(bounds); - int width = (int) (bounds.width() * 0.33f); - int height = (int) (bounds.height() * 0.33f); - for (int i = 0; i < getChildCount(); i++) { - int x = i % 3; - int y = i / 3; - int l = bounds.left + x * width; - int t = bounds.top + y * height; - Sprite sprite = getChildAt(i); - sprite.setDrawBounds(l, t, l + width, t + height); - } + @Override + protected void onBoundsChange(Rect bounds) { + super.onBoundsChange(bounds); + bounds = clipSquare(bounds); + int width = (int) (bounds.width() * 0.33f); + int height = (int) (bounds.height() * 0.33f); + for (int i = 0; i < getChildCount(); i++) { + int x = i % 3; + int y = i / 3; + int l = bounds.left + x * width; + int t = bounds.top + y * height; + Sprite sprite = getChildAt(i); + sprite.setDrawBounds(l, t, l + width, t + height); } + } - private class GridItem extends RectSprite { - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.35f, 0.7f, 1f}; - return new SpriteAnimatorBuilder(this). - scale(fractions, 1f, 0f, 1f, 1f). - duration(1300). - easeInOut(fractions) - .build(); - } + private class GridItem extends RectSprite { + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.35f, 0.7f, 1f }; + return new SpriteAnimatorBuilder(this) + .scale(fractions, 1f, 0f, 1f, 1f) + .duration(1300) + .easeInOut(fractions) + .build(); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/DoubleBounce.java b/library/src/main/java/com/github/ybq/android/spinkit/style/DoubleBounce.java index d1e154f..b457bbe 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/DoubleBounce.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/DoubleBounce.java @@ -2,7 +2,6 @@ import android.animation.ValueAnimator; import android.os.Build; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.sprite.CircleSprite; import com.github.ybq.android.spinkit.sprite.Sprite; @@ -13,37 +12,37 @@ */ public class DoubleBounce extends SpriteContainer { - @Override - public Sprite[] onCreateChild() { - return new Sprite[]{ - new Bounce(), new Bounce() - }; + @Override + public Sprite[] onCreateChild() { + return new Sprite[] { + new Bounce(), new Bounce() + }; + } + + @Override + public void onChildCreated(Sprite... sprites) { + super.onChildCreated(sprites); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + sprites[1].setAnimationDelay(1000); + } else { + sprites[1].setAnimationDelay(-1000); } + } - @Override - public void onChildCreated(Sprite... sprites) { - super.onChildCreated(sprites); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - sprites[1].setAnimationDelay(1000); - } else { - sprites[1].setAnimationDelay(-1000); - } - } + private class Bounce extends CircleSprite { - private class Bounce extends CircleSprite { - - Bounce() { - setAlpha(153); - setScale(0f); - } + Bounce() { + setAlpha(153); + setScale(0f); + } - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.5f, 1f}; - return new SpriteAnimatorBuilder(this).scale(fractions, 0f, 1f, 0f). - duration(2000). - easeInOut(fractions) - .build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.5f, 1f }; + return new SpriteAnimatorBuilder(this).scale(fractions, 0f, 1f, 0f) + .duration(2000) + .easeInOut(fractions) + .build(); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/FadingCircle.java b/library/src/main/java/com/github/ybq/android/spinkit/style/FadingCircle.java index 1f96ab1..74c905a 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/FadingCircle.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/FadingCircle.java @@ -2,10 +2,9 @@ import android.animation.ValueAnimator; import android.os.Build; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; -import com.github.ybq.android.spinkit.sprite.CircleSprite; import com.github.ybq.android.spinkit.sprite.CircleLayoutContainer; +import com.github.ybq.android.spinkit.sprite.CircleSprite; import com.github.ybq.android.spinkit.sprite.Sprite; /** @@ -13,33 +12,34 @@ */ public class FadingCircle extends CircleLayoutContainer { - @Override - public Sprite[] onCreateChild() { - Dot[] dots = new Dot[12]; - for (int i = 0; i < dots.length; i++) { - dots[i] = new Dot(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - dots[i].setAnimationDelay(1200 / 12 * i); - } else { - dots[i].setAnimationDelay(1200 / 12 * i + -1200); - } - } - return dots; + @Override + public Sprite[] onCreateChild() { + Dot[] dots = new Dot[12]; + for (int i = 0; i < dots.length; i++) { + dots[i] = new Dot(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + dots[i].setAnimationDelay(1200 / 12 * i); + } else { + dots[i].setAnimationDelay(1200 / 12 * i + -1200); + } } + return dots; + } - private class Dot extends CircleSprite { + private class Dot extends CircleSprite { - Dot() { - setAlpha(0); - } + Dot() { + setAlpha(0); + } - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.39f, 0.4f, 1f}; - return new SpriteAnimatorBuilder(this). - alpha(fractions, 0, 0, 255, 0). - duration(1200). - easeInOut(fractions).build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.39f, 0.4f, 1f }; + return new SpriteAnimatorBuilder(this) + .alpha(fractions, 0, 0, 255, 0) + .duration(1200) + .easeInOut(fractions) + .build(); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/FoldingCube.java b/library/src/main/java/com/github/ybq/android/spinkit/style/FoldingCube.java index 8cacc0e..8fe2bd7 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/FoldingCube.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/FoldingCube.java @@ -5,7 +5,6 @@ import android.graphics.Rect; import android.os.Build; import android.view.animation.LinearInterpolator; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.sprite.RectSprite; import com.github.ybq.android.spinkit.sprite.Sprite; @@ -16,89 +15,89 @@ */ public class FoldingCube extends SpriteContainer { - @SuppressWarnings("FieldCanBeLocal") - private boolean wrapContent = false; + @SuppressWarnings("FieldCanBeLocal") + private boolean wrapContent = false; - @Override - public Sprite[] onCreateChild() { - Cube[] cubes - = new Cube[4]; - for (int i = 0; i < cubes.length; i++) { - cubes[i] = new Cube(); + @Override + public Sprite[] onCreateChild() { + Cube[] cubes + = new Cube[4]; + for (int i = 0; i < cubes.length; i++) { + cubes[i] = new Cube(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - cubes[i].setAnimationDelay(300 * i); - } else { - cubes[i].setAnimationDelay(300 * i - 1200); - } - } - return cubes; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + cubes[i].setAnimationDelay(300 * i); + } else { + cubes[i].setAnimationDelay(300 * i - 1200); + } } + return cubes; + } - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - bounds = clipSquare(bounds); - int size = Math.min(bounds.width(), bounds.height()); - if (wrapContent) { - size = (int) Math.sqrt( - (size - * size) / 2); - int oW = (bounds.width() - size) / 2; - int oH = (bounds.height() - size) / 2; - bounds = new Rect( - bounds.left + oW, - bounds.top + oH, - bounds.right - oW, - bounds.bottom - oH - ); - } + @Override + protected void onBoundsChange(Rect bounds) { + super.onBoundsChange(bounds); + bounds = clipSquare(bounds); + int size = Math.min(bounds.width(), bounds.height()); + if (wrapContent) { + size = (int) Math.sqrt( + (size + * size) / 2); + int oW = (bounds.width() - size) / 2; + int oH = (bounds.height() - size) / 2; + bounds = new Rect( + bounds.left + oW, + bounds.top + oH, + bounds.right - oW, + bounds.bottom - oH + ); + } - int px = bounds.left + size / 2 + 1; - int py = bounds.top + size / 2 + 1; - for (int i = 0; i < getChildCount(); i++) { - Sprite sprite = getChildAt(i); - sprite.setDrawBounds( - bounds.left, - bounds.top, - px, - py - ); - sprite.setPivotX(sprite.getDrawBounds().right); - sprite.setPivotY(sprite.getDrawBounds().bottom); - } + int px = bounds.left + size / 2 + 1; + int py = bounds.top + size / 2 + 1; + for (int i = 0; i < getChildCount(); i++) { + Sprite sprite = getChildAt(i); + sprite.setDrawBounds( + bounds.left, + bounds.top, + px, + py + ); + sprite.setPivotX(sprite.getDrawBounds().right); + sprite.setPivotY(sprite.getDrawBounds().bottom); } + } - @Override - public void drawChild(Canvas canvas) { + @Override + public void drawChild(Canvas canvas) { - Rect bounds = clipSquare(getBounds()); - for (int i = 0; i < getChildCount(); i++) { - int count = canvas.save(); - canvas.rotate(45 + i * 90, bounds.centerX(), bounds.centerY()); - Sprite sprite = getChildAt(i); - sprite.draw(canvas); - canvas.restoreToCount(count); - } + Rect bounds = clipSquare(getBounds()); + for (int i = 0; i < getChildCount(); i++) { + int count = canvas.save(); + canvas.rotate(45 + i * 90, bounds.centerX(), bounds.centerY()); + Sprite sprite = getChildAt(i); + sprite.draw(canvas); + canvas.restoreToCount(count); } + } - private class Cube extends RectSprite { + private class Cube extends RectSprite { - Cube() { - setAlpha(0); - setRotateX(-180); - } + Cube() { + setAlpha(0); + setRotateX(-180); + } - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.1f, 0.25f, 0.75f, 0.9f, 1f}; - return new SpriteAnimatorBuilder(this). - alpha(fractions, 0, 0, 255, 255, 0, 0). - rotateX(fractions, -180, -180, 0, 0, 0, 0). - rotateY(fractions, 0, 0, 0, 0, 180, 180). - duration(2400). - interpolator(new LinearInterpolator()) - .build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.1f, 0.25f, 0.75f, 0.9f, 1f }; + return new SpriteAnimatorBuilder(this) + .alpha(fractions, 0, 0, 255, 255, 0, 0) + .rotateX(fractions, -180, -180, 0, 0, 0, 0) + .rotateY(fractions, 0, 0, 0, 0, 180, 180) + .duration(2400) + .interpolator(new LinearInterpolator()) + .build(); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/Horizontal.java b/library/src/main/java/com/github/ybq/android/spinkit/style/Horizontal.java new file mode 100644 index 0000000..9385ccd --- /dev/null +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/Horizontal.java @@ -0,0 +1,45 @@ +package com.github.ybq.android.spinkit.style; + +import android.animation.ValueAnimator; +import android.graphics.Canvas; +import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; +import com.github.ybq.android.spinkit.sprite.RectSprite; +import com.github.ybq.android.spinkit.sprite.Sprite; +import com.github.ybq.android.spinkit.sprite.SpriteContainer; + +public class Horizontal extends SpriteContainer { + + @Override public Sprite[] onCreateChild() { + return new Sprite[] { new Bar(), new Bar(), new Bar() }; + } + + @Override + public void onChildCreated(Sprite... sprites) { + super.onChildCreated(sprites); + sprites[1].setAnimationDelay(600); + sprites[2].setAnimationDelay(1200); + } + + @Override public void drawChild(Canvas canvas) { + int count = canvas.save(); + canvas.clipRect(getDrawBounds()); + super.drawChild(canvas); + canvas.restoreToCount(count); + } + + private class Bar extends RectSprite { + + @Override public void onPreStart() { + setScaleX(0); + } + + public ValueAnimator onCreateAnimation() { + float[] fractions = new float[] { 0.0F, 0.25F, 0.5F, 0.75F, 1.0F }; + return new SpriteAnimatorBuilder(this) + .translateXPercentage(fractions, new Float[] { -1.0F, -0.5F, 0.0F, 0.5F, 1.0F }) + .scaleX(fractions, new Float[] { 0.1F, 0.25F, 0.4F, 0.55F, 0.7F }) + .duration(1800L) + .build(); + } + } +} diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/MultiplePulse.java b/library/src/main/java/com/github/ybq/android/spinkit/style/MultiplePulse.java index 967ac4e..0cc8ea8 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/MultiplePulse.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/MultiplePulse.java @@ -7,19 +7,19 @@ * Created by ybq. */ public class MultiplePulse extends SpriteContainer { - @Override - public Sprite[] onCreateChild() { - return new Sprite[]{ - new Pulse(), - new Pulse(), - new Pulse(), - }; - } + @Override + public Sprite[] onCreateChild() { + return new Sprite[] { + new Pulse(), + new Pulse(), + new Pulse(), + }; + } - @Override - public void onChildCreated(Sprite... sprites) { - for (int i = 0; i < sprites.length; i++) { - sprites[i].setAnimationDelay(200 * (i + 1)); - } + @Override + public void onChildCreated(Sprite... sprites) { + for (int i = 0; i < sprites.length; i++) { + sprites[i].setAnimationDelay(200 * (i + 1)); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/MultiplePulseRing.java b/library/src/main/java/com/github/ybq/android/spinkit/style/MultiplePulseRing.java index 71a37f7..7748403 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/MultiplePulseRing.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/MultiplePulseRing.java @@ -8,19 +8,19 @@ */ public class MultiplePulseRing extends SpriteContainer { - @Override - public Sprite[] onCreateChild() { - return new Sprite[]{ - new PulseRing(), - new PulseRing(), - new PulseRing(), - }; - } + @Override + public Sprite[] onCreateChild() { + return new Sprite[] { + new PulseRing(), + new PulseRing(), + new PulseRing(), + }; + } - @Override - public void onChildCreated(Sprite... sprites) { - for (int i = 0; i < sprites.length; i++) { - sprites[i].setAnimationDelay(200 * (i + 1)); - } + @Override + public void onChildCreated(Sprite... sprites) { + for (int i = 0; i < sprites.length; i++) { + sprites[i].setAnimationDelay(200 * (i + 1)); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/Pulse.java b/library/src/main/java/com/github/ybq/android/spinkit/style/Pulse.java index 1b03f7f..2d4cb4a 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/Pulse.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/Pulse.java @@ -1,7 +1,6 @@ package com.github.ybq.android.spinkit.style; import android.animation.ValueAnimator; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.sprite.CircleSprite; @@ -10,18 +9,18 @@ */ public class Pulse extends CircleSprite { - public Pulse() { - setScale(0f); - } + public Pulse() { + setScale(0f); + } - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 1f}; - return new SpriteAnimatorBuilder(this). - scale(fractions, 0f, 1f). - alpha(fractions, 255, 0). - duration(1000). - easeInOut(fractions) - .build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 1f }; + return new SpriteAnimatorBuilder(this) + .scale(fractions, 0f, 1f) + .alpha(fractions, 255, 0) + .duration(1000) + .easeInOut(fractions) + .build(); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/PulseRing.java b/library/src/main/java/com/github/ybq/android/spinkit/style/PulseRing.java index e389b05..18009ee 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/PulseRing.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/PulseRing.java @@ -1,7 +1,6 @@ package com.github.ybq.android.spinkit.style; import android.animation.ValueAnimator; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.animation.interpolator.KeyFrameInterpolator; import com.github.ybq.android.spinkit.sprite.RingSprite; @@ -11,18 +10,18 @@ */ public class PulseRing extends RingSprite { - public PulseRing() { - setScale(0f); - } + public PulseRing() { + setScale(0f); + } - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.7f, 1f}; - return new SpriteAnimatorBuilder(this). - scale(fractions, 0f, 1f, 1f). - alpha(fractions, 255, (int) (255 * 0.7), 0). - duration(1000). - interpolator(KeyFrameInterpolator.pathInterpolator(0.21f, 0.53f, 0.56f, 0.8f, fractions)). - build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.7f, 1f }; + return new SpriteAnimatorBuilder(this) + .scale(fractions, 0f, 1f, 1f) + .alpha(fractions, 255, (int) (255 * 0.7), 0) + .duration(1000) + .interpolator(KeyFrameInterpolator.pathInterpolator(0.21f, 0.53f, 0.56f, 0.8f, fractions)) + .build(); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/RotatingCircle.java b/library/src/main/java/com/github/ybq/android/spinkit/style/RotatingCircle.java index 2033a33..bfaeaa0 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/RotatingCircle.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/RotatingCircle.java @@ -1,20 +1,19 @@ package com.github.ybq.android.spinkit.style; import android.animation.ValueAnimator; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.sprite.CircleSprite; public class RotatingCircle extends CircleSprite { - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.5f, 1f}; - return new SpriteAnimatorBuilder(this). - rotateX(fractions, 0, -180, -180). - rotateY(fractions, 0, 0, -180). - duration(1200). - easeInOut(fractions) - .build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.5f, 1f }; + return new SpriteAnimatorBuilder(this) + .rotateX(fractions, 0, -180, -180) + .rotateY(fractions, 0, 0, -180) + .duration(1200) + .easeInOut(fractions) + .build(); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/RotatingPlane.java b/library/src/main/java/com/github/ybq/android/spinkit/style/RotatingPlane.java index 8e67d76..e9c1b77 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/RotatingPlane.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/RotatingPlane.java @@ -2,7 +2,6 @@ import android.animation.ValueAnimator; import android.graphics.Rect; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.sprite.RectSprite; @@ -10,19 +9,19 @@ * Created by ybq. */ public class RotatingPlane extends RectSprite { - @Override - protected void onBoundsChange(Rect bounds) { - setDrawBounds(clipSquare(bounds)); - } + @Override + protected void onBoundsChange(Rect bounds) { + setDrawBounds(clipSquare(bounds)); + } - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.5f, 1f}; - return new SpriteAnimatorBuilder(this). - rotateX(fractions, 0, -180, -180). - rotateY(fractions, 0, 0, -180). - duration(1200). - easeInOut(fractions) - .build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.5f, 1f }; + return new SpriteAnimatorBuilder(this) + .rotateX(fractions, 0, -180, -180) + .rotateY(fractions, 0, 0, -180) + .duration(1200) + .easeInOut(fractions) + .build(); + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/ThreeBounce.java b/library/src/main/java/com/github/ybq/android/spinkit/style/ThreeBounce.java index e9fa7f2..9186678 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/ThreeBounce.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/ThreeBounce.java @@ -2,7 +2,6 @@ import android.animation.ValueAnimator; import android.graphics.Rect; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.sprite.CircleSprite; import com.github.ybq.android.spinkit.sprite.Sprite; @@ -13,52 +12,49 @@ */ public class ThreeBounce extends SpriteContainer { - @Override - public Sprite[] onCreateChild() { - return new Sprite[]{ - new Bounce(), - new Bounce(), - new Bounce() - }; + @Override + public Sprite[] onCreateChild() { + return new Sprite[] { + new Bounce(), + new Bounce(), + new Bounce() + }; + } + + @Override + public void onChildCreated(Sprite... sprites) { + super.onChildCreated(sprites); + sprites[1].setAnimationDelay(160); + sprites[2].setAnimationDelay(320); + } + + @Override + protected void onBoundsChange(Rect bounds) { + super.onBoundsChange(bounds); + bounds = clipSquare(bounds); + int radius = bounds.width() / 8; + int top = bounds.centerY() - radius; + int bottom = bounds.centerY() + radius; + + for (int i = 0; i < getChildCount(); i++) { + int left = bounds.width() * i / 3 + bounds.left; + getChildAt(i).setDrawBounds(left, top, left + radius * 2, bottom); } + } - @Override - public void onChildCreated(Sprite... sprites) { - super.onChildCreated(sprites); - sprites[1].setAnimationDelay(160); - sprites[2].setAnimationDelay(320); - } + private class Bounce extends CircleSprite { - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - bounds = clipSquare(bounds); - int radius = bounds.width() / 8; - int top = bounds.centerY() - radius; - int bottom = bounds.centerY() + radius; - - for (int i = 0; i < getChildCount(); i++) { - int left = bounds.width() * i / 3 - + bounds.left; - getChildAt(i).setDrawBounds( - left, top, left + radius * 2, bottom - ); - } + Bounce() { + setScale(0f); } - private class Bounce extends CircleSprite { - - Bounce() { - setScale(0f); - } - - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.4f, 0.8f, 1f}; - return new SpriteAnimatorBuilder(this).scale(fractions, 0f, 1f, 0f, 0f). - duration(1400). - easeInOut(fractions) - .build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.4f, 0.8f, 1f }; + return new SpriteAnimatorBuilder(this).scale(fractions, 0f, 1f, 0f, 0f) + .duration(1400) + .easeInOut(fractions) + .build(); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/WanderingCubes.java b/library/src/main/java/com/github/ybq/android/spinkit/style/WanderingCubes.java index cd8bb59..6d4bc17 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/WanderingCubes.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/WanderingCubes.java @@ -1,10 +1,8 @@ package com.github.ybq.android.spinkit.style; import android.animation.ValueAnimator; -import android.graphics.Color; import android.graphics.Rect; import android.os.Build; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.sprite.RectSprite; import com.github.ybq.android.spinkit.sprite.Sprite; @@ -15,59 +13,58 @@ */ public class WanderingCubes extends SpriteContainer { - @Override - public Sprite[] onCreateChild() { - return new Sprite[]{ - new Cube(0), - new Cube(3) - }; - } + @Override + public Sprite[] onCreateChild() { + return new Sprite[] { + new Cube(0), + new Cube(3) + }; + } - @Override - public void onChildCreated(Sprite... sprites) { - super.onChildCreated(sprites); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - sprites[1].setAnimationDelay(-900); - } + @Override + public void onChildCreated(Sprite... sprites) { + super.onChildCreated(sprites); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + sprites[1].setAnimationDelay(-900); } + } - @Override - protected void onBoundsChange(Rect bounds) { - bounds = clipSquare(bounds); - super.onBoundsChange(bounds); - for (int i = 0; i < getChildCount(); i++) { - Sprite sprite = getChildAt(i); - sprite.setDrawBounds( - bounds.left, - bounds.top, - bounds.left + bounds.width() / 4, - bounds.top + bounds.height() / 4 - ); - } + @Override + protected void onBoundsChange(Rect bounds) { + bounds = clipSquare(bounds); + super.onBoundsChange(bounds); + for (int i = 0; i < getChildCount(); i++) { + Sprite sprite = getChildAt(i); + sprite.setDrawBounds( + bounds.left, + bounds.top, + bounds.left + bounds.width() / 4, + bounds.top + bounds.height() / 4 + ); } + } - private class Cube extends RectSprite { - int startFrame; + private class Cube extends RectSprite { + int startFrame; - public Cube(int startFrame) { - this.startFrame = startFrame; - } + public Cube(int startFrame) { + this.startFrame = startFrame; + } - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.25f, 0.5f, 0.51f, 0.75f, 1f}; - SpriteAnimatorBuilder builder = new SpriteAnimatorBuilder(this). - rotate(fractions, 0, -90, -179, -180, -270, -360). - translateXPercentage(fractions, 0f, 0.75f, 0.75f, 0.75f, 0f, 0f). - translateYPercentage(fractions, 0f, 0f, 0.75f, 0.75f, 0.75f, 0f). - scale(fractions, 1f, 0.5f, 1f, 1f, 0.5f, 1f). - duration(1800). - easeInOut(fractions); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - builder. - startFrame(startFrame); - } - return builder.build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.25f, 0.5f, 0.51f, 0.75f, 1f }; + SpriteAnimatorBuilder builder = new SpriteAnimatorBuilder(this) + .rotate(fractions, 0, -90, -179, -180, -270, -360) + .translateXPercentage(fractions, 0f, 0.75f, 0.75f, 0.75f, 0f, 0f) + .translateYPercentage(fractions, 0f, 0f, 0.75f, 0.75f, 0.75f, 0f) + .scale(fractions, 1f, 0.5f, 1f, 1f, 0.5f, 1f) + .duration(1800) + .easeInOut(fractions); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + builder.startFrame(startFrame); + } + return builder.build(); } + } } diff --git a/library/src/main/java/com/github/ybq/android/spinkit/style/Wave.java b/library/src/main/java/com/github/ybq/android/spinkit/style/Wave.java index 6e7f479..662281b 100644 --- a/library/src/main/java/com/github/ybq/android/spinkit/style/Wave.java +++ b/library/src/main/java/com/github/ybq/android/spinkit/style/Wave.java @@ -3,7 +3,6 @@ import android.animation.ValueAnimator; import android.graphics.Rect; import android.os.Build; - import com.github.ybq.android.spinkit.animation.SpriteAnimatorBuilder; import com.github.ybq.android.spinkit.sprite.RectSprite; import com.github.ybq.android.spinkit.sprite.Sprite; @@ -14,48 +13,47 @@ */ public class Wave extends SpriteContainer { - @Override - public Sprite[] onCreateChild() { - WaveItem[] waveItems = new WaveItem[5]; - for (int i = 0; i < waveItems.length; i++) { - waveItems[i] = new WaveItem(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - waveItems[i].setAnimationDelay(600 + i * 100); - } else { - waveItems[i].setAnimationDelay(-1200 + i * 100); - } - - } - return waveItems; + @Override + public Sprite[] onCreateChild() { + WaveItem[] waveItems = new WaveItem[5]; + for (int i = 0; i < waveItems.length; i++) { + waveItems[i] = new WaveItem(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + waveItems[i].setAnimationDelay(600 + i * 100); + } else { + waveItems[i].setAnimationDelay(-1200 + i * 100); + } } - - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - bounds = clipSquare(bounds); - int rw = bounds.width() / getChildCount(); - int width = bounds.width() / 5 * 3 / 5; - for (int i = 0; i < getChildCount(); i++) { - Sprite sprite = getChildAt(i); - int l = bounds.left + i * rw + rw / 5; - int r = l + width; - sprite.setDrawBounds(l, bounds.top, r, bounds.bottom); - } + return waveItems; + } + + @Override + protected void onBoundsChange(Rect bounds) { + super.onBoundsChange(bounds); + bounds = clipSquare(bounds); + int rw = bounds.width() / getChildCount(); + int width = bounds.width() / 5 * 3 / 5; + for (int i = 0; i < getChildCount(); i++) { + Sprite sprite = getChildAt(i); + int l = bounds.left + i * rw + rw / 5; + int r = l + width; + sprite.setDrawBounds(l, bounds.top, r, bounds.bottom); } + } - private class WaveItem extends RectSprite { + private class WaveItem extends RectSprite { - WaveItem() { - setScaleY(0.4f); - } + WaveItem() { + setScaleY(0.4f); + } - @Override - public ValueAnimator onCreateAnimation() { - float fractions[] = new float[]{0f, 0.2f, 0.4f, 1f}; - return new SpriteAnimatorBuilder(this).scaleY(fractions, 0.4f, 1f, 0.4f, 0.4f). - duration(1200). - easeInOut(fractions) - .build(); - } + @Override + public ValueAnimator onCreateAnimation() { + float fractions[] = new float[] { 0f, 0.2f, 0.4f, 1f }; + return new SpriteAnimatorBuilder(this).scaleY(fractions, 0.4f, 1f, 0.4f, 0.4f) + .duration(1200) + .easeInOut(fractions) + .build(); } + } } diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index c7ec5de..233a26b 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -1,26 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml index 44ec138..969612f 100644 --- a/library/src/main/res/values/styles.xml +++ b/library/src/main/res/values/styles.xml @@ -1,205 +1,214 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 521bcdf..523239b 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,28 +1,28 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 24 - buildToolsVersion "24.0.2" + compileSdkVersion 27 + buildToolsVersion "27.0.3" - defaultConfig { - applicationId "com.github.ybq.android.spinkit" - minSdkVersion 14 - targetSdkVersion 24 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } + defaultConfig { + applicationId "com.github.ybq.android.spinkit" + minSdkVersion 14 + targetSdkVersion 27 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } + } } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:24.2.1' - compile 'com.android.support:design:24.2.1' - compile project(':library') + implementation fileTree(include: ['*.jar'], dir: 'libs') + testImplementation 'junit:junit:4.12' + implementation 'com.android.support:appcompat-v7:27.0.2' + implementation 'com.android.support:design:27.0.2' + implementation project(':library') } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 55994ef..97bb30f 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -2,26 +2,24 @@ - + - - - - - - - - - - + android:theme="@style/AppTheme.NoActionBar"> + + + + + + + diff --git a/sample/src/main/java/com/github/ybq/android/loading/ArgbEvaluator.java b/sample/src/main/java/com/github/ybq/android/loading/ArgbEvaluator.java index cf7b850..ab3070a 100644 --- a/sample/src/main/java/com/github/ybq/android/loading/ArgbEvaluator.java +++ b/sample/src/main/java/com/github/ybq/android/loading/ArgbEvaluator.java @@ -24,49 +24,49 @@ * values that represent ARGB colors. */ public class ArgbEvaluator implements TypeEvaluator { - private static final ArgbEvaluator sInstance = new ArgbEvaluator(); + private static final ArgbEvaluator sInstance = new ArgbEvaluator(); - /** - * Returns an instance of ArgbEvaluator that may be used in - * {@link android.animation.ValueAnimator#setEvaluator(TypeEvaluator)}. The same instance may - * be used in multiple Animators because it holds no state. - * - * @return An instance of ArgbEvalutor. - */ - public static ArgbEvaluator getInstance() { - return sInstance; - } + /** + * Returns an instance of ArgbEvaluator that may be used in + * {@link android.animation.ValueAnimator#setEvaluator(TypeEvaluator)}. The same instance may + * be used in multiple Animators because it holds no state. + * + * @return An instance of ArgbEvalutor. + */ + public static ArgbEvaluator getInstance() { + return sInstance; + } - /** - * This function returns the calculated in-between value for a color - * given integers that represent the start and end values in the four - * bytes of the 32-bit int. Each channel is separately linearly interpolated - * and the resulting calculated values are recombined into the return value. - * - * @param fraction The fraction from the starting to the ending values - * @param startValue A 32-bit int value representing colors in the - * separate bytes of the parameter - * @param endValue A 32-bit int value representing colors in the - * separate bytes of the parameter - * @return A value that is calculated to be the linearly interpolated - * result, derived by separating the start and end values into separate - * color channels and interpolating each one separately, recombining the - * resulting values in the same way. - */ - public Object evaluate(float fraction, Object startValue, Object endValue) { - int startInt = (Integer) startValue; - int startA = (startInt >> 24) & 0xff; - int startR = (startInt >> 16) & 0xff; - int startG = (startInt >> 8) & 0xff; - int startB = startInt & 0xff; - int endInt = (Integer) endValue; - int endA = (endInt >> 24) & 0xff; - int endR = (endInt >> 16) & 0xff; - int endG = (endInt >> 8) & 0xff; - int endB = endInt & 0xff; - return (startA + (int) (fraction * (endA - startA))) << 24 | - (startR + (int) (fraction * (endR - startR))) << 16 | - (startG + (int) (fraction * (endG - startG))) << 8 | - (startB + (int) (fraction * (endB - startB))); - } + /** + * This function returns the calculated in-between value for a color + * given integers that represent the start and end values in the four + * bytes of the 32-bit int. Each channel is separately linearly interpolated + * and the resulting calculated values are recombined into the return value. + * + * @param fraction The fraction from the starting to the ending values + * @param startValue A 32-bit int value representing colors in the + * separate bytes of the parameter + * @param endValue A 32-bit int value representing colors in the + * separate bytes of the parameter + * @return A value that is calculated to be the linearly interpolated + * result, derived by separating the start and end values into separate + * color channels and interpolating each one separately, recombining the + * resulting values in the same way. + */ + public Object evaluate(float fraction, Object startValue, Object endValue) { + int startInt = (Integer) startValue; + int startA = (startInt >> 24) & 0xff; + int startR = (startInt >> 16) & 0xff; + int startG = (startInt >> 8) & 0xff; + int startB = startInt & 0xff; + int endInt = (Integer) endValue; + int endA = (endInt >> 24) & 0xff; + int endR = (endInt >> 16) & 0xff; + int endG = (endInt >> 8) & 0xff; + int endB = endInt & 0xff; + return (startA + (int) (fraction * (endA - startA))) << 24 | + (startR + (int) (fraction * (endR - startR))) << 16 | + (startG + (int) (fraction * (endG - startG))) << 8 | + (startB + (int) (fraction * (endB - startB))); + } } \ No newline at end of file diff --git a/sample/src/main/java/com/github/ybq/android/loading/Colors.java b/sample/src/main/java/com/github/ybq/android/loading/Colors.java index fb0567a..5c68d2d 100644 --- a/sample/src/main/java/com/github/ybq/android/loading/Colors.java +++ b/sample/src/main/java/com/github/ybq/android/loading/Colors.java @@ -4,14 +4,14 @@ * Created by ybq. */ public interface Colors { - int[] colors = new int[]{ - android.graphics.Color.parseColor("#D55400"), - android.graphics.Color.parseColor("#2B3E51"), - android.graphics.Color.parseColor("#00BD9C"), - android.graphics.Color.parseColor("#227FBB"), - android.graphics.Color.parseColor("#7F8C8D"), - android.graphics.Color.parseColor("#FFCC5C"), - android.graphics.Color.parseColor("#D55400"), - android.graphics.Color.parseColor("#1AAF5D"), - }; + int[] colors = new int[] { + android.graphics.Color.parseColor("#D55400"), + android.graphics.Color.parseColor("#2B3E51"), + android.graphics.Color.parseColor("#00BD9C"), + android.graphics.Color.parseColor("#227FBB"), + android.graphics.Color.parseColor("#7F8C8D"), + android.graphics.Color.parseColor("#FFCC5C"), + android.graphics.Color.parseColor("#D55400"), + android.graphics.Color.parseColor("#1AAF5D"), + }; } diff --git a/sample/src/main/java/com/github/ybq/android/loading/DetailActivity.java b/sample/src/main/java/com/github/ybq/android/loading/DetailActivity.java index bf195fc..10bb697 100644 --- a/sample/src/main/java/com/github/ybq/android/loading/DetailActivity.java +++ b/sample/src/main/java/com/github/ybq/android/loading/DetailActivity.java @@ -11,7 +11,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; - import com.github.ybq.android.spinkit.SpinKitView; import com.github.ybq.android.spinkit.SpriteFactory; import com.github.ybq.android.spinkit.Style; @@ -19,71 +18,71 @@ public class DetailActivity extends AppCompatActivity implements Colors { - @SuppressWarnings("WeakerAccess") - public static void start(Context context, int position) { - Intent intent = new Intent(context, DetailActivity.class); - intent.putExtra("position", position); - context.startActivity(intent); - } + @SuppressWarnings("WeakerAccess") + public static void start(Context context, int position) { + Intent intent = new Intent(context, DetailActivity.class); + intent.putExtra("position", position); + context.startActivity(intent); + } - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_detail); - ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager); - viewPager.setOffscreenPageLimit(0); - viewPager.setAdapter(new PagerAdapter() { - @Override - public int getCount() { - return Style.values().length; - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_detail); + ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager); + viewPager.setOffscreenPageLimit(0); + viewPager.setAdapter(new PagerAdapter() { + @Override + public int getCount() { + return Style.values().length; + } - @Override - public boolean isViewFromObject(View view, Object object) { - return view == object; - } + @Override + public boolean isViewFromObject(View view, Object object) { + return view == object; + } - @Override - public Object instantiateItem(ViewGroup container, int position) { - @SuppressLint("InflateParams") View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_pager, null); + @Override + public Object instantiateItem(ViewGroup container, int position) { + @SuppressLint("InflateParams") View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_pager, null); - SpinKitView spinKitView = (SpinKitView) view.findViewById(R.id.spin_kit); - TextView name = (TextView) view.findViewById(R.id.name); - Style style = Style.values()[position]; - name.setText(style.name()); - Sprite drawable = SpriteFactory.create(style); - spinKitView.setIndeterminateDrawable(drawable); - container.addView(view); + SpinKitView spinKitView = (SpinKitView) view.findViewById(R.id.spin_kit); + TextView name = (TextView) view.findViewById(R.id.name); + Style style = Style.values()[position]; + name.setText(style.name()); + Sprite drawable = SpriteFactory.create(style); + spinKitView.setIndeterminateDrawable(drawable); + container.addView(view); - return view; - } + return view; + } - @Override - public void destroyItem(ViewGroup container, int position, Object object) { - container.removeView((View) object); - } - }); + @Override + public void destroyItem(ViewGroup container, int position, Object object) { + container.removeView((View) object); + } + }); - viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - int color = (int) ArgbEvaluator.getInstance().evaluate(positionOffset, - colors[position % colors.length], - colors[(position + 1) % colors.length]); - getWindow().getDecorView().setBackgroundColor(color); - } + viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + int color = (int) ArgbEvaluator.getInstance().evaluate(positionOffset, + colors[position % colors.length], + colors[(position + 1) % colors.length]); + getWindow().getDecorView().setBackgroundColor(color); + } - @Override - public void onPageSelected(int position) { - getWindow().getDecorView().setBackgroundColor(colors[position % colors.length]); - } + @Override + public void onPageSelected(int position) { + getWindow().getDecorView().setBackgroundColor(colors[position % colors.length]); + } - @Override - public void onPageScrollStateChanged(int state) { + @Override + public void onPageScrollStateChanged(int state) { - } - }); + } + }); - viewPager.setCurrentItem(getIntent().getIntExtra("position", 0)); - } + viewPager.setCurrentItem(getIntent().getIntExtra("position", 0)); + } } diff --git a/sample/src/main/java/com/github/ybq/android/loading/MainActivity.java b/sample/src/main/java/com/github/ybq/android/loading/MainActivity.java index 186c54d..fcd0010 100644 --- a/sample/src/main/java/com/github/ybq/android/loading/MainActivity.java +++ b/sample/src/main/java/com/github/ybq/android/loading/MainActivity.java @@ -9,42 +9,41 @@ public class MainActivity extends AppCompatActivity { - TabLayout mTabLayout; - ViewPager mViewPager; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - mTabLayout = (TabLayout) findViewById(R.id.tabs); - mViewPager = (ViewPager) findViewById(R.id.viewpager); - - mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { - - String[] titles = new String[]{ - "page1", "page2" - }; - - @Override - public Fragment getItem(int position) { - if (position == 0) { - return Page1Fragment.newInstance(); - } else { - return Page2Fragment.newInstance(); - } - } - - @Override - public int getCount() { - return 2; - } - - @Override - public CharSequence getPageTitle(int position) { - return titles[position]; - } - }); - mTabLayout.setupWithViewPager(mViewPager); - } - + TabLayout mTabLayout; + ViewPager mViewPager; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + mTabLayout = (TabLayout) findViewById(R.id.tabs); + mViewPager = (ViewPager) findViewById(R.id.viewpager); + + mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { + + String[] titles = new String[] { + "page1", "page2" + }; + + @Override + public Fragment getItem(int position) { + if (position == 0) { + return Page1Fragment.newInstance(); + } else { + return Page2Fragment.newInstance(); + } + } + + @Override + public int getCount() { + return 2; + } + + @Override + public CharSequence getPageTitle(int position) { + return titles[position]; + } + }); + mTabLayout.setupWithViewPager(mViewPager); + } } diff --git a/sample/src/main/java/com/github/ybq/android/loading/Page1Fragment.java b/sample/src/main/java/com/github/ybq/android/loading/Page1Fragment.java index 6030853..4089980 100644 --- a/sample/src/main/java/com/github/ybq/android/loading/Page1Fragment.java +++ b/sample/src/main/java/com/github/ybq/android/loading/Page1Fragment.java @@ -9,94 +9,76 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; - import com.github.ybq.android.spinkit.SpinKitView; import com.github.ybq.android.spinkit.SpriteFactory; import com.github.ybq.android.spinkit.Style; import com.github.ybq.android.spinkit.sprite.Sprite; -import com.github.ybq.android.spinkit.style.ChasingDots; -import com.github.ybq.android.spinkit.style.Circle; -import com.github.ybq.android.spinkit.style.CubeGrid; -import com.github.ybq.android.spinkit.style.DoubleBounce; -import com.github.ybq.android.spinkit.style.FadingCircle; -import com.github.ybq.android.spinkit.style.FoldingCube; -import com.github.ybq.android.spinkit.style.MultiplePulse; -import com.github.ybq.android.spinkit.style.MultiplePulseRing; -import com.github.ybq.android.spinkit.style.Pulse; -import com.github.ybq.android.spinkit.style.PulseRing; -import com.github.ybq.android.spinkit.style.RotatingCircle; -import com.github.ybq.android.spinkit.style.RotatingPlane; -import com.github.ybq.android.spinkit.style.ThreeBounce; -import com.github.ybq.android.spinkit.style.WanderingCubes; -import com.github.ybq.android.spinkit.style.Wave; /** * Created by ybq. */ public class Page1Fragment extends Fragment implements Colors { - public static Page1Fragment newInstance() { - return new Page1Fragment(); - } - + public static Page1Fragment newInstance() { + return new Page1Fragment(); + } - @SuppressLint("InflateParams") - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_page1, null); - } + @SuppressLint("InflateParams") + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_page1, null); + } - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list); - GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 4); - layoutManager.setOrientation(GridLayoutManager.VERTICAL); - recyclerView.setLayoutManager(layoutManager); + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + RecyclerView recyclerView = view.findViewById(R.id.list); + GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 4); + layoutManager.setOrientation(GridLayoutManager.VERTICAL); + recyclerView.setLayoutManager(layoutManager); - recyclerView.setAdapter(new RecyclerView.Adapter() { - @Override - public Holder onCreateViewHolder(ViewGroup parent, int viewType) { - @SuppressLint("InflateParams") View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, null); - return new Holder(view); - } + recyclerView.setAdapter(new RecyclerView.Adapter() { + @Override + public Holder onCreateViewHolder(ViewGroup parent, int viewType) { + @SuppressLint("InflateParams") View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, null); + return new Holder(view); + } - @Override - public void onBindViewHolder(Holder holder, int position) { - holder.bind(position); - } + @Override + public void onBindViewHolder(Holder holder, int position) { + holder.bind(position); + } - @Override - public int getItemCount() { - return Style.values().length; - } - }); - } + @Override + public int getItemCount() { + return Style.values().length; + } + }); + } - class Holder extends RecyclerView.ViewHolder { + class Holder extends RecyclerView.ViewHolder { - SpinKitView spinKitView; + SpinKitView spinKitView; - public Holder(View itemView) { - super(itemView); - spinKitView = (SpinKitView) itemView.findViewById(R.id.spin_kit); - } + public Holder(View itemView) { + super(itemView); + spinKitView = itemView.findViewById(R.id.spin_kit); + } - public void bind(int position) { - itemView.setBackgroundColor(colors[position % colors.length]); - final int finalPosition = position; - itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - DetailActivity.start(v.getContext(), finalPosition); - } - }); - position = position % 15; - Style style = Style.values()[position]; - Sprite drawable = SpriteFactory.create(style); - spinKitView.setIndeterminateDrawable(drawable); + public void bind(int position) { + itemView.setBackgroundColor(colors[position % colors.length]); + final int finalPosition = position; + itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + DetailActivity.start(v.getContext(), finalPosition); } + }); + position = position % Style.values().length; + Style style = Style.values()[position]; + Sprite drawable = SpriteFactory.create(style); + spinKitView.setIndeterminateDrawable(drawable); } - + } } diff --git a/sample/src/main/java/com/github/ybq/android/loading/Page2Fragment.java b/sample/src/main/java/com/github/ybq/android/loading/Page2Fragment.java index 0b9af41..82c785c 100644 --- a/sample/src/main/java/com/github/ybq/android/loading/Page2Fragment.java +++ b/sample/src/main/java/com/github/ybq/android/loading/Page2Fragment.java @@ -8,13 +8,14 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; - import com.github.ybq.android.spinkit.style.ChasingDots; import com.github.ybq.android.spinkit.style.Circle; import com.github.ybq.android.spinkit.style.DoubleBounce; +import com.github.ybq.android.spinkit.style.Horizontal; import com.github.ybq.android.spinkit.style.Wave; /** @@ -22,68 +23,78 @@ */ public class Page2Fragment extends Fragment implements Colors { - private Wave mWaveDrawable; - private Circle mCircleDrawable; - private ChasingDots mChasingDotsDrawable; + private Wave mWaveDrawable; + private Circle mCircleDrawable; + private ChasingDots mChasingDotsDrawable; + private Horizontal mHorizontal; + + public static Page2Fragment newInstance() { + return new Page2Fragment(); + } - public static Page2Fragment newInstance() { - return new Page2Fragment(); - } + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_page2, null); + } - @Nullable - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_page2, null); - } + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); + //ProgressBar + ProgressBar progressBar = view.findViewById(R.id.progress); + DoubleBounce doubleBounce = new DoubleBounce(); + doubleBounce.setBounds(0, 0, 100, 100); + doubleBounce.setColor(colors[7]); + progressBar.setIndeterminateDrawable(doubleBounce); - //ProgressBar - ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progress); - DoubleBounce doubleBounce = new DoubleBounce(); - doubleBounce.setBounds(0, 0, 100, 100); - doubleBounce.setColor(colors[7]); - progressBar.setIndeterminateDrawable(doubleBounce); + //Button + Button button = view.findViewById(R.id.button); + mWaveDrawable = new Wave(); + mWaveDrawable.setBounds(0, 0, 100, 100); + //noinspection deprecation + mWaveDrawable.setColor(getResources().getColor(R.color.colorAccent)); + button.setCompoundDrawables(mWaveDrawable, null, null, null); - //Button - Button button = (Button) view.findViewById(R.id.button); - mWaveDrawable = new Wave(); - mWaveDrawable.setBounds(0, 0, 100, 100); - //noinspection deprecation - mWaveDrawable.setColor(getResources().getColor(R.color.colorAccent)); - button.setCompoundDrawables(mWaveDrawable, null, null, null); + //TextView + TextView textView = view.findViewById(R.id.text); + mCircleDrawable = new Circle(); + mCircleDrawable.setBounds(0, 0, 100, 100); + mCircleDrawable.setColor(Color.WHITE); + textView.setCompoundDrawables(null, null, mCircleDrawable, null); + textView.setBackgroundColor(colors[2]); - //TextView - TextView textView = (TextView) view.findViewById(R.id.text); - mCircleDrawable = new Circle(); - mCircleDrawable.setBounds(0, 0, 100, 100); - mCircleDrawable.setColor(Color.WHITE); - textView.setCompoundDrawables(null, null, mCircleDrawable, null); - textView.setBackgroundColor(colors[2]); + //ImageView + ImageView imageView = view.findViewById(R.id.image); + mChasingDotsDrawable = new ChasingDots(); + mChasingDotsDrawable.setColor(Color.WHITE); + imageView.setImageDrawable(mChasingDotsDrawable); + imageView.setBackgroundColor(colors[0]); - //ImageView - ImageView imageView = (ImageView) view.findViewById(R.id.image); - mChasingDotsDrawable = new ChasingDots(); - mChasingDotsDrawable.setColor(Color.WHITE); - imageView.setImageDrawable(mChasingDotsDrawable); - imageView.setBackgroundColor(colors[0]); - } + //ImageView + FrameLayout layout = view.findViewById(R.id.layout); + mHorizontal = new Horizontal(); + mHorizontal.setColor(getResources().getColor(R.color.colorAccent)); + layout.setForeground(mHorizontal); + layout.setBackgroundColor(Color.WHITE); + } - @Override - public void onResume() { - super.onResume(); - mWaveDrawable.start(); - mCircleDrawable.start(); - mChasingDotsDrawable.start(); - } + @Override + public void onResume() { + super.onResume(); + mWaveDrawable.start(); + mCircleDrawable.start(); + mChasingDotsDrawable.start(); + mHorizontal.start(); + } - @Override - public void onStop() { - super.onStop(); - mWaveDrawable.stop(); - mCircleDrawable.stop(); - mChasingDotsDrawable.stop(); - } + @Override + public void onStop() { + super.onStop(); + mWaveDrawable.stop(); + mCircleDrawable.stop(); + mChasingDotsDrawable.stop(); + mHorizontal.stop(); + } } diff --git a/sample/src/main/java/com/github/ybq/android/loading/SquareFrameLayout.java b/sample/src/main/java/com/github/ybq/android/loading/SquareFrameLayout.java index a41da68..6012182 100644 --- a/sample/src/main/java/com/github/ybq/android/loading/SquareFrameLayout.java +++ b/sample/src/main/java/com/github/ybq/android/loading/SquareFrameLayout.java @@ -10,27 +10,27 @@ * Created by ybq. */ public class SquareFrameLayout extends FrameLayout { - public SquareFrameLayout(Context context) { - super(context); - } + public SquareFrameLayout(Context context) { + super(context); + } - public SquareFrameLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } + public SquareFrameLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } - public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @SuppressWarnings("unused") - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @SuppressWarnings("unused") + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - //noinspection SuspiciousNameCombination - super.onMeasure(widthMeasureSpec, widthMeasureSpec); - } + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + //noinspection SuspiciousNameCombination + super.onMeasure(widthMeasureSpec, widthMeasureSpec); + } } diff --git a/sample/src/main/res/layout/activity_detail.xml b/sample/src/main/res/layout/activity_detail.xml index 4c5a302..e9f7fcd 100644 --- a/sample/src/main/res/layout/activity_detail.xml +++ b/sample/src/main/res/layout/activity_detail.xml @@ -3,12 +3,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:clipChildren="false" - android:fitsSystemWindows="true"> - - + android:fitsSystemWindows="true" + > + diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 6c17bc8..b06c8c1 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -4,15 +4,16 @@ android:layout_height="match_parent" android:clipChildren="false" android:fitsSystemWindows="true" - android:orientation="vertical"> - - - - + android:orientation="vertical" + > + + diff --git a/sample/src/main/res/layout/fragment_page1.xml b/sample/src/main/res/layout/fragment_page1.xml index 9221756..f6b692f 100644 --- a/sample/src/main/res/layout/fragment_page1.xml +++ b/sample/src/main/res/layout/fragment_page1.xml @@ -3,10 +3,11 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:clipChildren="false" - android:fitsSystemWindows="true"> - - + android:fitsSystemWindows="true" + > + diff --git a/sample/src/main/res/layout/fragment_page2.xml b/sample/src/main/res/layout/fragment_page2.xml index 07b8446..3e24d97 100644 --- a/sample/src/main/res/layout/fragment_page2.xml +++ b/sample/src/main/res/layout/fragment_page2.xml @@ -3,112 +3,152 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:clipChildren="false" - android:fitsSystemWindows="true"> - - + + - - + + - - - - - - - - - - - - - -