Java Code Examples for android.animation.Animator#addListener()

The following examples show how to use android.animation.Animator#addListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NavigationActivity.java    From android with Apache License 2.0 6 votes vote down vote up
@Optional
@OnClick(R.id.fab)
public void onClickFab() {
  if (!leagueDetails.haveRoundsLeft()) {
    Util.showLeagueEndResults(userPreferences, leagueDetails, this);
    return;
  }
  LeagueRound round = leagueDetails.executeRound(leagueDetails.nextRound());
  //noinspection ConstantConditions
  circularRevealOverlay.setVisibility(View.VISIBLE);
  int distFromEdge = fabMargin + (fab.getWidth() / 2);
  int cx = drawerLayout.getWidth() - distFromEdge;
  int cy = drawerLayout.getHeight() - distFromEdge;
  float finalRadius = Math.max(drawerLayout.getWidth(), drawerLayout.getHeight());
  Animator circularReveal =
      ViewAnimationUtils.createCircularReveal(circularRevealOverlay, cx, cy, 0, finalRadius)
          .setDuration(400);
  circularReveal.addListener(new SimpleAnimatorListener() {
    @Override public void onAnimationEnd(Animator animation) {
      startMatchProgressActivity(round);
    }
  });
  circularReveal.start();
}
 
Example 2
Source File: StreetViewFragment.java    From animation-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onBackPressed() {
    if (isRestored) {
        getFragmentManager().popBackStack();
    } else {
        // Perform a circular conceal, then pop this fragment off the back stack.
        final FrameLayout view = ((FrameLayout) getView());
        //noinspection ConstantConditions
        Animator circularConceal = ViewUtils.createCircularConceal(mRevealCenter, mRevealWidth,
                view, INTERPOLATOR);
        circularConceal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
                getFragmentManager().popBackStack();
            }
        });
        circularConceal.start();
    }
}
 
Example 3
Source File: BeatBoxFragment.java    From AndroidProgramming3e with Apache License 2.0 6 votes vote down vote up
private void performRevealAnimation(final View view, int screenCenterX, int screenCenterY) {
    int[] animatingViewCoords = new int[2];
    view.getLocationOnScreen(animatingViewCoords);
    int centerX = screenCenterX - animatingViewCoords[0];
    int centerY = screenCenterY - animatingViewCoords[1];

    Point size = new Point();
    getActivity().getWindowManager().getDefaultDisplay().getSize(size);
    int maxRadius = size.y;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setVisibility(View.VISIBLE);
        Animator animator = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, 0, maxRadius);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        });
        animator.start();
    }
}
 
Example 4
Source File: OnboardingFragment.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPageChanged(final int newPage, int previousPage) {
    if (mContentAnimator != null) {
        mContentAnimator.end();
    }
    ArrayList<Animator> animators = new ArrayList<>();
    Animator fadeOut = createFadeOutAnimator(mContentView);

    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mContentView.setImageDrawable(getResources().getDrawable(pageImages[newPage]));
            ((AnimationDrawable) mContentView.getDrawable()).start();
        }
    });
    animators.add(fadeOut);
    animators.add(createFadeInAnimator(mContentView));
    AnimatorSet set = new AnimatorSet();
    set.playSequentially(animators);
    set.start();
    mContentAnimator = set;
}
 
Example 5
Source File: CommentsPresenter.java    From yahnac with Apache License 2.0 6 votes vote down vote up
private void hideReplyView() {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        int cx = (replyFab.getLeft() + replyFab.getRight()) / 2;
        int cy = (replyFab.getTop() + replyFab.getBottom()) / 2;
        int initialRadius = replyView.getWidth();
        Animator anim =
                ViewAnimationUtils.createCircularReveal(replyView, cx, cy, initialRadius, 0);

        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                replyView.clearAndHide();
            }
        });

        anim.start();
    } else {
        replyView.clearAndHide();
    }

    replyFab.show();
    commentsView.setVisibility(View.VISIBLE);
}
 
