From 05749f4fd044c0f49b9619beddd6104d76c84309 Mon Sep 17 00:00:00 2001 From: mengxn Date: Fri, 29 May 2020 15:37:20 +0800 Subject: [PATCH] listen animation state --- .../main/java/com/facebook/shimmer/ShimmerDrawable.java | 9 +++++++++ .../java/com/facebook/shimmer/ShimmerFrameLayout.java | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/shimmer/src/main/java/com/facebook/shimmer/ShimmerDrawable.java b/shimmer/src/main/java/com/facebook/shimmer/ShimmerDrawable.java index 79ace05..ed60dd8 100644 --- a/shimmer/src/main/java/com/facebook/shimmer/ShimmerDrawable.java +++ b/shimmer/src/main/java/com/facebook/shimmer/ShimmerDrawable.java @@ -8,6 +8,7 @@ package com.facebook.shimmer; +import android.animation.Animator; import android.animation.ValueAnimator; import android.graphics.Canvas; import android.graphics.ColorFilter; @@ -63,7 +64,15 @@ public void setShimmer(@Nullable Shimmer shimmer) { /** Starts the shimmer animation. */ public void startShimmer() { + startShimmer(null); + } + + /** Starts the shimmer animation with animation listener. */ + public void startShimmer(Animator.AnimatorListener listener) { if (mValueAnimator != null && !isShimmerStarted() && getCallback() != null) { + if (listener != null) { + mValueAnimator.addListener(listener); + } mValueAnimator.start(); } } diff --git a/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java b/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java index bd6f160..6e1b9f5 100644 --- a/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java +++ b/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java @@ -8,6 +8,7 @@ package com.facebook.shimmer; +import android.animation.Animator; import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; @@ -94,7 +95,12 @@ public ShimmerFrameLayout setShimmer(@Nullable Shimmer shimmer) { /** Starts the shimmer animation. */ public void startShimmer() { - mShimmerDrawable.startShimmer(); + startShimmer(null); + } + + /** Starts the shimmer animation with animation listener. */ + public void startShimmer(Animator.AnimatorListener listener) { + mShimmerDrawable.startShimmer(listener); } /** Stops the shimmer animation. */