Search in sources :

Example 36 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_packages_apps_Launcher2 by CyanogenMod.

the class AppWidgetResizeFrame method snapToWidget.

public void snapToWidget(boolean animate) {
    final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
    int xOffset = mCellLayout.getLeft() + mCellLayout.getPaddingLeft() + mDragLayer.getPaddingLeft() - mWorkspace.getScrollX();
    int yOffset = mCellLayout.getTop() + mCellLayout.getPaddingTop() + mDragLayer.getPaddingTop() - mWorkspace.getScrollY();
    int newWidth = mWidgetView.getWidth() + 2 * mBackgroundPadding - mWidgetPaddingLeft - mWidgetPaddingRight;
    int newHeight = mWidgetView.getHeight() + 2 * mBackgroundPadding - mWidgetPaddingTop - mWidgetPaddingBottom;
    int newX = mWidgetView.getLeft() - mBackgroundPadding + xOffset + mWidgetPaddingLeft;
    int newY = mWidgetView.getTop() - mBackgroundPadding + yOffset + mWidgetPaddingTop;
    // down accordingly to provide a proper touch target.
    if (newY < 0) {
        // In this case we shift the touch region down to start at the top of the DragLayer
        mTopTouchRegionAdjustment = -newY;
    } else {
        mTopTouchRegionAdjustment = 0;
    }
    if (newY + newHeight > mDragLayer.getHeight()) {
        // In this case we shift the touch region up to end at the bottom of the DragLayer
        mBottomTouchRegionAdjustment = -(newY + newHeight - mDragLayer.getHeight());
    } else {
        mBottomTouchRegionAdjustment = 0;
    }
    if (!animate) {
        lp.width = newWidth;
        lp.height = newHeight;
        lp.x = newX;
        lp.y = newY;
        mLeftHandle.setAlpha(1.0f);
        mRightHandle.setAlpha(1.0f);
        mTopHandle.setAlpha(1.0f);
        mBottomHandle.setAlpha(1.0f);
        requestLayout();
    } else {
        PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", lp.width, newWidth);
        PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", lp.height, newHeight);
        PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", lp.x, newX);
        PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", lp.y, newY);
        ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(lp, width, height, x, y);
        ObjectAnimator leftOa = LauncherAnimUtils.ofFloat(mLeftHandle, "alpha", 1.0f);
        ObjectAnimator rightOa = LauncherAnimUtils.ofFloat(mRightHandle, "alpha", 1.0f);
        ObjectAnimator topOa = LauncherAnimUtils.ofFloat(mTopHandle, "alpha", 1.0f);
        ObjectAnimator bottomOa = LauncherAnimUtils.ofFloat(mBottomHandle, "alpha", 1.0f);
        oa.addUpdateListener(new AnimatorUpdateListener() {

            public void onAnimationUpdate(ValueAnimator animation) {
                requestLayout();
            }
        });
        AnimatorSet set = LauncherAnimUtils.createAnimatorSet();
        if (mResizeMode == AppWidgetProviderInfo.RESIZE_VERTICAL) {
            set.playTogether(oa, topOa, bottomOa);
        } else if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) {
            set.playTogether(oa, leftOa, rightOa);
        } else {
            set.playTogether(oa, leftOa, rightOa, topOa, bottomOa);
        }
        set.setDuration(SNAP_DURATION);
        set.start();
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder) AnimatorSet(android.animation.AnimatorSet) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 37 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project AndroidChromium by JackyAndroid.

the class FocusAnimator method startAnimator.

