Example usage for android.animation ObjectAnimator ofFloat

List of usage examples for android.animation ObjectAnimator ofFloat

Introduction

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

Prototype

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty,
        Path path) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties.

Usage

From source file:com.flexible.flexibleadapter.AnimatorAdapter.java

/**
 * Animates the view based on the custom animator list built with {@link #getAnimators(View, int, boolean)}.
 *
 * @since 5.0.0-b1//from   w w w .  j  av  a 2s .com
 * @deprecated New system in place. Implement {@link FlexibleViewHolder#scrollAnimators(List, int, boolean)}
 * and add new animator(s) to the list of {@code animators}.
 */
@Deprecated
public final void animateView(final View itemView, int position) {
    //      if (DEBUG)
    //         Log.v(TAG, "shouldAnimate=" + shouldAnimate
    //               + " isFastScroll=" + isFastScroll
    //               + " isNotified=" + mAnimatorNotifierObserver.isPositionNotified()
    //               + " isReverseEnabled=" + isReverseEnabled
    //               + " mLastAnimatedPosition=" + mLastAnimatedPosition
    //               + (!isReverseEnabled ? " Pos>AniPos=" + (position > mLastAnimatedPosition) : "")
    //         );

    if (shouldAnimate && !isFastScroll && !mAnimatorNotifierObserver.isPositionNotified() && (isReverseEnabled
            || position > mLastAnimatedPosition || (position == 0 && mRecyclerView.getChildCount() == 0))) {

        //Cancel animation is necessary when fling
        cancelExistingAnimation(itemView.hashCode());

        //Retrieve user animators
        List<Animator> animators = getAnimators(itemView, position, position > mLastAnimatedPosition);

        //Add Alpha animator
        ViewCompat.setAlpha(itemView, 0);
        animators.add(ObjectAnimator.ofFloat(itemView, "alpha", 0f, 1f));
        Log.w(TAG, "Started Deprecated Animation on position " + position);

        //Execute the animations
        AnimatorSet set = new AnimatorSet();
        set.playTogether(animators);
        set.setInterpolator(mInterpolator);
        set.setDuration(mDuration);
        set.addListener(new HelperAnimatorListener(itemView.hashCode()));
        if (mEntryStep) {
            set.setStartDelay(calculateAnimationDelay(position));
        }
        set.start();
        mAnimators.put(itemView.hashCode(), set);

        //Animate only during initial loading?
        if (onlyEntryAnimation && mLastAnimatedPosition >= mMaxChildViews) {
            shouldAnimate = false;
        }
    }

    mAnimatorNotifierObserver.clearNotified();
    mLastAnimatedPosition = position;
}

From source file:io.plaidapp.designernews.ui.story.StoryActivity.java

private void doFabExpand() {
    // translate the chrome placeholder ui so that it is centered on the FAB
    int fabCenterX = (fab.getLeft() + fab.getRight()) / 2;
    int fabCenterY = ((fab.getTop() + fab.getBottom()) / 2) - fabExpand.getTop();
    int translateX = fabCenterX - (fabExpand.getWidth() / 2);
    int translateY = fabCenterY - (fabExpand.getHeight() / 2);
    fabExpand.setTranslationX(translateX);
    fabExpand.setTranslationY(translateY);

    // then reveal the placeholder ui, starting from the center & same dimens as fab
    fabExpand.setVisibility(View.VISIBLE);
    Animator reveal = ViewAnimationUtils
            .createCircularReveal(fabExpand, fabExpand.getWidth() / 2, fabExpand.getHeight() / 2,
                    fab.getWidth() / 2, (int) Math.hypot(fabExpand.getWidth() / 2, fabExpand.getHeight() / 2))
            .setDuration(fabExpandDuration);

    // translate the placeholder ui back into position along an arc
    GravityArcMotion arcMotion = new GravityArcMotion();
    arcMotion.setMinimumVerticalAngle(70f);
    Path motionPath = arcMotion.getPath(translateX, translateY, 0, 0);
    Animator position = ObjectAnimator.ofFloat(fabExpand, View.TRANSLATION_X, View.TRANSLATION_Y, motionPath)
            .setDuration(fabExpandDuration);

    // animate from the FAB colour to the placeholder background color
    Animator background = ObjectAnimator
            .ofArgb(fabExpand, ViewUtils.BACKGROUND_COLOR,
                    ContextCompat.getColor(this, io.plaidapp.R.color.designer_news),
                    ContextCompat.getColor(this, io.plaidapp.R.color.background_light))
            .setDuration(fabExpandDuration);

    // fade out the fab (rapidly)
    Animator fadeOutFab = ObjectAnimator.ofFloat(fab, View.ALPHA, 0f).setDuration(60);

    // play 'em all together with the material interpolator
    AnimatorSet show = new AnimatorSet();
    show.setInterpolator(getFastOutSlowInInterpolator(StoryActivity.this));
    show.playTogether(reveal, background, position, fadeOutFab);
    show.start();/*w  w  w .  j a  v a2 s  .c  om*/
}

