Search in sources :

Example 46 with AnimatorSet

use of android.animation.AnimatorSet in project Transitions-Everywhere by andkulikov.

the class ChangeBounds method createAnimator.

@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    if (sRectEvaluator == null) {
        sRectEvaluator = new RectEvaluator();
    }
    Map<String, Object> startParentVals = startValues.values;
    Map<String, Object> endParentVals = endValues.values;
    ViewGroup startParent = (ViewGroup) startParentVals.get(PROPNAME_PARENT);
    ViewGroup endParent = (ViewGroup) endParentVals.get(PROPNAME_PARENT);
    if (startParent == null || endParent == null) {
        return null;
    }
    final View view = endValues.view;
    if (parentMatches(startParent, endParent)) {
        Rect startBounds = (Rect) startValues.values.get(PROPNAME_BOUNDS);
        Rect endBounds = (Rect) endValues.values.get(PROPNAME_BOUNDS);
        final int startLeft = startBounds.left;
        final int endLeft = endBounds.left;
        final int startTop = startBounds.top;
        final int endTop = endBounds.top;
        final int startRight = startBounds.right;
        final int endRight = endBounds.right;
        final int startBottom = startBounds.bottom;
        final int endBottom = endBounds.bottom;
        final int startWidth = startRight - startLeft;
        final int startHeight = startBottom - startTop;
        final int endWidth = endRight - endLeft;
        final int endHeight = endBottom - endTop;
        Rect startClip = (Rect) startValues.values.get(PROPNAME_CLIP);
        Rect endClip = (Rect) endValues.values.get(PROPNAME_CLIP);
        int numChanges = 0;
        if ((startWidth != 0 && startHeight != 0) || (endWidth != 0 && endHeight != 0)) {
            if (startLeft != endLeft || startTop != endTop)
                ++numChanges;
            if (startRight != endRight || startBottom != endBottom)
                ++numChanges;
        }
        if ((startClip != null && !startClip.equals(endClip)) || (startClip == null && endClip != null)) {
            ++numChanges;
        }
        if (numChanges > 0) {
            Animator anim;
            if (!mResizeClip || (startClip == null && endClip == null)) {
                ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startRight, startBottom);
                if (numChanges == 2) {
                    if (startWidth == endWidth && startHeight == endHeight) {
                        anim = AnimatorUtils.ofPointF(view, POSITION_PROPERTY, getPathMotion(), startLeft, startTop, endLeft, endTop);
                    } else {
                        ViewBounds viewBounds = new ViewBounds(view);
                        Animator topLeftAnimator = AnimatorUtils.ofPointF(viewBounds, TOP_LEFT_PROPERTY, getPathMotion(), startLeft, startTop, endLeft, endTop);
                        Animator bottomRightAnimator = AnimatorUtils.ofPointF(viewBounds, BOTTOM_RIGHT_PROPERTY, getPathMotion(), startRight, startBottom, endRight, endBottom);
                        AnimatorSet set = new AnimatorSet();
                        set.playTogether(topLeftAnimator, bottomRightAnimator);
                        set.addListener(viewBounds);
                        anim = set;
                    }
                } else if (startLeft != endLeft || startTop != endTop) {
                    anim = AnimatorUtils.ofPointF(view, TOP_LEFT_ONLY_PROPERTY, getPathMotion(), startLeft, startTop, endLeft, endTop);
                } else {
                    anim = AnimatorUtils.ofPointF(view, BOTTOM_RIGHT_ONLY_PROPERTY, getPathMotion(), startRight, startBottom, endRight, endBottom);
                }
            } else {
                int maxWidth = Math.max(startWidth, endWidth);
                int maxHeight = Math.max(startHeight, endHeight);
                ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startLeft + maxWidth, startTop + maxHeight);
                Animator positionAnimator = null;
                if (startLeft != endLeft || startTop != endTop) {
                    positionAnimator = AnimatorUtils.ofPointF(view, POSITION_PROPERTY, getPathMotion(), startLeft, startTop, endLeft, endTop);
                }
                final Rect finalClip = endClip;
                if (startClip == null) {
                    startClip = new Rect(0, 0, startWidth, startHeight);
                }
                if (endClip == null) {
                    endClip = new Rect(0, 0, endWidth, endHeight);
                }
                ObjectAnimator clipAnimator = null;
                if (!startClip.equals(endClip)) {
                    ViewUtils.setClipBounds(view, startClip);
                    clipAnimator = ObjectAnimator.ofObject(view, ChangeClipBounds.VIEW_CLIP_BOUNDS, sRectEvaluator, startClip, endClip);
                    clipAnimator.addListener(new AnimatorListenerAdapter() {

                        private boolean mIsCanceled;

                        @Override
                        public void onAnimationCancel(Animator animation) {
                            mIsCanceled = true;
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (!mIsCanceled) {
                                ViewUtils.setClipBounds(view, finalClip);
                                ViewUtils.setLeftTopRightBottom(view, endLeft, endTop, endRight, endBottom);
                            }
                        }
                    });
                }
                anim = TransitionUtils.mergeAnimators(positionAnimator, clipAnimator);
            }
            if (view.getParent() instanceof ViewGroup) {
                final ViewGroup parent = (ViewGroup) view.getParent();
                ViewGroupUtils.suppressLayout(parent, true);
                TransitionListener transitionListener = new TransitionListenerAdapter() {

                    boolean mCanceled = false;

                    @Override
                    public void onTransitionCancel(Transition transition) {
                        ViewGroupUtils.suppressLayout(parent, false);
                        mCanceled = true;
                    }

                    @Override
                    public void onTransitionEnd(Transition transition) {
                        if (!mCanceled) {
                            ViewGroupUtils.suppressLayout(parent, false);
                        }
                    }

                    @Override
                    public void onTransitionPause(Transition transition) {
                        ViewGroupUtils.suppressLayout(parent, false);
                    }

                    @Override
                    public void onTransitionResume(Transition transition) {
                        ViewGroupUtils.suppressLayout(parent, true);
                    }
                };
                addListener(transitionListener);
            }
            return anim;
        }
    } else {
        sceneRoot.getLocationInWindow(tempLocation);
        int startX = (Integer) startValues.values.get(PROPNAME_WINDOW_X) - tempLocation[0];
        int startY = (Integer) startValues.values.get(PROPNAME_WINDOW_Y) - tempLocation[1];
        int endX = (Integer) endValues.values.get(PROPNAME_WINDOW_X) - tempLocation[0];
        int endY = (Integer) endValues.values.get(PROPNAME_WINDOW_Y) - tempLocation[1];
        // TODO: also handle size changes: check bounds and animate size changes
        if (startX != endX || startY != endY) {
            final int width = view.getWidth();
            final int height = view.getHeight();
            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            view.draw(canvas);
            final BitmapDrawable drawable = new BitmapDrawable(sceneRoot.getContext().getResources(), bitmap);
            drawable.setBounds(startX, startY, startX + width, startY + height);
            Animator anim;
            anim = AnimatorUtils.ofPointF(drawable, DRAWABLE_ORIGIN_PROPERTY, getPathMotion(), startX, startY, endX, endY);
            if (anim != null) {
                final float alpha = view.getAlpha();
                view.setAlpha(0);
                ViewOverlayUtils.addOverlay(sceneRoot, drawable);
                anim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        ViewOverlayUtils.removeOverlay(sceneRoot, drawable);
                        view.setAlpha(alpha);
                    }
                });
            }
            return anim;
        }
    }
    return null;
}
Also used : RectEvaluator(com.transitionseverywhere.utils.RectEvaluator) Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) ObjectAnimator(android.animation.ObjectAnimator) Canvas(android.graphics.Canvas) AnimatorSet(android.animation.AnimatorSet) BitmapDrawable(android.graphics.drawable.BitmapDrawable) View(android.view.View) Bitmap(android.graphics.Bitmap) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 47 with AnimatorSet

