Java Code Examples for android.view.animation.AnimationSet#setAnimationListener()

The following examples show how to use android.view.animation.AnimationSet#setAnimationListener() . 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: AnimationService.java    From Twire with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Hides every view in a RecyclerView to simulate clearing the RecyclerView
 * returns how long the animation takes to complete.
 * Returns -1 if there is nothing to animate
 */
public static int animateFakeClearing(int lastVisibleItemPosition, int firstVisibleItemPosition, AutoSpanRecyclerView aRecyclerView, Animation.AnimationListener animationListener, boolean includeTranslation) {
    final int DELAY_BETWEEN = 50;
    int clearingDuration = 0;

    int startPositionCol = getColumnPosFromIndex(firstVisibleItemPosition, aRecyclerView);
    int startPositionRow = getRowPosFromIndex(firstVisibleItemPosition, aRecyclerView);

    for (int i = lastVisibleItemPosition; i >= firstVisibleItemPosition; i--) {
        final View VIEW = aRecyclerView.getChildAt(lastVisibleItemPosition - i);

        int positionColumnDistance = Math.abs(getColumnPosFromIndex(i, aRecyclerView) - startPositionCol);
        int positionRowDistance = Math.abs(getRowPosFromIndex(i, aRecyclerView) - startPositionRow);
        int delay = (positionColumnDistance + positionRowDistance) * DELAY_BETWEEN + 1;

        AnimationSet mHideAnimations = AnimationService.startAlphaHideAnimation(delay, VIEW, includeTranslation);
        if (mHideAnimations == null) {
            return -1;
        }
        int hideAnimationDuration = (int) mHideAnimations.getDuration();

        if (hideAnimationDuration + delay > clearingDuration) {
            clearingDuration = hideAnimationDuration + delay;
        }

        // If the view is the last to animate, then start the intent when the animation finishes.
        if (i == lastVisibleItemPosition && animationListener != null) {
            mHideAnimations.setAnimationListener(animationListener);
        }
    }

    return clearingDuration;
}
 
Example 2
Source File: AwesomeFragment.java    From AndroidNavigation with MIT License 5 votes vote down vote up
private void animateDownOut(@NonNull final View contentView) {
    TranslateAnimation translate = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,
            Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f
    );
    AlphaAnimation alpha = new AlphaAnimation(1, 0);
    AnimationSet set = new AnimationSet(true);
    set.addAnimation(translate);
    set.addAnimation(alpha);
    set.setInterpolator(new DecelerateInterpolator());
    set.setDuration(200);
    set.setFillAfter(true);
    set.setAnimationListener(createAnimationListener(contentView));
    contentView.startAnimation(set);
}
 
Example 3
Source File: AnimationService.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Hides every view in a RecyclerView to simulate clearing the RecyclerView
 * returns how long the animation takes to complete.
 * Returns -1 if there is nothing to animate
 */
public static int animateFakeClearing(int lastVisibleItemPosition, int firstVisibleItemPosition, AutoSpanRecyclerView aRecyclerView, Animation.AnimationListener animationListener, boolean includeTranslation) {
	final int DELAY_BETWEEN = 50;
	int clearingDuration = 0;

	int startPositionCol = getColumnPosFromIndex(firstVisibleItemPosition, aRecyclerView);
	int startPositionRow = getRowPosFromIndex(firstVisibleItemPosition, aRecyclerView);

	for(int i = lastVisibleItemPosition; i >= firstVisibleItemPosition; i--) {
		final View VIEW = aRecyclerView.getChildAt(lastVisibleItemPosition - i);

		int positionColumnDistance = Math.abs(getColumnPosFromIndex(i, aRecyclerView) - startPositionCol);
		int positionRowDistance = Math.abs(getRowPosFromIndex(i, aRecyclerView) - startPositionRow);
		int delay = (positionColumnDistance + positionRowDistance) * DELAY_BETWEEN + 1;

		AnimationSet mHideAnimations = AnimationService.startAlphaHideAnimation(delay, VIEW, includeTranslation);
		if (mHideAnimations == null) {
			return -1;
		}
		int hideAnimationDuration = (int) mHideAnimations.getDuration();

		if (hideAnimationDuration + delay > clearingDuration) {
			clearingDuration = hideAnimationDuration + delay;
		}

		// If the view is the last to animate, then start the intent when the animation finishes.
		if(i == lastVisibleItemPosition && animationListener != null) {
			mHideAnimations.setAnimationListener(animationListener);
		}
	}

	return clearingDuration;
}
 
Example 4
Source File: HBButton.java    From Hamburger-Button with Apache License 2.0 4 votes vote down vote up
private void animateChangeDirection() {

		setClickable(false);
		final float origLeft;
		final float finalLeft;
		final float origRight;
		final float finalRight;
		final float rangeOfLeft;
		final float rangeOfRight;

		if (isSlideLeftToRight()) {

			origRight = mRFSlider.right;
			finalRight = mWidth;

			rangeOfRight = finalRight - origRight;
			rangeOfLeft = rangeOfRight + mWidth / 3;

			mRFSlider.left -= rangeOfRight;
			origLeft = mRFSlider.left;
		} else {
			origLeft = mRFSlider.left;
			finalLeft = 0;

			rangeOfLeft = finalLeft - origLeft;
			rangeOfRight = rangeOfLeft - mWidth / 3;

			mRFSlider.right += -rangeOfLeft;
			origRight = mRFSlider.right;
		}

		Animation animation = new Animation() {
			@Override
			protected void applyTransformation(float interpolatedTime, Transformation t) {
				super.applyTransformation(interpolatedTime, t);
				mRFSlider.set(origLeft + rangeOfLeft * interpolatedTime, mRFSlider.top, origRight + rangeOfRight * interpolatedTime, mRFSlider.bottom);
				invalidate();
			}
		};

		animation.setDuration(getAnimationDuration() / 2);

		AnimationSet animationSet = new AnimationSet(true);
		animationSet.addAnimation(animation);
		animationSet.setInterpolator(new AccelerateDecelerateInterpolator());

		Animation animationLineTop1;
		Animation animationLineCenter1;
		Animation animationLineBottom1;

		Animation animationLineTop2;
		Animation animationLineCenter2;
		Animation animationLineBottom2;

		if (isSlideLeftToRight()) {
			animationLineTop1 = generateLineBackLTRStep1(mLineTop);
			animationLineCenter1 = generateLineBackLTRStep1(mLineCenter);
			animationLineBottom1 = generateLineBackLTRStep1(mLineBottom);

			animationLineTop2 = generateLineBackLTRStep2(mLineTop);
			animationLineCenter2 = generateLineBackLTRStep2(mLineCenter);
			animationLineBottom2 = generateLineBackLTRStep2(mLineBottom);
		} else {
			animationLineTop1 = generateLineBackRTLStep1(mLineTop);
			animationLineCenter1 = generateLineBackRTLStep1(mLineCenter);
			animationLineBottom1 = generateLineBackRTLStep1(mLineBottom);

			animationLineTop2 = generateLineBackRTLStep2(mLineTop);
			animationLineCenter2 = generateLineBackRTLStep2(mLineCenter);
			animationLineBottom2 = generateLineBackRTLStep2(mLineBottom);
		}

		animationSet.addAnimation(animationLineTop1);
		animationSet.addAnimation(animationLineCenter1);
		animationSet.addAnimation(animationLineBottom1);

		animationSet.addAnimation(animationLineTop2);
		animationSet.addAnimation(animationLineCenter2);
		animationSet.addAnimation(animationLineBottom2);

		animationSet.setAnimationListener(directionChangeListener);

		startAnimation(animationSet);
	}