Java Code Examples for android.animation.AnimatorSet#play()

The following examples show how to use android.animation.AnimatorSet#play() . 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: HazeType.java    From FakeWeather with Apache License 2.0 6 votes vote down vote up
@Override
public void startAnimation(final DynamicWeatherView dynamicWeatherView, int fromColor) {
    super.startAnimation(dynamicWeatherView, fromColor);
    ValueAnimator animator1 = ValueAnimator.ofFloat(0, 1);
    animator1.setInterpolator(new OvershootInterpolator());
    animator1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            speed = (float) animation.getAnimatedValue() * 32;
            rotate = (float) animation.getAnimatedValue();
        }
    });

    AnimatorSet animSet = new AnimatorSet();
    animSet.play(animator1);
    animSet.setDuration(1000);
    animSet.start();

}
 
Example 2
Source File: SandstormType.java    From FakeWeather with Apache License 2.0 6 votes vote down vote up
@Override
public void endAnimation(DynamicWeatherView dynamicWeatherView, Animator.AnimatorListener listener) {
    super.endAnimation(dynamicWeatherView, listener);

    ValueAnimator animator1 = ValueAnimator.ofFloat(1, 0);
    animator1.setInterpolator(new AccelerateInterpolator());
    animator1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            speed = (float) animation.getAnimatedValue() * 32;
            rotate = (float) animation.getAnimatedValue();
        }
    });

    AnimatorSet animSet = new AnimatorSet();
    animSet.play(animator1);
    animSet.setDuration(1000);
    if (listener != null) {
        animSet.addListener(listener);
    }
    animSet.start();
}
 
Example 3
Source File: ShortcutsItemView.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Animator createOpenAnimation(boolean isContainerAboveIcon, boolean pivotLeft) {
    AnimatorSet openAnimation = LauncherAnimUtils.createAnimatorSet();
    openAnimation.play(super.createOpenAnimation(isContainerAboveIcon, pivotLeft));
    for (int i = 0; i < mShortcutsLayout.getChildCount(); i++) {
        if (!(mShortcutsLayout.getChildAt(i) instanceof DeepShortcutView)) {
            continue;
        }
        DeepShortcutView shortcutView = ((DeepShortcutView) mShortcutsLayout.getChildAt(i));
        View deepShortcutIcon = shortcutView.getIconView();
        deepShortcutIcon.setScaleX(0);
        deepShortcutIcon.setScaleY(0);
        openAnimation.play(LauncherAnimUtils.ofPropertyValuesHolder(
                deepShortcutIcon, new PropertyListBuilder().scale(1).build()));
    }
    return openAnimation;
}
 
Example 4
Source File: BrowserActivity.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
private void animateToolbarOpen(int openPercentHeight, int duration) {
    ValueAnimator animator = ValueAnimator.ofInt(0, percentHeightToPx(openPercentHeight)).setDuration(duration);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Integer value = (Integer) animation.getAnimatedValue();
            frameLayout.getLayoutParams().height = value.intValue();
            frameLayout.requestLayout();
        }
    });

    frameLayout.setVisibility(View.VISIBLE);
    ViewCompat.setTranslationZ(frameLayoutContainerRL, 5f);
    AnimatorSet set = new AnimatorSet();
    set.play(animator);
    set.setInterpolator(new AccelerateDecelerateInterpolator());
    set.start();
}
 