From source file:com.anyline.reactnative.Document4Activity.java

private void showErrorMessageUiAnimated(String message) {
    if (lastErrorRecieved == 0) {
        // the cleanup takes care of removing the message after some time if the error did not show up again
        handler.post(errorMessageCleanup);
    }/*from w  ww . j ava  2 s  .c  om*/
    lastErrorRecieved = System.currentTimeMillis();
    if (errorMessageAnimator != null
            && (errorMessageAnimator.isRunning() || errorMessage.getText().equals(message))) {
        return;
    }

    errorMessageLayout.setVisibility(View.VISIBLE);
    errorMessage.setBackgroundColor(ContextCompat.getColor(this,
            getResources().getIdentifier("anyline_blue_darker", "color", getPackageName())));
    errorMessage.setAlpha(0f);
    errorMessage.setText(message);
    errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", 0f, 1f);
    errorMessageAnimator.setDuration(ERROR_MESSAGE_DELAY);
    errorMessageAnimator.setInterpolator(new DecelerateInterpolator());
    errorMessageAnimator.start();
}

From source file:com.serenegiant.aceparrot.BaseFragment.java

/**
 * 10??(View)??//from   ww w  . ja  va 2 s  .co m
 * @param target
 * @param startDelay
 */
@SuppressLint("NewApi")
protected final void fadeOut(final View target, final long duration, final long startDelay) {
    //      if (DEBUG) Log.v(TAG, "fadeOut,target=" + target);
    if (target == null)
        return;
    target.clearAnimation();
    if (target.getVisibility() == View.VISIBLE) {
        target.setTag(R.id.anim_type, ANIM_FADE_OUT); // ??
        target.setScaleX(1.0f);
        target.setScaleY(1.0f);
        target.setAlpha(1.0f);
        final ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(target, "alpha", 1f, 0f);
        objectAnimator.addListener(mAnimatorListener);
        if (BuildCheck.isAndroid4_3())
            objectAnimator.setAutoCancel(true); // API >= 18 ??????Animator????
        objectAnimator.setDuration(duration > 0 ? duration : 500); // 0.5???
        objectAnimator.setStartDelay(startDelay > 0 ? startDelay : 0); // ???
        objectAnimator.start(); // 
    }
}

From source file:eu.davidea.flexibleadapter.FlexibleAnimatorAdapter.java

/**
 * Item will scale.<br/>//from  w  ww .j  av a2s . c  om
 * Ignored if SCALE animator was already added.
 * <p><b>Note:</b> Only 1 animator of the same compatible type can be added per time.<br/>
 * Incompatible with LEFT, RIGHT, BOTTOM animators.<br/>
 *
 * @param animators user defined list
 * @param view      itemView to animate
 * @param scaleFrom initial scale value
 */
public void addScaleInAnimator(@NonNull List<Animator> animators, @NonNull View view,
        @FloatRange(from = 0.0, to = 1.0) float scaleFrom) {
    if (animatorsUsed.contains(AnimatorEnum.SCALE))
        return;
    animators.add(ObjectAnimator.ofFloat(view, "scaleX", scaleFrom, 1f));
    animators.add(ObjectAnimator.ofFloat(view, "scaleY", scaleFrom, 1f));
    animatorsUsed.add(AnimatorEnum.SCALE);
}

From source file:com.android.deskclock.timer.TimerFragment.java

