Java Code Examples for android.animation.ObjectAnimator#ofPropertyValuesHolder()

The following examples show how to use android.animation.ObjectAnimator#ofPropertyValuesHolder() . 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: FragmentTransactionExtended.java    From Kernel-Tuner with GNU General Public License v3.0 6 votes vote down vote up
public void slideForward() {
    View movingFragmentView = mFirstFragment.getView();
    PropertyValuesHolder rotateX = PropertyValuesHolder.ofFloat("rotationX", 40f);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1f);
    ObjectAnimator movingFragmentAnimator = ObjectAnimator.ofPropertyValuesHolder(movingFragmentView, rotateX, scaleX, scaleY, alpha);

    ObjectAnimator movingFragmentRotator = ObjectAnimator.ofFloat(movingFragmentView, "rotationX", 0);
    movingFragmentRotator.setStartDelay(mContext.getResources().getInteger(R.integer.half_slide_up_down_duration));

    AnimatorSet s = new AnimatorSet();
    s.playTogether(movingFragmentAnimator, movingFragmentRotator);
    s.setStartDelay(mContext.getResources().getInteger(R.integer.slide_up_down_duration));
    s.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mIsAnimating = false;
            mDidSlideOut = true;
        }
    });
    s.start();
    ((Activity) this.mContext).getFragmentManager().removeOnBackStackChangedListener(this);
}
 
Example 2
Source File: ScaleHideAnimator.java    From AndroidSkinAnimator with MIT License 6 votes vote down vote up
@Override
public SkinAnimator apply(@NonNull final View view, @Nullable final Action action) {
    animator = ObjectAnimator.ofPropertyValuesHolder(view,
            PropertyValuesHolder.ofFloat("alpha", 1, 0),
            PropertyValuesHolder.ofFloat("scaleX", 1, 0),
            PropertyValuesHolder.ofFloat("scaleY", 1, 0)
    );
    animator.setDuration(3 * PRE_DURATION);
    animator.setInterpolator(new AnticipateInterpolator());
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            resetView(view);
            if (action != null) {
                action.action();
            }
        }
    });
    return this;
}
 
Example 3
Source File: Utils.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
/**
 * Render an animator to pulsate a view in place.
 * @param labelToAnimate the view to pulsate.
 * @return The animator object. Use .start() to begin.
 */
public static ObjectAnimator getPulseAnimator(View labelToAnimate, float decreaseRatio,
        float increaseRatio) {
    Keyframe k0 = Keyframe.ofFloat(0f, 1f);
    Keyframe k1 = Keyframe.ofFloat(0.275f, decreaseRatio);
    Keyframe k2 = Keyframe.ofFloat(0.69f, increaseRatio);
    Keyframe k3 = Keyframe.ofFloat(1f, 1f);

    PropertyValuesHolder scaleX = PropertyValuesHolder.ofKeyframe("scaleX", k0, k1, k2, k3);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofKeyframe("scaleY", k0, k1, k2, k3);
    ObjectAnimator pulseAnimator =
            ObjectAnimator.ofPropertyValuesHolder(labelToAnimate, scaleX, scaleY);
    pulseAnimator.setDuration(PULSE_ANIMATOR_DURATION);

    return pulseAnimator;
}
 
Example 4
Source File: SoftKeyboardView.java    From AndroidTVWidget with Apache License 2.0 6 votes vote down vote up
private void scaleAnim(final SoftKey oldSoftkey, final SoftKey targetSoftKey) {
    try {
        PropertyValuesHolder valuesY1Holder = PropertyValuesHolder.ofFloat("width", targetSoftKey.getWidth(), targetSoftKey.getWidth() * mScale);
        PropertyValuesHolder valuesY2Holder = PropertyValuesHolder.ofFloat("height", targetSoftKey.getHeight(), targetSoftKey.getHeight() * mScale);
        invalidate();
        final ObjectAnimator scaleAnimator = ObjectAnimator.ofPropertyValuesHolder(targetSoftKey, valuesY1Holder, valuesY2Holder);
        scaleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float width = (float) animation.getAnimatedValue("width");
                float height = (float) animation.getAnimatedValue("height");
                SoftKey softKey = (SoftKey) scaleAnimator.getTarget();
                softKey.setWidth(width);
                softKey.setHeight(height);
                postInvalidate();
            }
        });
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(scaleAnimator);
        animatorSet.setDuration(mMoveDuration);
        animatorSet.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: TranslationAlphaHideAnimator.java    From AndroidSkinAnimator with MIT License 6 votes vote down vote up