Example 5
Source File: MaterialRippleLayout.java    From KickAssSlidingMenu with Apache License 2.0 5 votes vote down vote up
@TargetApi(14)
private void startRipple(final Runnable animationEndRunnable) {
    if (eventCancelled) return;

    float endRadius = getEndRadius();

    cancelAnimations();

    rippleAnimator = new AnimatorSet();
    rippleAnimator.addListener(new AnimatorListenerAdapter() {
        @Override public void onAnimationEnd(Animator animation) {
            if (!ripplePersistent) {
                setRadius(0);
                setRippleAlpha(rippleAlpha);
            }
            if (animationEndRunnable != null && rippleDelayClick) {
                animationEndRunnable.run();
            }
            childView.setPressed(false);
        }
    });

    ObjectAnimator ripple = ObjectAnimator.ofFloat(this, radiusProperty(), radius, endRadius);
    ripple.setDuration(rippleDuration);
    ripple.setInterpolator(new DecelerateInterpolator());
    ObjectAnimator fade = ObjectAnimator.ofInt(this, circleAlphaProperty(), rippleAlpha, 0);
    fade.setDuration(rippleFadeDuration);
    fade.setInterpolator(new AccelerateInterpolator());
    fade.setStartDelay(rippleDuration - rippleFadeDuration - FADE_EXTRA_DELAY);

    if (ripplePersistent) {
        rippleAnimator.play(ripple);
    } else if (getRadius() > endRadius) {
        fade.setStartDelay(0);
        rippleAnimator.play(fade);
    } else {
        rippleAnimator.playTogether(ripple, fade);
    }
    rippleAnimator.start();
}
 
Example 6
Source File: QuranPageReadActivity.java    From QuranAndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Function to show tool bar
 */
public void showToolbar() {
    ObjectAnimator animY = ObjectAnimator.ofFloat(myToolbarContainer, "y", 0);
    AnimatorSet animSetXY = new AnimatorSet();
    animSetXY.setInterpolator(new LinearInterpolator());
    animSetXY.play(animY);
    animSetXY.start();
}
 
Example 7
Source File: QuranPageReadActivity.java    From QuranAndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Function to show tool bar
 */
public void showToolbar() {
    ObjectAnimator animY = ObjectAnimator.ofFloat(myToolbarContainer, "y", 0);
    AnimatorSet animSetXY = new AnimatorSet();
    animSetXY.setInterpolator(new LinearInterpolator());
    animSetXY.play(animY);
    animSetXY.start();
}
 
Example 8
Source File: FlatPlayerFragment.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void animateColorChange(int newColor) {
    super.animateColorChange(newColor);

    AnimatorSet animatorSet = createDefaultColorChangeAnimatorSet(newColor);
    animatorSet.play(ViewUtil.createBackgroundColorTransition(fragment.toolbar, fragment.lastColor, newColor));
    animatorSet.start();
}
 
Example 9
Source File: KlyphAnimationAdapter.java    From Klyph with MIT License 5 votes vote down vote up
private void showView(View view)
{
	ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha", 1);
	AnimatorSet set = new AnimatorSet();
	set.play(animator);
	set.setStartDelay(calculateAnimationDelay());
	set.setDuration(0);
	set.start();
}
 
Example 10
Source File: RippleBackground.java    From Carbon with Apache License 2.0 5 votes vote down vote up
@Override
protected Animator createSoftwareExit() {
    final AnimatorSet set = new AnimatorSet();

    // Linear exit after enter is completed.
    final ObjectAnimator exit = ObjectAnimator.ofFloat(this, RippleBackground.OPACITY, 0);
    exit.setInterpolator(LINEAR_INTERPOLATOR);
    exit.setDuration(OPACITY_EXIT_DURATION);
    AnimatorsCompat.setAutoCancel(exit);
    //exit.setAutoCancel(true);

    final AnimatorSet.Builder builder = set.play(exit);

    // Linear "fast" enter based on current opacity.
    final int fastEnterDuration = (int) ((1 - mOpacity) * OPACITY_ENTER_DURATION_FAST);
    if (fastEnterDuration > 0) {
        final ObjectAnimator enter = ObjectAnimator.ofFloat(this, RippleBackground.OPACITY, 1);
        enter.setInterpolator(LINEAR_INTERPOLATOR);
        enter.setDuration(fastEnterDuration);
        AnimatorsCompat.setAutoCancel(enter);
        //enter.setAutoCancel(true);

        builder.after(enter);
    }

    return set;
}
 
Example 11
Source File: ChangeTranslation.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to handle creating and running the Animator.
 */
