From 841b7df9155366f6e2daaa01964f6eea8ff71f21 Mon Sep 17 00:00:00 2001 From: Scott C Date: Fri, 28 Jun 2019 10:25:59 +0100 Subject: [PATCH 1/2] Add show + hide functionality --- .../facebook/shimmer/ShimmerFrameLayout.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java b/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java index 36e1b30..8c6a4e9 100644 --- a/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java +++ b/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java @@ -30,6 +30,8 @@ public class ShimmerFrameLayout extends FrameLayout { private final Paint mContentPaint = new Paint(); private final ShimmerDrawable mShimmerDrawable = new ShimmerDrawable(); + private Boolean mShowShimmer = true; + public ShimmerFrameLayout(Context context) { super(context); init(context, null); @@ -100,6 +102,36 @@ public boolean isShimmerStarted() { return mShimmerDrawable.isShimmerStarted(); } + /** + * Sets the ShimmerDrawable to be visible. + * @param startShimmer Whether to start the shimmer again. + */ + public void showShimmer(boolean startShimmer) { + if (mShowShimmer) { + return; + } + mShowShimmer = true; + if (startShimmer) { + startShimmer(); + } + } + + /** Sets the ShimmerDrawable to be invisible, stopping it in the process. */ + public void hideShimmer() { + if (!mShowShimmer) { + return; + } + + stopShimmer(); + mShowShimmer = false; + invalidate(); + } + + /** Return whether the shimmer drawable is visible. */ + public boolean isShimmerVisible() { + return mShowShimmer; + } + @Override public void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); @@ -123,7 +155,9 @@ public void onDetachedFromWindow() { @Override public void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); - mShimmerDrawable.draw(canvas); + if (mShowShimmer) { + mShimmerDrawable.draw(canvas); + } } @Override From 3bd25dbcc9c87799fb514b6fb442daad6d144d4e Mon Sep 17 00:00:00 2001 From: Scott C Date: Fri, 28 Jun 2019 10:36:19 +0100 Subject: [PATCH 2/2] Replace boxed bool with primitive --- .../src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java b/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java index 8c6a4e9..42c8fbe 100644 --- a/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java +++ b/shimmer/src/main/java/com/facebook/shimmer/ShimmerFrameLayout.java @@ -30,7 +30,7 @@ public class ShimmerFrameLayout extends FrameLayout { private final Paint mContentPaint = new Paint(); private final ShimmerDrawable mShimmerDrawable = new ShimmerDrawable(); - private Boolean mShowShimmer = true; + private boolean mShowShimmer = true; public ShimmerFrameLayout(Context context) { super(context);