Search in sources :

Example 1 with SpringAnimation

use of androidx.dynamicanimation.animation.SpringAnimation in project plaid by nickbutcher.

the class BottomSheet method animateSettle.

void animateSettle(int targetOffset, float initialVelocity) {
    if (settling)
        return;
    if (sheetOffsetHelper.getTopAndBottomOffset() == targetOffset) {
        if (targetOffset >= dismissOffset) {
            dispatchDismissCallback();
        }
        return;
    }
    settling = true;
    final boolean dismissing = targetOffset == dismissOffset;
    // if we're dismissing, we don't want the view to decelerate as it reaches the bottom
    // so set a target position that actually overshoots a little
    final float finalPosition = dismissing ? dismissOffset * 1.1f : targetOffset;
    SpringAnimation anim = new SpringAnimation(sheetOffsetHelper, ViewOffsetHelper.OFFSET_Y, finalPosition).setStartValue(sheetOffsetHelper.getTopAndBottomOffset()).setStartVelocity(initialVelocity).setMinimumVisibleChange(DynamicAnimation.MIN_VISIBLE_CHANGE_PIXELS);
    anim.getSpring().setStiffness(SETTLE_STIFFNESS).setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY);
    anim.addEndListener((animation, canceled, value, velocity) -> {
        dispatchPositionChangedCallback();
        if (dismissing) {
            dispatchDismissCallback();
        }
        settling = false;
    });
    if (callbacks != null && !callbacks.isEmpty()) {
        anim.addUpdateListener((animation, value, velocity) -> dispatchPositionChangedCallback());
    }
    anim.start();
}
Also used : SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation)

Example 2 with SpringAnimation

use of androidx.dynamicanimation.animation.SpringAnimation in project android_packages_apps_Launcher3 by crdroidandroid.

the class RectFSpringAnim method start.

/**
 * Starts the fling/spring animation.
 * @param context The activity context.
 * @param velocityPxPerMs Velocity of swipe in px/ms.
 */
public void start(Context context, PointF velocityPxPerMs) {
    // Only tell caller that we ended if both x and y animations have ended.
    OnAnimationEndListener onXEndListener = ((animation, canceled, centerX, velocityX) -> {
        mRectXAnimEnded = true;
        maybeOnEnd();
    });
    OnAnimationEndListener onYEndListener = ((animation, canceled, centerY, velocityY) -> {
        mRectYAnimEnded = true;
        maybeOnEnd();
    });
    float startX = mCurrentCenterX;
    float endX = mTargetRect.centerX();
    float minXValue = Math.min(startX, endX);
    float maxXValue = Math.max(startX, endX);
    mRectXAnim = new FlingSpringAnim(this, context, RECT_CENTER_X, startX, endX, velocityPxPerMs.x * 1000, mMinVisChange, minXValue, maxXValue, 1f, onXEndListener);
    float startVelocityY = velocityPxPerMs.y * 1000;
    // Scale the Y velocity based on the initial velocity to tune the curves.
    float springVelocityFactor = 0.1f + 0.9f * Math.abs(startVelocityY) / 20000.0f;
    float startY = mCurrentY;
    float endY = mTrackingBottomY ? mTargetRect.bottom : mTargetRect.top;
    float minYValue = Math.min(startY, endY - mYOvershoot);
    float maxYValue = Math.max(startY, endY);
    mRectYAnim = new FlingSpringAnim(this, context, RECT_Y, startY, endY, startVelocityY, mMinVisChange, minYValue, maxYValue, springVelocityFactor, onYEndListener);
    float minVisibleChange = Math.abs(1f / mStartRect.height());
    ResourceProvider rp = DynamicResource.provider(context);
    float damping = rp.getFloat(R.dimen.swipe_up_rect_scale_damping_ratio);
    float stiffness = rp.getFloat(R.dimen.swipe_up_rect_scale_stiffness);
    mRectScaleAnim = new SpringAnimation(this, RECT_SCALE_PROGRESS).setSpring(new SpringForce(1f).setDampingRatio(damping).setStiffness(stiffness)).setStartVelocity(velocityPxPerMs.y * minVisibleChange).setMaxValue(1f).setMinimumVisibleChange(minVisibleChange).addEndListener((animation, canceled, value, velocity) -> {
        mRectScaleAnimEnded = true;
        maybeOnEnd();
    });
    setCanRelease(false);
    mAnimsStarted = true;
    mRectXAnim.start();
    mRectYAnim.start();
    mRectScaleAnim.start();
    for (Animator.AnimatorListener animatorListener : mAnimatorListeners) {
        animatorListener.onAnimationStart(null);
    }
}
Also used : RectF(android.graphics.RectF) Utilities(com.android.launcher3.Utilities) Context(android.content.Context) SpringForce(androidx.dynamicanimation.animation.SpringForce) PointF(android.graphics.PointF) FloatPropertyCompat(androidx.dynamicanimation.animation.FloatPropertyCompat) DynamicResource(com.android.launcher3.util.DynamicResource) ReleaseCheck(com.android.quickstep.RemoteAnimationTargets.ReleaseCheck) Animator(android.animation.Animator) FlingSpringAnim(com.android.launcher3.anim.FlingSpringAnim) ResourceProvider(com.android.systemui.plugins.ResourceProvider) ArrayList(java.util.ArrayList) OnAnimationEndListener(androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener) List(java.util.List) Nullable(androidx.annotation.Nullable) R(com.android.launcher3.R) SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation) FlingSpringAnim(com.android.launcher3.anim.FlingSpringAnim) Animator(android.animation.Animator) SpringForce(androidx.dynamicanimation.animation.SpringForce) ResourceProvider(com.android.systemui.plugins.ResourceProvider) SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation) OnAnimationEndListener(androidx.dynamicanimation.animation.DynamicAnimation.OnAnimationEndListener)

