Example usage for android.animation ObjectAnimator ofObject

List of usage examples for android.animation ObjectAnimator ofObject

Introduction

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

Prototype

@NonNull
@SafeVarargs
public static <T, V, P> ObjectAnimator ofObject(T target, Property<T, P> property,
        TypeConverter<V, P> converter, TypeEvaluator<V> evaluator, V... values) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates between Object values.

Usage

From source file:com.lambdasoup.quickfit.util.ui.BackgroundTintListAnimator.java

public static ObjectAnimator create(@NonNull Context context, @NonNull Object target, @ColorRes int startColor,
        @ColorRes int endColor, long duration) {
    ColorStateList startColorStateList = ColorStateList.valueOf(ContextCompat.getColor(context, startColor));
    ColorStateList endColorStateList = ColorStateList.valueOf(ContextCompat.getColor(context, endColor));
    ObjectAnimator animator = ObjectAnimator.ofObject(target, "backgroundTintList",
            ColorStateListEvaluator.INSTANCE, startColorStateList, endColorStateList);
    animator.setDuration(duration);//from  w w  w . java2s .  c  o m
    return animator;
}

From source file:me.calebjones.spacelaunchnow.utils.Utils.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void animateViewColor(View v, int startColor, int endColor) {

    ObjectAnimator animator = ObjectAnimator.ofObject(v, "backgroundColor", new ArgbEvaluator(), startColor,
            endColor);/*www  .j  a  v  a  2 s .  c  om*/

    animator.setInterpolator(new PathInterpolator(0.4f, 0f, 1f, 1f));
    animator.setDuration(COLOR_ANIMATION_DURATION);
    animator.start();
}

From source file:com.awt.supark.LayoutHandler.java

public void appBackgroundColorChange(View view, int time, int r, int g, int b) {
    ColorDrawable wBack = (ColorDrawable) view.getBackground();
    int color = wBack.getColor();
    int r1 = Color.red(color);
    int g1 = Color.green(color);
    int b1 = Color.blue(color);

    ObjectAnimator colorFade = ObjectAnimator.ofObject(view, "backgroundColor", new ArgbEvaluator(),
            Color.argb(255, r1, g1, b1), Color.argb(255, r, g, b));
    colorFade.setDuration(time);//w ww.j  a va 2s  .  c  o m
    colorFade.start();
}

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

@Override
public Animator createAnimator(@NonNull final ViewGroup sceneRoot, TransitionValues startValues,
        TransitionValues endValues) {/*from ww w.  j ava 2  s.  co m*/
    if (startValues == null || endValues == null || !startValues.values.containsKey(PROPNAME_CLIP)
            || !endValues.values.containsKey(PROPNAME_CLIP)) {
        return null;
    }
    Rect start = (Rect) startValues.values.get(PROPNAME_CLIP);
    Rect end = (Rect) endValues.values.get(PROPNAME_CLIP);
    final boolean endIsNull = end == null;
    if (start == null && end == null) {
        return null; // No animation required since there is no clip.
    }

    if (start == null) {
        start = (Rect) startValues.values.get(PROPNAME_BOUNDS);
    } else if (end == null) {
        end = (Rect) endValues.values.get(PROPNAME_BOUNDS);
    }
    if (start.equals(end)) {
        return null;
    }

    ViewCompat.setClipBounds(endValues.view, start);
    RectEvaluator evaluator = new RectEvaluator(new Rect());
    ObjectAnimator animator = ObjectAnimator.ofObject(endValues.view, ViewUtils.CLIP_BOUNDS, evaluator, start,
            end);
    if (endIsNull) {
        final View endView = endValues.view;
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                ViewCompat.setClipBounds(endView, null);
            }
        });
    }
    return animator;
}

From source file:com.asc_ii.bangnote.bigbang.BigBangActionBar.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int width = getMeasuredWidth();
    int height = getMeasuredHeight();

    layoutSubView(mSearch, mActionGap, 0);
    layoutSubView(mShare, width - mActionGap * 2 - mShare.getMeasuredWidth() - mCopy.getMeasuredWidth(), 0);
    layoutSubView(mCopy, width - mActionGap - mCopy.getMeasuredWidth(), 0);

    Rect oldBounds = mBorder.getBounds();
    Rect newBounds = new Rect(0, mSearch.getMeasuredHeight() / 2, width, height);

    if (!oldBounds.equals(newBounds)) {
        ObjectAnimator.ofObject(mBorder, "bounds", new RectEvaluator(), oldBounds, newBounds).setDuration(200)
                .start();/*from w w  w  .  jav  a2 s.c om*/
    }
}