Example 6
Source File: FloatingMenuAnimationHandler.java    From floatingMenu with Apache License 2.0 5 votes vote down vote up
private AnimatorSet openMenuAnimation(Point center) {
    setAnimating(true);
    Animator lastAnimation = null;
    List<SubButton> subActionItems = menu.getSubMenuButtons();
    ArrayList<Animator> animatorArrayList = new ArrayList<>();
    for (int i = 0; i < subActionItems.size(); i++) {
        SubButton currentSubButton = subActionItems.get(i);
        ArrayList<PropertyValuesHolder> properties = new ArrayList<>();
        properties.add(PropertyValuesHolder.ofFloat(View.TRANSLATION_X, currentSubButton.getX() - center.x + currentSubButton.getWidth() / 2));
        properties.add(PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, currentSubButton.getY() - center.y + currentSubButton.getHeight() / 2));
        if (shouldRotate) {
            properties.add(PropertyValuesHolder.ofFloat(View.ROTATION, 720));
        }
        if (shouldScale) {
            properties.add(PropertyValuesHolder.ofFloat(View.SCALE_X, 1));
            properties.add(PropertyValuesHolder.ofFloat(View.SCALE_Y, 1));
        }
        if (shouldFade) {
            properties.add(PropertyValuesHolder.ofFloat(View.ALPHA, 1));
        }
        PropertyValuesHolder[] parameters = new PropertyValuesHolder[properties.size() - 1];
        parameters = properties.toArray(parameters);
        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(currentSubButton.getView(), parameters);
        animation.setDuration(openingDuration);
        animation.setInterpolator(openingInterpolator);
        menuButtonAnimationListener = new FloatingMenuButtonAnimationListener(FloatingMenuAnimationHandler.this, currentSubButton, MenuState.OPENING);
        animation.addListener(menuButtonAnimationListener);
        if (i == 0) {
            lastAnimation = animation;
        }
        animation.setStartDelay((subActionItems.size() - i) * lagBetweenItems);
        animatorArrayList.add(animation);
    }
    if (lastAnimation != null) {
        lastAnimation.addListener(this);
    }
    AnimatorSet openAnimatorSet = new AnimatorSet();
    openAnimatorSet.playTogether(animatorArrayList);
    return openAnimatorSet;
}
 
Example 7
Source File: SearchPlaceActivity.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
private void showBottom(View view, Animator.AnimatorListener listener) {

        view.setVisibility(View.VISIBLE);
        Animator iconAnim = ObjectAnimator.ofPropertyValuesHolder(view,
                PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, view.getHeight(), 0f));
        iconAnim.setDuration(VIEW_ANIMATION);
        iconAnim.addListener(listener);
        iconAnim.start();
    }
 
Example 8
Source File: CollapsedViewHolder.java    From FancyAccordionView with Apache License 2.0 5 votes vote down vote up
@Override
public Animator onAnimateChange(final ViewHolder oldHolder, ViewHolder newHolder,
                                long duration) {
    if (!(oldHolder instanceof ArrowItemViewHolder)
            || !(newHolder instanceof ArrowItemViewHolder)) {
        return null;
    }

    final boolean isCollapsing = this == newHolder;
    setChangingViewsAlpha(isCollapsing ? 0f : 1f);

    final Animator changeAnimatorSet = isCollapsing
            ? createCollapsingAnimator((ArrowItemViewHolder) oldHolder, duration)
            : createExpandingAnimator((ArrowItemViewHolder) newHolder, duration);
    changeAnimatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            if (arrow != null) {
                arrow.setVisibility(View.VISIBLE);
                arrow.setTranslationY(0f);
                arrow.jumpDrawablesToCurrentState();
            }
            setChangingViewsAlpha(1f);
        }
    });
    return changeAnimatorSet;
}
 
Example 9
Source File: DefaultAnimationHandler.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void animateMenuOpening(Point center) {
    super.animateMenuOpening(center);

    setAnimating(true);

    Animator lastAnimation = null;
    for (int i = 0; i < menu.getSubActionItems().size(); i++) {

        menu.getSubActionItems().get(i).view.setScaleX(0);
        menu.getSubActionItems().get(i).view.setScaleY(0);
        menu.getSubActionItems().get(i).view.setAlpha(0);

        PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2);
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2);
        PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 720);
        PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
        PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
        PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 1);

        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
        animation.setDuration(DURATION);
        animation.setInterpolator(new OvershootInterpolator(0.9f));
        animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.OPENING));

        if(i == 0) {
            lastAnimation = animation;
        }

        // Put a slight lag between each of the menu items to make it asymmetric
        animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
        animation.start();
    }
    if(lastAnimation != null) {
        lastAnimation.addListener(new LastAnimationListener());
    }

}
 
