Example usage for android.animation AnimatorSet addListener

List of usage examples for android.animation AnimatorSet addListener

Introduction

In this page you can find the example usage for android.animation AnimatorSet addListener.

Prototype

public void addListener(AnimatorListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

From source file:com.rukiasoft.androidapps.cocinaconroll.ui.RecipeListRecyclerViewAdapter.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void flipCard(final View card) {
    final View front = frontCard;
    final View back = backCard;
    final AnimatorSet flipCard = (card.getRotationY() == 0)
            ? (AnimatorSet) AnimatorInflater.loadAnimator(mContext, R.animator.card_flip_rotate_half)
            : (AnimatorSet) AnimatorInflater.loadAnimator(mContext, R.animator.card_flip_rotate_full);
    final AnimatorSet disappear = (AnimatorSet) AnimatorInflater.loadAnimator(mContext,
            R.animator.view_disappear);/*  w  ww  . j a v  a  2s .  c o  m*/
    //final AnimatorSet flipPositive = (AnimatorSet) AnimatorInflater.loadAnimator(mContext, R.animator.card_flip_rotate_full);
    final AnimatorSet appear = (AnimatorSet) AnimatorInflater.loadAnimator(mContext, R.animator.view_appear);
    flipCard.setTarget(card);
    disappear.setTarget(front);
    //flipPositive.setTarget(card);
    appear.setTarget(back);
    //setLeftIn.setTarget(backView);
    flipCard.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            disappear.start();
            appear.start();
            back.setVisibility(View.VISIBLE);
            back.setAlpha(0);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            front.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });

    flipCard.start();
}

From source file:Main.java

public static void animatePhotoLike(final View vBgLike, final View ivLike) {
    vBgLike.setVisibility(View.VISIBLE);
    ivLike.setVisibility(View.VISIBLE);

    vBgLike.setScaleY(0.1f);/*  w w w .  j a  v a  2 s.co  m*/
    vBgLike.setScaleX(0.1f);
    vBgLike.setAlpha(1f);
    ivLike.setScaleY(0.1f);
    ivLike.setScaleX(0.1f);

    android.animation.AnimatorSet animatorSet = new android.animation.AnimatorSet();

    android.animation.ObjectAnimator bgScaleYAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "scaleY",
            0.1f, 1f);
    bgScaleYAnim.setDuration(200);
    bgScaleYAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator bgScaleXAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "scaleX",
            0.1f, 1f);
    bgScaleXAnim.setDuration(200);
    bgScaleXAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator bgAlphaAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "alpha",
            1f, 0f);
    bgAlphaAnim.setDuration(200);
    bgAlphaAnim.setStartDelay(150);
    bgAlphaAnim.setInterpolator(DECCELERATE_INTERPOLATOR);

    android.animation.ObjectAnimator imgScaleUpYAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleY", 0.1f, 1f);
    imgScaleUpYAnim.setDuration(300);
    imgScaleUpYAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator imgScaleUpXAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleX", 0.1f, 1f);
    imgScaleUpXAnim.setDuration(300);
    imgScaleUpXAnim.setInterpolator(DECCELERATE_INTERPOLATOR);

    android.animation.ObjectAnimator imgScaleDownYAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleY", 1f, 0f);
    imgScaleDownYAnim.setDuration(300);
    imgScaleDownYAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator imgScaleDownXAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleX", 1f, 0f);
    imgScaleDownXAnim.setDuration(300);
    imgScaleDownXAnim.setInterpolator(ACCELERATE_INTERPOLATOR);

    animatorSet.playTogether(bgScaleYAnim, bgScaleXAnim, bgAlphaAnim, imgScaleUpYAnim, imgScaleUpXAnim);
    animatorSet.play(imgScaleDownYAnim).with(imgScaleDownXAnim).after(imgScaleUpYAnim);

    animatorSet.addListener(new android.animation.AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(android.animation.Animator animation) {
            vBgLike.setVisibility(View.INVISIBLE);
            ivLike.setVisibility(View.INVISIBLE);
        }
    });
    animatorSet.start();
}

From source file:com.sysdata.widget.accordion.CollapsedViewHolder.java

