Example usage for android.animation ValueAnimator start

List of usage examples for android.animation ValueAnimator start

Introduction

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

Prototype

@Override
    public void start() 

Source Link

Usage

From source file:com.taobao.weex.ui.view.refresh.core.WXSwipeLayout.java

/**
 * Start Refresh/*from w w  w  .  java  2  s  .c o m*/
 * @param headerViewHeight
 */
private void startRefresh(int headerViewHeight) {
    mRefreshing = true;
    ValueAnimator animator = ValueAnimator.ofFloat(headerViewHeight, refreshViewHeight);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LayoutParams lp = (LayoutParams) headerView.getLayoutParams();
            lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
            headerView.setLayoutParams(lp);
            moveTargetView(lp.height);
        }
    });
    animator.addListener(new WXRefreshAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            headerView.startAnimation();
            //TODO updateLoadText
            if (onRefreshListener != null) {
                onRefreshListener.onRefresh();
            }
        }
    });
    animator.setDuration(300);
    animator.start();
}

From source file:com.taobao.weex.ui.view.refresh.core.WXSwipeLayout.java

/**
 * Start loadmore/*w  w w .j  a  va  2  s .  com*/
 * @param headerViewHeight
 */
private void startLoadmore(int headerViewHeight) {
    mRefreshing = true;
    ValueAnimator animator = ValueAnimator.ofFloat(headerViewHeight, loadingViewHeight);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LayoutParams lp = (LayoutParams) footerView.getLayoutParams();
            lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
            footerView.setLayoutParams(lp);
            moveTargetView(-lp.height);
        }
    });
    animator.addListener(new WXRefreshAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            footerView.startAnimation();
            //TODO updateLoadText
            if (onLoadingListener != null) {
                onLoadingListener.onLoading();
            }
        }
    });
    animator.setDuration(300);
    animator.start();
}

From source file:com.bitants.wally.activities.ImageDetailsActivity.java

/**
 * Animations animations animations./*from ww  w .ja v a2 s  .co m*/
 * @param visibility if VISIBLE, expands toolbar.
 */
private void animateToolbar(int visibility) {
    float from;
    float to;
    int toolbarOffset;
    int fabOffset;
    if (visibility == View.VISIBLE) {
        from = 0.0f;
        to = 1.0f;
        fabOffset = 200;
        toolbarOffset = 0;
    } else {
        from = 1.0f;
        to = 0.0f;
        fabOffset = 0;
        toolbarOffset = 200;
    }

    buttonFullscreen.animate().scaleX(to).scaleY(to).setDuration(400).setStartDelay(fabOffset)
            .setInterpolator(new EaseInOutBezierInterpolator()).setListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animator) {
                    buttonFullscreen.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationEnd(Animator animator) {

                }

                @Override
                public void onAnimationCancel(Animator animator) {

                }

                @Override
                public void onAnimationRepeat(Animator animator) {

                }
            }).start();

    int toolbarFrom;
    int toolbarTo;

    if (from > 0.0f) {
        toolbarFrom = getResources().getDimensionPixelSize(R.dimen.details_toolbar_height);
        toolbarTo = 0;
    } else {
        toolbarFrom = 0;
        toolbarTo = getResources().getDimensionPixelSize(R.dimen.details_toolbar_height);
    }

    ValueAnimator valueAnimator = ValueAnimator.ofInt(toolbarFrom, toolbarTo);
    valueAnimator.setDuration(400);
    valueAnimator.setStartDelay(toolbarOffset);
    valueAnimator.setInterpolator(new EaseInOutBezierInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            RelativeLayout.LayoutParams toolbarParams = (RelativeLayout.LayoutParams) toolbar.getLayoutParams();
            toolbarParams.height = val;
            toolbar.setLayoutParams(toolbarParams);
        }
    });
    valueAnimator.start();

}

From source file:com.telenav.nodeflow.NodeFlowLayout.java

