Skip to content

Commit

Permalink
Up version to 1.9.2, add more convenient initializers and builders fo…
Browse files Browse the repository at this point in the history
…r animation states
  • Loading branch information
David Ganster committed Sep 6, 2021
1 parent 70e35d3 commit 960b0bd
Show file tree
Hide file tree
Showing 14 changed files with 355 additions and 85 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Get a good overview of this library here: https://medium.com/@david.gansterd/bri
To use `AdditiveAnimator` in your project, add the following lines to your `build.gradle`:
```
dependencies {
compile 'at.wirecube:additive_animations:1.9.1'
compile 'at.wirecube:additive_animations:1.9.2'
}
```

Expand Down Expand Up @@ -99,6 +99,11 @@ AdditiveAnimator.animate(view)

The new `ViewVisibilityAnimation` class provides a convenient constructor to make your own view state animations - an example can be found in the new demo (`StateDemoFragment`).

**New in 1.9.2**
The API for building new AnimationStates and view visibility animations has been improved.
You can now access the `AnimationState.Builder<T>` class to more easily use one-off states.
There are also more specializations for `View`-specific classes, like the `ViewAnimation`, `ViewAnimationState` and `ViewStateBuilder`.

# Animation States

`AdditiveAnimator` now supports the concept of _animation states_.
Expand Down
8 changes: 4 additions & 4 deletions additive_animations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 30
versionCode 26
versionName "1.9.1"
versionCode 27
versionName "1.9.2"
}
buildTypes {
release {
Expand All @@ -42,6 +42,6 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.13'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Map;
import java.util.Set;

import at.wirecube.additiveanimations.additive_animator.animation_set.AnimationState;
import at.wirecube.additiveanimations.additive_animator.view_visibility.ViewVisibilityAnimation;
import at.wirecube.additiveanimations.helper.AnimationUtils;
import at.wirecube.additiveanimations.helper.evaluators.ColorEvaluator;
Expand Down Expand Up @@ -187,7 +188,7 @@ public T fadeVisibility(int visibility) {
return self();
}

public T visibility(ViewVisibilityAnimation animation) {
public T visibility(AnimationState<View> animation) {
return state(animation);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,78 @@
package at.wirecube.additiveanimations.additive_animator.animation_set;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public abstract class AnimationState<T extends Object> implements AnimationAction<T> {

public static class Builder<T> {

@NonNull
protected final List<Animation<T>> animations = new ArrayList<>();

@Nullable
protected AnimationEndAction<T> endAction;

@Nullable
protected AnimationStartAction<T> startAction;

public Builder() {}

@NonNull
public Builder<T> addAnimation(@NonNull AnimationAction.Animation<T> animation) {
animations.add(animation);
return this;
}

@NonNull
public Builder<T> addAnimations(@NonNull List<AnimationAction.Animation<T>> animations) {
this.animations.addAll(animations);
return this;
}

@SafeVarargs
@NonNull
public final Builder<T> addAnimations(@NonNull AnimationAction.Animation<T>... animations) {
this.animations.addAll(Arrays.asList(animations));
return this;
}

@NonNull
public Builder<T> withEndAction(@Nullable AnimationEndAction<T> endAction) {
this.endAction = endAction;
return this;
}

@NonNull
public Builder<T> withStartAction(@Nullable AnimationStartAction<T> startAction) {
this.startAction = startAction;
return this;
}

public AnimationState<T> build() {
return new AnimationState<T>() {
@Override
public List<Animation<T>> getAnimations() {
return animations;
}

@Override
public AnimationEndAction<T> getAnimationEndAction() {
return endAction;
}

@Override
public AnimationStartAction<T> getAnimationStartAction() {
return startAction;
}
};
}
}

public interface AnimationStartAction<T> {
void onStart(T target);
}
Expand All @@ -11,18 +82,18 @@ public interface AnimationEndAction<T> {
}

/**
* By default, the animations are only allowed to run if the current state of the animated object matches
* The animations are only allowed to run if the current state of the animated object matches
* this state.
*/
public boolean shouldRun(AnimationState currentState) {
public final boolean shouldRun(AnimationState<T> currentState) {
return currentState == null || currentState == this;
}

/**
* By default, the animationEndListener is only allowed to run if the current state of the animated object matches
* The animationEndListener is only allowed to run if the current state of the animated object matches
* this state.
*/
public boolean shouldRunEndListener(AnimationState currentState) {
public final boolean shouldRunEndListener(AnimationState<T> currentState) {
return currentState == null || currentState == this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package at.wirecube.additiveanimations.additive_animator.animation_set.view;

import android.animation.TypeEvaluator;
import android.util.Property;
import android.view.View;

import at.wirecube.additiveanimations.additive_animator.animation_set.AnimationAction;

public class ViewAnimation extends AnimationAction.Animation<View> {
public ViewAnimation(Property<View, Float> property, float targetValue) {
super(property, targetValue);
}

public ViewAnimation(Property<View, Float> property, float targetValue, TypeEvaluator<Float> evaluator) {
super(property, targetValue, evaluator);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package at.wirecube.additiveanimations.additive_animator.animation_set.view;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import at.wirecube.additiveanimations.additive_animator.animation_set.AnimationAction;
import at.wirecube.additiveanimations.additive_animator.animation_set.AnimationState;

public class ViewAnimationState extends AnimationState<View> {

@NonNull
private final List<AnimationAction.Animation<View>> mAnimations = new ArrayList<>();
@Nullable
private final AnimationStartAction<View> mStartAction;
@Nullable
private final AnimationEndAction<View> mEndAction;

public ViewAnimationState(@NonNull List<ViewAnimation> animations) {
this(animations, null, null);
}

public ViewAnimationState(@NonNull ViewAnimation... animations) {
this(Arrays.asList(animations), null, null);
}

public ViewAnimationState(@NonNull List<ViewAnimation> animations, @Nullable AnimationStartAction<View> startAction) {
this(animations, startAction, null);
}

public ViewAnimationState(ViewAnimation animation, @Nullable AnimationStartAction<View> startAction) {
this(Arrays.asList(animation), startAction, null);
}

public ViewAnimationState(@Nullable AnimationStartAction<View> startAction, @NonNull ViewAnimation... animations) {
this(Arrays.asList(animations), startAction, null);
}

public ViewAnimationState(@NonNull ViewAnimation animation, @Nullable AnimationEndAction<View> endAction) {
this(Arrays.asList(animation), null, endAction);
}

public ViewAnimationState(@NonNull List<ViewAnimation> animations, @Nullable AnimationEndAction<View> endAction) {
this(animations, null, endAction);
}

public ViewAnimationState(@Nullable AnimationEndAction<View> endAction, @NonNull ViewAnimation... animations) {
this(Arrays.asList(animations), null, endAction);
}

public ViewAnimationState(@NonNull ViewAnimation animation, @Nullable AnimationStartAction<View> startAction, @Nullable AnimationEndAction<View> endAction) {
this(Arrays.asList(animation), startAction, endAction);
}

public ViewAnimationState(@Nullable AnimationStartAction<View> startAction, @Nullable AnimationEndAction<View> endAction, @NonNull ViewAnimation... animations) {
this(Arrays.asList(animations), startAction, endAction);
}

public ViewAnimationState(@NonNull List<ViewAnimation> animations, @Nullable AnimationStartAction<View> startAction, @Nullable AnimationEndAction<View> endAction) {
mAnimations.addAll(animations);
mStartAction = startAction;
mEndAction = endAction;
}

@Override
public List<Animation<View>> getAnimations() {
return mAnimations;
}

@Override
public AnimationStartAction<View> getAnimationStartAction() {
return mStartAction;
}

@Override
public AnimationEndAction<View> getAnimationEndAction() {
return mEndAction;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package at.wirecube.additiveanimations.additive_animator.animation_set.view;

import android.view.View;

import at.wirecube.additiveanimations.additive_animator.animation_set.AnimationState;

public class ViewStateBuilder extends AnimationState.Builder<View> {
}
Loading

0 comments on commit 960b0bd

Please sign in to comment.