Example usage for android.animation ObjectAnimator ofPropertyValuesHolder

List of usage examples for android.animation ObjectAnimator ofPropertyValuesHolder

Introduction

In this page you can find the example usage for android.animation ObjectAnimator ofPropertyValuesHolder.

Prototype

@NonNull
public static ObjectAnimator ofPropertyValuesHolder(Object target, PropertyValuesHolder... values) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates between the sets of values specified in PropertyValueHolder objects.

Usage

From source file:com.chauffeurprive.kronos.time.RadialTextsView.java

/**
 * Render the animations for appearing and disappearing.
 */// ww w . java2 s . c o m
private void renderAnimations() {
    Keyframe kf0, kf1, kf2, kf3;
    float midwayPoint = 0.2f;
    int duration = 500;

    // Set up animator for disappearing.
    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier);
    PropertyValuesHolder radiusDisappear = PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0,
            kf1, kf2);

    kf0 = Keyframe.ofFloat(0f, 1f);
    kf1 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);

    mDisappearAnimator = ObjectAnimator.ofPropertyValuesHolder(this, fadeOut).setDuration(duration);
    mDisappearAnimator.addUpdateListener(mInvalidateUpdateListener);

    // Set up animator for reappearing.
    float delayMultiplier = 0.25f;
    float transitionDurationMultiplier = 1f;
    float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
    int totalDuration = (int) (duration * totalDurationMultiplier);
    float delayPoint = (delayMultiplier * duration) / totalDuration;
    midwayPoint = 1 - (midwayPoint * (1 - delayPoint));

    kf0 = Keyframe.ofFloat(0f, mTransitionEndRadiusMultiplier);
    kf1 = Keyframe.ofFloat(delayPoint, mTransitionEndRadiusMultiplier);
    kf2 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf3 = Keyframe.ofFloat(1f, 1);
    PropertyValuesHolder radiusReappear = PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1,
            kf2, kf3);

    kf0 = Keyframe.ofFloat(0f, 0f);
    kf1 = Keyframe.ofFloat(delayPoint, 0f);
    kf2 = Keyframe.ofFloat(1f, 1f);
    PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2);

    mReappearAnimator = ObjectAnimator.ofPropertyValuesHolder(this, radiusReappear, fadeIn)
            .setDuration(totalDuration);
    mReappearAnimator.addUpdateListener(mInvalidateUpdateListener);
}

From source file:com.androidinspain.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java

private Animator createCollapsingAnimator(AlarmItemViewHolder newHolder, long duration) {
    arrow.setVisibility(View.INVISIBLE);
    clock.setVisibility(View.INVISIBLE);
    onOff.setVisibility(View.INVISIBLE);

    final boolean daysVisible = repeatDays.getVisibility() == View.VISIBLE;
    final int numberOfItems = countNumberOfItems();

    final View oldView = itemView;
    final View newView = newHolder.itemView;

    final Animator backgroundAnimator = ObjectAnimator.ofPropertyValuesHolder(oldView,
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 255, 0));
    backgroundAnimator.setDuration(duration);

    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(oldView, oldView, newView);
    boundsAnimator.setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final long shortDuration = (long) (duration * ANIM_SHORT_DURATION_MULTIPLIER);
    final Animator repeatAnimation = ObjectAnimator.ofFloat(repeat, View.ALPHA, 0f).setDuration(shortDuration);
    final Animator editLabelAnimation = ObjectAnimator.ofFloat(editLabel, View.ALPHA, 0f)
            .setDuration(shortDuration);
    final Animator repeatDaysAnimation = ObjectAnimator.ofFloat(repeatDays, View.ALPHA, 0f)
            .setDuration(shortDuration);
    final Animator vibrateAnimation = ObjectAnimator.ofFloat(vibrate, View.ALPHA, 0f)
            .setDuration(shortDuration);
    final Animator ringtoneAnimation = ObjectAnimator.ofFloat(ringtone, View.ALPHA, 0f)
            .setDuration(shortDuration);
    final Animator dismissAnimation = ObjectAnimator.ofFloat(preemptiveDismissButton, View.ALPHA, 0f)
            .setDuration(shortDuration);
    final Animator deleteAnimation = ObjectAnimator.ofFloat(delete, View.ALPHA, 0f).setDuration(shortDuration);
    final Animator hairLineAnimation = ObjectAnimator.ofFloat(hairLine, View.ALPHA, 0f)
            .setDuration(shortDuration);

    // Set the staggered delays; use the first portion (duration * (1 - 1/4 - 1/6)) of the time,
    // so that the final animation, with a duration of 1/4 the total duration, finishes exactly
    // before the collapsed holder begins expanding.
    long startDelay = 0L;
    final long delayIncrement = (long) (duration * ANIM_LONG_DELAY_INCREMENT_MULTIPLIER) / (numberOfItems - 1);
    deleteAnimation.setStartDelay(startDelay);
    if (preemptiveDismissButton.getVisibility() == View.VISIBLE) {
        startDelay += delayIncrement;//from  w  ww. ja  v  a  2s .  c  o m
        dismissAnimation.setStartDelay(startDelay);
    }
    hairLineAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    editLabelAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    vibrateAnimation.setStartDelay(startDelay);
    ringtoneAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    if (daysVisible) {
        repeatDaysAnimation.setStartDelay(startDelay);
        startDelay += delayIncrement;
    }
    repeatAnimation.setStartDelay(startDelay);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(backgroundAnimator, boundsAnimator, repeatAnimation, repeatDaysAnimation,
            vibrateAnimation, ringtoneAnimation, editLabelAnimation, deleteAnimation, hairLineAnimation,
            dismissAnimation);
    return animatorSet;
}