/**
 * perform opening animation for the specified node
 *
 * @param node node to be animated//from   w  w  w. j  a v a2s .c o  m
 */
private void animateDrillIn(final Node<?> node) {
    final int index = activeNode.getIndex() + (activeNode.getDepth() > 1 ? 1 : 0);
    ValueAnimator animator = ValueAnimator.ofFloat(1);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {

            for (int i = 0; i < getChildCount(); ++i) {
                if (i < index) {
                    getChildAt(i).setTranslationY(
                            headerHeight * i - ((Float) animation.getAnimatedValue()) * headerHeight * index);
                } else if (i > index) {
                    getChildAt(i).setTranslationY(headerHeight * i
                            + ((Float) animation.getAnimatedValue()) * (getHeight() - headerHeight * index));
                } else {
                    getChildAt(i).setTranslationY(
                            headerHeight * i - ((Float) animation.getAnimatedValue()) * headerHeight * index); // move active item
                }
            }
        }
    });
    animator.addListener(new CustomAnimationListener() {
        @Override
        public void onAnimationEnd(Animator animator) {
            updateViews(node, true);
        }
    });
    animator.setDuration(duration);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.start();
    animateDrillAlpha(index + 1, getChildCount(), 0);
}

From source file:com.bitants.wally.activities.ImageDetailsActivity.java

/**
 * Animations animations animations.//from w  w w.  j  a  v  a 2 s .c o  m
 */
private void toggleZoomImage() {

    int animationDuration = 400;

    if (isInFullscreen()) {
        scrollView.smoothScrollTo(0, (Integer) scrollView.getTag());
        if (photoViewAttacher != null) {
            photoViewAttacher.cleanup();
            photoViewAttacher = null;
            photoView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        }
    } else {
        scrollView.setTag(scrollView.getScrollY());
        scrollView.smoothScrollTo(0, 0);

        if (photoViewAttacher == null) {
            photoViewAttacher = new PhotoViewAttacher(photoView);
            photoViewAttacher.setZoomable(true);
            photoViewAttacher.setScaleType(ImageView.ScaleType.CENTER_CROP);
        }
    }

    if (getSupportActionBar() != null) {
        getToolbar().animate().translationY(isInFullscreen() ? 0.0f : -getToolbar().getMeasuredHeight())
                .alpha(isInFullscreen() ? 1.0f : 0.0f).setDuration(500)
                .setInterpolator(new EaseInOutBezierInterpolator()).start();
    }

    findViewById(R.id.image_details_protective_shadow).animate().alpha(isInFullscreen() ? 1.0f : 0.0f)
            .setDuration(500).setInterpolator(new EaseInOutBezierInterpolator()).start();

    int minimumAllowedHeight = getToolbar().getMeasuredHeight()
            + getResources().getDimensionPixelSize(R.dimen.fab_padding_positive);

    if (imageSize.getHeight() < minimumAllowedHeight) {
        int topFrom;
        int topTo;
        if (isInFullscreen()) {
            topFrom = 0;
            topTo = getToolbar().getMeasuredHeight();
        } else {
            topFrom = photoLayoutHolder.getPaddingTop();
            topTo = 0;
        }
        ValueAnimator topValueAnimator = ValueAnimator.ofInt(topFrom, topTo);
        topValueAnimator.setDuration(animationDuration);
        topValueAnimator.setInterpolator(new EaseInOutBezierInterpolator());
        topValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int val = (Integer) valueAnimator.getAnimatedValue();
                photoLayoutHolder.setPadding(photoLayoutHolder.getPaddingLeft(), val,
                        photoLayoutHolder.getPaddingRight(), photoLayoutHolder.getPaddingBottom());
            }
        });
        topValueAnimator.start();
    }

    if (photoLayoutHolder.getTranslationY() != 0.0f) {
        photoLayoutHolder.animate().translationY(0.0f).setInterpolator(new EaseInOutBezierInterpolator())
                .setDuration(animationDuration).start();
    }

    WindowManager win = getWindowManager();
    Display d = win.getDefaultDisplay();

    int from = photoView.getMeasuredHeight();
    int to = isInFullscreen() ? imageSize.getHeight() : d.getHeight();

    ValueAnimator valueAnimator = ValueAnimator.ofInt(from, to);
    valueAnimator.setDuration(animationDuration);
    valueAnimator.setInterpolator(new EaseInOutBezierInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            RelativeLayout.LayoutParams toolbarParams = (RelativeLayout.LayoutParams) photoView
                    .getLayoutParams();
            toolbarParams.height = val;
            photoView.setLayoutParams(toolbarParams);
        }
    });
    valueAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            if (photoViewAttacher != null) {
                photoViewAttacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
                    @Override
                    public void onPhotoTap(View view, float v, float v2) {
                        toggleZoomImage();
                    }
                });
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    valueAnimator.start();

    int scrollTo = isInFullscreen() ? 0 : d.getHeight();

    scrollView.animate().y(scrollTo).setDuration(animationDuration)
            .setInterpolator(new EaseInOutBezierInterpolator()).start();

    isInFullscreen = !isInFullscreen;
}