From source file:com.hippo.android.animator.AnimatorsBase.java

static <T> Animator ofPointF(T target, Property<T, PointF> property, float startX, float startY, float endX,
        float endY) {
    TypeEvaluator<PointF> evaluator = new LinePointFEvaluator(startX, startY, endX, endY);
    return ObjectAnimator.ofObject(target, property, evaluator, DUMP_POINT_F, DUMP_POINT_F);
}

From source file:com.hippo.android.animator.AnimatorsBase.java

static <T> Animator ofPointF(T target, Property<T, PointF> property, Path path) {
    TypeEvaluator<PointF> evaluator = new PathPointFEvaluator(path);
    return ObjectAnimator.ofObject(target, property, evaluator, DUMP_POINT_F, DUMP_POINT_F);
}

From source file:com.andremion.counterfab.CounterFab.java

private void startAnimation() {
    float start = 0f;
    float end = 1f;
    if (mCount == 0) {
        start = 1f;/*from w ww  .j a  va  2  s  .co  m*/
        end = 0f;
    }
    if (isAnimating()) {
        mAnimator.cancel();
    }
    mAnimator = ObjectAnimator.ofObject(this, ANIMATION_PROPERTY, null, start, end);
    mAnimator.setInterpolator(ANIMATION_INTERPOLATOR);
    mAnimator.setDuration(mAnimationDuration);
    mAnimator.start();
}

From source file:com.example.google.maps.flyover.MainActivity.java

public void animateRoute() {
    LinkedList<Animator> animators = new LinkedList<Animator>();

    // For each segment of the route, create one heading adjustment animator
    // and one segment fly-over animator.
    for (int i = 0; i < ROUTE.length - 1; i++) {
        // If it the first segment, ensure the camera is rotated properly.
        float h1;
        if (i == 0) {
            h1 = mMap.getCameraPosition().bearing;
        } else {//from ww w  . j  ava  2s  .c  o  m
            h1 = (float) SphericalUtil.computeHeading(ROUTE[i - 1], ROUTE[i]);
        }

        float h2 = (float) SphericalUtil.computeHeading(ROUTE[i], ROUTE[i + 1]);

        ValueAnimator va = ValueAnimator.ofFloat(h1, h2);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float bearing = (Float) animation.getAnimatedValue();
                CameraPosition pos = CameraPosition.builder(mMap.getCameraPosition()).bearing(bearing).build();
                mMap.moveCamera(CameraUpdateFactory.newCameraPosition(pos));
            }
        });

        // Use the change in degrees of the heading for the animation
        // duration.
        long d = Math.round(Math.abs(h1 - h2));
        va.setDuration(d * CAMERA_HEADING_CHANGE_RATE);
        animators.add(va);

        ObjectAnimator oa = ObjectAnimator.ofObject(mMarker, "position",
                new LatLngEvaluator(ROUTE[i], ROUTE[i + 1]), ROUTE[i], ROUTE[i + 1]);

        oa.setInterpolator(new LinearInterpolator());
        oa.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                LatLng target = (LatLng) animation.getAnimatedValue();
                mMap.moveCamera(CameraUpdateFactory.newLatLng(target));
            }
        });

        // Use the distance of the route segment for the duration.
        double dist = SphericalUtil.computeDistanceBetween(ROUTE[i], ROUTE[i + 1]);
        oa.setDuration(Math.round(dist) * 10);

        animators.add(oa);
    }

    mAnimatorSet = new AnimatorSet();
    mAnimatorSet.playSequentially(animators);
    mAnimatorSet.start();

    mAnimatorSet.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationCancel(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_replay);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_replay);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationStart(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_stop);
        }
    });
}

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

@Override
@Nullable//  w ww  . jav a2s. 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;
}