private Animator createCollapsingAnimator(ArrowItemViewHolder oldHolder, long duration) {
    final View oldView = oldHolder.itemView;
    final View newView = itemView;
    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(newView, oldView, newView)
            .setDuration(duration);/*from   ww  w .  j a v a  2s  . c  o m*/
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final AnimatorSet animatorSet;
    if (arrow != null) {
        final View oldArrow = oldHolder.arrow;
        final Rect oldArrowRect = new Rect(0, 0, oldArrow.getWidth(), oldArrow.getHeight());
        final Rect newArrowRect = new Rect(0, 0, arrow.getWidth(), arrow.getHeight());
        ((ViewGroup) newView).offsetDescendantRectToMyCoords(arrow, newArrowRect);
        ((ViewGroup) oldView).offsetDescendantRectToMyCoords(oldArrow, oldArrowRect);
        final float arrowTranslationY = oldArrowRect.bottom - newArrowRect.bottom;
        arrow.setTranslationY(arrowTranslationY);
        arrow.setVisibility(View.VISIBLE);

        final Animator arrowAnimation = ObjectAnimator.ofFloat(arrow, View.TRANSLATION_Y, 0f)
                .setDuration(duration);
        arrowAnimation.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

        animatorSet = new AnimatorSet();
        animatorSet.playTogether(boundsAnimator, arrowAnimation);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                AnimatorUtils.startDrawableAnimation(arrow);
            }
        });
    } else {
        animatorSet = new AnimatorSet();
        animatorSet.playTogether(boundsAnimator);
    }

    return animatorSet;
}

From source file:io.plaidapp.ui.SearchActivity.java

@OnClick(R.id.results_scrim)
protected void hideSaveConfimation() {
    if (confirmSaveContainer.getVisibility() == View.VISIBLE) {
        // contract the bubble & hide the scrim
        AnimatorSet hideConfirmation = new AnimatorSet();
        hideConfirmation.playTogether(/*  w  w  w . j  a v  a 2s.  co m*/
                ViewAnimationUtils.createCircularReveal(confirmSaveContainer,
                        confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2,
                        confirmSaveContainer.getWidth() / 2, fab.getWidth() / 2),
                ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT));
        hideConfirmation.setDuration(150L);
        hideConfirmation.setInterpolator(
                AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in));
        hideConfirmation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                confirmSaveContainer.setVisibility(View.GONE);
                resultsScrim.setVisibility(View.GONE);
                fab.setVisibility(results.getVisibility());
            }
        });
        hideConfirmation.start();
    }
}

From source file:com.android.calculator2.Calculator.java

private void reveal(View sourceView, int colorRes, AnimatorListener listener) {
    final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay();

    final Rect displayRect = new Rect();
    mDisplayView.getGlobalVisibleRect(displayRect);

    // Make reveal cover the display and status bar.
    final View revealView = new View(this);
    revealView.setBottom(displayRect.bottom);
    revealView.setLeft(displayRect.left);
    revealView.setRight(displayRect.right);
    revealView.setBackgroundColor(getResources().getColor(colorRes));
    groupOverlay.add(revealView);/*from  w  w  w . j  a  v  a  2  s .  c  om*/

    final int[] clearLocation = new int[2];
    sourceView.getLocationInWindow(clearLocation);
    clearLocation[0] += sourceView.getWidth() / 2;
    clearLocation[1] += sourceView.getHeight() / 2;

    final int revealCenterX = clearLocation[0] - revealView.getLeft();
    final int revealCenterY = clearLocation[1] - revealView.getTop();

    final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
    final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
    final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
    final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

    final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
            revealCenterY, 0.0f, revealRadius);
    revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    revealAnimator.addListener(listener);

    final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(revealAnimator).before(alphaAnimator);
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            groupOverlay.remove(revealView);
            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:com.hamzahrmalik.calculator2.Calculator.java