@Override
public SkinAnimator apply(@NonNull final View view, @Nullable final Action action) {
    int offset = -view.getWidth() / 2;
    animator = ObjectAnimator.ofPropertyValuesHolder(view,
            PropertyValuesHolder.ofFloat("alpha", 1, 0),
            PropertyValuesHolder.ofFloat("translationX", 0, - offset, -offset, offset, offset, 0),
            PropertyValuesHolder.ofFloat("rotation", 0, -30, -30, 30, 30, 0),
            PropertyValuesHolder.ofFloat("translationY", 0, 3 * view.getHeight())
    );
    animator.setDuration(5 * PRE_DURATION);
    animator.setInterpolator(new LinearInterpolator());
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            resetView(view);
            if (action != null) {
                action.action();
            }
        }
    });
    return this;
}
 
Example 6
Source File: SlideInAnimationHandler.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
    public void animateMenuClosing(Point center) {
        super.animateMenuOpening(center);

        setAnimating(true);

        Animator lastAnimation = null;
        for (int i = 0; i < menu.getSubActionItems().size(); i++) {
//            PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, - (menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2));
            PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, DIST_Y);
//            PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 0);
//            PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0);
            PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 0);

            final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhY, pvhA);
            animation.setDuration(DURATION);
            animation.setInterpolator(new AccelerateInterpolator());
            animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.CLOSING));

            if(i == 0) {
                lastAnimation = animation;
            }

            if(i <= menu.getSubActionItems().size()/2) {
                animation.setStartDelay(i * LAG_BETWEEN_ITEMS);
            }
            else {
                animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
            }
            animation.start();
        }
        if(lastAnimation != null) {
            lastAnimation.addListener(new LastAnimationListener());
        }
    }
 
Example 7
Source File: ObjectAnimatorCompatBase.java    From MaterialProgressBar with Apache License 2.0 5 votes vote down vote up
@NonNull
public static ObjectAnimator ofFloat(@Nullable Object target, @NonNull String xPropertyName,
                                     @NonNull String yPropertyName, @NonNull Path path) {

    float[] xValues = new float[NUM_POINTS];
    float[] yValues = new float[NUM_POINTS];
    calculateXYValues(path, xValues, yValues);

    PropertyValuesHolder xPvh = PropertyValuesHolder.ofFloat(xPropertyName, xValues);
    PropertyValuesHolder yPvh = PropertyValuesHolder.ofFloat(yPropertyName, yValues);

    return ObjectAnimator.ofPropertyValuesHolder(target, xPvh, yPvh);
}
 
Example 8
Source File: SlideInAnimationHandler.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
    public void animateMenuOpening(Point center) {
        super.animateMenuOpening(center);

        setAnimating(true);

        Animator lastAnimation = null;
        for (int i = 0; i < menu.getSubActionItems().size(); i++) {

            menu.getSubActionItems().get(i).view.setAlpha(0);

            FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) menu.getSubActionItems().get(i).view.getLayoutParams();
            params.setMargins(menu.getSubActionItems().get(i).x, menu.getSubActionItems().get(i).y + DIST_Y, 0, 0);
            menu.getSubActionItems().get(i).view.setLayoutParams(params);

//            PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, menu.getSubActionItems().get(i).x/* - center.x + menu.getSubActionItems().get(i).width / 2*/);
            PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -DIST_Y);
//            PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
//            PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
            PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 1);

            final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhY, pvhA);
            animation.setDuration(DURATION);
            animation.setInterpolator(new DecelerateInterpolator());
            animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.OPENING));

            if(i == 0) {
                lastAnimation = animation;
            }

            animation.setStartDelay(Math.abs(menu.getSubActionItems().size()/2-i) * LAG_BETWEEN_ITEMS);
            animation.start();
        }
        if(lastAnimation != null) {
            lastAnimation.addListener(new LastAnimationListener());
        }

    }
 
Example 9
Source File: DefaultAnimationHandler.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void animateMenuClosing(Point center) {
    super.animateMenuOpening(center);

    setAnimating(true);

    Animator lastAnimation = null;
    for (int i = 0; i < menu.getSubActionItems().size(); i++) {
        PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, - (menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2));
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, - (menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2));
        PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, -720);
        PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 0);
        PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0);
        PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 0);

        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
        animation.setDuration(DURATION);
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.CLOSING));

        if(i == 0) {
            lastAnimation = animation;
        }

        animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
        animation.start();
    }
    if(lastAnimation != null) {
        lastAnimation.addListener(new LastAnimationListener());
    }
}
 
