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.hippo.widget.lockpattern.LockPatternView.java

private void startSizeAnimation(float start, float end, long duration, Interpolator interpolator,
        final CellState state, final Runnable endRunnable) {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(start, end);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*w  ww  . j a va2  s  .  com*/
        public void onAnimationUpdate(ValueAnimator animation) {
            state.size = (float) animation.getAnimatedValue();
            invalidate();
        }
    });
    if (endRunnable != null) {
        valueAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                endRunnable.run();
            }
        });
    }
    valueAnimator.setInterpolator(interpolator);
    valueAnimator.setDuration(duration);
    valueAnimator.start();
}

From source file:com.tengio.FloatingSearchView.java

private void refreshLeftIcon(boolean showAnim) {
    int leftActionWidthAndMarginLeft = Util.dpToPx(LEFT_MENU_WIDTH_AND_MARGIN_START);
    int queryTranslationX = 0;

    mLeftAction.setVisibility(VISIBLE);/*from  w w  w.  j  a v  a  2 s .  co m*/
    switch (mLeftActionMode) {
    case LEFT_ACTION_MODE_SHOW_HAMBURGER:
        if (showAnim && mMenuBtnDrawable.getProgress() == 1.0f) {
            ValueAnimator anim = ValueAnimator.ofFloat(1.0f, 0.0f);
            anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float value = (Float) animation.getAnimatedValue();
                    mMenuBtnDrawable.setProgress(value);
                }
            });
            anim.setDuration(MENU_ICON_ANIM_DURATION);
            anim.start();
            break;
        }
        mLeftAction.setImageDrawable(mMenuBtnDrawable);
        mMenuBtnDrawable.setProgress(0.0f);
        break;
    case LEFT_ACTION_MODE_SHOW_SEARCH:
        mLeftAction.setImageDrawable(mIconSearch);
        break;
    case LEFT_ACTION_MODE_SHOW_HOME:
        if (showAnim && mMenuBtnDrawable.getProgress() == 0.0f) {
            ValueAnimator anim = ValueAnimator.ofFloat(0.0f, 1.0f);
            anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float value = (Float) animation.getAnimatedValue();
                    mMenuBtnDrawable.setProgress(value);
                }
            });
            anim.setDuration(MENU_ICON_ANIM_DURATION);
            anim.start();
            break;
        }
        mLeftAction.setImageDrawable(mMenuBtnDrawable);
        mMenuBtnDrawable.setProgress(1.0f);
        break;
    case LEFT_ACTION_MODE_NO_LEFT_ACTION:
        mLeftAction.setVisibility(View.INVISIBLE);
        queryTranslationX = -leftActionWidthAndMarginLeft;
        break;
    }
    mSearchInputParent.setTranslationX(queryTranslationX);
}

From source file:com.dgmltn.ranger.internal.AbsRangeBar.java

/**
 * Set the thumb to be in the pressed state and calls invalidate() to redraw
 * the canvas to reflect the updated state.
 *
 * @param thumb the thumb to press//from   ww w .jav a 2  s .c o  m
 */
private void pressPin(final PinView thumb) {
    if (mArePinsTemporary) {
        ValueAnimator animator = ValueAnimator.ofFloat(0, mExpandedPinRadius);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mPinRadius = (Float) animation.getAnimatedValue();
                thumb.setSize(mPinRadius, mPinPadding * animation.getAnimatedFraction());
                invalidate();
            }
        });
        animator.start();
        thumb.press();
    } else {
        thumb.setSize(mExpandedPinRadius, mPinPadding);
    }
}

From source file:com.dgmltn.ranger.internal.AbsRangeBar.java

/**
 * Set the thumb to be in the normal/un-pressed state and calls invalidate()
 * to redraw the canvas to reflect the updated state.
 *
 * @param pinView the thumb to release/*www  . j  av a  2s. c o m*/
 */
private void releasePin(final PinView pinView) {
    PointF point = new PointF();
    getNearestIndexPosition(pinView.getPosition(), point);
    pinView.setPosition(point);
    int tickIndex = getNearestIndex(pinView);

    pinView.setLabel(getPinLabel(tickIndex));

    if (mArePinsTemporary) {
        ValueAnimator animator = ValueAnimator.ofFloat(mExpandedPinRadius, 0);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mPinRadius = (Float) (animation.getAnimatedValue());
                pinView.setSize(mPinRadius, mPinPadding - (mPinPadding * animation.getAnimatedFraction()));
                invalidate();
            }
        });
        animator.start();
        pinView.release();
    } else {
        invalidate();
    }
}

From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java