Example 10
Source File: TranslationAnimationCreator.java    From Transitions-Everywhere with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an animator that can be used for x and/or y translations. When interrupted,
 * it sets a tag to keep track of the position so that it may be continued from position.
 *
 * @param view The view being moved. This may be in the overlay for onDisappear.
 * @param values The values containing the view in the view hierarchy.
 * @param viewPosX The x screen coordinate of view
 * @param viewPosY The y screen coordinate of view
 * @param startX The start translation x of view
 * @param startY The start translation y of view
 * @param endX The end translation x of view
 * @param endY The end translation y of view
 * @param interpolator The interpolator to use with this animator.
 * @return An animator that moves from (startX, startY) to (endX, endY) unless there was
 * a previous interruption, in which case it moves from the current position to (endX, endY).
 */
@Nullable
public static Animator createAnimation(View view, TransitionValues values, int viewPosX, int viewPosY,
                                       float startX, float startY, float endX, float endY, TimeInterpolator interpolator,
                                       @NonNull Transition transition) {
    if (TRANSLATIONS_PROPERTY == null) {
        return null;
    }
    float terminalX = view.getTranslationX();
    float terminalY = view.getTranslationY();
    int[] startPosition = (int[]) values.view.getTag(R.id.transitionPosition);
    if (startPosition != null) {
        startX = startPosition[0] - viewPosX + terminalX;
        startY = startPosition[1] - viewPosY + terminalY;
    }
    // Initial position is at translation startX, startY, so position is offset by that amount
    int startPosX = viewPosX + Math.round(startX - terminalX);
    int startPosY = viewPosY + Math.round(startY - terminalY);

    view.setTranslationX(startX);
    view.setTranslationY(startY);
    Animator anim = AnimatorUtils.ofPointF(view, TRANSLATIONS_PROPERTY,
            startX, startY, endX, endY);

    if (anim != null) {
        TransitionPositionListener listener = new TransitionPositionListener(view, values.view,
                startPosX, startPosY, terminalX, terminalY);
        transition.addListener(listener);
        anim.addListener(listener);
        AnimatorUtils.addPauseListener(anim, listener);
        anim.setInterpolator(interpolator);
    }
    return anim;
}
 
Example 11
Source File: DemoLikeTumblrActivity.java    From ArcLayout with Apache License 2.0 5 votes vote down vote up
private void hideMenu(int cx, int cy, float startRadius, float endRadius) {
  List<Animator> animList = new ArrayList<>();

  for (int i = arcLayout.getChildCount() - 1; i >= 0; i--) {
    animList.add(createHideItemAnimator(arcLayout.getChildAt(i)));
  }

  animList.add(createHideItemAnimator(centerItem));

  Animator revealAnim = createCircularReveal(menuLayout, cx, cy, startRadius, endRadius);
  revealAnim.setInterpolator(new AccelerateDecelerateInterpolator());
  revealAnim.setDuration(200);
  revealAnim.addListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
      super.onAnimationEnd(animation);
      menuLayout.setVisibility(View.INVISIBLE);
    }
  });

  animList.add(revealAnim);

  AnimatorSet animSet = new AnimatorSet();
  animSet.playSequentially(animList);
  animSet.start();

}
 
Example 12
Source File: HomeBaseActivity.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
private void exitReveal(final View myView, final int screenType) {
    menuShown = false;
    centerButton.animate().rotation(0).setInterpolator(new AccelerateInterpolator()).setDuration(50);

    // get the center for the clipping circle
    int cx = myView.getMeasuredWidth() / 2;
    int cy = myView.getMeasuredHeight();

    // get the initial radius for the clipping circle
    int initialRadius = Math.max(myView.getWidth(), myView.getHeight());

    // create the animation (the final radius is zero)
    Animator anim =
            ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0);

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

    anim.setDuration(Constant.REVEAL_DURATION);
    // start the animation
    anim.start();

    setSelected(screenType);
}
 
