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.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

@Override
public void onTextSizeChanged(final TextView textView, float oldSize) {
    if (mCurrentState != CalculatorState.INPUT) {
        // Only animate text changes that occur from user input.
        return;//from w w  w.jav  a2s.c o m
    }

    // Calculate the values needed to perform the scale and translation animations,
    // maintaining the same apparent baseline for the displayed text.
    final float textScale = oldSize / textView.getTextSize();
    final float translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd());
    final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f),
            ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f),
            ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f),
            ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.start();
}

From source file:com.itsronald.widget.IndicatorDotPathView.java

@NonNull
private static Animator scaleAnimator(final View view, float originalScale, float scaleX, float scaleY) {
    final Animator animator;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        final PropertyValuesHolder scaleXProperty = PropertyValuesHolder.ofFloat(View.SCALE_X, originalScale,
                scaleX);/*from  w  w w  . j a  v  a2 s.  c o  m*/
        final PropertyValuesHolder scaleYProperty = PropertyValuesHolder.ofFloat(View.SCALE_Y, originalScale,
                scaleY);
        animator = ObjectAnimator.ofPropertyValuesHolder(view, scaleXProperty, scaleYProperty);
    } else {
        final Animator scaleXAnimator = ObjectAnimator.ofFloat(view, "scaleX", originalScale, scaleX);
        final Animator scaleYAnimator = ObjectAnimator.ofFloat(view, "scaleY", originalScale, scaleY);

        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(scaleXAnimator, scaleYAnimator);
        animator = animatorSet;
    }
    return animator;
}

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

/**
 * Item will slide from Right to Left.<br/>
 * Ignored if LEFT, RIGHT or BOTTOM animators were already added.
 * <p><b>Note:</b> Only 1 animator of the same compatible type can be added per time.<br/>
 * Incompatible with RIGHT, BOTTOM animators.<br/>
 *
 * @param animators user defined list/* w  w w  . java  2s  .co  m*/
 * @param view      ItemView to animate
 * @param percent   Any % multiplier (between 0 and 1) of the LayoutManager Width
 */
public void addSlideInFromRightAnimator(@NonNull List<Animator> animators, @NonNull View view,
        @FloatRange(from = 0.5, to = 1.0) float percent) {
    if (animatorsUsed.contains(AnimatorEnum.SLIDE_IN_LEFT)
            || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_RIGHT)
            || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_BOTTOM))
        return;
    animators.add(ObjectAnimator.ofFloat(view, "translationX",
            mRecyclerView.getLayoutManager().getWidth() * percent, 0));
    animatorsUsed.add(AnimatorEnum.SLIDE_IN_RIGHT);
}

From source file:com.anyline.reactnative.DocumentActivity.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);// w ww. ja va  2s. c  o  m
    errorMessage.setText(message);

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

    errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", 0f, 1f);
    errorMessageAnimator.setDuration(getResources()
            .getInteger(getResources().getIdentifier("error_message_delay", "integer", getPackageName())));
    errorMessageAnimator.setInterpolator(new DecelerateInterpolator());
    errorMessageAnimator.setRepeatMode(ValueAnimator.REVERSE);
    errorMessageAnimator.setRepeatCount(1);
    errorMessageAnimator.start();
}

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

/**
 * @param timerToRemove the timer to be removed during the animation
 *//*from www . j  a  v a2  s  .  co  m*/
private void animateTimerRemove(final Timer timerToRemove) {
    final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0);
    fadeOut.setDuration(mShortAnimationDuration);
    fadeOut.setInterpolator(new DecelerateInterpolator());
    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            DataModel.getDataModel().removeTimer(timerToRemove);
            Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock);
        }
    });

    final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1);
    fadeIn.setDuration(mShortAnimationDuration);
    fadeIn.setInterpolator(new AccelerateInterpolator());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(fadeOut).before(fadeIn);
    animatorSet.start();
}

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

/**
 * 01??(View)??//from   w w  w.  jav a  2s  .co m
 * @param target
 * @param startDelay
 */
@SuppressLint("NewApi")
protected final void fadeIn(final View target, final long duration, final long startDelay) {
    //      if (DEBUG) Log.v(TAG, "fadeIn:target=" + target);
    if (target == null)
        return;
    target.clearAnimation();
    target.setVisibility(View.VISIBLE);
    target.setTag(R.id.anim_type, ANIM_FADE_IN); // ???
    target.setScaleX(1.0f);
    target.setScaleY(1.0f);
    target.setAlpha(0.0f);
    final ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(target, "alpha", 0f, 1f);
    objectAnimator.addListener(mAnimatorListener);
    if (BuildCheck.isJellyBeanMR2())
        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: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 {//  ww  w .ja  v a  2s.c  o  m
        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:eu.davidea.flexibleadapter.FlexibleAnimatorAdapter.java

/**
 * Item will slide from Bottom of the screen to its natural position.<br/>
 * Ignored if LEFT, RIGHT or BOTTOM animators were 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.</p>
 *
 * @param animators user defined list/* w w  w.  j  a  va 2 s  . co  m*/
 * @param view      itemView to animate
 */
public void addSlideInFromBottomAnimator(@NonNull List<Animator> animators, @NonNull View view) {
    if (animatorsUsed.contains(AnimatorEnum.SLIDE_IN_LEFT)
            || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_RIGHT)
            || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_BOTTOM))
        return;
    animators.add(ObjectAnimator.ofFloat(view, "translationY", mRecyclerView.getMeasuredHeight() >> 1, 0));
    animatorsUsed.add(AnimatorEnum.SLIDE_IN_BOTTOM);
}

From source file:com.android.contacts.activities.PhotoSelectionActivity.java

private void animateInBackground() {
    ObjectAnimator.ofFloat(mBackdrop, "alpha", 0, 0.5f).setDuration(PHOTO_EXPAND_DURATION).start();
}

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

/**
 * /*from  w ww. j  av  a  2 s. c  om*/
 *
 * @return ??
 */
public boolean expand() {
    if (isAnimating || mCalendarShowMode == CALENDAR_SHOW_MODE_ONLY_WEEK_VIEW || mContentView == null)
        return false;
    if (mMonthView.getVisibility() != VISIBLE) {
        mWeekPager.setVisibility(GONE);
        onShowMonthView();
        mMonthView.setVisibility(VISIBLE);
    }
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mContentView, "translationY",
            mContentView.getTranslationY(), 0f);
    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;
            hideWeek();

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