/**
 * //from   w  ww .  j  av  a  2s . c o  m
 * @param view
 */
@Override
public void onClick(View view) {
    if (mTvExpandCollapse.getVisibility() != View.VISIBLE) {
        return;
    }
    mCollapsed = !mCollapsed;
    ///?
    if (showExpandCollapseDrawable) {
        mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null,
                mCollapsed ? mExpandDrawable : mCollapseDrawable, null);
    }
    mTvExpandCollapse.setText(
            mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink));
    //???
    if (mCollapsedStatus != null) {
        mCollapsedStatus.put(mPosition, mCollapsed);
    }
    // /
    mAnimating = true;
    ValueAnimator valueAnimator;
    if (mCollapsed) {
        //            mTvContent.setMaxLines(mMaxCollapsedLines);
        valueAnimator = new ValueAnimator().ofInt(getHeight(), mCollapsedHeight);
    } else {
        valueAnimator = new ValueAnimator().ofInt(getHeight(),
                getHeight() + mTextHeightWithMaxLines - mTvContent.getHeight());
    }
    valueAnimator.addUpdateListener(valueAnimator1 -> {
        int animatedValue = (int) valueAnimator1.getAnimatedValue();
        mTvContent.setMaxHeight(animatedValue - mMarginBetweenTxtAndBottom);
        getLayoutParams().height = animatedValue;
        requestLayout();
    });
    valueAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {

        }

        @Override
        public void onAnimationEnd(Animator animator) {
            // ??????
            /// clear the animation flag
            mAnimating = false;
            // notify the listener
            if (mListener != null) {
                mListener.onExpandStateChanged(mTvContent, !mCollapsed);
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {

        }

        @Override
        public void onAnimationRepeat(Animator animator) {

        }
    });
    valueAnimator.setDuration(mAnimationDuration);
    valueAnimator.start();
}

From source file:com.test.xujixiao.xjx.widget.view.swipe_listview.SwipeListViewTouchListener.java

/**
 * Perform dismiss action// ww  w. j  a va2  s  .c  o  m
 *
 * @param dismissView     View
 * @param dismissPosition Position of list
 */
protected void performDismiss(final View dismissView, final int dismissPosition, boolean doPendingDismiss) {
    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(animationTime);

    if (doPendingDismiss) {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                --dismissAnimationRefCount;
                if (dismissAnimationRefCount == 0) {
                    removePendingDismisses(originalHeight);
                }
            }
        });
    }

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    pendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

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

/**
 * perform closing animation for the specified node
 *
 * @param node node to be animated/*from  w ww  . j a v  a 2s. c  o m*/
 */
private void animateDrillOut(final Node<?> node) {
    final Node<?> parent = node.getParent();
    if (parent.getDepth() > 0)
        addView(_getHeaderView(node.getParent()), 0);//add parent
    if (nodeChangeListener != null && node.getParent().getDepth() > 0)
        nodeChangeListener.onParentNodeOpening(getChildAt(0), node.getParent());
    for (int i = 0; i < node.getParent().getChildCount(); ++i) {
        if (i != node.getIndex())
            addView(_getHeaderView(node.getParent().getChildAt(i)), i + (parent.getDepth() > 0 ? 1 : 0));
    }

    final int newIndex = node.getIndex() + (parent.getDepth() > 0 ? 1 : 0);
    final int aux = parent.getChildCount() + (parent.getDepth() > 0 ? 1 : 0);
    ValueAnimator animator = ValueAnimator.ofFloat(1);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            for (int i = 0; i < aux; ++i) {
                if (i < newIndex) {
                    getChildAt(i).setTranslationY(headerHeight * (-newIndex + i)
                            + headerHeight * newIndex * ((Float) animation.getAnimatedValue()));
                } else if (i > newIndex) {
                    getChildAt(i)
                            .setTranslationY((getHeight() + headerHeight * (i - (newIndex + 1))) - ((getHeight()
                                    - (node.getIndex() + 1 + (parent.getDepth() > 0 ? 1 : 0)) * headerHeight)
                                    * ((Float) animation.getAnimatedValue())));
                } else {
                    getChildAt(newIndex)
                            .setTranslationY(headerHeight * newIndex * ((Float) animation.getAnimatedValue()));
                }
            }
        }
    });
    animator.addListener(new CustomAnimationListener() {
        @Override
        public void onAnimationEnd(Animator animator) {
            activeNode = parent;
            updateViews(node, false);
        }
    });
    animator.setDuration(duration);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.start();
    animateDrillAlpha(newIndex + 1, aux, 1);
}

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);
    }//  w w  w.  j  a  v  a2  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:cw.kop.autobackground.sources.SourceListFragment.java