/**
 * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView}
 * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer
 *      should be removed/*  w ww .j a  v  a  2  s. c o m*/
 */
private void animateToView(View toView, final Timer timerToRemove) {
    if (mCurrentView == toView) {
        throw new IllegalStateException("toView is already the current view");
    }

    final boolean toTimers = toView == mTimersView;

    // Avoid double-taps by enabling/disabling the set of buttons active on the new view.
    mLeftButton.setEnabled(toTimers);
    mRightButton.setEnabled(toTimers);
    mCancelCreateButton.setEnabled(!toTimers);

    final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0);
    rotateFrom.setDuration(mShortAnimationDuration);
    rotateFrom.setInterpolator(new DecelerateInterpolator());
    rotateFrom.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (timerToRemove != null) {
                DataModel.getDataModel().removeTimer(timerToRemove);
                Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock);
            }

            mCurrentView.setScaleX(1);
            if (toTimers) {
                showTimersView();
            } else {
                showCreateTimerView();
            }
        }
    });

    final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1);
    rotateTo.setDuration(mShortAnimationDuration);
    rotateTo.setInterpolator(new AccelerateInterpolator());

    final float preScale = toTimers ? 0 : 1;
    final float postScale = toTimers ? 1 : 0;
    final Animator fabAnimator = getScaleAnimator(mFab, preScale, postScale);
    final Animator leftButtonAnimator = getScaleAnimator(mLeftButton, preScale, postScale);
    final Animator rightButtonAnimator = getScaleAnimator(mRightButton, preScale, postScale);

    final AnimatorSet buttons = new AnimatorSet();
    buttons.setDuration(toTimers ? mMediumAnimationDuration : mShortAnimationDuration);
    buttons.play(leftButtonAnimator).with(rightButtonAnimator).with(fabAnimator);
    buttons.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mLeftButton.setVisibility(toTimers ? VISIBLE : INVISIBLE);
            mRightButton.setVisibility(toTimers ? VISIBLE : INVISIBLE);

            mFab.setScaleX(1);
            mFab.setScaleY(1);
            mLeftButton.setScaleX(1);
            mLeftButton.setScaleY(1);
            mRightButton.setScaleX(1);
            mRightButton.setScaleY(1);
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(rotateFrom).before(rotateTo).with(buttons);
    animatorSet.start();
}

From source file:com.evandroid.musica.fragment.LocalLyricsFragment.java