private Animator createAnimation(View view, float[] startTranslation, float[] endTranslation,
                                 Animator.AnimatorListener listener, TimeInterpolator interpolator) {
    if (startTranslation == null || endTranslation == null ||
            startTranslation.length != endTranslation.length || equals(startTranslation, endTranslation)) {
        // run listener if we're noop'ing the animation, to get the end-state results now
        if (listener != null) {
            listener.onAnimationEnd(null);
        }
        return null;
    }

    final AnimatorSet anim = new AnimatorSet();
    ObjectAnimator animX = null, animY = null;

    if ((mTranslationDirection & X) != 0) {
        animX = ObjectAnimator.ofFloat(view, View.X,
                startTranslation[0], endTranslation[0]);
    }

    if ((mTranslationDirection & Y) != 0) {
        animY = ObjectAnimator.ofFloat(view, View.Y,
                startTranslation[1], endTranslation[1]);
    }

    if (null != animX && null == animY) anim.play(animX);
    if (null == animX && null != animY) anim.play(animY);
    if (null != animX && null != animY) anim.playTogether(animX, animY);
    if (null == animX && null == animY) return null;

    if (listener != null) {
        anim.addListener(listener);
    }

    anim.setInterpolator(interpolator);
    return anim;
}
 
Example 12
Source File: TouchManager.java    From scissors with Apache License 2.0 5 votes vote down vote up
private void animate(Interpolator interpolator, long duration, ValueAnimator first, ValueAnimator... animators) {
    animator = new AnimatorSet();
    animator.setDuration(duration);
    animator.setInterpolator(interpolator);
    animator.addListener(animatorListener);
    AnimatorSet.Builder builder = animator.play(first);
    for(ValueAnimator valueAnimator : animators) {
        builder.with(valueAnimator);
    }
    animator.start();
}
 
Example 13
Source File: KlyphAnimationAdapter.java    From Klyph with MIT License 5 votes vote down vote up
private void hideView(View view)
{
	ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha", 0);
	AnimatorSet set = new AnimatorSet();
	set.play(animator);
	set.setDuration(0);
	set.start();
}
 
Example 14
Source File: InfoBarContainerLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
Animator createAnimator() {
    // The amount by which mNewFrontWrapper will grow (negative value indicates shrinking).
    int deltaHeight = (mNewFrontWrapper.getHeight() - mBackInfobarHeight)
            - mOldFrontWrapper.getHeight();
    int startTranslationY = Math.max(deltaHeight, 0);
    int endTranslationY = Math.max(-deltaHeight, 0);

    // Slide the front infobar down and away.
    AnimatorSet animator = new AnimatorSet();
    mOldFrontWrapper.setTranslationY(startTranslationY);
    animator.play(createTranslationYAnimator(mOldFrontWrapper,
            startTranslationY + mOldFrontWrapper.getHeight())
            .setDuration(DURATION_SLIDE_UP_MS));

    // Slide the other infobars to their new positions.
    // Note: animator.play() causes these animations to run simultaneously.
    for (int i = 1; i < mInfoBarWrappers.size(); i++) {
        mInfoBarWrappers.get(i).setTranslationY(startTranslationY);
        animator.play(createTranslationYAnimator(mInfoBarWrappers.get(i),
                endTranslationY).setDuration(DURATION_SLIDE_UP_MS));
    }

    mNewFrontContents.setAlpha(0f);
    animator.play(ObjectAnimator.ofFloat(mNewFrontContents, View.ALPHA, 1f)
            .setDuration(DURATION_FADE_MS)).after(DURATION_SLIDE_UP_MS);

    return animator;
}
 