use of android.animation.AnimatorSet in project platform_frameworks_base by android.

the class FragmentManagerImpl method modifiesAlpha.

static boolean modifiesAlpha(Animator anim) {
    if (anim == null) {
        return false;
    }
    if (anim instanceof ValueAnimator) {
        ValueAnimator valueAnim = (ValueAnimator) anim;
        PropertyValuesHolder[] values = valueAnim.getValues();
        for (int i = 0; i < values.length; i++) {
            if (("alpha").equals(values[i].getPropertyName())) {
                return true;
            }
        }
    } else if (anim instanceof AnimatorSet) {
        List<Animator> animList = ((AnimatorSet) anim).getChildAnimations();
        for (int i = 0; i < animList.size(); i++) {
            if (modifiesAlpha(animList.get(i))) {
                return true;
            }
        }
    }
    return false;
}
Also used : PropertyValuesHolder(android.animation.PropertyValuesHolder) AnimatorSet(android.animation.AnimatorSet) ArrayList(java.util.ArrayList) List(java.util.List) ValueAnimator(android.animation.ValueAnimator)

Example 48 with AnimatorSet

use of android.animation.AnimatorSet in project platform_frameworks_base by android.

the class FloatingToolbar method createExitAnimation.

/**
     * Creates a "disappear" animation for the specified view.
     *
     * @param view  The view to animate
     * @param startDelay  The start delay of the animation
     * @param listener  The animation listener
     */
