diff --git a/README.md b/README.md index 451acae..471c9d8 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Add the dependency ```groovy dependencies { // After AndroidX - implementation ('com.github.niorgai:StatusBarCompat:2.3.2', { + implementation ('com.github.niorgai:StatusBarCompat:2.3.3', { exclude group: 'androidx.appcompat:appcompat' exclude group: 'com.google.android.material:material' }) diff --git a/library/src/main/java/qiu/niorgai/StatusBarCompatLollipop.java b/library/src/main/java/qiu/niorgai/StatusBarCompatLollipop.java index 876cab7..a734821 100644 --- a/library/src/main/java/qiu/niorgai/StatusBarCompatLollipop.java +++ b/library/src/main/java/qiu/niorgai/StatusBarCompatLollipop.java @@ -156,15 +156,15 @@ public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { - final Window weakWindow = windowWeakReference.get(); + Window weakWindow = windowWeakReference.get(); if (weakWindow != null) { if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { if (weakWindow.getStatusBarColor() != statusColor) { - startColorAnimation(weakWindow.getStatusBarColor(), statusColor, collapsingToolbarLayout.getScrimAnimationDuration(), weakWindow); + startColorAnimation(weakWindow.getStatusBarColor(), statusColor, collapsingToolbarLayout.getScrimAnimationDuration(), windowWeakReference); } } else { if (weakWindow.getStatusBarColor() != Color.TRANSPARENT) { - startColorAnimation(weakWindow.getStatusBarColor(), Color.TRANSPARENT, collapsingToolbarLayout.getScrimAnimationDuration(), weakWindow); + startColorAnimation(weakWindow.getStatusBarColor(), Color.TRANSPARENT, collapsingToolbarLayout.getScrimAnimationDuration(), windowWeakReference); } } } @@ -177,7 +177,7 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { /** * use ValueAnimator to change statusBarColor when using collapsingToolbarLayout */ - private static void startColorAnimation(int startColor, int endColor, long duration, final Window window) { + private static void startColorAnimation(int startColor, int endColor, long duration, final WeakReference windowWeakReference) { if (sAnimator != null) { sAnimator.cancel(); } @@ -186,6 +186,7 @@ private static void startColorAnimation(int startColor, int endColor, long durat sAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { + final Window window = windowWeakReference.get(); if (window != null) { window.setStatusBarColor((Integer) valueAnimator.getAnimatedValue()); }