Example 10
Source File: InsertAbleGridView.java    From ClassifyView with Apache License 2.0 5 votes vote down vote up
private Animator createTransformAnimator(final View view) {
    view.setPivotX(mInnerPadding);
    view.setPivotY(mInnerPadding);
    float width = view.getWidth();
    float height = view.getHeight();
    float scaleX = getItemWidth((int) width) / width;
    float scaleY = getItemHeight((int) height) / height;
    PropertyValuesHolder scaleXPvh = PropertyValuesHolder.ofFloat("scaleX", scaleX);
    PropertyValuesHolder scaleYPvh = PropertyValuesHolder.ofFloat("scaleY", scaleY);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(view, scaleXPvh, scaleYPvh);
    animator.setInterpolator(new DecelerateInterpolator());
    return animator;
}
 
Example 11
Source File: FocusIndicatorHelper.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFocusChange(View v, boolean hasFocus) {
    if (hasFocus) {
        endCurrentAnimation();

        if (mAlpha > MIN_VISIBLE_ALPHA) {
            mTargetView = v;

            mCurrentAnimation = ObjectAnimator.ofPropertyValuesHolder(this,
                    PropertyValuesHolder.ofFloat(ALPHA, 1),
                    PropertyValuesHolder.ofFloat(SHIFT, 1));
            mCurrentAnimation.addListener(new ViewSetListener(v, true));
        } else {
            setCurrentView(v);

            mCurrentAnimation = ObjectAnimator.ofPropertyValuesHolder(this,
                    PropertyValuesHolder.ofFloat(ALPHA, 1));
        }

        mLastFocusedView = v;
    } else {
        if (mLastFocusedView == v) {
            mLastFocusedView = null;
            endCurrentAnimation();
            mCurrentAnimation = ObjectAnimator.ofPropertyValuesHolder(this,
                    PropertyValuesHolder.ofFloat(ALPHA, 0));
            mCurrentAnimation.addListener(new ViewSetListener(null, false));
        }
    }

    // invalidate once
    invalidateDirty();

    mLastFocusedView = hasFocus ? v : null;
    if (mCurrentAnimation != null) {
        mCurrentAnimation.addUpdateListener(this);
        mCurrentAnimation.setDuration(ANIM_DURATION).start();
    }
}
 
Example 12
Source File: Pop.java    From Interessant with Apache License 2.0 5 votes vote down vote up
@Override
public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues,
                            TransitionValues endValues) {
    return ObjectAnimator.ofPropertyValuesHolder(
            view,
            PropertyValuesHolder.ofFloat(View.ALPHA, 0f),
            PropertyValuesHolder.ofFloat(View.SCALE_X, 0f),
            PropertyValuesHolder.ofFloat(View.SCALE_Y, 0f));
}
 
Example 13
Source File: ObjectAnimatorCompatBase.java    From MaterialProgressBar with Apache License 2.0 5 votes vote down vote up
@NonNull
public static ObjectAnimator ofInt(@Nullable Object target, @NonNull String xPropertyName,
                                   @NonNull String yPropertyName, @NonNull Path path) {

    int[] xValues = new int[NUM_POINTS];
    int[] yValues = new int[NUM_POINTS];
    calculateXYValues(path, xValues, yValues);

    PropertyValuesHolder xPvh = PropertyValuesHolder.ofInt(xPropertyName, xValues);
    PropertyValuesHolder yPvh = PropertyValuesHolder.ofInt(yPropertyName, yValues);

    return ObjectAnimator.ofPropertyValuesHolder(target, xPvh, yPvh);
}
 
Example 14
Source File: ScaleTransition.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
public Animator createAnimation(View view, float startScale, float endScale) {
    view.setScaleX(startScale);
    view.setScaleY(startScale);
    PropertyValuesHolder holderX = PropertyValuesHolder.ofFloat("scaleX", startScale, endScale);
    PropertyValuesHolder holderY = PropertyValuesHolder.ofFloat("scaleY", startScale, endScale);
    return ObjectAnimator.ofPropertyValuesHolder(view, holderX, holderY);
}
 
Example 15
Source File: BlogReaderAnim.java    From Cotable with Apache License 2.0 5 votes vote down vote up
public static void scaleOut(final View target,
                            final int endVisibility,
                            Duration duration,
                            final AnimationEndListener endListener) {
    if (target == null || duration == null) {
        return;
    }

    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1f, 0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f, 0f);

    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, scaleX, scaleY);
    animator.setDuration(duration.toMillis(target.getContext()));
    animator.setInterpolator(new AccelerateInterpolator());

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            target.setVisibility(endVisibility);
            if (endListener != null) {
                endListener.onAnimationEnd();
            }
        }
    });

    animator.start();
}
 
Example 16
Source File: SlideDistanceProvider.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private static Animator createTranslationYAnimator(
    View view, float startTranslation, float endTranslation) {
  return ObjectAnimator.ofPropertyValuesHolder(
      view, PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, startTranslation, endTranslation));
}
 
