com.google.android.material.animation.AnimationUtils Java Examples
The following examples show how to use
com.google.android.material.animation.AnimationUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HideTopViewOnScrollBehavior.java From HaoReader with GNU General Public License v3.0 | 6 votes |
/** * Perform an animation that will slide the child from it's current position to be totally off the * screen. */ public void slideDown(V child) { if (currentState == STATE_SCROLLED_DOWN) { return; } if (currentAnimator != null) { currentAnimator.cancel(); child.clearAnimation(); } currentState = STATE_SCROLLED_DOWN; animateChildTo( child, 0, EXIT_ANIMATION_DURATION, AnimationUtils.FAST_OUT_LINEAR_IN_INTERPOLATOR); }
Example #2
Source File: BookFloatingActionMenu.java From HaoReader with GNU General Public License v3.0 | 6 votes |
private void animateShowLabelView(View labelView) { labelView.animate().cancel(); if (labelView.getVisibility() != VISIBLE) { labelView.setTranslationX(1.0f * labelView.getWidth() / 2); labelView.setAlpha(0f); } labelView.animate().translationX(0f).alpha(1f) .setDuration(200L) .setInterpolator(AnimationUtils.LINEAR_OUT_SLOW_IN_INTERPOLATOR) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { labelView.setVisibility(VISIBLE); } }) .start(); }
Example #3
Source File: AppBarLayout.java From material-components-android with Apache License 2.0 | 6 votes |
private void startLiftOnScrollElevationOverlayAnimation( @NonNull final MaterialShapeDrawable background, boolean lifted) { float appBarElevation = getResources().getDimension(R.dimen.design_appbar_elevation); float fromElevation = lifted ? 0 : appBarElevation; float toElevation = lifted ? appBarElevation : 0; if (elevationOverlayAnimator != null) { elevationOverlayAnimator.cancel(); } elevationOverlayAnimator = ValueAnimator.ofFloat(fromElevation, toElevation); elevationOverlayAnimator.setDuration( getResources().getInteger(R.integer.app_bar_elevation_anim_duration)); elevationOverlayAnimator.setInterpolator(AnimationUtils.LINEAR_INTERPOLATOR); elevationOverlayAnimator.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) { background.setElevation((float) valueAnimator.getAnimatedValue()); } }); elevationOverlayAnimator.start(); }
Example #4
Source File: CircularIndeterminateAnimatorDelegate.java From material-components-android with Apache License 2.0 | 6 votes |
@Override protected void registerDrawable(@NonNull IndeterminateDrawable drawable) { super.registerDrawable(drawable); colorFadingAnimator = ObjectAnimator.ofObject( this, DISPLAYED_INDICATOR_COLOR, new ArgbEvaluatorCompat(), drawable.combinedIndicatorColorArray[indicatorColorIndex], drawable.combinedIndicatorColorArray[getNextIndicatorColorIndex()]); colorFadingAnimator.setDuration(COLOR_FADING_DURATION); colorFadingAnimator.setStartDelay(COLOR_FADING_DELAY); colorFadingAnimator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); animatorSet.playTogether(colorFadingAnimator); }
Example #5
Source File: HideBottomViewOnScrollBehavior.java From material-components-android with Apache License 2.0 | 6 votes |
/** * Perform an animation that will slide the child from it's current position to be totally off the * screen. */ public void slideDown(@NonNull V child) { if (currentState == STATE_SCROLLED_DOWN) { return; } if (currentAnimator != null) { currentAnimator.cancel(); child.clearAnimation(); } currentState = STATE_SCROLLED_DOWN; animateChildTo( child, height + additionalHiddenOffsetY, EXIT_ANIMATION_DURATION, AnimationUtils.FAST_OUT_LINEAR_IN_INTERPOLATOR); }
Example #6
Source File: DropdownMenuEndIconDelegate.java From material-components-android with Apache License 2.0 | 5 votes |
private ValueAnimator getAlphaAnimator(int duration, float... values) { ValueAnimator animator = ValueAnimator.ofFloat(values); animator.setInterpolator(AnimationUtils.LINEAR_INTERPOLATOR); animator.setDuration(duration); animator.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(@NonNull ValueAnimator animation) { float alpha = (float) animation.getAnimatedValue(); endIconView.setAlpha(alpha); } }); return animator; }
Example #7
Source File: HideTopViewOnScrollBehavior.java From HaoReader with GNU General Public License v3.0 | 5 votes |
/** * Perform an animation that will slide the child from it's current position to be totally on the * screen. */ public void slideUp(V child) { if (currentState == STATE_SCROLLED_UP) { return; } if (currentAnimator != null) { currentAnimator.cancel(); child.clearAnimation(); } currentState = STATE_SCROLLED_UP; animateChildTo( child, -height + additionalHiddenOffsetY, ENTER_ANIMATION_DURATION, AnimationUtils.LINEAR_OUT_SLOW_IN_INTERPOLATOR); }
Example #8
Source File: ClearTextEndIconDelegate.java From material-components-android with Apache License 2.0 | 5 votes |
private ValueAnimator getScaleAnimator() { ValueAnimator animator = ValueAnimator.ofFloat(ANIMATION_SCALE_FROM_VALUE, 1); animator.setInterpolator(AnimationUtils.LINEAR_OUT_SLOW_IN_INTERPOLATOR); animator.setDuration(ANIMATION_SCALE_DURATION); animator.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(@NonNull ValueAnimator animation) { float scale = (float) animation.getAnimatedValue(); endIconView.setScaleX(scale); endIconView.setScaleY(scale); } }); return animator; }
Example #9
Source File: ClearTextEndIconDelegate.java From material-components-android with Apache License 2.0 | 5 votes |
private ValueAnimator getAlphaAnimator(float... values) { ValueAnimator animator = ValueAnimator.ofFloat(values); animator.setInterpolator(AnimationUtils.LINEAR_INTERPOLATOR); animator.setDuration(ANIMATION_FADE_DURATION); animator.addUpdateListener( new AnimatorUpdateListener() { @Override public void onAnimationUpdate(@NonNull ValueAnimator animation) { float alpha = (float) animation.getAnimatedValue(); endIconView.setAlpha(alpha); } }); return animator; }
Example #10
Source File: IndicatorViewController.java From material-components-android with Apache License 2.0 | 5 votes |
private ObjectAnimator createCaptionTranslationYAnimator(TextView captionView) { ObjectAnimator translationYAnimator = ObjectAnimator.ofFloat(captionView, TRANSLATION_Y, -captionTranslationYPx, 0f); translationYAnimator.setDuration(CAPTION_TRANSLATE_Y_ANIMATION_DURATION); translationYAnimator.setInterpolator(AnimationUtils.LINEAR_OUT_SLOW_IN_INTERPOLATOR); return translationYAnimator; }
Example #11
Source File: IndicatorViewController.java From material-components-android with Apache License 2.0 | 5 votes |
private ObjectAnimator createCaptionOpacityAnimator(TextView captionView, boolean display) { float endValue = display ? 1f : 0f; ObjectAnimator opacityAnimator = ObjectAnimator.ofFloat(captionView, View.ALPHA, endValue); opacityAnimator.setDuration(CAPTION_OPACITY_FADE_ANIMATION_DURATION); opacityAnimator.setInterpolator(AnimationUtils.LINEAR_INTERPOLATOR); return opacityAnimator; }
Example #12
Source File: CollapsingTextHelper.java From material-components-android with Apache License 2.0 | 5 votes |
private static float lerp( float startValue, float endValue, float fraction, @Nullable TimeInterpolator interpolator) { if (interpolator != null) { fraction = interpolator.getInterpolation(fraction); } return AnimationUtils.lerp(startValue, endValue, fraction); }
Example #13
Source File: CollapsingTextHelper.java From material-components-android with Apache License 2.0 | 5 votes |
private void calculateOffsets(final float fraction) { interpolateBounds(fraction); currentDrawX = lerp(expandedDrawX, collapsedDrawX, fraction, positionInterpolator); currentDrawY = lerp(expandedDrawY, collapsedDrawY, fraction, positionInterpolator); setInterpolatedTextSize( lerp(expandedTextSize, collapsedTextSize, fraction, textSizeInterpolator)); setCollapsedTextBlend( 1 - lerp(0, 1, 1 - fraction, AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR)); setExpandedTextBlend(lerp(1, 0, fraction, AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR)); if (collapsedTextColor != expandedTextColor) { // If the collapsed and expanded text colors are different, blend them based on the // fraction textPaint.setColor( blendColors(getCurrentExpandedTextColor(), getCurrentCollapsedTextColor(), fraction)); } else { textPaint.setColor(getCurrentCollapsedTextColor()); } textPaint.setShadowLayer( lerp(expandedShadowRadius, collapsedShadowRadius, fraction, null), lerp(expandedShadowDx, collapsedShadowDx, fraction, null), lerp(expandedShadowDy, collapsedShadowDy, fraction, null), blendColors( getCurrentColor(expandedShadowColor), getCurrentColor(collapsedShadowColor), fraction)); ViewCompat.postInvalidateOnAnimation(view); }
Example #14
Source File: HideBottomViewOnScrollBehavior.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Perform an animation that will slide the child from it's current position to be totally on the * screen. */ public void slideUp(@NonNull V child) { if (currentState == STATE_SCROLLED_UP) { return; } if (currentAnimator != null) { currentAnimator.cancel(); child.clearAnimation(); } currentState = STATE_SCROLLED_UP; animateChildTo( child, 0, ENTER_ANIMATION_DURATION, AnimationUtils.LINEAR_OUT_SLOW_IN_INTERPOLATOR); }
Example #15
Source File: AppBarLayout.java From material-components-android with Apache License 2.0 | 5 votes |
public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.AppBarLayout_Layout); scrollFlags = a.getInt(R.styleable.AppBarLayout_Layout_layout_scrollFlags, 0); if (a.hasValue(R.styleable.AppBarLayout_Layout_layout_scrollInterpolator)) { int resId = a.getResourceId(R.styleable.AppBarLayout_Layout_layout_scrollInterpolator, 0); scrollInterpolator = android.view.animation.AnimationUtils.loadInterpolator(c, resId); } a.recycle(); }
Example #16
Source File: SubtitleCollapsingTextHelper.java From collapsingtoolbarlayout-subtitle with Apache License 2.0 | 5 votes |
private static float lerp( float startValue, float endValue, float fraction, @Nullable TimeInterpolator interpolator) { if (interpolator != null) { fraction = interpolator.getInterpolation(fraction); } return AnimationUtils.lerp(startValue, endValue, fraction); }
Example #17
Source File: BookFloatingActionMenu.java From HaoReader with GNU General Public License v3.0 | 5 votes |
private void animateHideLabelView(View labelView) { labelView.animate().cancel(); labelView.animate().translationX(1.0f * labelView.getWidth() / 2).alpha(0f) .setDuration(200L) .setInterpolator(AnimationUtils.FAST_OUT_LINEAR_IN_INTERPOLATOR) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { labelView.setVisibility(GONE); } }).start(); }
Example #18
Source File: MaterialVisibility.java From material-components-android with Apache License 2.0 | 4 votes |
protected MaterialVisibility( P primaryAnimatorProvider, @Nullable VisibilityAnimatorProvider secondaryAnimatorProvider) { this.primaryAnimatorProvider = primaryAnimatorProvider; this.secondaryAnimatorProvider = secondaryAnimatorProvider; setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); }
Example #19
Source File: DrawableWithAnimatedVisibilityChange.java From material-components-android with Apache License 2.0 | 4 votes |
private void initializeShowAnimator() { showAnimator = ObjectAnimator.ofFloat(this, GROW_FRACTION, 0f, 1f); showAnimator.setDuration(GROW_DURATION); showAnimator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); setShowAnimator(showAnimator); }
Example #20
Source File: DrawableWithAnimatedVisibilityChange.java From material-components-android with Apache License 2.0 | 4 votes |
private void initializeHideAnimator() { hideAnimator = ObjectAnimator.ofFloat(this, GROW_FRACTION, 1f, 0f); hideAnimator.setDuration(GROW_DURATION); hideAnimator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); setHideAnimator(hideAnimator); }
Example #21
Source File: MaterialContainerTransform.java From material-components-android with Apache License 2.0 | 4 votes |
public MaterialContainerTransform() { setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); }
Example #22
Source File: MaterialVisibility.java From material-components-android with Apache License 2.0 | 4 votes |
protected MaterialVisibility( P primaryAnimatorProvider, @Nullable VisibilityAnimatorProvider secondaryAnimatorProvider) { this.primaryAnimatorProvider = primaryAnimatorProvider; this.secondaryAnimatorProvider = secondaryAnimatorProvider; setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); }
Example #23
Source File: MaterialContainerTransform.java From material-components-android with Apache License 2.0 | 4 votes |
public MaterialContainerTransform() { setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); }
Example #24
Source File: CollapsingToolbarLayout.java From material-components-android with Apache License 2.0 | 4 votes |
public CollapsingToolbarLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(wrap(context, attrs, defStyleAttr, DEF_STYLE_RES), attrs, defStyleAttr); // Ensure we are using the correctly themed context rather than the context that was passed in. context = getContext(); collapsingTextHelper = new CollapsingTextHelper(this); collapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR); TypedArray a = ThemeEnforcement.obtainStyledAttributes( context, attrs, R.styleable.CollapsingToolbarLayout, defStyleAttr, DEF_STYLE_RES); collapsingTextHelper.setExpandedTextGravity( a.getInt( R.styleable.CollapsingToolbarLayout_expandedTitleGravity, GravityCompat.START | Gravity.BOTTOM)); collapsingTextHelper.setCollapsedTextGravity( a.getInt( R.styleable.CollapsingToolbarLayout_collapsedTitleGravity, GravityCompat.START | Gravity.CENTER_VERTICAL)); expandedMarginStart = expandedMarginTop = expandedMarginEnd = expandedMarginBottom = a.getDimensionPixelSize( R.styleable.CollapsingToolbarLayout_expandedTitleMargin, 0); if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart)) { expandedMarginStart = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart, 0); } if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd)) { expandedMarginEnd = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd, 0); } if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop)) { expandedMarginTop = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop, 0); } if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom)) { expandedMarginBottom = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom, 0); } collapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_titleEnabled, true); setTitle(a.getText(R.styleable.CollapsingToolbarLayout_title)); // First load the default text appearances collapsingTextHelper.setExpandedTextAppearance( R.style.TextAppearance_Design_CollapsingToolbar_Expanded); collapsingTextHelper.setCollapsedTextAppearance( androidx.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Title); // Now overlay any custom text appearances if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance)) { collapsingTextHelper.setExpandedTextAppearance( a.getResourceId(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance, 0)); } if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance)) { collapsingTextHelper.setCollapsedTextAppearance( a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0)); } scrimVisibleHeightTrigger = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_scrimVisibleHeightTrigger, -1); if (a.hasValue(R.styleable.CollapsingToolbarLayout_maxLines)) { collapsingTextHelper.setMaxLines(a.getInt(R.styleable.CollapsingToolbarLayout_maxLines, 1)); } scrimAnimationDuration = a.getInt( R.styleable.CollapsingToolbarLayout_scrimAnimationDuration, DEFAULT_SCRIM_ANIMATION_DURATION); setContentScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_contentScrim)); setStatusBarScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_statusBarScrim)); toolbarId = a.getResourceId(R.styleable.CollapsingToolbarLayout_toolbarId, -1); a.recycle(); setWillNotDraw(false); ViewCompat.setOnApplyWindowInsetsListener( this, new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets( View v, @NonNull WindowInsetsCompat insets) { return onWindowInsetChanged(insets); } }); }
Example #25
Source File: SubtitleCollapsingToolbarLayout.java From collapsingtoolbarlayout-subtitle with Apache License 2.0 | 4 votes |
public SubtitleCollapsingToolbarLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); collapsingTextHelper = new SubtitleCollapsingTextHelper(this); collapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR); TypedArray a = ThemeEnforcement.obtainStyledAttributes( context, attrs, R.styleable.SubtitleCollapsingToolbarLayout, defStyleAttr, R.style.Widget_Design_SubtitleCollapsingToolbar); collapsingTextHelper.setExpandedTextGravity(a.getInt( R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleGravity, GravityCompat.START | Gravity.BOTTOM)); collapsingTextHelper.setCollapsedTextGravity(a.getInt( R.styleable.SubtitleCollapsingToolbarLayout_collapsedTitleGravity, GravityCompat.START | Gravity.CENTER_VERTICAL)); expandedMarginStart = expandedMarginTop = expandedMarginEnd = expandedMarginBottom = a.getDimensionPixelSize(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleMargin, 0); if (a.hasValue(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleMarginStart)) { expandedMarginStart = a.getDimensionPixelSize(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleMarginStart, 0); } if (a.hasValue(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleMarginEnd)) { expandedMarginEnd = a.getDimensionPixelSize(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleMarginEnd, 0); } if (a.hasValue(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleMarginTop)) { expandedMarginTop = a.getDimensionPixelSize(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleMarginTop, 0); } if (a.hasValue(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleMarginBottom)) { expandedMarginBottom = a.getDimensionPixelSize(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleMarginBottom, 0); } collapsingTitleEnabled = a.getBoolean(R.styleable.SubtitleCollapsingToolbarLayout_titleEnabled, true); setTitle(a.getText(R.styleable.SubtitleCollapsingToolbarLayout_title)); setSubtitle(a.getText(R.styleable.SubtitleCollapsingToolbarLayout_subtitle)); // First load the default text appearances collapsingTextHelper.setExpandedTitleTextAppearance( R.style.TextAppearance_Design_SubtitleCollapsingToolbar_ExpandedTitle); collapsingTextHelper.setCollapsedTitleTextAppearance( androidx.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Title); collapsingTextHelper.setExpandedSubtitleTextAppearance( R.style.TextAppearance_Design_SubtitleCollapsingToolbar_ExpandedSubtitle); collapsingTextHelper.setCollapsedSubtitleTextAppearance( androidx.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Subtitle); // Now overlay any custom text appearances if (a.hasValue(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleTextAppearance)) { collapsingTextHelper.setExpandedTitleTextAppearance( a.getResourceId(R.styleable.SubtitleCollapsingToolbarLayout_expandedTitleTextAppearance, 0)); } if (a.hasValue(R.styleable.SubtitleCollapsingToolbarLayout_collapsedTitleTextAppearance)) { collapsingTextHelper.setCollapsedTitleTextAppearance( a.getResourceId(R.styleable.SubtitleCollapsingToolbarLayout_collapsedTitleTextAppearance, 0)); } if (a.hasValue(R.styleable.SubtitleCollapsingToolbarLayout_expandedSubtitleTextAppearance)) { collapsingTextHelper.setExpandedSubtitleTextAppearance( a.getResourceId(R.styleable.SubtitleCollapsingToolbarLayout_expandedSubtitleTextAppearance, 0)); } if (a.hasValue(R.styleable.SubtitleCollapsingToolbarLayout_collapsedSubtitleTextAppearance)) { collapsingTextHelper.setCollapsedSubtitleTextAppearance( a.getResourceId(R.styleable.SubtitleCollapsingToolbarLayout_collapsedSubtitleTextAppearance, 0)); } scrimVisibleHeightTrigger = a .getDimensionPixelSize(R.styleable.SubtitleCollapsingToolbarLayout_scrimVisibleHeightTrigger, -1); scrimAnimationDuration = a.getInt( R.styleable.SubtitleCollapsingToolbarLayout_scrimAnimationDuration, DEFAULT_SCRIM_ANIMATION_DURATION); setContentScrim(a.getDrawable(R.styleable.SubtitleCollapsingToolbarLayout_contentScrim)); setStatusBarScrim(a.getDrawable(R.styleable.SubtitleCollapsingToolbarLayout_statusBarScrim)); toolbarId = a.getResourceId(R.styleable.SubtitleCollapsingToolbarLayout_toolbarId, -1); a.recycle(); setWillNotDraw(false); ViewCompat.setOnApplyWindowInsetsListener(this, new androidx.core.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return onWindowInsetChanged(insets); } } ); }