From source file:com.taobao.weex.dom.transition.WXTransition.java

/**
 *  transform, opacity, backgroundcolor which not effect layout use android system animation in main thread.
 * *//*from  w  ww. j av  a  2  s.  c  o m*/
private void doPendingTransformAnimation(int token) {
    if (transformAnimator != null) {
        transformAnimator.cancel();
        transformAnimator = null;
    }
    if (transformPendingUpdates.size() == 0) {
        return;
    }
    final View taregtView = getTargetView();
    if (taregtView == null) {
        return;
    }
    List<PropertyValuesHolder> holders = new ArrayList<>(8);
    String transform = WXUtils.getString(transformPendingUpdates.remove(Constants.Name.TRANSFORM), null);
    if (!TextUtils.isEmpty(transform)) {
        Map<Property<View, Float>, Float> properties = TransformParser.parseTransForm(transform,
                (int) domObject.getLayoutWidth(), (int) domObject.getLayoutHeight(),
                domObject.getViewPortWidth());
        PropertyValuesHolder[] transformHolders = TransformParser.toHolders(properties);
        for (PropertyValuesHolder holder : transformHolders) {
            holders.add(holder);
        }
        synchronized (targetStyles) {
            targetStyles.put(Constants.Name.TRANSFORM, transform);
        }
    }

    for (String property : properties) {
        if (!TRANSFORM_PROPERTIES.contains(property)) {
            continue;
        }
        if (!transformPendingUpdates.containsKey(property)) {
            continue;
        }
        Object value = transformPendingUpdates.remove(property);
        synchronized (targetStyles) {
            targetStyles.put(property, value);
        }
        switch (property) {
        case Constants.Name.OPACITY: {
            holders.add(PropertyValuesHolder.ofFloat(View.ALPHA, taregtView.getAlpha(),
                    WXUtils.getFloat(value, 1.0f)));
            taregtView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); //hardware or none has bug on some platform
        }
            break;
        case Constants.Name.BACKGROUND_COLOR: {
            int fromColor = WXResourceUtils
                    .getColor(WXUtils.getString(domObject.getStyles().getBackgroundColor(), null), 0);
            int toColor = WXResourceUtils.getColor(WXUtils.getString(value, null), 0);
            if (WXViewUtils.getBorderDrawable(taregtView) != null) {
                fromColor = WXViewUtils.getBorderDrawable(taregtView).getColor();
            } else if (taregtView.getBackground() instanceof ColorDrawable) {
                fromColor = ((ColorDrawable) taregtView.getBackground()).getColor();
            }
            holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(),
                    fromColor, toColor));
        }
            break;
        default:
            break;
        }
    }

    if (token == lockToken.get()) {
        transformPendingUpdates.clear();
    }
    transformAnimator = ObjectAnimator.ofPropertyValuesHolder(taregtView,
            holders.toArray(new PropertyValuesHolder[holders.size()]));
    transformAnimator.setDuration((long) duration);
    if ((long) delay > 0) {
        transformAnimator.setStartDelay((long) delay);
    }
    if (interpolator != null) {
        transformAnimator.setInterpolator(interpolator);
    }
    transformAnimator.addListener(new AnimatorListenerAdapter() {
        boolean hasCancel = false;

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            hasCancel = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (hasCancel) {
                return;
            }
            super.onAnimationEnd(animation);
            WXTransition.this.onTransitionAnimationEnd();
            if (WXEnvironment.isApkDebugable()) {
                WXLogUtils.d("WXTransition transform onTransitionAnimationEnd " + domObject.getRef());
            }
        }
    });
    transformAnimator.start();
}