Example 3 with SpringAnimation

use of androidx.dynamicanimation.animation.SpringAnimation in project android_packages_apps_Launcher3 by crdroidandroid.

the class RectFSpringAnim2 method start.

/**
 * Starts the fling/spring animation.
 * @param context The activity context.
 * @param velocityPxPerMs Velocity of swipe in px/ms.
 */
public void start(Context context, PointF velocityPxPerMs) {
    mRectXAnim = new SpringAnimation(this, RECT_CENTER_X).setStartValue(mCurrentCenterX).setStartVelocity(velocityPxPerMs.x * 1000).setSpring(new SpringForce(mTargetX).setStiffness(mXStiffness).setDampingRatio(mXDamping));
    mRectXAnim.addEndListener(((animation, canceled, centerX, velocityX) -> {
        mRectXAnimEnded = true;
        maybeOnEnd();
    }));
    mRectYAnim = new SpringAnimation(this, RECT_Y).setStartValue(mCurrentCenterY).setStartVelocity(velocityPxPerMs.y * 1000).setSpring(new SpringForce(mTargetY).setStiffness(mYStiffness).setDampingRatio(mYDamping));
    mRectYAnim.addEndListener(((animation, canceled, centerY, velocityY) -> {
        mRectYAnimEnded = true;
        maybeOnEnd();
    }));
    mRectScaleAnim = ObjectAnimator.ofFloat(this, PROGRESS, 0, 1f).setDuration(mDuration);
    mRectScaleAnim.setInterpolator(mCloseInterpolator);
    mRectScaleAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mRectScaleAnimEnded = true;
            maybeOnEnd();
        }
    });
    mValues = buildConfig();
    mRectScaleAnim.addUpdateListener(mValues);
    setCanRelease(false);
    mAnimsStarted = true;
    mRectXAnim.start();
    mRectYAnim.start();
    mRectScaleAnim.start();
    for (Animator.AnimatorListener animatorListener : mAnimatorListeners) {
        animatorListener.onAnimationStart(null);
    }
}
Also used : RectF(android.graphics.RectF) PathInterpolatorCompat(androidx.core.view.animation.PathInterpolatorCompat) Utilities(com.android.launcher3.Utilities) Context(android.content.Context) SpringForce(androidx.dynamicanimation.animation.SpringForce) PointF(android.graphics.PointF) Interpolator(android.view.animation.Interpolator) ObjectAnimator(android.animation.ObjectAnimator) FloatPropertyCompat(androidx.dynamicanimation.animation.FloatPropertyCompat) DynamicResource(com.android.launcher3.util.DynamicResource) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ResourceProvider(com.android.systemui.plugins.ResourceProvider) Property(android.util.Property) ArrayList(java.util.ArrayList) LINEAR(com.android.launcher3.anim.Interpolators.LINEAR) List(java.util.List) R(com.android.launcher3.R) Locale(java.util.Locale) Utilities.dpToPx(com.android.launcher3.Utilities.dpToPx) SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation) PathParser(android.util.PathParser) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) SpringForce(androidx.dynamicanimation.animation.SpringForce) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation)

