From e8cf5f6678464d676d09e5aa2ffc72d73e960a14 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Wed, 30 Nov 2016 01:27:22 +0000 Subject: [PATCH] am 581de875: am 25c8477a: Merge "Improvements around CollapsingToolbarLayout\'s scrims" into mnc-ub-dev * commit '581de87570b31ac402eb2be6467227e59c475462': Improvements around CollapsingToolbarLayout's scrims GitOrigin-RevId=8942fdd83bf150fc26e198e1b2dafcbff00e79ef PiperOrigin-RevId: 140549623 --- api/current.txt | 2 + .../widget/CollapsingToolbarLayout.java | 62 +++++++++++-------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/api/current.txt b/api/current.txt index e8a1f33fb..789c23918 100644 --- a/api/current.txt +++ b/api/current.txt @@ -84,6 +84,8 @@ package android.support.design.widget { method public void setExpandedTitleColor(int); method public void setExpandedTitleGravity(int); method public void setExpandedTitleTextAppearance(int); + method public void setScrimsShown(boolean); + method public void setScrimsShown(boolean, boolean); method public void setStatusBarScrim(android.graphics.drawable.Drawable); method public void setStatusBarScrimColor(int); method public void setStatusBarScrimResource(int); diff --git a/src/android/support/design/widget/CollapsingToolbarLayout.java b/src/android/support/design/widget/CollapsingToolbarLayout.java index 5c65e5195..1f4509892 100644 --- a/src/android/support/design/widget/CollapsingToolbarLayout.java +++ b/src/android/support/design/widget/CollapsingToolbarLayout.java @@ -464,25 +464,38 @@ public class CollapsingToolbarLayout extends FrameLayout { return mCollapsingTitleEnabled; } - private void showScrim() { - if (!mScrimsAreShown) { - if (ViewCompat.isLaidOut(this) && !isInEditMode()) { - animateScrim(255); - } else { - setScrimAlpha(255); - } - mScrimsAreShown = true; - } + /** + * Set whether the content scrim and/or status bar scrim should be shown or not. Any change + * in the vertical scroll may overwrite this value. Any visibility change will be animated if + * this view has already been laid out. + * + * @param shown whether the scrims should be shown + * + * @see #getStatusBarScrim() + * @see #getContentScrim() + */ + public void setScrimsShown(boolean shown) { + setScrimsShown(shown, ViewCompat.isLaidOut(this) && !isInEditMode()); } - private void hideScrim() { - if (mScrimsAreShown) { - if (ViewCompat.isLaidOut(this) && !isInEditMode()) { - animateScrim(0); + /** + * Set whether the content scrim and/or status bar scrim should be shown or not. Any change + * in the vertical scroll may overwrite this value. + * + * @param shown whether the scrims should be shown + * @param animate whether to animate the visibility change + * + * @see #getStatusBarScrim() + * @see #getContentScrim() + */ + public void setScrimsShown(boolean shown, boolean animate) { + if (mScrimsAreShown != shown) { + if (animate) { + animateScrim(shown ? 0xFF : 0x0); } else { - setScrimAlpha(0); + setScrimAlpha(shown ? 0xFF : 0x0); } - mScrimsAreShown = false; + mScrimsAreShown = shown; } } @@ -531,11 +544,14 @@ public class CollapsingToolbarLayout extends FrameLayout { if (mContentScrim != null) { mContentScrim.setCallback(null); } - - mContentScrim = drawable; - drawable.setBounds(0, 0, getWidth(), getHeight()); - drawable.setCallback(this); - drawable.mutate().setAlpha(mScrimAlpha); + if (drawable != null) { + mContentScrim = drawable.mutate(); + drawable.setBounds(0, 0, getWidth(), getHeight()); + drawable.setCallback(this); + drawable.setAlpha(mScrimAlpha); + } else { + mContentScrim = null; + } ViewCompat.postInvalidateOnAnimation(this); } } @@ -880,11 +896,7 @@ public class CollapsingToolbarLayout extends FrameLayout { // Show or hide the scrims if needed if (mContentScrim != null || mStatusBarScrim != null) { - if (getHeight() + verticalOffset < getScrimTriggerOffset() + insetTop) { - showScrim(); - } else { - hideScrim(); - } + setScrimsShown(getHeight() + verticalOffset < getScrimTriggerOffset() + insetTop); } if (mStatusBarScrim != null && insetTop > 0) {