Example 15
Source File: CardPlayerFragment.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
public AnimatorSet createDefaultColorChangeAnimatorSet(int newColor) {
    Animator backgroundAnimator;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        //noinspection ConstantConditions
        int x = (int) (fragment.playbackControlsFragment.playPauseFab.getX() + fragment.playbackControlsFragment.playPauseFab.getWidth() / 2 + fragment.playbackControlsFragment.getView().getX());
        int y = (int) (fragment.playbackControlsFragment.playPauseFab.getY() + fragment.playbackControlsFragment.playPauseFab.getHeight() / 2 + fragment.playbackControlsFragment.getView().getY() + fragment.playbackControlsFragment.progressSlider.getHeight());
        float startRadius = Math.max(fragment.playbackControlsFragment.playPauseFab.getWidth() / 2, fragment.playbackControlsFragment.playPauseFab.getHeight() / 2);
        float endRadius = Math.max(fragment.colorBackground.getWidth(), fragment.colorBackground.getHeight());
        fragment.colorBackground.setBackgroundColor(newColor);
        backgroundAnimator = ViewAnimationUtils.createCircularReveal(fragment.colorBackground, x, y, startRadius, endRadius);
    } else {
        backgroundAnimator = ViewUtil.createBackgroundColorTransition(fragment.colorBackground, fragment.lastColor, newColor);
    }

    AnimatorSet animatorSet = new AnimatorSet();

    animatorSet.play(backgroundAnimator);

    if (!ATHUtil.isWindowBackgroundDark(fragment.getActivity())) {
        int adjustedLastColor = ColorUtil.isColorLight(fragment.lastColor) ? ColorUtil.darkenColor(fragment.lastColor) : fragment.lastColor;
        int adjustedNewColor = ColorUtil.isColorLight(newColor) ? ColorUtil.darkenColor(newColor) : newColor;
        Animator subHeaderAnimator = ViewUtil.createTextColorTransition(fragment.playerQueueSubHeader, adjustedLastColor, adjustedNewColor);
        animatorSet.play(subHeaderAnimator);
    }

    animatorSet.setDuration(ViewUtil.PHONOGRAPH_ANIM_TIME);
    return animatorSet;
}
 
Example 16
Source File: SlideInLeftAnimation.java    From GetApk with MIT License 4 votes vote down vote up
@Override
public AnimatorSet getAnimators(View view) {
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(view, "translationX", -view.getMeasuredWidth(), 0));
    return set;
}
 
Example 17
Source File: InfoBarContainerLayout.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
Animator createAnimator() {
    // After adding the new wrapper, the new front item's view, and the old front item's
    // view are both in their wrappers, and the height of the stack as determined by
    // FrameLayout will take both into account. This means the height of the container will
    // be larger than it needs to be, if the previous old front item is larger than the sum
    // of the new front item and mBackInfobarHeight.
    //
    // First work out how much the container will grow or shrink by.
    int heightDelta =
            mFrontWrapper.getHeight() + mBackInfobarHeight - mOldFrontWrapper.getHeight();

    // Now work out where to animate the new front item to / from.
    int newFrontStart = mFrontWrapper.getHeight();
    int newFrontEnd = 0;
    if (heightDelta < 0) {
        // If the container is shrinking, this won't be reflected in the layout just yet.
        // The layout will have extra space in it for the previous front infobar, which the
        // animation of the new front infobar has to take into account.
        newFrontStart -= heightDelta;
        newFrontEnd -= heightDelta;
    }
    mFrontWrapper.setTranslationY(newFrontStart);
    mFrontContents.setAlpha(0f);

    AnimatorSet animator = new AnimatorSet();
    animator.play(createTranslationYAnimator(mFrontWrapper,
            newFrontEnd).setDuration(DURATION_SLIDE_UP_MS));

    // If the container is shrinking, the back infobars need to animate down (from 0 to the
    // positive delta). Otherwise they have to animate up (from the negative delta to 0).
    int backStart = Math.max(0, heightDelta);
    int backEnd = Math.max(-heightDelta, 0);
    for (int i = 1; i < mInfoBarWrappers.size(); i++) {
        mInfoBarWrappers.get(i).setTranslationY(backStart);
        animator.play(createTranslationYAnimator(mInfoBarWrappers.get(i),
                backEnd).setDuration(DURATION_SLIDE_UP_MS));
    }

    animator.play(ObjectAnimator.ofFloat(mFrontContents, View.ALPHA, 1f)
                            .setDuration(DURATION_FADE_MS))
            .after(DURATION_SLIDE_UP_MS);

    return animator;
}
 