private void startAnimator(final Runnable callback) {
    // Don't animate anything if the number of children changed.
    if (mInitialNumberOfChildren != mLayout.getChildCount()) {
        finishAnimation(callback);
        return;
    }
    // Don't animate if children are already all in the correct places.
    boolean isAnimationNecessary = false;
    ArrayList<Integer> finalChildTops = calculateChildTops();
    for (int i = 0; i < finalChildTops.size() && !isAnimationNecessary; i++) {
        isAnimationNecessary |= finalChildTops.get(i).compareTo(mInitialTops.get(i)) != 0;
    }
    if (!isAnimationNecessary) {
        finishAnimation(callback);
        return;
    }
    // Animate each child moving and changing size to match their final locations.
    ArrayList<Animator> animators = new ArrayList<Animator>();
    ValueAnimator childAnimator = ValueAnimator.ofFloat(0f, 1f);
    animators.add(childAnimator);
    for (int i = 0; i < mLayout.getChildCount(); i++) {
        // The child is already where it should be.
        if (mInitialTops.get(i).compareTo(finalChildTops.get(i)) == 0 && mInitialTops.get(i + 1).compareTo(finalChildTops.get(i + 1)) == 0) {
            continue;
        }
        final View child = mLayout.getChildAt(i);
        final int translationDifference = mInitialTops.get(i) - finalChildTops.get(i);
        final int oldHeight = mInitialTops.get(i + 1) - mInitialTops.get(i);
        final int newHeight = finalChildTops.get(i + 1) - finalChildTops.get(i);
        // Translate the child to its new place while changing where its bottom is drawn to
        // animate the child changing height without causing another layout.
        childAnimator.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float progress = (Float) animation.getAnimatedValue();
                child.setTranslationY(translationDifference * (1f - progress));
                if (oldHeight != newHeight) {
                    float animatedHeight = oldHeight * (1f - progress) + newHeight * progress;
                    child.setBottom(child.getTop() + (int) animatedHeight);
                }
            }
        });
        // Explicitly place the child in its final position in the end.
        childAnimator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animator) {
                child.setTranslationY(0);
                child.setBottom(child.getTop() + newHeight);
            }
        });
    }
    // Animate the height of the container itself changing.
    int oldContainerHeight = mInitialTops.get(mInitialTops.size() - 1);
    int newContainerHeight = finalChildTops.get(finalChildTops.size() - 1);
    ValueAnimator layoutAnimator = ValueAnimator.ofInt(oldContainerHeight, newContainerHeight);
    layoutAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mLayout.setBottom(((Integer) animation.getAnimatedValue()));
            requestChildFocus();
        }
    });
    animators.add(layoutAnimator);
    // Set up and kick off the animation.
    AnimatorSet animator = new AnimatorSet();
    animator.setDuration(ANIMATION_LENGTH_MS);
    animator.setInterpolator(new LinearOutSlowInInterpolator());
    animator.playTogether(animators);
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animator) {
            finishAnimation(callback);
            // Request a layout to put everything in the right final place.
            mLayout.requestLayout();
        }
    });
    animator.start();
}
Also used : ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) LinearOutSlowInInterpolator(android.support.v4.view.animation.LinearOutSlowInInterpolator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 38 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project AndroidChromium by JackyAndroid.

the class CustomTabToolbar method onPrimaryColorChanged.

/**
     * For extending classes to override and carry out the changes related with the primary color
     * for the current tab changing.
     */
@Override
protected void onPrimaryColorChanged(boolean shouldAnimate) {
    if (mBrandColorTransitionActive)
        mBrandColorTransitionAnimation.cancel();
    final ColorDrawable background = getBackground();
    final int initialColor = background.getColor();
    final int finalColor = getToolbarDataProvider().getPrimaryColor();
    if (background.getColor() == finalColor)
        return;
    mBrandColorTransitionAnimation = ValueAnimator.ofFloat(0, 1).setDuration(ToolbarPhone.THEME_COLOR_TRANSITION_DURATION);
    mBrandColorTransitionAnimation.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    mBrandColorTransitionAnimation.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float fraction = animation.getAnimatedFraction();
            int red = (int) (Color.red(initialColor) + fraction * (Color.red(finalColor) - Color.red(initialColor)));
            int green = (int) (Color.green(initialColor) + fraction * (Color.green(finalColor) - Color.green(initialColor)));
            int blue = (int) (Color.blue(initialColor) + fraction * (Color.blue(finalColor) - Color.blue(initialColor)));
            background.setColor(Color.rgb(red, green, blue));
        }
    });
    mBrandColorTransitionAnimation.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mBrandColorTransitionActive = false;
            // Using the current background color instead of the final color in case this
            // animation was cancelled.  This ensures the assets are updated to the visible
            // color.
            mUseDarkColors = !ColorUtils.shouldUseLightForegroundOnBackground(background.getColor());
            updateVisualsForState();
        }
    });
    mBrandColorTransitionAnimation.start();
    mBrandColorTransitionActive = true;
    if (!shouldAnimate)
        mBrandColorTransitionAnimation.end();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) SuppressLint(android.annotation.SuppressLint)

Example 39 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by DirtyUnicorns.

the class SwipeHelper method dismissChild.

/**
     * @param view The view to be dismissed
     * @param velocity The desired pixels/second speed at which the view should move
     * @param endAction The action to perform at the end
     * @param delay The delay after which we should start
     * @param useAccelerateInterpolator Should an accelerating Interpolator be used
     * @param fixedDuration If not 0, this exact duration will be taken
     */
