androidx.dynamicanimation.animation.DynamicAnimation Java Examples
The following examples show how to use
androidx.dynamicanimation.animation.DynamicAnimation.
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: DynamicReboundSmoothRefreshLayout.java From SmoothRefreshLayout with MIT License | 6 votes |
@Override public void onAnimationUpdate(DynamicAnimation animation, float value, float velocity) { float deltaY = value - mLastY; if (sDebug) { Log.d( TAG, String.format( "ScrollChecker: onAnimationUpdate(): mode: %d, curPos: %d, curY: %f, last: %f, delta: %f", mMode, mIndicator.getCurrentPos(), value, mLastY, deltaY)); } mLastY = value; if (isMovingHeader()) { moveHeaderPos(deltaY); } else if (isMovingFooter()) { if (isPreFling()) { moveFooterPos(deltaY); } else { moveFooterPos(-deltaY); } } tryToDispatchNestedFling(); }
Example #2
Source File: DeterminateDrawable.java From material-components-android with Apache License 2.0 | 6 votes |
public DeterminateDrawable( @NonNull ProgressIndicator progressIndicator, @NonNull DrawingDelegate drawingDelegate) { super(progressIndicator); this.drawingDelegate = drawingDelegate; springForce = new SpringForce(); springForce.setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY); springForce.setStiffness(SPRING_FORCE_STIFFNESS); springAnimator = new SpringAnimation(this, INDICATOR_LENGTH_FRACTION); springAnimator.setSpring(springForce); springAnimator.addUpdateListener( new OnAnimationUpdateListener() { @Override public void onAnimationUpdate(DynamicAnimation animation, float value, float velocity) { setIndicatorFraction(value / MAX_DRAWABLE_LEVEL); } }); setGrowFraction(1f); }
Example #3
Source File: DynamicReboundSmoothRefreshLayout.java From SmoothRefreshLayout with MIT License | 5 votes |
@Override public void onAnimationEnd( DynamicAnimation animation, boolean canceled, float value, float velocity) { if (sDebug) { Log.d( TAG, String.format( "ScrollChecker: onAnimationEnd(): mode: %d, curPos: %d, canceled: %b", mMode, mIndicator.getCurrentPos(), canceled)); } if (!canceled) { switch (mMode) { case Constants.SCROLLER_MODE_SPRING_BACK: stop(); if (!mIndicator.isAlreadyHere(IIndicator.START_POS)) { onRelease(); } break; case Constants.SCROLLER_MODE_PRE_FLING: case Constants.SCROLLER_MODE_FLING: stop(); mMode = Constants.SCROLLER_MODE_FLING_BACK; if (isEnabledPerformFreshWhenFling() || isRefreshing() || isLoadingMore() || (isEnabledAutoLoadMore() && isMovingFooter()) || (isEnabledAutoRefresh() && isMovingHeader())) { onRelease(); } else { tryScrollBackToTop(); } } } }
Example #4
Source File: ChatAttachAlert.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private void showLayout(AttachAlertLayout layout) { if (viewChangeAnimator != null || commentsAnimator != null) { return; } if (currentAttachLayout == layout) { currentAttachLayout.scrollToTop(); return; } if (layout == photoLayout) { selectedId = 1; } else if (layout == audioLayout) { selectedId = 3; } else if (layout == documentLayout) { selectedId = 4; } else if (layout == contactsLayout) { selectedId = 5; } else if (layout == locationLayout) { selectedId = 6; } else if (layout == pollLayout) { selectedId = 9; } int count = buttonsRecyclerView.getChildCount(); for (int a = 0; a < count; a++) { View child = buttonsRecyclerView.getChildAt(a); if (child instanceof AttachButton) { AttachButton attachButton = (AttachButton) child; attachButton.updateCheckedState(true); } } int t = currentAttachLayout.getFirstOffset() - AndroidUtilities.dp(11) - scrollOffsetY[0]; nextAttachLayout = layout; if (Build.VERSION.SDK_INT >= 20) { container.setLayerType(View.LAYER_TYPE_HARDWARE, null); } actionBar.setVisibility(nextAttachLayout.needsActionBar() != 0 ? View.VISIBLE : View.INVISIBLE); actionBarShadow.setVisibility(actionBar.getVisibility()); if (actionBar.isSearchFieldVisible()) { actionBar.closeSearchField(); } currentAttachLayout.onHide(); nextAttachLayout.onShow(); nextAttachLayout.setVisibility(View.VISIBLE); nextAttachLayout.setAlpha(0.0f); if (layout.getParent() != null) { containerView.removeView(nextAttachLayout); } int index = containerView.indexOfChild(currentAttachLayout); containerView.addView(nextAttachLayout, nextAttachLayout == locationLayout ? index : index + 1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); nextAttachLayout.setTranslationY(AndroidUtilities.dp(78)); AnimatorSet animator = new AnimatorSet(); animator.playTogether(ObjectAnimator.ofFloat(currentAttachLayout, View.TRANSLATION_Y, AndroidUtilities.dp(78) + t), ObjectAnimator.ofFloat(currentAttachLayout, ATTACH_ALERT_LAYOUT_TRANSLATION, 0.0f, 1.0f)); animator.setInterpolator(CubicBezierInterpolator.DEFAULT); animator.setDuration(180); animator.setStartDelay(20); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { currentAttachLayout.setAlpha(0.0f); SpringAnimation springAnimation = new SpringAnimation(nextAttachLayout, DynamicAnimation.TRANSLATION_Y, 0); springAnimation.getSpring().setDampingRatio(0.7f); springAnimation.getSpring().setStiffness(400.0f); springAnimation.addUpdateListener((animation12, value, velocity) -> { if (nextAttachLayout == pollLayout) { updateSelectedPosition(1); } nextAttachLayout.onContainerTranslationUpdated(); containerView.invalidate(); }); springAnimation.addEndListener((animation1, canceled, value, velocity) -> { if (Build.VERSION.SDK_INT >= 20) { container.setLayerType(View.LAYER_TYPE_NONE, null); } viewChangeAnimator = null; containerView.removeView(currentAttachLayout); currentAttachLayout.setVisibility(View.GONE); currentAttachLayout.onHidden(); nextAttachLayout.onShown(); currentAttachLayout = nextAttachLayout; nextAttachLayout = null; scrollOffsetY[0] = scrollOffsetY[1]; }); viewChangeAnimator = springAnimation; springAnimation.start(); } }); viewChangeAnimator = animator; animator.start(); }
Example #5
Source File: ChatAttachAlert.java From Telegram with GNU General Public License v2.0 | 4 votes |
private void showLayout(AttachAlertLayout layout) { if (viewChangeAnimator != null || commentsAnimator != null) { return; } if (currentAttachLayout == layout) { currentAttachLayout.scrollToTop(); return; } if (layout == photoLayout) { selectedId = 1; } else if (layout == audioLayout) { selectedId = 3; } else if (layout == documentLayout) { selectedId = 4; } else if (layout == contactsLayout) { selectedId = 5; } else if (layout == locationLayout) { selectedId = 6; } else if (layout == pollLayout) { selectedId = 9; } int count = buttonsRecyclerView.getChildCount(); for (int a = 0; a < count; a++) { View child = buttonsRecyclerView.getChildAt(a); if (child instanceof AttachButton) { AttachButton attachButton = (AttachButton) child; attachButton.updateCheckedState(true); } } int t = currentAttachLayout.getFirstOffset() - AndroidUtilities.dp(11) - scrollOffsetY[0]; nextAttachLayout = layout; if (Build.VERSION.SDK_INT >= 20) { container.setLayerType(View.LAYER_TYPE_HARDWARE, null); } actionBar.setVisibility(nextAttachLayout.needsActionBar() != 0 ? View.VISIBLE : View.INVISIBLE); actionBarShadow.setVisibility(actionBar.getVisibility()); if (actionBar.isSearchFieldVisible()) { actionBar.closeSearchField(); } currentAttachLayout.onHide(); nextAttachLayout.onShow(); nextAttachLayout.setVisibility(View.VISIBLE); nextAttachLayout.setAlpha(0.0f); if (layout.getParent() != null) { containerView.removeView(nextAttachLayout); } int index = containerView.indexOfChild(currentAttachLayout); containerView.addView(nextAttachLayout, nextAttachLayout == locationLayout ? index : index + 1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); nextAttachLayout.setTranslationY(AndroidUtilities.dp(78)); AnimatorSet animator = new AnimatorSet(); animator.playTogether(ObjectAnimator.ofFloat(currentAttachLayout, View.TRANSLATION_Y, AndroidUtilities.dp(78) + t), ObjectAnimator.ofFloat(currentAttachLayout, ATTACH_ALERT_LAYOUT_TRANSLATION, 0.0f, 1.0f)); animator.setInterpolator(CubicBezierInterpolator.DEFAULT); animator.setDuration(180); animator.setStartDelay(20); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { currentAttachLayout.setAlpha(0.0f); SpringAnimation springAnimation = new SpringAnimation(nextAttachLayout, DynamicAnimation.TRANSLATION_Y, 0); springAnimation.getSpring().setDampingRatio(0.7f); springAnimation.getSpring().setStiffness(400.0f); springAnimation.addUpdateListener((animation12, value, velocity) -> { if (nextAttachLayout == pollLayout) { updateSelectedPosition(1); } nextAttachLayout.onContainerTranslationUpdated(); containerView.invalidate(); }); springAnimation.addEndListener((animation1, canceled, value, velocity) -> { if (Build.VERSION.SDK_INT >= 20) { container.setLayerType(View.LAYER_TYPE_NONE, null); } viewChangeAnimator = null; containerView.removeView(currentAttachLayout); currentAttachLayout.setVisibility(View.GONE); currentAttachLayout.onHidden(); nextAttachLayout.onShown(); currentAttachLayout = nextAttachLayout; nextAttachLayout = null; scrollOffsetY[0] = scrollOffsetY[1]; }); viewChangeAnimator = springAnimation; springAnimation.start(); } }); viewChangeAnimator = animator; animator.start(); }