Example 13
Source File: DefaultAnimationHandler.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
@Override
public void animateMenuClosing(Point center) {
    super.animateMenuOpening(center);

    setAnimating(true);

    Animator lastAnimation = null;
    for (int i = 0; i < menu.getSubActionItems().size(); i++) {
        PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, - (menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2));
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, - (menu.getSubActionItems().get(i).y - center.y + menu.getSubActionItems().get(i).height / 2));
        PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, -720);
        PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 0);
        PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0);
        PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 0);

        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhX, pvhY, pvhR, pvhsX, pvhsY, pvhA);
        animation.setDuration(DURATION);
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.CLOSING));

        if(i == 0) {
            lastAnimation = animation;
        }

        animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
        animation.start();
    }
    if(lastAnimation != null) {
        lastAnimation.addListener(new LastAnimationListener());
    }
}
 
Example 14
Source File: CircularAnimUtil.java    From SeeWeather with Apache License 2.0 5 votes vote down vote up
/**
 * 由满向中间收缩,直到隐藏。
 */
@SuppressLint("NewApi")
public static void hide(final View myView, float endRadius, long durationMills) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        myView.setVisibility(View.INVISIBLE);
        return;
    }

    int cx = (myView.getLeft() + myView.getRight()) / 2;
    int cy = (myView.getTop() + myView.getBottom()) / 2;
    int w = myView.getWidth();
    int h = myView.getHeight();

    // 勾股定理 & 进一法
    int initialRadius = (int) Math.sqrt(w * w + h * h) + 1;

    Animator anim =
        ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, endRadius);
    anim.setDuration(durationMills);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            myView.setVisibility(View.INVISIBLE);
        }
    });

    anim.start();
}
 
Example 15
Source File: KeyPreviewChoreographer.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
public Animator createShowUpAnimator(final Key key, final KeyPreviewView keyPreviewView) {
    final Animator showUpAnimator = mParams.createShowUpAnimator(keyPreviewView);
    showUpAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(final Animator animator) {
            showKeyPreview(key, keyPreviewView, false /* withAnimation */);
        }
    });
    return showUpAnimator;
}
 
Example 16
Source File: PeriscopeLayout.java    From PeriscopeLayout with Apache License 2.0 5 votes vote down vote up
public void addHeart() {

        ImageView imageView = new ImageView(getContext());
        //随机选一个
        imageView.setImageDrawable(drawables[random.nextInt(3)]);
        imageView.setLayoutParams(lp);

        addView(imageView);

        Animator set = getAnimator(imageView);
        set.addListener(new AnimEndListener(imageView));
        set.start();

    }
 
Example 17
Source File: PlayPauseDrawable.java    From DMAudioStreamer with Apache License 2.0 5 votes vote down vote up
public Animator getPausePlayAnimator() {
	final Animator anim = ObjectAnimator.ofFloat(this, PROGRESS, mIsPlay ? 1 : 0, mIsPlay ? 0 : 1);
	anim.addListener(new AnimatorListenerAdapter() {
		@Override
		public void onAnimationEnd(Animator animation) {
			mIsPlay = !mIsPlay;
		}
	});
	return anim;
}
 
Example 18
Source File: DynamicRoundTextView.java    From customview-samples with Apache License 2.0 5 votes vote down vote up
/**
 * 出现
 */
public void appear(AnimatorListenerAdapter animatorListenerAdapter){
    if(mState == STATE_DISAPPEAR) {
        setVisibility(View.VISIBLE);
        Animator animator = buildAppearAnimator();
        if(animatorListenerAdapter!=null){
            animator.addListener(animatorListenerAdapter);
        }
        animator.start();
        mState = STATE_NORMAL;
    }
}
 
Example 19
Source File: ViewStack.java    From Pancakes with MIT License 4 votes vote down vote up
private void startAnimation(AnimatorFactory animatorFactory, View view,
                            Animator.AnimatorListener listener) {
    Animator animator = animatorFactory.createAnimator(view);
    animator.addListener(listener);
    animator.start();
}
 
Example 20
Source File: StateAnimator.java    From Carbon with Apache License 2.0 2 votes vote down vote up
/**
 * Associates the given Animation with the provided drawable state specs so that it will be run
 * when the View's drawable state matches the specs.
 *
 * @param specs     drawable state specs to match against
 * @param animation The Animation to run when the specs match
 */
public void addState(int[] specs, Animator animation, Animator.AnimatorListener listener) {
    Tuple tuple = new Tuple(specs, animation, listener);
    animation.addListener(mAnimationListener);
    mTuples.add(tuple);
}