public void dismissChild(final View animView, float velocity, final Runnable endAction, long delay, boolean useAccelerateInterpolator, long fixedDuration, boolean isDismissAll) {
    final boolean canBeDismissed = mCallback.canChildBeDismissed(animView);
    float newPos;
    boolean isLayoutRtl = animView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    // if we use the Menu to dismiss an item in landscape, animate up
    boolean animateUpForMenu = velocity == 0 && (getTranslation(animView) == 0 || isDismissAll) && mSwipeDirection == Y;
    // if the language is rtl we prefer swiping to the left
    boolean animateLeftForRtl = velocity == 0 && (getTranslation(animView) == 0 || isDismissAll) && isLayoutRtl;
    boolean animateLeft = velocity < 0 || (velocity == 0 && getTranslation(animView) < 0 && !isDismissAll);
    if (animateLeft || animateLeftForRtl || animateUpForMenu) {
        newPos = -getSize(animView);
    } else {
        newPos = getSize(animView);
    }
    long duration;
    if (fixedDuration == 0) {
        duration = MAX_ESCAPE_ANIMATION_DURATION;
        if (velocity != 0) {
            duration = Math.min(duration, (int) (Math.abs(newPos - getTranslation(animView)) * 500f / Math.abs(velocity)));
        } else {
            duration = DEFAULT_ESCAPE_ANIMATION_DURATION;
        }
    } else {
        duration = fixedDuration;
    }
    if (!mDisableHwLayers) {
        animView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    AnimatorUpdateListener updateListener = new AnimatorUpdateListener() {

        public void onAnimationUpdate(ValueAnimator animation) {
            onTranslationUpdate(animView, (float) animation.getAnimatedValue(), canBeDismissed);
        }
    };
    Animator anim = getViewTranslationAnimator(animView, newPos, updateListener);
    if (anim == null) {
        return;
    }
    if (useAccelerateInterpolator) {
        anim.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN);
        anim.setDuration(duration);
    } else {
        mFlingAnimationUtils.applyDismissing(anim, getTranslation(animView), newPos, velocity, getSize(animView));
    }
    if (delay > 0) {
        anim.setStartDelay(delay);
    }
    anim.addListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

        public void onAnimationCancel(Animator animation) {
            mCancelled = true;
        }

        public void onAnimationEnd(Animator animation) {
            updateSwipeProgressFromOffset(animView, canBeDismissed);
            mDismissPendingMap.remove(animView);
            if (!mCancelled) {
                mCallback.onChildDismissed(animView);
            }
            if (endAction != null) {
                endAction.run();
            }
            if (!mDisableHwLayers) {
                animView.setLayerType(View.LAYER_TYPE_NONE, null);
            }
        }
    });
    prepareDismissAnimation(animView, anim);
    mDismissPendingMap.put(animView, anim);
    anim.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 40 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by DirtyUnicorns.

the class VolumeDialogMotion method startShowAnimation.

private void startShowAnimation() {
    if (D.BUG)
        Log.d(TAG, "startShowAnimation");
    mDialogView.animate().translationY(0).setDuration(scaledDuration(300)).setInterpolator(new LogDecelerateInterpolator()).setListener(null).setUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            if (mChevronPositionAnimator == null)
                return;
            // reposition chevron
            final float v = (Float) mChevronPositionAnimator.getAnimatedValue();
            final int posY = chevronPosY();
            mChevron.setTranslationY(posY + v + -mDialogView.getTranslationY());
        }
    }).start();
    mContentsPositionAnimator = ValueAnimator.ofFloat(-chevronDistance(), 0).setDuration(scaledDuration(400));
    mContentsPositionAnimator.addListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCancelled)
                return;
            if (D.BUG)
                Log.d(TAG, "show.onAnimationEnd");
            setShowing(false);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (D.BUG)
                Log.d(TAG, "show.onAnimationCancel");
            mCancelled = true;
        }
    });
    mContentsPositionAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float v = (Float) animation.getAnimatedValue();
            mContents.setTranslationY(v + -mDialogView.getTranslationY());
        }
    });
    mContentsPositionAnimator.setInterpolator(new LogDecelerateInterpolator());
    mContentsPositionAnimator.start();
    mContents.setAlpha(0);
    mContents.animate().alpha(1).setDuration(scaledDuration(150)).setInterpolator(new PathInterpolator(0f, 0f, .2f, 1f)).start();
    mChevronPositionAnimator = ValueAnimator.ofFloat(-chevronDistance(), 0).setDuration(scaledDuration(250));
    mChevronPositionAnimator.setInterpolator(new PathInterpolator(.4f, 0f, .2f, 1f));
    mChevronPositionAnimator.start();
    mChevron.setAlpha(0);
    mChevron.animate().alpha(1).setStartDelay(scaledDuration(50)).setDuration(scaledDuration(150)).setInterpolator(new PathInterpolator(.4f, 0f, 1f, 1f)).start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) PathInterpolator(android.view.animation.PathInterpolator)

Aggregations

AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)94 ValueAnimator (android.animation.ValueAnimator)88 Animator (android.animation.Animator)65 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)62 ObjectAnimator (android.animation.ObjectAnimator)31 TimeInterpolator (android.animation.TimeInterpolator)14 View (android.view.View)13 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)12 Interpolator (android.view.animation.Interpolator)12 Resources (android.content.res.Resources)9 SuppressLint (android.annotation.SuppressLint)8 AnimatorSet (android.animation.AnimatorSet)7 Rect (android.graphics.Rect)7 ImageView (android.widget.ImageView)7 PropertyValuesHolder (android.animation.PropertyValuesHolder)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)6 Point (android.graphics.Point)6 PointF (android.graphics.PointF)6 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)6 TextView (android.widget.TextView)6