private void onResult(final String result) {
    // Calculate the values needed to perform the scale and translation
    // animations,
    // accounting for how the scale will affect the final position of the
    // text./*from ww  w . j a va  2  s .c om*/
    final float resultScale = mFormulaEditText.getVariableTextSize(result) / mResultEditText.getTextSize();
    final float resultTranslationX = (1.0f - resultScale)
            * (mResultEditText.getWidth() / 2.0f - mResultEditText.getPaddingEnd());
    final float resultTranslationY = (1.0f - resultScale)
            * (mResultEditText.getHeight() / 2.0f - mResultEditText.getPaddingBottom())
            + (mFormulaEditText.getBottom() - mResultEditText.getBottom())
            + (mResultEditText.getPaddingBottom() - mFormulaEditText.getPaddingBottom());
    final float formulaTranslationY = -mFormulaEditText.getBottom();

    // Use a value animator to fade to the final text color over the course
    // of the animation.
    final int resultTextColor = mResultEditText.getCurrentTextColor();
    final int formulaTextColor = mFormulaEditText.getCurrentTextColor();
    final ValueAnimator textColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), resultTextColor,
            formulaTextColor);
    textColorAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            /*
             * mResultEditText.setTextColor((int) valueAnimator
             * .getAnimatedValue());
             */
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(textColorAnimator,
            ObjectAnimator.ofFloat(mResultEditText, View.SCALE_X, resultScale),
            ObjectAnimator.ofFloat(mResultEditText, View.SCALE_Y, resultScale),
            ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_X, resultTranslationX),
            ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_Y, resultTranslationY),
            ObjectAnimator.ofFloat(mFormulaEditText, View.TRANSLATION_Y, formulaTranslationY));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            mResultEditText.setText(result);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // Reset all of the values modified during the animation.
            mResultEditText.setTextColor(resultTextColor);
            mResultEditText.setScaleX(1.0f);
            mResultEditText.setScaleY(1.0f);
            mResultEditText.setTranslationX(0.0f);
            mResultEditText.setTranslationY(0.0f);
            mFormulaEditText.setTranslationY(0.0f);

            // Finally update the formula to use the current result.
            mFormulaEditText.setText(result);
            setState(CalculatorState.RESULT);

            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:com.sysdata.widget.accordion.ExpandedViewHolder.java

private Animator createExpandingAnimator(ArrowItemViewHolder oldHolder, long duration) {
    final View oldView = oldHolder.itemView;
    final View newView = itemView;
    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(newView, oldView, newView);
    boundsAnimator.setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final Animator backgroundAnimator = ObjectAnimator.ofPropertyValuesHolder(newView,
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 0, 255));
    backgroundAnimator.setDuration(duration);

    final AnimatorSet animatorSet;
    if (arrow != null) {
        final View oldArrow = oldHolder.arrow;
        final Rect oldArrowRect = new Rect(0, 0, oldArrow.getWidth(), oldArrow.getHeight());
        final Rect newArrowRect = new Rect(0, 0, arrow.getWidth(), arrow.getHeight());
        ((ViewGroup) newView).offsetDescendantRectToMyCoords(arrow, newArrowRect);
        ((ViewGroup) oldView).offsetDescendantRectToMyCoords(oldArrow, oldArrowRect);
        final float arrowTranslationY = oldArrowRect.bottom - newArrowRect.bottom;

        arrow.setTranslationY(arrowTranslationY);
        arrow.setVisibility(View.VISIBLE);

        final Animator arrowAnimation = ObjectAnimator.ofFloat(arrow, View.TRANSLATION_Y, 0f)
                .setDuration(duration);//from  ww  w  . j  a  va 2 s . c o  m
        arrowAnimation.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

        animatorSet = new AnimatorSet();
        animatorSet.playTogether(backgroundAnimator, boundsAnimator, arrowAnimation);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                AnimatorUtils.startDrawableAnimation(arrow);
            }
        });
    } else {
        animatorSet = new AnimatorSet();
        animatorSet.playTogether(backgroundAnimator, boundsAnimator);
    }

    return animatorSet;
}

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

