From ad83271080f3cbfcc98f09d9080f85152841d938 Mon Sep 17 00:00:00 2001 From: Julian Winkler Date: Fri, 1 Sep 2023 12:30:27 +0200 Subject: [PATCH] add more Animation APIs and call onAnimationEnd() Directly calling onAnimationEnd() skips the animation and directly sets the target values --- src/api-impl/android/animation/Animator.java | 5 +++++ .../android/animation/AnimatorListenerAdapter.java | 2 +- src/api-impl/android/animation/ValueAnimator.java | 3 ++- .../android/view/ViewPropertyAnimator.java | 14 ++++++++++++++ .../android/view/animation/AlphaAnimation.java | 7 +++++++ src/api-impl/android/view/animation/Animation.java | 6 ++++++ .../android/view/animation/AnimationUtils.java | 4 ++++ src/api-impl/meson.build | 1 + 8 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/api-impl/android/view/animation/AlphaAnimation.java diff --git a/src/api-impl/android/animation/Animator.java b/src/api-impl/android/animation/Animator.java index d4318b49..449d3aaa 100644 --- a/src/api-impl/android/animation/Animator.java +++ b/src/api-impl/android/animation/Animator.java @@ -3,10 +3,15 @@ package android.animation; public class Animator { public interface AnimatorListener { + public abstract void onAnimationEnd (Animator animation); } public void setTarget(Object target) {} public void start() {} + + public void addListener(AnimatorListener listener) { + listener.onAnimationEnd(Animator.this); + } } diff --git a/src/api-impl/android/animation/AnimatorListenerAdapter.java b/src/api-impl/android/animation/AnimatorListenerAdapter.java index 4d86df97..7ffdb7aa 100644 --- a/src/api-impl/android/animation/AnimatorListenerAdapter.java +++ b/src/api-impl/android/animation/AnimatorListenerAdapter.java @@ -21,7 +21,7 @@ package android.animation; * Any custom listener that cares only about a subset of the methods of this listener can * simply subclass this adapter class instead of implementing the interface directly. */ -public abstract class AnimatorListenerAdapter /*implements Animator.AnimatorListener, +public abstract class AnimatorListenerAdapter implements Animator.AnimatorListener/*, Animator.AnimatorPauseListener*/ { /** * {@inheritDoc} diff --git a/src/api-impl/android/animation/ValueAnimator.java b/src/api-impl/android/animation/ValueAnimator.java index d19624e4..85f3e59e 100644 --- a/src/api-impl/android/animation/ValueAnimator.java +++ b/src/api-impl/android/animation/ValueAnimator.java @@ -28,8 +28,9 @@ public class ValueAnimator extends Animator { public int getRepeatCount() {return 0;} public int getRepeatMode() {return 0;} public void setInterpolator(TimeInterpolator interpolator) {} - public void addListener(Animator.AnimatorListener listener) {} public void setFloatValues(float[] values) {} + public boolean isRunning() {return false;} + public void setIntValues(int[] values) {} /** * Implementors of this interface can add themselves as update listeners diff --git a/src/api-impl/android/view/ViewPropertyAnimator.java b/src/api-impl/android/view/ViewPropertyAnimator.java index b920d2e0..e4c1a15f 100644 --- a/src/api-impl/android/view/ViewPropertyAnimator.java +++ b/src/api-impl/android/view/ViewPropertyAnimator.java @@ -12,6 +12,8 @@ public class ViewPropertyAnimator { } public ViewPropertyAnimator setListener(Animator.AnimatorListener listener) { + if (listener != null) + listener.onAnimationEnd(null); return this; } @@ -27,5 +29,17 @@ public class ViewPropertyAnimator { return this; } + public ViewPropertyAnimator rotation(float rotation) { + return this; + } + + public ViewPropertyAnimator translationX(float translationX) { + return this; + } + + public ViewPropertyAnimator translationY(float translationY) { + return this; + } + public void start() {} } diff --git a/src/api-impl/android/view/animation/AlphaAnimation.java b/src/api-impl/android/view/animation/AlphaAnimation.java new file mode 100644 index 00000000..6391a6ad --- /dev/null +++ b/src/api-impl/android/view/animation/AlphaAnimation.java @@ -0,0 +1,7 @@ +package android.view.animation; + +public class AlphaAnimation extends Animation { + + public AlphaAnimation(float fromAlpha, float toAlpha) { + } +} diff --git a/src/api-impl/android/view/animation/Animation.java b/src/api-impl/android/view/animation/Animation.java index 2376d9aa..92ffe99b 100644 --- a/src/api-impl/android/view/animation/Animation.java +++ b/src/api-impl/android/view/animation/Animation.java @@ -2,4 +2,10 @@ package android.view.animation; public class Animation { + public interface AnimationListener {} + + public void setDuration(long durationMillis) {} + + public void setInterpolator(Interpolator i) {} + } diff --git a/src/api-impl/android/view/animation/AnimationUtils.java b/src/api-impl/android/view/animation/AnimationUtils.java index 15ba6b6a..c206540c 100644 --- a/src/api-impl/android/view/animation/AnimationUtils.java +++ b/src/api-impl/android/view/animation/AnimationUtils.java @@ -4,4 +4,8 @@ import android.content.Context; public class AnimationUtils { public static Animation loadAnimation(Context context, int dummy) { return new Animation(); } + + public static long currentAnimationTimeMillis() { + return System.currentTimeMillis(); + } } diff --git a/src/api-impl/meson.build b/src/api-impl/meson.build index 953f973f..b7028cd2 100644 --- a/src/api-impl/meson.build +++ b/src/api-impl/meson.build @@ -320,6 +320,7 @@ hax_jar = jar('hax', [ 'android/view/WindowManagerImpl.java', 'android/view/WindowManager.java', 'android/view/animation/AccelerateDecelerateInterpolator.java', + 'android/view/animation/AlphaAnimation.java', 'android/view/animation/Animation.java', 'android/view/animation/AnimationUtils.java', 'android/view/animation/LinearInterpolator.java',