Skip to content

Commit

Permalink
[TopAppBar] Applied formatting only.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 713744692
  • Loading branch information
pekingme authored and leticiarossi committed Jan 10, 2025
1 parent d28488d commit 32633a6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
69 changes: 35 additions & 34 deletions lib/java/com/google/android/material/appbar/AppBarLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,14 @@ public AppBarLayout(@NonNull Context context, @Nullable AttributeSet attrs, int
}
}

liftOnScrollColorDuration = MotionUtils.resolveThemeDuration(context,
R.attr.motionDurationMedium2,
getResources().getInteger(R.integer.app_bar_elevation_anim_duration));
liftOnScrollColorInterpolator = MotionUtils.resolveThemeInterpolator(context,
R.attr.motionEasingStandardInterpolator, AnimationUtils.LINEAR_INTERPOLATOR);
liftOnScrollColorDuration =
MotionUtils.resolveThemeDuration(
context,
R.attr.motionDurationMedium2,
getResources().getInteger(R.integer.app_bar_elevation_anim_duration));
liftOnScrollColorInterpolator =
MotionUtils.resolveThemeInterpolator(
context, R.attr.motionEasingStandardInterpolator, AnimationUtils.LINEAR_INTERPOLATOR);

if (a.hasValue(R.styleable.AppBarLayout_expanded)) {
setExpanded(
Expand Down Expand Up @@ -354,16 +357,17 @@ private void initializeLiftOnScrollWithColor(
private void initializeLiftOnScrollWithElevation(
Context context, MaterialShapeDrawable background) {
background.initializeElevationOverlay(context);
liftOnScrollColorUpdateListener = valueAnimator -> {
float elevation = (float) valueAnimator.getAnimatedValue();
background.setElevation(elevation);
if (statusBarForeground instanceof MaterialShapeDrawable) {
((MaterialShapeDrawable) statusBarForeground).setElevation(elevation);
}
for (LiftOnScrollListener liftOnScrollListener : liftOnScrollListeners) {
liftOnScrollListener.onUpdate(elevation, background.getResolvedTintColor());
}
};
liftOnScrollColorUpdateListener =
valueAnimator -> {
float elevation = (float) valueAnimator.getAnimatedValue();
background.setElevation(elevation);
if (statusBarForeground instanceof MaterialShapeDrawable) {
((MaterialShapeDrawable) statusBarForeground).setElevation(elevation);
}
for (LiftOnScrollListener liftOnScrollListener : liftOnScrollListeners) {
liftOnScrollListener.onUpdate(elevation, background.getResolvedTintColor());
}
};

setBackground(background);
}
Expand Down Expand Up @@ -559,8 +563,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
case MeasureSpec.AT_MOST:
// For AT_MOST, we need to clamp our desired height with the max height
newHeight =
clamp(
getMeasuredHeight() + getTopInset(), 0, MeasureSpec.getSize(heightMeasureSpec));
clamp(getMeasuredHeight() + getTopInset(), 0, MeasureSpec.getSize(heightMeasureSpec));
break;
case MeasureSpec.UNSPECIFIED:
// For UNSPECIFIED we can use any height so just add the top inset
Expand Down Expand Up @@ -634,9 +637,10 @@ private void invalidateScrollRanges() {
// If there's a pending action, we should skip this step and respect the pending action.
SavedState savedState =
behavior == null
|| totalScrollRange == INVALID_SCROLL_RANGE
|| pendingAction != PENDING_ACTION_NONE
? null : behavior.saveScrollState(AbsSavedState.EMPTY_STATE, this);
|| totalScrollRange == INVALID_SCROLL_RANGE
|| pendingAction != PENDING_ACTION_NONE
? null
: behavior.saveScrollState(AbsSavedState.EMPTY_STATE, this);
// Invalidate the scroll ranges
totalScrollRange = INVALID_SCROLL_RANGE;
downPreScrollRange = INVALID_SCROLL_RANGE;
Expand Down Expand Up @@ -1040,8 +1044,7 @@ private boolean isLiftOnScrollCompatibleBackground() {
return getBackground() instanceof MaterialShapeDrawable;
}

private void startLiftOnScrollColorAnimation(
float fromValue, float toValue) {
private void startLiftOnScrollColorAnimation(float fromValue, float toValue) {
if (liftOnScrollColorAnimator != null) {
liftOnScrollColorAnimator.cancel();
}
Expand Down Expand Up @@ -1225,6 +1228,7 @@ public static class LayoutParams extends LinearLayout.LayoutParams {
})
@Retention(RetentionPolicy.SOURCE)
public @interface ScrollFlags {}

/**
* Disable scrolling on the view. This flag should not be combined with any of the other scroll
* flags.
Expand Down Expand Up @@ -1296,8 +1300,8 @@ public static class LayoutParams extends LinearLayout.LayoutParams {

/**
* An effect that will "compress" this view as it hits the scroll ceiling (typically the top of
* the screen). This is a parallax effect that masks this view and decreases its scroll ratio
* in relation to the AppBarLayout's offset.
* the screen). This is a parallax effect that masks this view and decreases its scroll ratio in
* relation to the AppBarLayout's offset.
*/
public static final int SCROLL_EFFECT_COMPRESS = 1;

Expand Down Expand Up @@ -1396,9 +1400,7 @@ private ChildScrollEffect createScrollEffectFromInt(int scrollEffectInt) {
}
}

/**
* Get the scroll effect to be applied when the AppBarLayout's offset changes
*/
/** Get the scroll effect to be applied when the AppBarLayout's offset changes */
@Nullable
public ChildScrollEffect getScrollEffect() {
return scrollEffect;
Expand All @@ -1408,7 +1410,7 @@ public ChildScrollEffect getScrollEffect() {
* Set the scroll effect to be applied when the AppBarLayout's offset changes.
*
* @param scrollEffect An {@code AppBarLayoutChildScrollEffect} implementation. If null is
* passed, the scroll effect will be cleared and no effect will be applied.
* passed, the scroll effect will be cleared and no effect will be applied.
*/
public void setScrollEffect(@Nullable ChildScrollEffect scrollEffect) {
this.scrollEffect = scrollEffect;
Expand All @@ -1417,9 +1419,9 @@ public void setScrollEffect(@Nullable ChildScrollEffect scrollEffect) {
/**
* Set the scroll effect to be applied when the AppBarLayout's offset changes.
*
* @param scrollEffect An {@code AppBarLayoutChildScrollEffect} implementation. If
* {@link #SCROLL_EFFECT_NONE} is passed, the scroll effect will be cleared and no
* effect will be applied.
* @param scrollEffect An {@code AppBarLayoutChildScrollEffect} implementation. If {@link
* #SCROLL_EFFECT_NONE} is passed, the scroll effect will be cleared and no effect will be
* applied.
*/
public void setScrollEffect(@ScrollEffect int scrollEffect) {
this.scrollEffect = createScrollEffectFromInt(scrollEffect);
Expand Down Expand Up @@ -1816,7 +1818,7 @@ public boolean onLayoutChild(
// Keep fully expanded.
setHeaderTopBottomOffset(parent, abl, 0);
} else {
// Not fully scrolled, restore the visible percetage of child layout.
// Not fully scrolled, restore the visible percentage of child layout.
View child = abl.getChildAt(savedState.firstVisibleChildIndex);
int offset = -child.getBottom();
if (savedState.firstVisibleChildAtMinimumHeight) {
Expand Down Expand Up @@ -1850,8 +1852,7 @@ public boolean onLayoutChild(

// We may have changed size, so let's constrain the top and bottom offset correctly,
// just in case we're out of the bounds
setTopAndBottomOffset(
clamp(getTopAndBottomOffset(), -abl.getTotalScrollRange(), 0));
setTopAndBottomOffset(clamp(getTopAndBottomOffset(), -abl.getTotalScrollRange(), 0));

// Update the AppBarLayout's drawable state for any elevation changes. This is needed so that
// the elevation is set in the first layout, so that we don't get a visual jump pre-N (due to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2155,14 +2155,16 @@ public void onOffsetChanged(AppBarLayout layout, int verticalOffset) {
int height = getHeight();
final int expandRange = height - getMinimumHeight() - insetTop;
final int scrimRange = height - getScrimVisibleHeightTrigger();
final int currentOffsetY = currentOffset + expandRange;
final float expansionFraction = Math.abs(verticalOffset) / (float) expandRange;
collapsingTitleHelper.setFadeModeStartFraction(
Math.min(1, (float) scrimRange / (float) expandRange));
collapsingTitleHelper.setCurrentOffsetY(currentOffset + expandRange);
collapsingTitleHelper.setExpansionFraction(Math.abs(verticalOffset) / (float) expandRange);
collapsingTitleHelper.setCurrentOffsetY(currentOffsetY);
collapsingTitleHelper.setExpansionFraction(expansionFraction);
collapsingSubtitleHelper.setFadeModeStartFraction(
Math.min(1, (float) scrimRange / (float) expandRange));
collapsingSubtitleHelper.setCurrentOffsetY(currentOffset + expandRange);
collapsingSubtitleHelper.setExpansionFraction(Math.abs(verticalOffset) / (float) expandRange);
collapsingSubtitleHelper.setCurrentOffsetY(currentOffsetY);
collapsingSubtitleHelper.setExpansionFraction(expansionFraction);
}
}

Expand Down

0 comments on commit 32633a6

Please sign in to comment.