@@ -223,7 +223,7 @@ public class MaterialContainerTransform extends Transition {
223
223
@ IdRes private int startViewId = View .NO_ID ;
224
224
@ IdRes private int endViewId = View .NO_ID ;
225
225
@ ColorInt private int containerColor = Color .TRANSPARENT ;
226
- @ ColorInt private int scrimColor ;
226
+ @ ColorInt private int scrimColor = - 1 ;
227
227
@ TransitionDirection private int transitionDirection = TRANSITION_DIRECTION_AUTO ;
228
228
@ FadeMode private int fadeMode = FADE_MODE_IN ;
229
229
@ FitMode private int fitMode = FIT_MODE_AUTO ;
@@ -236,9 +236,8 @@ public class MaterialContainerTransform extends Transition {
236
236
@ Nullable private ProgressThresholds scaleMaskProgressThresholds ;
237
237
@ Nullable private ProgressThresholds shapeMaskProgressThresholds ;
238
238
239
- public MaterialContainerTransform (@ NonNull Context context ) {
239
+ public MaterialContainerTransform () {
240
240
setInterpolator (AnimationUtils .FAST_OUT_SLOW_IN_INTERPOLATOR );
241
- scrimColor = getDefaultScrimColor (context );
242
241
}
243
242
244
243
/** Get the id of the View which will be used as the start shared element container. */
@@ -368,8 +367,8 @@ public int getDrawingViewId() {
368
367
/**
369
368
* Set the id of the View whose overlay this transition will be added to.
370
369
*
371
- * <p>If {@param drawingViewId} is the same as the end View's id, MaterialContainerTransform
372
- * will add the transition's drawable to the {@param drawingViewId}'s parent instead.
370
+ * <p>If {@param drawingViewId} is the same as the end View's id, MaterialContainerTransform will
371
+ * add the transition's drawable to the {@param drawingViewId}'s parent instead.
373
372
*/
374
373
public void setDrawingViewId (@ IdRes int drawingViewId ) {
375
374
this .drawingViewId = drawingViewId ;
@@ -400,6 +399,9 @@ public void setContainerColor(@ColorInt int containerColor) {
400
399
/**
401
400
* Get the color to be drawn under the morphing container but within the bounds of the {@link
402
401
* #getDrawingViewId()}.
402
+ *
403
+ * <p>If this is not set, -1 will be returned, meaning the default, R.attr.scrimBackground, will
404
+ * be as the scrim color.
403
405
*/
404
406
@ ColorInt
405
407
public int getScrimColor () {
@@ -410,14 +412,14 @@ public int getScrimColor() {
410
412
* Set the color to be drawn under the morphing container but within the bounds of the {@link
411
413
* #getDrawingViewId()}.
412
414
*
413
- * <p>By default this is set to your theme's {@link R.attr#scrimBackground}. Drawing a scrim
414
- * is primarily useful for transforming from a partial-screen View (eg. Card in a grid) to a full
415
+ * <p>By default this is set to your theme's {@link R.attr#scrimBackground}. Drawing a scrim is
416
+ * primarily useful for transforming from a partial-screen View (eg. Card in a grid) to a full
415
417
* screen. The scrim will gradually fade in and cover the content being transformed over by the
416
418
* morphing container.
417
419
*
418
420
* <p>Manually setting a scrim color can be useful when transitioning between two Views in a
419
421
* layout, where the ending View does not cover any outgoing content (eg. a FAB to a bottom
420
- * toolbar). For scenarios such as these, set the scrim color to transparent.
422
+ * toolbar). For scenarios such as these, set the scrim color to transparent (0) .
421
423
*/
422
424
public void setScrimColor (@ ColorInt int scrimColor ) {
423
425
this .scrimColor = scrimColor ;
@@ -447,18 +449,14 @@ public void setTransitionDirection(@TransitionDirection int transitionDirection)
447
449
this .transitionDirection = transitionDirection ;
448
450
}
449
451
450
- /**
451
- * The fade mode to be used to swap the content of the start View with that of the end
452
- * View.
453
- */
452
+ /** The fade mode to be used to swap the content of the start View with that of the end View. */
454
453
@ FadeMode
455
454
public int getFadeMode () {
456
455
return fadeMode ;
457
456
}
458
457
459
458
/**
460
- * Set the fade mode to be used to swap the content of the start View with that of the end
461
- * View.
459
+ * Set the fade mode to be used to swap the content of the start View with that of the end View.
462
460
*
463
461
* <p>By default, the fade mode is set to {@link #FADE_MODE_IN}.
464
462
*
@@ -740,7 +738,7 @@ public Animator createAnimator(
740
738
endBounds ,
741
739
endShapeAppearanceModel ,
742
740
containerColor ,
743
- scrimColor ,
741
+ getScrimColorOrDefault ( startView . getContext ()) ,
744
742
entering ,
745
743
FadeModeEvaluators .get (fadeMode , entering ),
746
744
FitModeEvaluators .get (fitMode , entering , startBounds , endBounds ),
@@ -793,9 +791,15 @@ public void onAnimationEnd(Animator animation) {
793
791
}
794
792
795
793
@ ColorInt
796
- private static int getDefaultScrimColor (Context context ) {
797
- return MaterialColors .getColor (
798
- context , R .attr .scrimBackground , ContextCompat .getColor (context , R .color .mtrl_scrim_color ));
794
+ private int getScrimColorOrDefault (Context context ) {
795
+ if (scrimColor == -1 ) {
796
+ return MaterialColors .getColor (
797
+ context ,
798
+ R .attr .scrimBackground ,
799
+ ContextCompat .getColor (context , R .color .mtrl_scrim_color ));
800
+ }
801
+
802
+ return scrimColor ;
799
803
}
800
804
801
805
private static RectF calculateDrawableBounds (
@@ -1075,8 +1079,7 @@ private void updateProgress(float progress) {
1075
1079
currentStartBounds ,
1076
1080
currentStartBoundsMasked ,
1077
1081
currentEndBoundsMasked ,
1078
- progressThresholds .shapeMask
1079
- );
1082
+ progressThresholds .shapeMask );
1080
1083
1081
1084
// Cross-fade images of the start/end states over range of `progress`
1082
1085
float fadeStartFraction = checkNotNull (progressThresholds .fade .start );
0 commit comments