Java Code Examples for android.animation.PropertyValuesHolder#ofObject()

The following examples show how to use android.animation.PropertyValuesHolder#ofObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbsoluteChangeBounds.java    From scene with Apache License 2.0 5 votes vote down vote up
@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }

    final View view = endValues.view;
    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(bitmap);
        view.setAlpha(0);
        drawable.setBounds(startX, startY, startX + width, startY + height);
        sceneRoot.getOverlay().add(drawable);
        Path topLeftPath = getPathMotion().getPath(startX, startY, endX, endY);
        PropertyValuesHolder origin = PropertyValuesHolder.ofObject(
                DRAWABLE_ORIGIN_PROPERTY, null, topLeftPath);
        ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(drawable, origin);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                sceneRoot.getOverlay().remove(drawable);
                view.setAlpha(1);
            }
        });
        return anim;
    }
    return null;
}
 
Example 2
Source File: PropertyAnimationActivity.java    From Android-Animation-Set with Apache License 2.0 5 votes vote down vote up
/**
 * ObjectAnimator: You can also create multiple animations by PropertyValuesHolder.
 * <p>
 * ValueAnimator has the same method, but we don't use it that way. #ValueAnimator.ofPropertyValuesHolder()#
 *
 * @return
 */
public Animator getObjectAnimatorByPropertyValuesHolder() {
    PropertyValuesHolder bgColorAnimator = PropertyValuesHolder.ofObject("backgroundColor",
            new ArgbEvaluator(),
            0xff009688, 0xff795548);
    PropertyValuesHolder rotationXAnimator = PropertyValuesHolder.ofFloat("rotationX",
            0f, 360f);
    ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(mPuppet, bgColorAnimator, rotationXAnimator);
    objectAnimator.setDuration(3000);
    objectAnimator.setRepeatCount(1);
    objectAnimator.setRepeatMode(ValueAnimator.REVERSE);
    return objectAnimator;
}
 
Example 3
Source File: ObjectAnimatorValueHolderFragment.java    From AndroidAll with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    super.onClick(v);
    switch (v.getId()) {
        case R.id.btn_start_animation_a:

            PropertyValuesHolder colorHolder = PropertyValuesHolder.ofInt("backgroundColor",
                    0xffffffff, 0xffff00ff, 0xffffff00, 0xffffffff);
            PropertyValuesHolder rotationHolder = PropertyValuesHolder.ofFloat("rotation", 180, -90, 90, 0);

            ObjectAnimator
                    .ofPropertyValuesHolder(tvTargetA, colorHolder, rotationHolder)
                    .setDuration(3000)
                    .start();
            break;

        case R.id.btn_start_animation_b:
            PropertyValuesHolder valuesHolder = PropertyValuesHolder
                    .ofObject("char", new CharacterEvaluate(), 'A', 'Z');

            ObjectAnimator
                    .ofPropertyValuesHolder(tvTargetB, valuesHolder)
                    .setDuration(4000)
                    .start();
            break;
        case R.id.btn_start_animation_c:
            ObjectAnimator.ofPropertyValuesHolder(ivTargetC,
                    getRotationValuesHolder(),
                    getScaleXValuesHolder(), getScaleYValuesHolder())
                    .setDuration(800)
                    .start();
            break;
    }
}
 
Example 4
Source File: ReflowTextAnimatorHelper.java    From reflow-animator with Apache License 2.0 5 votes vote down vote up
@TargetApi(LOLLIPOP)
private PropertyValuesHolder getPathValuesHolder(Run run, int dy, int dx) {
    PropertyValuesHolder propertyValuesHolder;
    if (IS_LOLLIPOP_OR_ABOVE) {
        PathMotion pathMotion = new PathMotion() {
            @Override
            public Path getPath(float startX, float startY, float endX, float endY) {
                return ReflowTextAnimatorHelper.getPath(startX, startY, endX, endY);
            }
        };
        propertyValuesHolder = PropertyValuesHolder.ofObject(SwitchDrawable.TOP_LEFT, null,
                pathMotion.getPath(
                        run.getStart().left,
                        run.getStart().top,
                        run.getEnd().left - dx,
                        run.getEnd().top - dy));
    } else {
        PointF startPoint = new PointF(run.getStart().left, run.getStart().top);
        PointF endPoint = new PointF(run.getEnd().left - dx, run.getEnd().top - dy);
        propertyValuesHolder = PropertyValuesHolder.ofObject(SwitchDrawable.TOP_LEFT, new TypeEvaluator<PointF>() {
            private final PointF point = new PointF();

            @Override
            public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
                float x = startValue.x + (endValue.x - startValue.x) * fraction;
                float y = startValue.y + (endValue.y - startValue.y) * fraction;

                point.set(x, y);

                return point;
            }
        }, startPoint, endPoint);
    }

    return propertyValuesHolder;
}
 
Example 5
Source File: PropertyAnimationActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * ObjectAnimator: You can also create multiple animations by PropertyValuesHolder.
 * <p>
 * ValueAnimator has the same method, but we don't use it that way. #ValueAnimator.ofPropertyValuesHolder()#
 *
 * @return
 */
public Animator getObjectAnimatorByPropertyValuesHolder() {
    PropertyValuesHolder bgColorAnimator = PropertyValuesHolder.ofObject("backgroundColor",
            new ArgbEvaluator(),
            0xff009688, 0xff795548);
    PropertyValuesHolder rotationXAnimator = PropertyValuesHolder.ofFloat("rotationX",
            0f, 360f);
    ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(mPuppet, bgColorAnimator, rotationXAnimator);
    objectAnimator.setDuration(3000);
    objectAnimator.setRepeatCount(1);
    objectAnimator.setRepeatMode(ValueAnimator.REVERSE);
    return objectAnimator;
}