Search in sources :

Example 36 with Animation

use of android.view.animation.Animation in project material-components-android by material-components.

the class BaseTransientBottomBar method animateViewIn.

void animateViewIn() {
    if (Build.VERSION.SDK_INT >= 12) {
        final int viewHeight = mView.getHeight();
        if (USE_OFFSET_API) {
            ViewCompat.offsetTopAndBottom(mView, viewHeight);
        } else {
            ViewCompat.setTranslationY(mView, viewHeight);
        }
        final ValueAnimatorCompat animator = ViewUtils.createAnimator();
        animator.setIntValues(viewHeight, 0);
        animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new ValueAnimatorCompat.AnimatorListenerAdapter() {

            @Override
            public void onAnimationStart(ValueAnimatorCompat animator) {
                mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION, ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(ValueAnimatorCompat animator) {
                onViewShown();
            }
        });
        animator.addUpdateListener(new ValueAnimatorCompat.AnimatorUpdateListener() {

            private int previousAnimatedIntValue = viewHeight;

            @Override
            public void onAnimationUpdate(ValueAnimatorCompat animator) {
                int currentAnimatedIntValue = animator.getAnimatedIntValue();
                if (USE_OFFSET_API) {
                    // On JB versions of the platform sometimes View.setTranslationY does not
                    // result in layout / draw pass
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - previousAnimatedIntValue);
                } else {
                    ViewCompat.setTranslationY(mView, currentAnimatedIntValue);
                }
                previousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_in);
        anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationEnd(Animation animation) {
                onViewShown();
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}
Also used : Animation(android.view.animation.Animation)

Example 37 with Animation

use of android.view.animation.Animation in project material-components-android by material-components.

the class BaseTransientBottomBar method animateViewOut.

private void animateViewOut(final int event) {
    if (Build.VERSION.SDK_INT >= 12) {
        final ValueAnimatorCompat animator = ViewUtils.createAnimator();
        animator.setIntValues(0, mView.getHeight());
        animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new ValueAnimatorCompat.AnimatorListenerAdapter() {

            @Override
            public void onAnimationStart(ValueAnimatorCompat animator) {
                mContentViewCallback.animateContentOut(0, ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(ValueAnimatorCompat animator) {
                onViewHidden(event);
            }
        });
        animator.addUpdateListener(new ValueAnimatorCompat.AnimatorUpdateListener() {

            private int previousAnimatedIntValue = 0;

            @Override
            public void onAnimationUpdate(ValueAnimatorCompat animator) {
                int currentAnimatedIntValue = animator.getAnimatedIntValue();
                if (USE_OFFSET_API) {
                    // On JB versions of the platform sometimes View.setTranslationY does not
                    // result in layout / draw pass
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - previousAnimatedIntValue);
                } else {
                    ViewCompat.setTranslationY(mView, currentAnimatedIntValue);
                }
                previousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_out);
        anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationEnd(Animation animation) {
                onViewHidden(event);
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}
Also used : Animation(android.view.animation.Animation)

Example 38 with Animation

use of android.view.animation.Animation in project robolectric by robolectric.

the class ShadowViewTest method startAnimation.

@Test
public void startAnimation() {
    TestView view = new TestView(buildActivity(Activity.class).create().get());
    AlphaAnimation animation = new AlphaAnimation(0, 1);
    Animation.AnimationListener listener = mock(Animation.AnimationListener.class);
    animation.setAnimationListener(listener);
    view.startAnimation(animation);
    verify(listener).onAnimationStart(animation);
    verify(listener).onAnimationEnd(animation);
}
Also used : Robolectric.buildActivity(org.robolectric.Robolectric.buildActivity) Activity(android.app.Activity) Animation(android.view.animation.Animation) AlphaAnimation(android.view.animation.AlphaAnimation) AlphaAnimation(android.view.animation.AlphaAnimation) Test(org.junit.Test)

Example 39 with Animation

use of android.view.animation.Animation in project robolectric by robolectric.

the class ShadowViewTest method shouldSetAnimation.

@Test
public void shouldSetAnimation() throws Exception {
    Animation anim = new TestAnimation();
    view.setAnimation(anim);
    assertThat(view.getAnimation()).isSameAs(anim);
}
Also used : Animation(android.view.animation.Animation) AlphaAnimation(android.view.animation.AlphaAnimation) Test(org.junit.Test)

Example 40 with Animation

use of android.view.animation.Animation in project robolectric by robolectric.

the class ShadowViewTest method setAnimation.

@Test
public void setAnimation() {
    TestView view = new TestView(buildActivity(Activity.class).create().get());
    AlphaAnimation animation = new AlphaAnimation(0, 1);
    Animation.AnimationListener listener = mock(Animation.AnimationListener.class);
    animation.setAnimationListener(listener);
    animation.setStartTime(1000);
    view.setAnimation(animation);
    verifyZeroInteractions(listener);
    Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable();
    verify(listener).onAnimationStart(animation);
    verify(listener).onAnimationEnd(animation);
}
Also used : Robolectric.buildActivity(org.robolectric.Robolectric.buildActivity) Activity(android.app.Activity) Animation(android.view.animation.Animation) AlphaAnimation(android.view.animation.AlphaAnimation) AlphaAnimation(android.view.animation.AlphaAnimation) Test(org.junit.Test)

Aggregations

Animation (android.view.animation.Animation)620 AlphaAnimation (android.view.animation.AlphaAnimation)164 TranslateAnimation (android.view.animation.TranslateAnimation)125 ScaleAnimation (android.view.animation.ScaleAnimation)99 AnimationListener (android.view.animation.Animation.AnimationListener)80 AnimationSet (android.view.animation.AnimationSet)71 View (android.view.View)68 Transformation (android.view.animation.Transformation)62 RotateAnimation (android.view.animation.RotateAnimation)43 Point (android.graphics.Point)35 WindowAnimation_activityCloseEnterAnimation (com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation)35 WindowAnimation_activityCloseExitAnimation (com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation)35 WindowAnimation_activityOpenEnterAnimation (com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation)35 WindowAnimation_activityOpenExitAnimation (com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation)35 WindowAnimation_taskCloseEnterAnimation (com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation)35 WindowAnimation_taskCloseExitAnimation (com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation)35 WindowAnimation_taskOpenEnterAnimation (com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation)35 WindowAnimation_taskOpenExitAnimation (com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation)35 WindowAnimation_taskToBackEnterAnimation (com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation)35 WindowAnimation_taskToBackExitAnimation (com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation)35