public void animateUndo(Lyrics[] lyricsArray) {
    final HashMap<Long, Integer> itemIdTopMap = new HashMap<>();
    int firstVisiblePosition = megaListView.getFirstVisiblePosition();
    for (int i = 0; i < megaListView.getChildCount(); ++i) {
        View child = megaListView.getChildAt(i);
        int position = firstVisiblePosition + i;
        long itemId = megaListView.getAdapter().getItemId(position);
        itemIdTopMap.put(itemId, child.getTop());
    }/*from   w w w.  j a v  a 2  s  . c o  m*/
    final boolean[] firstAnimation = { true };
    // Delete the item from the adapter
    final int groupPosition = ((LocalAdapter) getExpandableListAdapter()).add(lyricsArray[0]);
    megaListView.setAdapter(getExpandableListAdapter());
    megaListView.post(new Runnable() {
        @Override
        public void run() {
            megaListView.expandGroupWithAnimation(groupPosition);
        }
    });
    new WriteToDatabaseTask(LocalLyricsFragment.this).execute(LocalLyricsFragment.this, null, lyricsArray);

    final ViewTreeObserver[] observer = { megaListView.getViewTreeObserver() };
    observer[0].addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        public boolean onPreDraw() {
            observer[0].removeOnPreDrawListener(this);
            firstAnimation[0] = true;
            int firstVisiblePosition = megaListView.getFirstVisiblePosition();
            for (int i = 0; i < megaListView.getChildCount(); ++i) {
                final View child = megaListView.getChildAt(i);
                int position = firstVisiblePosition + i;
                long itemId = getListView().getAdapter().getItemId(position);
                Integer formerTop = itemIdTopMap.get(itemId);
                int newTop = child.getTop();
                if (formerTop != null) {
                    if (formerTop != newTop) {
                        int delta = formerTop - newTop;
                        child.setTranslationY(delta);
                        int MOVE_DURATION = 500;
                        child.animate().setDuration(MOVE_DURATION).translationY(0);
                        if (firstAnimation[0]) {
                            child.animate().setListener(new AnimatorActionListener(new Runnable() {
                                public void run() {
                                    mBackgroundContainer.hideBackground();
                                    mSwiping = false;
                                    getListView().setEnabled(true);
                                }
                            }, AnimatorActionListener.ActionType.END));
                            firstAnimation[0] = false;
                        }
                    }
                } else {
                    // Animate new views along with the others. The catch is that they did not
                    // exist in the start state, so we must calculate their starting position
                    // based on neighboring views.
                    int childHeight = child.getHeight() + megaListView.getDividerHeight();
                    formerTop = newTop - childHeight;
                    int delta = formerTop - newTop;
                    final float z = ((CardView) child).getCardElevation();
                    ((CardView) child).setCardElevation(0f);
                    child.setTranslationY(delta);
                    final int MOVE_DURATION = 500;
                    child.animate().setDuration(MOVE_DURATION).translationY(0);
                    child.animate().setListener(new AnimatorActionListener(new Runnable() {
                        public void run() {
                            mBackgroundContainer.hideBackground();
                            mSwiping = false;
                            getListView().setEnabled(true);
                            ObjectAnimator anim = ObjectAnimator.ofFloat(child, "cardElevation", 0f, z);
                            anim.setDuration(200);
                            anim.setInterpolator(new AccelerateInterpolator());
                            anim.start();
                        }
                    }, AnimatorActionListener.ActionType.END));
                    firstAnimation[0] = false;
                }
            }
            if (firstAnimation[0]) {
                mBackgroundContainer.hideBackground();
                mSwiping = false;
                getListView().setEnabled(true);
                firstAnimation[0] = false;
            }
            itemIdTopMap.clear();
            return true;
        }
    });
}

From source file:com.anyline.reactnative.Document4Activity.java

private void showHighlightErrorMessageUiAnimated(String message) {
    lastErrorRecieved = System.currentTimeMillis();
    errorMessageLayout.setVisibility(View.VISIBLE);
    errorMessage.setBackgroundColor(ContextCompat.getColor(this,
            getResources().getIdentifier("anyline_red", "color", getPackageName())));
    errorMessage.setAlpha(0f);/*from  w w w .jav  a2 s .c om*/
    errorMessage.setText(message);

    if (errorMessageAnimator != null && errorMessageAnimator.isRunning()) {
        errorMessageAnimator.cancel();
    }

    errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", 0f, 1f);
    errorMessageAnimator.setDuration(ERROR_MESSAGE_DELAY);
    errorMessageAnimator.setInterpolator(new DecelerateInterpolator());
    errorMessageAnimator.setRepeatMode(ValueAnimator.REVERSE);
    errorMessageAnimator.setRepeatCount(1);
    errorMessageAnimator.start();
}

From source file:com.github.antoniodisanto92.swipeselector.SwipeAdapter.java

private void animate(float alpha, ImageView button) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        button.animate().alpha(alpha).setDuration(120).start();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        ObjectAnimator.ofFloat(button, "alpha", alpha == 1 ? 0 : alpha, alpha == 1 ? alpha : 0).setDuration(120)
                .start();//from  w ww .  ja va 2  s.  c o  m
    } else {
        setAlpha(alpha, button);
    }
}

From source file:com.gitstudy.rili.liarbry.CalendarLayout.java

/**
 * /*w w w. j  a  va2  s  .co m*/
 *
 * @return ?
 */
public boolean shrink() {
    if (isAnimating || mContentView == null) {
        return false;
    }
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mContentView, "translationY",
            mContentView.getTranslationY(), -mContentViewTranslateY);
    objectAnimator.setDuration(240);
    objectAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float currentValue = (Float) animation.getAnimatedValue();
            float percent = currentValue * 1.0f / mContentViewTranslateY;
            mMonthView.setTranslationY(mViewPagerTranslateY * percent);
            isAnimating = true;
        }
    });
    objectAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            isAnimating = false;
            showWeek();

        }
    });
    objectAnimator.start();
    return true;
}