private static AnimatorSet createExitAnimation(View view, int startDelay, Animator.AnimatorListener listener) {
    AnimatorSet animation = new AnimatorSet();
    animation.playTogether(ObjectAnimator.ofFloat(view, View.ALPHA, 1, 0).setDuration(100));
    animation.setStartDelay(startDelay);
    animation.addListener(listener);
    return animation;
}
Also used : AnimatorSet(android.animation.AnimatorSet)

Example 49 with AnimatorSet

use of android.animation.AnimatorSet in project FlyRefresh by race604.

the class FlyRefreshLayout method startRefresh.

@Override
public void startRefresh() {
    if (mFlyAnimator != null) {
        mFlyAnimator.end();
    }
    final View iconView = getIconView();
    UIUtils.clearAnimator(iconView);
    AnimatorSet flyUpAnim = new AnimatorSet();
    flyUpAnim.setDuration(800);
    ObjectAnimator transX = ObjectAnimator.ofFloat(iconView, "translationX", 0, getWidth());
    ObjectAnimator transY = ObjectAnimator.ofFloat(iconView, "translationY", 0, -mHeaderController.getHeight());
    transY.setInterpolator(PathInterpolatorCompat.create(0.7f, 1f));
    ObjectAnimator rotation = ObjectAnimator.ofFloat(iconView, "rotation", -45, 0);
    rotation.setInterpolator(new DecelerateInterpolator());
    ObjectAnimator rotationX = ObjectAnimator.ofFloat(iconView, "rotationX", 0, 60);
    rotationX.setInterpolator(new DecelerateInterpolator());
    flyUpAnim.playTogether(transX, transY, rotationX, ObjectAnimator.ofFloat(iconView, "scaleX", 1, 0.5f), ObjectAnimator.ofFloat(iconView, "scaleY", 1, 0.5f), rotation);
    mFlyAnimator = flyUpAnim;
    mFlyAnimator.start();
    if (mListener != null) {
        mListener.onRefresh(FlyRefreshLayout.this);
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) MountanScenceView(com.race604.flyrefresh.internal.MountanScenceView)

Example 50 with AnimatorSet

use of android.animation.AnimatorSet in project FlyRefresh by race604.

the class SampleItemAnimator method animateAddImpl.

@Override
protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
    View target = holder.itemView;
    View icon = target.findViewById(R.id.icon);
    Animator swing = ObjectAnimator.ofFloat(icon, "rotationX", 45, 0);
    swing.setInterpolator(new OvershootInterpolator(5));
    View right = holder.itemView.findViewById(R.id.right);
    Animator rotateIn = ObjectAnimator.ofFloat(right, "rotationY", 90, 0);
    rotateIn.setInterpolator(new DecelerateInterpolator());
    AnimatorSet animator = new AnimatorSet();
    animator.setDuration(getAddDuration());
    animator.playTogether(swing, rotateIn);
    animator.start();
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) BaseItemAnimator(jp.wasabeef.recyclerview.animators.BaseItemAnimator) OvershootInterpolator(android.view.animation.OvershootInterpolator) AnimatorSet(android.animation.AnimatorSet) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

AnimatorSet (android.animation.AnimatorSet)491 ObjectAnimator (android.animation.ObjectAnimator)343 Animator (android.animation.Animator)285 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)144 View (android.view.View)109 ValueAnimator (android.animation.ValueAnimator)103 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)52 ArrayList (java.util.ArrayList)50 Rect (android.graphics.Rect)43 ViewGroup (android.view.ViewGroup)42 ImageView (android.widget.ImageView)36 TextView (android.widget.TextView)32 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)26 PropertyValuesHolder (android.animation.PropertyValuesHolder)25 Paint (android.graphics.Paint)25 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)25 Bitmap (android.graphics.Bitmap)17 Point (android.graphics.Point)15 OvershootInterpolator (android.view.animation.OvershootInterpolator)15 BitmapDrawable (android.graphics.drawable.BitmapDrawable)14