Search in sources :

Example 81 with Animator

use of android.animation.Animator in project weiciyuan by qii.

the class GalleryActivity method animateClose.

private void animateClose(PhotoView imageView) {
    currentViewPositionLayout.setVisibility(View.INVISIBLE);
    animationView.setImageDrawable(imageView.getDrawable());
    pager.setVisibility(View.INVISIBLE);
    final Rect startBounds = rect;
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();
    animationView.getGlobalVisibleRect(finalBounds, globalOffset);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);
    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) {
        // Extend start bounds horizontally
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        // Extend start bounds vertically
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }
    animationView.setPivotX(0f);
    animationView.setPivotY(0f);
    final float startScaleFinal = startScale;
    animationView.animate().setInterpolator(new DecelerateInterpolator()).x(startBounds.left).y(startBounds.top).scaleY(startScaleFinal).scaleX(startScaleFinal).setDuration(300).setListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            GalleryActivity.this.finish();
            overridePendingTransition(0, 0);
        }
    }).start();
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Rect(android.graphics.Rect) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Point(android.graphics.Point)

Example 82 with Animator

use of android.animation.Animator in project weiciyuan by qii.

the class GalleryAnimationActivity method onBackPressed.

@Override
public void onBackPressed() {
    ContainerFragment fragment = fragmentMap.get(pager.getCurrentItem());
    if (fragment != null && fragment.canAnimateCloseActivity()) {
        backgroundColor = new ColorDrawable(Color.BLACK);
        ObjectAnimator bgAnim = ObjectAnimator.ofInt(backgroundColor, "alpha", 0);
        bgAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                background.setBackground(backgroundColor);
            }
        });
        bgAnim.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                GalleryAnimationActivity.super.finish();
                overridePendingTransition(-1, -1);
            }
        });
        fragment.animationExit(bgAnim);
    } else {
        super.onBackPressed();
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 83 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class LockPatternView method startLineEndAnimation.

private void startLineEndAnimation(final CellState state, final float startX, final float startY, final float targetX, final float targetY) {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float t = (float) animation.getAnimatedValue();
            state.lineEndX = (1 - t) * startX + t * targetX;
            state.lineEndY = (1 - t) * startY + t * targetY;
            invalidate();
        }
    });
    valueAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            state.lineAnimator = null;
        }
    });
    valueAnimator.setInterpolator(mFastOutSlowInInterpolator);
    valueAnimator.setDuration(100);
    valueAnimator.start();
    state.lineAnimator = valueAnimator;
}
Also used : Animator(android.animation.Animator) RenderNodeAnimator(android.view.RenderNodeAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 84 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class TaskStackAnimationHelper method startDeleteTaskAnimation.

/**
     * Starts the delete animation for the specified {@link TaskView}.
     */
public void startDeleteTaskAnimation(final TaskView deleteTaskView, final ReferenceCountedTrigger postAnimationTrigger) {
    TaskStackViewTouchHandler touchHandler = mStackView.getTouchHandler();
    touchHandler.onBeginManualDrag(deleteTaskView);
    postAnimationTrigger.increment();
    postAnimationTrigger.addLastDecrementRunnable(() -> {
        touchHandler.onChildDismissed(deleteTaskView);
    });
    final float dismissSize = touchHandler.getScaledDismissSize();
    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
    animator.setDuration(400);
    animator.addUpdateListener((animation) -> {
        float progress = (Float) animation.getAnimatedValue();
        deleteTaskView.setTranslationX(progress * dismissSize);
        touchHandler.updateSwipeProgress(deleteTaskView, true, progress);
    });
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            postAnimationTrigger.decrement();
        }
    });
    animator.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 85 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class ScrimController method startScrimAnimation.

private void startScrimAnimation(final View scrim, float target) {
    float current = getCurrentScrimAlpha(scrim);
    ValueAnimator anim = ValueAnimator.ofFloat(current, target);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float alpha = (float) animation.getAnimatedValue();
            setCurrentScrimAlpha(scrim, alpha);
            updateScrimColor(scrim);
        }
    });
    anim.setInterpolator(getInterpolator());
    anim.setStartDelay(mAnimationDelay);
    anim.setDuration(mDurationOverride != -1 ? mDurationOverride : ANIMATION_DURATION);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mOnAnimationFinished != null) {
                mOnAnimationFinished.run();
                mOnAnimationFinished = null;
            }
            if (mKeyguardFadingOutInProgress) {
                mKeyguardFadeoutAnimation = null;
                mKeyguardFadingOutInProgress = false;
            }
            scrim.setTag(TAG_KEY_ANIM, null);
            scrim.setTag(TAG_KEY_ANIM_TARGET, null);
        }
    });
    anim.start();
    if (mAnimateKeyguardFadingOut) {
        mKeyguardFadingOutInProgress = true;
        mKeyguardFadeoutAnimation = anim;
    }
    if (mSkipFirstFrame) {
        anim.setCurrentPlayTime(16);
    }
    scrim.setTag(TAG_KEY_ANIM, anim);
    scrim.setTag(TAG_KEY_ANIM_TARGET, target);
}
Also used : Animator(android.animation.Animator) StackStateAnimator(com.android.systemui.statusbar.stack.StackStateAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Aggregations

Animator (android.animation.Animator)1413 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)868 ObjectAnimator (android.animation.ObjectAnimator)724 ValueAnimator (android.animation.ValueAnimator)630 AnimatorSet (android.animation.AnimatorSet)285 View (android.view.View)230 ViewGroup (android.view.ViewGroup)110 ArrayList (java.util.ArrayList)104 PropertyValuesHolder (android.animation.PropertyValuesHolder)96 Paint (android.graphics.Paint)79 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)75 ImageView (android.widget.ImageView)68 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)67 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)65 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)64 TextView (android.widget.TextView)61 RenderNodeAnimator (android.view.RenderNodeAnimator)51 ViewPropertyAnimator (android.view.ViewPropertyAnimator)51 Rect (android.graphics.Rect)50 Interpolator (android.view.animation.Interpolator)49