From source file:com.taobao.weex.ui.animation.WXAnimationModule.java

private static @Nullable ObjectAnimator createAnimator(@NonNull WXAnimationBean animation, final View target,
        final int viewPortWidth) {
    if (target == null) {
        return null;
    }//from  w ww.j a va2 s.c  om
    WXAnimationBean.Style style = animation.styles;
    if (style != null) {
        ObjectAnimator animator;
        List<PropertyValuesHolder> holders = style.getHolders();
        if (!TextUtils.isEmpty(style.backgroundColor)) {
            BorderDrawable borderDrawable;
            if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) {
                holders.add(PropertyValuesHolder.ofObject(WXAnimationBean.Style.BACKGROUND_COLOR,
                        new ArgbEvaluator(), borderDrawable.getColor(),
                        WXResourceUtils.getColor(style.backgroundColor)));
            } else if (target.getBackground() instanceof ColorDrawable) {
                holders.add(PropertyValuesHolder.ofObject(WXAnimationBean.Style.BACKGROUND_COLOR,
                        new ArgbEvaluator(), ((ColorDrawable) target.getBackground()).getColor(),
                        WXResourceUtils.getColor(style.backgroundColor)));
            }
        }
        if (style.getPivot() != null) {
            Pair<Float, Float> pair = style.getPivot();
            target.setPivotX(pair.first);
            target.setPivotY(pair.second);
        }
        animator = ObjectAnimator.ofPropertyValuesHolder(target,
                holders.toArray(new PropertyValuesHolder[holders.size()]));
        animator.setStartDelay(animation.delay);
        if (target.getLayoutParams() != null
                && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) {
            DimensionUpdateListener listener = new DimensionUpdateListener(target);
            ViewGroup.LayoutParams layoutParams = target.getLayoutParams();
            if (!TextUtils.isEmpty(style.width)) {
                listener.setWidth(layoutParams.width,
                        (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth));
            }
            if (!TextUtils.isEmpty(style.height)) {
                listener.setHeight(layoutParams.height,
                        (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth));
            }
            animator.addUpdateListener(listener);
        }
        return animator;
    } else {
        return null;
    }
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void showLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float endFabX;
    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        endFabX = rootWidth / 2f + (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 0.98f;
    } else {/*from   w w  w.j a va 2  s .  c om*/
        endFabX = rootWidth / 2f - (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 1.02f;
    }

    /**
     * Animate FAB movement
     */
    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, endFabX, getY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Fade FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration((long) (FAB_MORPH_DURATION / 3f));
        anim.start();
    }

    /**
     * Animate FAB elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, dpToPixels(2));
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Create circular reveal
     */
    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) mFab.getWidth() / 2f, (float) (Math.hypot(getWidth() / 2, getHeight() / 2)));

    toolbarReveal.setDuration(CIRCULAR_REVEAL_DURATION);
    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mFab.setVisibility(View.INVISIBLE);
            setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mMorphing = false;
        }
    });

    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_REVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, dpToPixels(2));
    anim.setDuration(CIRCULAR_REVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_REVEAL_DELAY);
    anim.start();
}

From source file:com.androidinspain.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java