private Animator getScaleFooterButtonsAnimator(final boolean show) {
    final AnimatorSet animatorSet = new AnimatorSet();
    final Animator leftButtonAnimator = AnimatorUtils.getScaleAnimator(mLeftButton, show ? 0.0f : 1.0f,
            show ? 1.0f : 0.0f);/*from  w ww.ja  va 2  s.  c om*/
    final Animator rightButtonAnimator = AnimatorUtils.getScaleAnimator(mRightButton, show ? 0.0f : 1.0f,
            show ? 1.0f : 0.0f);
    final float fabStartScale = (show && mFab.getVisibility() == View.INVISIBLE) ? 0.0f : 1.0f;
    final Animator fabAnimator = AnimatorUtils.getScaleAnimator(mFab, fabStartScale, show ? 1.0f : 0.0f);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mLeftButton.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
            mRightButton.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
            restoreScale(mLeftButton);
            restoreScale(mRightButton);
            restoreScale(mFab);
        }
    });
    // If not show, means transiting from timer view to setup view,
    // when the setup view starts to rotate, the footer buttons are already invisible,
    // so the scaling has to finish before the setup view starts rotating
    animatorSet.setDuration(show ? ROTATE_ANIM_DURATION_MILIS * 2 : ROTATE_ANIM_DURATION_MILIS);
    animatorSet.play(leftButtonAnimator).with(rightButtonAnimator).with(fabAnimator);
    return animatorSet;
}

From source file:com.tmall.wireless.tangram.ext.SwipeItemTouchListener.java

private void resetViews(RecyclerView recyclerView, final int swipingType, final boolean reachActionEdge,
        final int direction) {
    int contentWidth = recyclerView.getWidth();
    AnimatorSet animatorSet = new AnimatorSet();
    List<Animator> list = new ArrayList<>();
    String translation = "translationX";
    if (swipingType == SWIPING_VER) {
        translation = "translationY";
    }//from   w  w w  .  jav  a  2  s .c o  m
    for (View view : mChildList) {
        ObjectAnimator animator;
        if (reachActionEdge) {
            animator = ObjectAnimator.ofFloat(view, translation, contentWidth * direction)
                    .setDuration(ANIMATE_DURATION);
            animator.setInterpolator(new AccelerateInterpolator());
        } else {
            animator = ObjectAnimator.ofFloat(view, translation, 0).setDuration(ANIMATE_DURATION);
            animator.setInterpolator(new DecelerateInterpolator());
        }
        list.add(animator);
    }
    animatorSet.playTogether(list);
    animatorSet.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (swipingType == SWIPING_HOR && reachActionEdge) {
                if (mSwipeCardRef != null && mSwipeCardRef.get() != null) {
                    SwipeCard swipeCard = mSwipeCardRef.get();
                    swipeCard.switchTo(swipeCard.getCurrentIndex() - direction);
                }
            }
            mChildList.clear();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    animatorSet.start();

    if (swipingType == SWIPING_VER) {
        if (pullFromEndListener != null) {
            if (mDistanceY < 0 && (mDistanceY < -pullFromEndListener.getPullEdge())) {
                pullFromEndListener.onAction();
            } else {
                pullFromEndListener.onReset();
            }
        }
    }

    swipeType = SWIPING_NONE;
}

From source file:com.hannesdorfmann.search.SearchActivity.java

@OnClick(R.id.results_scrim)
  protected void hideSaveConfimation() {
      if (confirmSaveContainer.getVisibility() == View.VISIBLE) {
          // contract the bubble & hide the scrim
          AnimatorSet hideConfirmation = new AnimatorSet();
          hideConfirmation.playTogether(
                  ViewAnimationUtils.createCircularReveal(confirmSaveContainer,
                          confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2,
                          confirmSaveContainer.getWidth() / 2, fab.getWidth() / 2),
                  ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT));
          hideConfirmation.setDuration(150L);
          hideConfirmation.setInterpolator(
                  AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in));
          hideConfirmation.addListener(new AnimatorListenerAdapter() {
              @Override//from  www .j  a  v a 2  s  .c  o  m
              public void onAnimationEnd(Animator animation) {
                  confirmSaveContainer.setVisibility(View.GONE);
                  resultsScrim.setVisibility(View.GONE);
                  fab.setVisibility(results.getVisibility());
              }
          });
          hideConfirmation.start();
      }
  }