Example usage for android.animation ValueAnimator getAnimatedValue

List of usage examples for android.animation ValueAnimator getAnimatedValue

Introduction

In this page you can find the example usage for android.animation ValueAnimator getAnimatedValue.

Prototype

public Object getAnimatedValue() 

Source Link

Document

The most recent value calculated by this ValueAnimator when there is just one property being animated.

Usage

From source file:com.roughike.bottombar.BottomBarTab.java

private void setTopPaddingAnimated(int start, int end) {
    if (type == Type.TABLET || isTitleless) {
        return;//from w ww. j av  a  2 s.c o  m
    }

    ValueAnimator paddingAnimator = ValueAnimator.ofInt(start, end);
    paddingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            iconView.setPadding(iconView.getPaddingLeft(), (Integer) animation.getAnimatedValue(),
                    iconView.getPaddingRight(), iconView.getPaddingBottom());
        }
    });

    paddingAnimator.setDuration(ANIMATION_DURATION);
    paddingAnimator.start();
}

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

/**
 * /*w  w  w  .  ja  v a  2 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;
}

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

/**
 * // w w w. j a v a2s . co  m
 *
 * @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;
}

From source file:com.jsibbold.zoomage.ZoomageView.java

private void animateMatrixIndex(final int index, final float to) {
    ValueAnimator animator = ValueAnimator.ofFloat(mValues[index], to);
    animator.addUpdateListener(new AnimatorUpdateListener() {

        final float[] values = new float[9];
        Matrix current = new Matrix();

        @Override/* w w  w . j av a 2s  . c  o m*/
        public void onAnimationUpdate(ValueAnimator animation) {
            current.set(getImageMatrix());
            current.getValues(values);
            values[index] = (Float) animation.getAnimatedValue();
            current.setValues(values);
            setImageMatrix(current);
        }
    });
    animator.setDuration(RESET_DURATION);
    animator.start();
}

From source file:com.shopify.buy.ui.ProductDetailsFragmentView.java

@Override
public void setImageAreaSize(final boolean grow) {
    final int finalHeight = grow ? getHeight() : imageAreaHeight;

    // hide or show the checkout button
    if (grow && !imageAreaIsExpanded) {
        hideCheckoutButton(IMAGE_AREA_FEATURES_ANIMATION_DURATION);
    } else if (!grow && imageAreaIsExpanded) {
        showCheckoutButton(IMAGE_AREA_FEATURES_ANIMATION_DURATION);
    }/*from w w w. jav  a  2 s  .c o  m*/

    // Animate the image changing size
    ValueAnimator anim = ValueAnimator.ofInt(imageAreaWrapper.getHeight(), finalHeight);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams containerLayoutParams = imageAreaWrapper.getLayoutParams();
            containerLayoutParams.height = val;
            imageAreaWrapper.setLayoutParams(containerLayoutParams);
        }

    });
    anim.setDuration(IMAGE_AREA_FEATURES_ANIMATION_DURATION);

    // Disable touch handler for duration of image resizing
    imagePager.setOnTouchListener(null);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);

            // Re-enable the touch handle on the image
            imagePager.setOnTouchListener(imageAreaTouchHandler);

            if (grow) {
                onExpandImageArea();
            } else {
                onCollapseImageArea();
            }
        }
    });

    anim.start();
}

From source file:com.actionbarsherlock.sample.hcgallery.MainActivity.java