From source file:org.protocoderrunner.apprunner.api.PUI.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@ProtocoderScript/*from  www. j a  v  a  2 s  .  c  om*/
@APIParam(params = { "View" })
public void unreveal(final View v) {

    // get the center for the clipping circle
    int cx = (v.getLeft() + v.getRight()) / 2;
    int cy = (v.getTop() + v.getBottom()) / 2;

    // get the initial radius for the clipping circle
    int initialRadius = v.getWidth();

    // create the animation (the final radius is zero)
    ValueAnimator anim = (ValueAnimator) ViewAnimationUtils.createCircularReveal(v, cx, cy, initialRadius, 0);
    anim.setDuration(1000);

    // make the view invisible when the animation is done
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            v.setVisibility(View.INVISIBLE);
        }
    });

    // start the animation
    anim.start();
}

From source file:com.waz.zclient.pages.main.participants.dialog.ParticipantsDialogFragment.java

private void updateParticipantsDialogSizeAndPos(boolean keyboardIsVisible, int minParticipantsDialogHeight,
        int keyboardHeight) {
    // Expand / collapse when needed
    final boolean shouldExpand = !keyboardIsVisible && isParticipantsDialogMinimized();
    final boolean shouldCollapse = keyboardIsVisible && !isParticipantsDialogMinimized()
            && ViewUtils.isInLandscape(getActivity());
    final ValueAnimator sizeAnimator;
    if (shouldExpand) {
        sizeAnimator = ValueAnimator.ofObject(new HeightEvaluator(dialogFrameLayout),
                dialogFrameLayout.getMeasuredHeight(), regularParticipantsDialogHeight);
    } else if (shouldCollapse) {
        sizeAnimator = ValueAnimator.ofObject(new HeightEvaluator(dialogFrameLayout),
                dialogFrameLayout.getMeasuredHeight(), minParticipantsDialogHeight);
    } else {//  w w w .ja v  a2  s . c  o  m
        sizeAnimator = null;
    }

    if (sizeAnimator != null) {
        sizeAnimator.setDuration(getResources().getInteger(R.integer.framework_animation_duration_short));
        sizeAnimator.start();
    }

    // Update vertical position
    if (keyboardIsVisible && !isParticipantsDialogShiftedUp()) {
        final int navigationBarHeight = ViewUtils.getNavigationBarHeight(getActivity());
        int dialogDY;
        int markerDY;
        if (selfGravity == Gravity.TOP) {
            dialogDY = navigationBarHeight - keyboardHeight + participantDialogPadding;
            markerDY = navigationBarHeight - keyboardHeight + participantDialogPadding;
        } else {
            dialogDY = -keyboardHeight;
            markerDY = -keyboardHeight;
        }
        if (shouldCollapse) {
            dialogDY += dialogFrameLayout.getMeasuredHeight() - minParticipantsDialogHeight;
        }
        dialogFrameLayout.animate().translationYBy(dialogDY)
                .setDuration(getResources().getInteger(R.integer.framework_animation_duration_short))
                .withEndAction(new Runnable() {
                    @Override
                    public void run() {
                        if (getView() == null) {
                            return;
                        }
                        // Invalidate to avoid view being incorrectly drawn multiple times due to animation
                        getView().invalidate();
                    }
                }).start();

        marker.animate().translationYBy(markerDY)
                .setDuration(getResources().getInteger(R.integer.framework_animation_duration_short)).start();
    } else if (!keyboardIsVisible && isParticipantsDialogShiftedUp()) {
        dialogFrameLayout.animate().translationY(dialogTranslationY)
                .setDuration(getResources().getInteger(R.integer.framework_animation_duration_short))
                .withEndAction(new Runnable() {
                    @Override
                    public void run() {
                        if (getView() == null) {
                            return;
                        }
                        // Invalidate to avoid view being incorrectly drawn multiple times due to animation
                        getView().invalidate();
                    }
                }).start();

        marker.animate().translationY(markerTranslationY)
                .setDuration(getResources().getInteger(R.integer.framework_animation_duration_short)).start();
    }
}