private Animator createExpandingAnimator(AlarmItemViewHolder oldHolder, long duration) {
    final View oldView = oldHolder.itemView;
    final View newView = itemView;
    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(newView, oldView, newView);
    boundsAnimator.setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final Animator backgroundAnimator = ObjectAnimator.ofPropertyValuesHolder(newView,
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 0, 255));
    backgroundAnimator.setDuration(duration);

    final View oldArrow = oldHolder.arrow;
    final Rect oldArrowRect = new Rect(0, 0, oldArrow.getWidth(), oldArrow.getHeight());
    final Rect newArrowRect = new Rect(0, 0, arrow.getWidth(), arrow.getHeight());
    ((ViewGroup) newView).offsetDescendantRectToMyCoords(arrow, newArrowRect);
    ((ViewGroup) oldView).offsetDescendantRectToMyCoords(oldArrow, oldArrowRect);
    final float arrowTranslationY = oldArrowRect.bottom - newArrowRect.bottom;

    arrow.setTranslationY(arrowTranslationY);
    arrow.setVisibility(View.VISIBLE);
    clock.setVisibility(View.VISIBLE);
    onOff.setVisibility(View.VISIBLE);

    final long longDuration = (long) (duration * ANIM_LONG_DURATION_MULTIPLIER);
    final Animator repeatAnimation = ObjectAnimator.ofFloat(repeat, View.ALPHA, 1f).setDuration(longDuration);
    final Animator repeatDaysAnimation = ObjectAnimator.ofFloat(repeatDays, View.ALPHA, 1f)
            .setDuration(longDuration);//from   w  ww.  j  av  a  2  s. co  m
    final Animator ringtoneAnimation = ObjectAnimator.ofFloat(ringtone, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator dismissAnimation = ObjectAnimator.ofFloat(preemptiveDismissButton, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator vibrateAnimation = ObjectAnimator.ofFloat(vibrate, View.ALPHA, 1f).setDuration(longDuration);
    final Animator editLabelAnimation = ObjectAnimator.ofFloat(editLabel, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator hairLineAnimation = ObjectAnimator.ofFloat(hairLine, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator deleteAnimation = ObjectAnimator.ofFloat(delete, View.ALPHA, 1f).setDuration(longDuration);
    final Animator arrowAnimation = ObjectAnimator.ofFloat(arrow, View.TRANSLATION_Y, 0f).setDuration(duration);
    arrowAnimation.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    // Set the stagger delays; delay the first by the amount of time it takes for the collapse
    // to complete, then stagger the expansion with the remaining time.
    long startDelay = (long) (duration * ANIM_STANDARD_DELAY_MULTIPLIER);
    final int numberOfItems = countNumberOfItems();
    final long delayIncrement = (long) (duration * ANIM_SHORT_DELAY_INCREMENT_MULTIPLIER) / (numberOfItems - 1);
    repeatAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    final boolean daysVisible = repeatDays.getVisibility() == View.VISIBLE;
    if (daysVisible) {
        repeatDaysAnimation.setStartDelay(startDelay);
        startDelay += delayIncrement;
    }
    ringtoneAnimation.setStartDelay(startDelay);
    vibrateAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    editLabelAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    hairLineAnimation.setStartDelay(startDelay);
    if (preemptiveDismissButton.getVisibility() == View.VISIBLE) {
        dismissAnimation.setStartDelay(startDelay);
        startDelay += delayIncrement;
    }
    deleteAnimation.setStartDelay(startDelay);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(backgroundAnimator, repeatAnimation, boundsAnimator, repeatDaysAnimation,
            vibrateAnimation, ringtoneAnimation, editLabelAnimation, deleteAnimation, hairLineAnimation,
            dismissAnimation, arrowAnimation);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animator) {
            AnimatorUtils.startDrawableAnimation(arrow);
        }
    });
    return animatorSet;
}

From source file:android.support.transition.ChangeBounds.java