public void toggleVisibleTitles() {
    // Use these for custom animations.
    final FragmentManager fm = getSupportFragmentManager();
    final TitlesFragment f = (TitlesFragment) fm.findFragmentById(R.id.frag_title);
    final View titlesView = f.getView();
    mLabelIndex = 1 - mLabelIndex;/*from w  w w . j  a  v a  2  s . co  m*/

    // Determine if we're in portrait, and whether we're showing or hiding the titles
    // with this toggle.
    final boolean isPortrait = getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;

    final boolean shouldShow = f.isHidden() || mCurrentTitlesAnimator != null;

    // Cancel the current titles animation if there is one.
    if (mCurrentTitlesAnimator != null)
        mCurrentTitlesAnimator.cancel();

    // Begin setting up the object animator. We'll animate the bottom or right edge of the
    // titles view, as well as its alpha for a fade effect.
    ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(titlesView,
            PropertyValuesHolder.ofInt(isPortrait ? "bottom" : "right",
                    shouldShow ? getResources().getDimensionPixelSize(R.dimen.titles_size) : 0),
            PropertyValuesHolder.ofFloat("alpha", shouldShow ? 1 : 0));

    // At each step of the animation, we'll perform layout by calling setLayoutParams.
    final ViewGroup.LayoutParams lp = titlesView.getLayoutParams();
    objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // *** WARNING ***: triggering layout at each animation frame highly impacts
            // performance so you should only do this for simple layouts. More complicated
            // layouts can be better served with individual animations on child views to
            // avoid the performance penalty of layout.
            if (isPortrait) {
                lp.height = (Integer) valueAnimator.getAnimatedValue();
            } else {
                lp.width = (Integer) valueAnimator.getAnimatedValue();
            }
            titlesView.setLayoutParams(lp);
        }
    });

    if (shouldShow) {
        fm.beginTransaction().show(f).commit();
        objectAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animator) {
                mCurrentTitlesAnimator = null;
            }
        });

    } else {
        objectAnimator.addListener(new AnimatorListenerAdapter() {
            boolean canceled;

            @Override
            public void onAnimationCancel(Animator animation) {
                canceled = true;
                super.onAnimationCancel(animation);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                if (canceled)
                    return;
                mCurrentTitlesAnimator = null;
                fm.beginTransaction().hide(f).commit();
            }
        });
    }

    // Start the animation.
    objectAnimator.start();
    mCurrentTitlesAnimator = objectAnimator;

    invalidateOptionsMenu();

    // Manually trigger onNewIntent to check for ACTION_DIALOG.
    onNewIntent(getIntent());
}

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

/**
 * ??// w  ww  .ja  v  a 2 s. c  o  m
 */
final void initStatus() {
    if (mContentView == null) {
        return;
    }
    if ((mDefaultStatus == STATUS_SHRINK || mCalendarShowMode == CALENDAR_SHOW_MODE_ONLY_WEEK_VIEW)
            && mCalendarShowMode != CALENDAR_SHOW_MODE_ONLY_MONTH_VIEW) {
        post(new Runnable() {
            @Override
            public void run() {
                ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mContentView, "translationY",
                        mContentView.getTranslationY(), -mContentViewTranslateY);
                objectAnimator.setDuration(0);
                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();
            }
        });
    } else {
        if (mDelegate.mViewChangeListener == null) {
            return;
        }
        post(new Runnable() {
            @Override
            public void run() {
                mDelegate.mViewChangeListener.onViewChange(true);
            }
        });
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.viewanimator.AnimationBuilder.java

/**
 * Custom animation builder./*from w  w w . j av  a2s .  c o m*/
 *
 * @param update the update
 * @param values the values
 * @return the animation builder
 */
public AnimationBuilder custom(final AnimationListener.Update update, float... values) {
    for (final View view : views) {
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(getValues(values));
        if (update != null)
            valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    //noinspection unchecked
                    update.update(view, (Float) animation.getAnimatedValue());
                }
            });
        add(valueAnimator);
    }
    return this;
}

From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java

private void fadeIn() {
    int colorFrom = Color.parseColor("#00000000");
    int colorTo = Color.parseColor("#40000000");
    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    colorAnimation.setDuration(250); // milliseconds
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override/*ww  w .  j  a va  2 s  .c  o m*/
        public void onAnimationUpdate(ValueAnimator animator) {
            setBackgroundColor((int) animator.getAnimatedValue());
        }

    });
    colorAnimation.start();
}

From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java

public void fadeOut() {
    int colorFrom = Color.parseColor("#40000000");
    int colorTo = Color.parseColor("#00000000");
    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    colorAnimation.setDuration(250); // milliseconds
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override//from w w w .j  a v a 2 s .  co m
        public void onAnimationUpdate(ValueAnimator animator) {
            setBackgroundColor((int) animator.getAnimatedValue());
        }

    });
    colorAnimation.start();
}