/**
 * Shows LocalImageFragment to view images
 *
 * @param view  source card which was selected
 * @param index position of source in listAdapter
 *///ww  w  . j  av  a2  s  .  co  m
private void showViewImageFragment(final View view, final int index) {
    sourceList.setOnItemClickListener(null);
    sourceList.setEnabled(false);

    listAdapter.saveData();
    Source item = listAdapter.getItem(index);
    String type = item.getType();
    String directory;
    if (type.equals(AppSettings.FOLDER)) {
        directory = item.getData().split(AppSettings.DATA_SPLITTER)[0];
    } else {
        directory = AppSettings.getDownloadPath() + "/" + item.getTitle() + " " + AppSettings.getImagePrefix();
    }

    Log.i(TAG, "Directory: " + directory);

    final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container);
    final ImageView sourceImage = (ImageView) view.findViewById(R.id.source_image);
    final View imageOverlay = view.findViewById(R.id.source_image_overlay);
    final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title);
    final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);
    final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container);

    final float viewStartHeight = sourceContainer.getHeight();
    final float viewStartY = view.getY();
    final float overlayStartAlpha = imageOverlay.getAlpha();
    final float listHeight = sourceList.getHeight();
    Log.i(TAG, "listHeight: " + listHeight);
    Log.i(TAG, "viewStartHeight: " + viewStartHeight);

    final LocalImageFragment localImageFragment = new LocalImageFragment();
    Bundle arguments = new Bundle();
    arguments.putString("view_path", directory);
    localImageFragment.setArguments(arguments);

    Animation animation = new Animation() {

        private boolean needsFragment = true;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (needsFragment && interpolatedTime >= 1) {
                needsFragment = false;
                getFragmentManager().beginTransaction()
                        .add(R.id.content_frame, localImageFragment, "image_fragment").addToBackStack(null)
                        .setTransition(FragmentTransaction.TRANSIT_NONE).commit();
            }
            ViewGroup.LayoutParams params = sourceContainer.getLayoutParams();
            params.height = (int) (viewStartHeight + (listHeight - viewStartHeight) * interpolatedTime);
            sourceContainer.setLayoutParams(params);
            view.setY(viewStartY - interpolatedTime * viewStartY);
            deleteButton.setAlpha(1.0f - interpolatedTime);
            viewButton.setAlpha(1.0f - interpolatedTime);
            editButton.setAlpha(1.0f - interpolatedTime);
            sourceTitle.setAlpha(1.0f - interpolatedTime);
            imageOverlay.setAlpha(overlayStartAlpha - overlayStartAlpha * (1.0f - interpolatedTime));
            sourceExpandContainer.setAlpha(1.0f - interpolatedTime);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getDialogColor(appContext),
            getResources().getColor(AppSettings.getBackgroundColorResource()));
    cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue());
        }

    });

    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);

    animation.setDuration(INFO_ANIMATION_TIME);
    cardColorAnimation.setDuration(INFO_ANIMATION_TIME);

    animation.setInterpolator(decelerateInterpolator);
    cardColorAnimation.setInterpolator(decelerateInterpolator);

    needsListReset = true;
    cardColorAnimation.start();
    view.startAnimation(animation);

}

From source file:com.klinker.android.sliding.MultiShrinkScroller.java

public void runExpansionAnimation() {

    final Interpolator interpolator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in);
    } else {/*from w  w w .j ava2 s. c  o m*/
        interpolator = new DecelerateInterpolator();
    }

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenHeight = size.y;
    int screenWidth = size.x;

    final ValueAnimator heightExpansion = ValueAnimator.ofInt(expansionViewHeight, getHeight());
    heightExpansion.setInterpolator(interpolator);
    heightExpansion.setDuration(ANIMATION_DURATION);
    heightExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = val;
            setLayoutParams(params);
        }
    });
    heightExpansion.start();

    final ValueAnimator widthExpansion = ValueAnimator.ofInt(expansionViewWidth, getWidth());
    widthExpansion.setInterpolator(interpolator);
    widthExpansion.setDuration(ANIMATION_DURATION);
    widthExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.width = val;
            setLayoutParams(params);
        }
    });
    widthExpansion.start();

    ObjectAnimator translationX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, expansionLeftOffset, 0f);
    translationX.setInterpolator(interpolator);
    translationX.setDuration(ANIMATION_DURATION);
    translationX.start();

    ObjectAnimator translationY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, expansionTopOffset, 0f);
    translationY.setInterpolator(interpolator);
    translationY.setDuration(ANIMATION_DURATION);
    translationY.start();
}