@Override
@Nullable//from   ww  w . j av  a  2 s .c o m
public Animator createAnimator(@NonNull final ViewGroup sceneRoot, @Nullable TransitionValues startValues,
        @Nullable TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    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) {
                ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startRight, startBottom);
                if (numChanges == 2) {
                    if (startWidth == endWidth && startHeight == endHeight) {
                        Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                        anim = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY, topLeftPath);
                    } else {
                        final ViewBounds viewBounds = new ViewBounds(view);
                        Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                        ObjectAnimator topLeftAnimator = ObjectAnimatorUtils.ofPointF(viewBounds,
                                TOP_LEFT_PROPERTY, topLeftPath);

                        Path bottomRightPath = getPathMotion().getPath(startRight, startBottom, endRight,
                                endBottom);
                        ObjectAnimator bottomRightAnimator = ObjectAnimatorUtils.ofPointF(viewBounds,
                                BOTTOM_RIGHT_PROPERTY, bottomRightPath);
                        AnimatorSet set = new AnimatorSet();
                        set.playTogether(topLeftAnimator, bottomRightAnimator);
                        anim = set;
                        set.addListener(new AnimatorListenerAdapter() {
                            // We need a strong reference to viewBounds until the
                            // animator ends (The ObjectAnimator holds only a weak reference).
                            @SuppressWarnings("unused")
                            private ViewBounds mViewBounds = viewBounds;
                        });
                    }
                } else if (startLeft != endLeft || startTop != endTop) {
                    Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                    anim = ObjectAnimatorUtils.ofPointF(view, TOP_LEFT_ONLY_PROPERTY, topLeftPath);
                } else {
                    Path bottomRight = getPathMotion().getPath(startRight, startBottom, endRight, endBottom);
                    anim = ObjectAnimatorUtils.ofPointF(view, BOTTOM_RIGHT_ONLY_PROPERTY, bottomRight);
                }
            } else {
                int maxWidth = Math.max(startWidth, endWidth);
                int maxHeight = Math.max(startHeight, endHeight);

                ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startLeft + maxWidth,
                        startTop + maxHeight);

                ObjectAnimator positionAnimator = null;
                if (startLeft != endLeft || startTop != endTop) {
                    Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                    positionAnimator = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY, topLeftPath);
                }
                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)) {
                    ViewCompat.setClipBounds(view, startClip);
                    clipAnimator = ObjectAnimator.ofObject(view, "clipBounds", 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) {
                                ViewCompat.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(@NonNull Transition transition) {
                        ViewGroupUtils.suppressLayout(parent, false);
                        mCanceled = true;
                    }

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

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

                    @Override
                    public void onTransitionResume(@NonNull Transition transition) {
                        ViewGroupUtils.suppressLayout(parent, true);
                    }
                };
                addListener(transitionListener);
            }
            return anim;
        }
    } else {
        int startX = (Integer) startValues.values.get(PROPNAME_WINDOW_X);
        int startY = (Integer) startValues.values.get(PROPNAME_WINDOW_Y);
        int endX = (Integer) endValues.values.get(PROPNAME_WINDOW_X);
        int endY = (Integer) endValues.values.get(PROPNAME_WINDOW_Y);
        // TODO: also handle size changes: check bounds and animate size changes
        if (startX != endX || startY != endY) {
            sceneRoot.getLocationInWindow(mTempLocation);
            Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            view.draw(canvas);
            @SuppressWarnings("deprecation")
            final BitmapDrawable drawable = new BitmapDrawable(bitmap);
            final float transitionAlpha = ViewUtils.getTransitionAlpha(view);
            ViewUtils.setTransitionAlpha(view, 0);
            ViewUtils.getOverlay(sceneRoot).add(drawable);
            Path topLeftPath = getPathMotion().getPath(startX - mTempLocation[0], startY - mTempLocation[1],
                    endX - mTempLocation[0], endY - mTempLocation[1]);
            PropertyValuesHolder origin = PropertyValuesHolderUtils.ofPointF(DRAWABLE_ORIGIN_PROPERTY,
                    topLeftPath);
            ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(drawable, origin);
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    ViewUtils.getOverlay(sceneRoot).remove(drawable);
                    ViewUtils.setTransitionAlpha(view, transitionAlpha);
                }
            });
            return anim;
        }
    }
    return null;
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void hideLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        controlX = mFabOriginalX * 0.98f;
    } else {/*  w  w  w.j a va 2  s .  c  om*/
        controlX = mFabOriginalX * 1.02f;
    }

    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, mFabOriginalX, mFabOriginalY + getTranslationY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_UNMORPH_DURATION);
    anim.setStartDelay(FAB_UNMORPH_DELAY);
    anim.start();

    /**
     * Animate FAB elevation back to 6dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, 0);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_UNMORPH_DURATION);
    anim.setStartDelay(FAB_UNMORPH_DELAY);
    anim.start();

    /**
     * Restore alpha of FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 255));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration(FAB_UNMORPH_DURATION);
        anim.setStartDelay(FAB_UNMORPH_DELAY);
        anim.start();
    }

    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) (Math.hypot(getWidth() / 2, getHeight() / 2)), (float) mFab.getWidth() / 2f);

    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            setVisibility(View.INVISIBLE);
            mFab.setVisibility(View.VISIBLE);
            mMorphing = false;
        }
    });
    toolbarReveal.setDuration(CIRCULAR_UNREVEAL_DURATION);
    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_UNREVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar animation back to 6dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0);
    anim.setDuration(CIRCULAR_UNREVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_UNREVEAL_DELAY);
    anim.start();
}

From source file:com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator.java

@SuppressLint("NewApi")
public ObjectAnimator get() {
    if (hasView()) {
        Collection<PropertyValuesHolder> holders = mPropertyHoldersMap.values();
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mView.get(),
                holders.toArray(new PropertyValuesHolder[holders.size()]));
        if (mWithLayer) {
            animator.addListener(new AnimatorListenerAdapter() {
                int mCurrentLayerType = View.LAYER_TYPE_NONE;

                @Override//from   w ww. ja v a2  s .  c o m
                public void onAnimationStart(Animator animation) {
                    if (hasView()) {
                        View view = mView.get();
                        mCurrentLayerType = view.getLayerType();
                        view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
                        if (ViewCompat.isAttachedToWindow(view)) {
                            view.buildLayer();
                        }
                    }
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    if (hasView()) {
                        mView.get().setLayerType(mCurrentLayerType, null);
                    }
                }
            });
        }
        if (mStartDelay != -1) {
            animator.setStartDelay(mStartDelay);
        }
        if (mDuration != -1) {
            animator.setDuration(mDuration);
        }
        if (mInterpolator != null) {
            animator.setInterpolator(mInterpolator);
        }
        for (Animator.AnimatorListener listener : mListeners) {
            animator.addListener(listener);
        }
        if (mMarginListener != null) {
            animator.addUpdateListener(mMarginListener);
        }
        if (mDimensionListener != null) {
            animator.addUpdateListener(mDimensionListener);
        }
        if (mPaddingListener != null) {
            animator.addUpdateListener(mPaddingListener);
        }
        if (mScrollListener != null) {
            animator.addUpdateListener(mScrollListener);
        }
        if (mPercentListener != null) {
            animator.addUpdateListener(mPercentListener);
        }
        for (ValueAnimator.AnimatorUpdateListener listener : mUpdateListeners) {
            animator.addUpdateListener(listener);
        }
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            for (Animator.AnimatorPauseListener listener : mPauseListeners) {
                animator.addPauseListener(listener);
            }
        }
        return animator;
    }
    return ObjectAnimator.ofFloat(null, View.ALPHA, 1, 1);
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private static ObjectAnimator getFadeInAnimator(IntHolder target, int startAlpha, int endAlpha,
        InvalidateUpdateListener updateListener) {
    final float delayMultiplier = 0.25f;
    final float transitionDurationMultiplier = 1f;
    final float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
    final int totalDuration = (int) (FADE_IN_DURATION * totalDurationMultiplier);
    final float delayPoint = (delayMultiplier * FADE_IN_DURATION) / totalDuration;

    final Keyframe kf0, kf1, kf2;
    kf0 = Keyframe.ofInt(0f, startAlpha);
    kf1 = Keyframe.ofInt(delayPoint, startAlpha);
    kf2 = Keyframe.ofInt(1f, endAlpha);//from   w ww  .j a  v  a2 s .com
    final PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("value", kf0, kf1, kf2);

    final ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, fadeIn);
    animator.setDuration(totalDuration);
    animator.addUpdateListener(updateListener);
    return animator;
}