Example 18
Source File: SlideOutUnderneathAnimation.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public void animate() {
	final ViewGroup parentView = (ViewGroup) view.getParent();
	final FrameLayout slideOutFrame = new FrameLayout(view.getContext());
	final int positionView = parentView.indexOfChild(view);
	slideOutFrame.setLayoutParams(view.getLayoutParams());
	slideOutFrame.setClipChildren(true);
	parentView.removeView(view);
	slideOutFrame.addView(view);
	parentView.addView(slideOutFrame, positionView);

	switch (direction) {
	case DIRECTION_LEFT:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_X,
				view.getTranslationX() - view.getWidth());
		break;
	case DIRECTION_RIGHT:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_X,
				view.getTranslationX() + view.getWidth());
		break;
	case DIRECTION_UP:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y,
				view.getTranslationY() - view.getHeight());
		break;
	case DIRECTION_DOWN:
		slideAnim = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y,
				view.getTranslationY() + view.getHeight());
		break;
	default:
		break;
	}

	AnimatorSet slideSet = new AnimatorSet();
	slideSet.play(slideAnim);
	slideSet.setInterpolator(interpolator);
	slideSet.setDuration(duration);
	slideSet.addListener(new AnimatorListenerAdapter() {

		@Override
		public void onAnimationEnd(Animator animation) {
			view.setVisibility(View.INVISIBLE);
			slideAnim.reverse();
			slideOutFrame.removeAllViews();
			parentView.removeView(slideOutFrame);
			parentView.addView(view, positionView);
			if (getListener() != null) {
				getListener().onAnimationEnd(
						SlideOutUnderneathAnimation.this);
			}
		}
	});
	slideSet.start();
}
 
Example 19
Source File: InfoBarContainerLayout.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
Animator createAnimator() {
    // After adding the new wrapper, the new front item's view, and the old front item's
    // view are both in their wrappers, and the height of the stack as determined by
    // FrameLayout will take both into account. This means the height of the container will
    // be larger than it needs to be, if the previous old front item is larger than the sum
    // of the new front item and mBackInfobarHeight.
    //
    // First work out how much the container will grow or shrink by.
    int heightDelta =
            mFrontWrapper.getHeight() + mBackInfobarHeight - mOldFrontWrapper.getHeight();

    // Now work out where to animate the new front item to / from.
    int newFrontStart = mFrontWrapper.getHeight();
    int newFrontEnd = 0;
    if (heightDelta < 0) {
        // If the container is shrinking, this won't be reflected in the layout just yet.
        // The layout will have extra space in it for the previous front infobar, which the
        // animation of the new front infobar has to take into account.
        newFrontStart -= heightDelta;
        newFrontEnd -= heightDelta;
    }
    mFrontWrapper.setTranslationY(newFrontStart);
    mFrontContents.setAlpha(0f);

    AnimatorSet animator = new AnimatorSet();
    animator.play(createTranslationYAnimator(mFrontWrapper,
            newFrontEnd).setDuration(DURATION_SLIDE_UP_MS));

    // If the container is shrinking, the back infobars need to animate down (from 0 to the
    // positive delta). Otherwise they have to animate up (from the negative delta to 0).
    int backStart = Math.max(0, heightDelta);
    int backEnd = Math.max(-heightDelta, 0);
    for (int i = 1; i < mInfoBarWrappers.size(); i++) {
        mInfoBarWrappers.get(i).setTranslationY(backStart);
        animator.play(createTranslationYAnimator(mInfoBarWrappers.get(i),
                backEnd).setDuration(DURATION_SLIDE_UP_MS));
    }

    animator.play(ObjectAnimator.ofFloat(mFrontContents, View.ALPHA, 1f)
                            .setDuration(DURATION_FADE_MS))
            .after(DURATION_SLIDE_UP_MS);

    return animator;
}
 
Example 20
Source File: SlideDownTransition.java    From scoop with Apache License 2.0 3 votes vote down vote up
private Animator createAnimator(View from) {
    int fromTranslation = from.getHeight();

    AnimatorSet set = new AnimatorSet();

    set.play(ObjectAnimator.ofFloat(from, View.TRANSLATION_Y, fromTranslation));

    return set;
}