Example 4 with SpringAnimation

use of androidx.dynamicanimation.animation.SpringAnimation in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatAttachAlert method showLayout.

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(currentPanTranslationY);
                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();
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Rect(android.graphics.Rect) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) PackageManager(android.content.pm.PackageManager) AdjustPanLayoutHelper(org.telegram.ui.ActionBar.AdjustPanLayoutHelper) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) Drawable(android.graphics.drawable.Drawable) Property(android.util.Property) Manifest(android.Manifest) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) Keep(androidx.annotation.Keep) SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation) MediaController(org.telegram.messenger.MediaController) View(android.view.View) Button(android.widget.Button) Canvas(android.graphics.Canvas) Emoji(org.telegram.messenger.Emoji) RecyclerView(androidx.recyclerview.widget.RecyclerView) RectF(android.graphics.RectF) ObjectAnimator(android.animation.ObjectAnimator) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) PhotoPickerSearchActivity(org.telegram.ui.PhotoPickerSearchActivity) Outline(android.graphics.Outline) HapticFeedbackConstants(android.view.HapticFeedbackConstants) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) TextPaint(android.text.TextPaint) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) TextWatcher(android.text.TextWatcher) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) ChatActivity(org.telegram.ui.ChatActivity) Context(android.content.Context) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) KeyEvent(android.view.KeyEvent) ImageSpan(android.text.style.ImageSpan) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) Editable(android.text.Editable) ArrayList(java.util.ArrayList) DynamicAnimation(androidx.dynamicanimation.animation.DynamicAnimation) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) MediaDataController(org.telegram.messenger.MediaDataController) Build(android.os.Build) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) Gravity(android.view.Gravity) PhotoPickerActivity(org.telegram.ui.PhotoPickerActivity) UserObject(org.telegram.messenger.UserObject) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) OvershootInterpolator(android.view.animation.OvershootInterpolator) PassportActivity(org.telegram.ui.PassportActivity) Vibrator(android.os.Vibrator) ColorUtils(androidx.core.graphics.ColorUtils) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SpringAnimation(androidx.dynamicanimation.animation.SpringAnimation) AnimatorSet(android.animation.AnimatorSet) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Aggregations

Animator (android.animation.Animator)3 Context (android.content.Context)3 RectF (android.graphics.RectF)3 SpringAnimation (androidx.dynamicanimation.animation.SpringAnimation)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 ObjectAnimator (android.animation.ObjectAnimator)2 ValueAnimator (android.animation.ValueAnimator)2 PointF (android.graphics.PointF)2 Property (android.util.Property)2 FloatPropertyCompat (androidx.dynamicanimation.animation.FloatPropertyCompat)2 SpringForce (androidx.dynamicanimation.animation.SpringForce)2 R (com.android.launcher3.R)2 Utilities (com.android.launcher3.Utilities)2 DynamicResource (com.android.launcher3.util.DynamicResource)2 ResourceProvider (com.android.systemui.plugins.ResourceProvider)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Manifest (android.Manifest)1 AnimatorSet (android.animation.AnimatorSet)1 SuppressLint (android.annotation.SuppressLint)1