From source file:com.folioreader.view.ConfigView.java

private void toggleBlackTheme() {

    int day = getResources().getColor(R.color.white);
    int night = getResources().getColor(R.color.night);
    int darkNight = getResources().getColor(R.color.dark_night);
    final int diffNightDark = night - darkNight;

    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), mIsNightMode ? night : day,
            mIsNightMode ? day : night);
    colorAnimation.setDuration(FADE_DAY_NIGHT_MODE);
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override//from ww w.jav  a 2s  . com
        public void onAnimationUpdate(ValueAnimator animator) {
            int value = (int) animator.getAnimatedValue();
            mContainer.setBackgroundColor(value);
            if (mConfigViewCallback != null) {
                mConfigViewCallback.onBackgroundUpdate(value - diffNightDark);
            }
        }
    });

    colorAnimation.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            mIsNightMode = !mIsNightMode;
            Config.getConfig().setNightMode(mIsNightMode);
            mConfigViewCallback.onConfigChange();
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });

    colorAnimation.setDuration(FADE_DAY_NIGHT_MODE);
    colorAnimation.start();
}

From source file:org.protocoderrunner.apprunner.api.PUI.java

@ProtocoderScript
@APIMethod(description = "Resize a view to a given width and height. If a parameter is -1 then that dimension is not changed", example = "")
@APIParam(params = { "View", "width", "height" })
public void resize(final View v, int h, int w) {
    boolean animated = false;

    if (!animated) {
        if (h != -1) {
            v.getLayoutParams().height = h;
        }// w  ww. j  a  va  2 s  .  co m
        if (w != -1) {
            v.getLayoutParams().width = w;
        }
        v.setLayoutParams(v.getLayoutParams());
    } else {

        int initHeight = v.getLayoutParams().height;
        // v.setLayoutParams(v.getLayoutParams());

        ValueAnimator anim = ValueAnimator.ofInt(initHeight, h);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int val = (Integer) valueAnimator.getAnimatedValue();
                v.getLayoutParams().height = val;
                v.setLayoutParams(v.getLayoutParams());

            }
        });
        anim.setDuration(200);
        anim.start();
    }
}

From source file:com.tengio.FloatingSearchView.java

private void fadeInBackground() {
    ValueAnimator anim = ValueAnimator.ofInt(BACKGROUND_DRAWABLE_ALPHA_SEARCH_NOT_FOCUSED,
            BACKGROUND_DRAWABLE_ALPHA_SEARCH_FOCUSED);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override// w w w. j  av a  2 s. com
        public void onAnimationUpdate(ValueAnimator animation) {

            int value = (Integer) animation.getAnimatedValue();
        }
    });
    anim.setDuration(BACKGROUND_FADE_ANIM_DURATION);
    anim.start();
}