Example 17
Source File: CoolMenu.java    From Android-CoolMenu with Apache License 2.0 4 votes vote down vote up
public void dismiss() {

        int childCount = getChildCount();
        if (childCount > 1) {

            float x = 0.5f * mEdge;
            float y = 0.5f * mEdge;

            Animator[] before = new Animator[childCount];

            Animator[] after = new Animator[childCount - 1];

            for (int i = 0; i < childCount; i++) {

                View child = getChildAt(i);
                float pivotX = x - child.getLeft();
                float pivotY = y - child.getTop();
                float childX = 0.5f * child.getLeft() + child.getRight() * 0.5f;
                float childY = 0.5f * child.getTop() + 0.5f * child.getBottom();

                child.setPivotX(pivotX);
                child.setPivotY(pivotY);

                PropertyValuesHolder ca = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0);
                PropertyValuesHolder csx = PropertyValuesHolder.ofFloat("scaleX", 1.0f, 0);
                PropertyValuesHolder csy = PropertyValuesHolder.ofFloat("scaleY", 1.0f, 0);

                if (i == 0) {

                    before[i] = ObjectAnimator.ofPropertyValuesHolder(child, ca, csx, csy);

                } else {

                    PropertyValuesHolder ctx = PropertyValuesHolder.ofFloat("translationX", 0, x - childX);
                    PropertyValuesHolder cty = PropertyValuesHolder.ofFloat("translationY", 0, y - childY);
                    PropertyValuesHolder cr = PropertyValuesHolder.ofFloat("rotation", 0, 360f);
                    before[i] = ObjectAnimator.ofPropertyValuesHolder(child, cr, ctx, cty);

                    PropertyValuesHolder cx = PropertyValuesHolder.ofFloat("translationX", x - childX, (childX - x) * 10);
                    PropertyValuesHolder cy = PropertyValuesHolder.ofFloat("translationY", y - childY, (childY - y) * 10);

                    after[i - 1] = ObjectAnimator.ofPropertyValuesHolder(child, cx, cy);
                }
            }

            AnimatorSet set = new AnimatorSet();
            AnimatorSet first = new AnimatorSet();
            AnimatorSet last = new AnimatorSet();
            first.playTogether(before);
            last.playTogether(after);
            set.setDuration(ANIM_DISMISS_DURATION);
            set.setInterpolator(new DecelerateInterpolator());
            set.play(first).before(last);
            set.start();

        }
    }
 
Example 18
Source File: AnimatorUtils.java    From Qiitanium with MIT License 4 votes vote down vote up
public static Animator rotationX(View target, float... values) {
  return ObjectAnimator.ofPropertyValuesHolder(target, ofRotationX(values));
}
 
Example 19
Source File: AnimatorUtils.java    From Qiitanium with MIT License 4 votes vote down vote up
public static Animator of(View target, PropertyValuesHolder... values) {
  return ObjectAnimator.ofPropertyValuesHolder(target, values);
}
 
Example 20
Source File: FloatingAnimatorImpl.java    From FloatingToolbar with Apache License 2.0 4 votes vote down vote up
@Override
public void show() {
    super.show();
    int rootWidth = getRootView().getWidth();
    float endFabX;

    if (shouldMoveFabX()) {
        if (getFab().getLeft() > rootWidth / 2f) {
            endFabX = getFab().getLeft() - getFab().getWidth();
        } else {
            endFabX = getFab().getLeft() + getFab().getWidth();
        }
    } else {
        endFabX = getFab().getLeft();
    }

    PropertyValuesHolder xProperty = PropertyValuesHolder.ofFloat(View.X, endFabX);
    PropertyValuesHolder yProperty
            = PropertyValuesHolder.ofFloat(View.Y, getFloatingToolbar().getY() * 0.95f);
    PropertyValuesHolder scaleXProperty = PropertyValuesHolder.ofFloat(View.SCALE_X, 0);
    PropertyValuesHolder scaleYProperty = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0);

    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(getFab(), xProperty,
            yProperty, scaleXProperty, scaleYProperty);
    animator.setDuration(FAB_MORPH_DURATION);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.start();

    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(getFloatingToolbar(), "scaleX", 1f);
    objectAnimator.setDuration(CIRCULAR_REVEAL_DURATION);
    objectAnimator.setStartDelay(CIRCULAR_REVEAL_DELAY);
    objectAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    objectAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            getFloatingToolbar().setVisibility(View.VISIBLE);
            getFab().setVisibility(View.INVISIBLE);
        }
    });
    objectAnimator.start();
}