Example usage for android.animation AnimatorSet AnimatorSet

List of usage examples for android.animation AnimatorSet AnimatorSet

Introduction

In this page you can find the example usage for android.animation AnimatorSet AnimatorSet.

Prototype

public AnimatorSet() 

Source Link

Usage

From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButtonLollipop.java

@Override
void onElevationsChanged(final float elevation, final float pressedTranslationZ) {
    if (Build.VERSION.SDK_INT == 21) {
        // Animations produce NPE in version 21. Bluntly set the values instead (matching the
        // logic in the animations below).
        if (mView.isEnabled()) {
            mView.setElevation(elevation);
            if (mView.isFocused() || mView.isPressed()) {
                mView.setTranslationZ(pressedTranslationZ);
            } else {
                mView.setTranslationZ(0);
            }/*  w ww.  j  a v  a2 s .c o m*/
        } else {
            mView.setElevation(0);
            mView.setTranslationZ(0);
        }
    } else {
        final StateListAnimator stateListAnimator = new StateListAnimator();

        // Animate elevation and translationZ to our values when pressed
        AnimatorSet set = new AnimatorSet();
        set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator
                .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, set);

        // Same deal for when we're focused
        set = new AnimatorSet();
        set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator
                .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, set);

        // Animate translationZ to 0 if not pressed
        set = new AnimatorSet();
        List<Animator> animators = new ArrayList<>();
        animators.add(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0));
        if (Build.VERSION.SDK_INT >= 22 && Build.VERSION.SDK_INT <= 24) {
            // This is a no-op animation which exists here only for introducing the duration
            // because setting the delay (on the next animation) via "setDelay" or "after"
            // can trigger a NPE between android versions 22 and 24 (due to a framework
            // bug). The issue has been fixed in version 25.
            animators.add(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, mView.getTranslationZ())
                    .setDuration(PRESSED_ANIM_DELAY));
        }
        animators.add(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION));
        set.playSequentially(animators.toArray(new ObjectAnimator[0]));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(ENABLED_STATE_SET, set);

        // Animate everything to 0 when disabled
        set = new AnimatorSet();
        set.play(ObjectAnimator.ofFloat(mView, "elevation", 0f).setDuration(0))
                .with(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(0));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(EMPTY_STATE_SET, set);

        mView.setStateListAnimator(stateListAnimator);
    }

    if (mShadowViewDelegate.isCompatPaddingEnabled()) {
        updatePadding();
    }
}

From source file:android.support.design.widget.FloatingActionButtonLollipop.java

@Override
void onElevationsChanged(final float elevation, final float pressedTranslationZ) {
    final int sdk = Build.VERSION.SDK_INT;
    if (sdk == 21) {
        // Animations produce NPE in version 21. Bluntly set the values instead (matching the
        // logic in the animations below).
        if (mView.isEnabled()) {
            mView.setElevation(elevation);
            if (mView.isFocused() || mView.isPressed()) {
                mView.setTranslationZ(pressedTranslationZ);
            } else {
                mView.setTranslationZ(0);
            }//from   w  w w .jav  a2  s .co  m
        } else {
            mView.setElevation(0);
            mView.setTranslationZ(0);
        }
    } else {
        final StateListAnimator stateListAnimator = new StateListAnimator();

        // Animate elevation and translationZ to our values when pressed
        AnimatorSet set = new AnimatorSet();
        set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator
                .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, set);

        // Same deal for when we're focused
        set = new AnimatorSet();
        set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator
                .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, set);

        // Animate translationZ to 0 if not pressed
        set = new AnimatorSet();
        set.playSequentially(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0),
                // This is a no-op animation which exists here only for introducing the duration
                // because setting the delay (on the next animation) via "setDelay" or "after"
                // can trigger a NPE between android versions 22 and 24 (due to a framework
                // bug). The issue has been fixed in version 25.
                ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, mView.getTranslationZ())
                        .setDuration(PRESSED_ANIM_DELAY),
                ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(ENABLED_STATE_SET, set);

        // Animate everything to 0 when disabled
        set = new AnimatorSet();
        set.play(ObjectAnimator.ofFloat(mView, "elevation", 0f).setDuration(0))
                .with(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(0));
        set.setInterpolator(ANIM_INTERPOLATOR);
        stateListAnimator.addState(EMPTY_STATE_SET, set);

        mView.setStateListAnimator(stateListAnimator);
    }

    if (mShadowViewDelegate.isCompatPaddingEnabled()) {
        updatePadding();
    }
}

From source file:com.hitherejoe.animate.util.MorphButtonToDialog.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues,
        final TransitionValues endValues) {
    Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues);
    if (startValues == null || endValues == null || changeBounds == null)
        return null;

    Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR);
    Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR);

    if (startColor == null || endColor == null)
        return null;

    MorphDrawable background = new MorphDrawable(startColor, 0);
    endValues.view.setBackground(background);

    Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor);

    // ease in the dialog's child views (slide up & fade_fast in)
    if (endValues.view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) endValues.view;
        float offset = vg.getHeight() / 3;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            v.setTranslationY(offset);/*from w  w w  . j  a  v a2s . c  om*/
            v.setAlpha(0f);
            v.animate().alpha(1f).translationY(0f).setDuration(150).setStartDelay(150).setInterpolator(
                    AnimationUtils.loadInterpolator(vg.getContext(), android.R.interpolator.fast_out_slow_in));
            offset *= 1.8f;
        }
    }

    AnimatorSet transition = new AnimatorSet();
    transition.playTogether(changeBounds, color);
    transition.setDuration(300);
    transition.setInterpolator(
            AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in));
    return transition;
}

From source file:MainActivity.java

private void zoomFromThumbnail(final ImageView imageViewThumb) {
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();//ww  w . j  a va 2s.c om
    }

    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    imageViewThumb.getGlobalVisibleRect(startBounds);
    findViewById(R.id.frameLayout).getGlobalVisibleRect(finalBounds, globalOffset);
    mImageViewExpanded
            .setImageBitmap(loadSampledResource(R.drawable.image, finalBounds.height(), finalBounds.width()));

    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()) {
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    imageViewThumb.setVisibility(View.GONE);
    mImageViewExpanded.setVisibility(View.VISIBLE);
    mImageViewExpanded.setPivotX(0f);
    mImageViewExpanded.setPivotY(0f);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(ObjectAnimator.ofFloat(mImageViewExpanded, View.X, startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.Y, startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.SCALE_Y, startScale, 1f));
    animatorSet.setDuration(1000);
    animatorSet.setInterpolator(new AccelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    animatorSet.start();
    mCurrentAnimator = animatorSet;
}

From source file:com.metinkale.prayerapp.compass._2D.Frag2D.java

public void show() {
    mHidden = false;//from  w w w.ja va 2s .com
    mCompassView.post(new Runnable() {
        @Override
        public void run() {
            ObjectAnimator scaleX = ObjectAnimator.ofFloat(mCompassView, "scaleX", 0, 1);
            ObjectAnimator scaleY = ObjectAnimator.ofFloat(mCompassView, "scaleY", 0, 1);

            ObjectAnimator scaleX2 = ObjectAnimator.ofFloat(mInfo, "scaleX", 0, 1);
            ObjectAnimator scaleY2 = ObjectAnimator.ofFloat(mInfo, "scaleY", 0, 1);
            AnimatorSet animSetXY = new AnimatorSet();
            animSetXY.playTogether(scaleX, scaleY, scaleX2, scaleY2);
            animSetXY.setInterpolator(overshootInterpolator);
            animSetXY.setDuration(300);
            animSetXY.start();
        }
    });

}

From source file:com.gudong.appkit.ui.helper.AppItemAnimator.java

private void animateAddImpl(final RecyclerView.ViewHolder viewHolder) {
    final View target = viewHolder.itemView;
    mAddAnimations.add(viewHolder);/*from  w w w.  ja  v a 2  s.com*/
    final AnimatorSet animator = new AnimatorSet();
    animator.playTogether(ObjectAnimator.ofFloat(target, "translationX", -target.getMeasuredWidth(), 0, 0f),
            ObjectAnimator.ofFloat(target, "alpha", 0.5f, 1.0f));
    animator.setTarget(target);
    animator.setDuration(KEY_DURATION_TIME);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            dispatchAddStarting(viewHolder);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            ViewCompat.setAlpha(target, 1);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            animator.removeAllListeners();
            dispatchAddFinished(viewHolder);
            mAddAnimations.remove(viewHolder);
            dispatchFinishedWhenDone();
        }
    });
    animator.start();
}

From source file:com.sysdata.widget.accordion.CollapsedViewHolder.java

private Animator createExpandingAnimator(ArrowItemViewHolder newHolder, long duration) {
    if (arrow != null) {
        arrow.setVisibility(View.INVISIBLE);
    }//from  ww  w .j a  v a  2  s.co  m

    final View oldView = itemView;
    final View newView = newHolder.itemView;
    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(oldView, oldView, newView)
            .setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(boundsAnimator);
    return animatorSet;
}

From source file:co.lemonlabs.mortar.example.core.util.ScreenConductor.java

public void showScreen(S newScreen, S oldScreen, final Flow.Direction direction) {

    // Cancel previous transition and set end values
    if (screenTransition != null) {
        screenTransition.end();//www. j  a  v a  2 s  .  co  m
    }

    final View oldChild = getContentView();

    if (destroyOldScope(newScreen, oldChild)) {
        storeViewState(oldChild, oldScreen);
        final View newChild = createNewChildView(newScreen, contentViewId);

        Transitions.Animators transitions = null;
        if (oldChild != null) {
            switch (direction) {
            case FORWARD:
                // Load animations from Transition annotations, store them into backstack and set them to views
                storeTransitions(oldScreen, newScreen);
                transitions = Transitions.forward(context, newScreen);
                break;
            case BACKWARD:
                if (newScreen instanceof TransitionScreen) {
                    // Try to load animations from a screen and set them
                    int[] transitionIds = ((TransitionScreen) newScreen).getTransitions();
                    transitions = Transitions.backward(context, transitionIds);
                }
                break;
            case REPLACE:
                // no animations
                break;
            }
        }

        if (oldChild != null) {
            // Settings animator for each view and removing the old view
            // after animation ends
            if (transitions != null) {
                transitions.out.setTarget(oldChild);
                transitions.in.setTarget(newChild);
                screenTransition = new AnimatorSet();
                screenTransition.playTogether(transitions.out, transitions.in);
                screenTransition.addListener(new SimpleAnimatorListener() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        container.removeView(oldChild);
                    }
                });
            } else {
                // remove view immediately if no transitions to run
                container.removeView(oldChild);
            }
        }

        container.addView(newChild, 0);

        if (screenTransition != null) {
            screenTransition.start();
        }

        // Makes the new view z-index higher than the old view
        // for transitions forward to make feel more natural
        if (direction == Flow.Direction.FORWARD) {
            container.post(new Runnable() {
                @Override
                public void run() {
                    container.bringChildToFront(newChild);
                    container.requestLayout();
                    container.invalidate();
                }
            });
        }
    }

}

From source file:com.example.android.tryanimationt.TryAnimationFragment.java

void animButtons(ImageButton bt, boolean in, int animTime, int delay) {

    //delay = 0;/* ww  w  .ja v a2s .c o m*/

    float rotateStart, rotateEnd;
    float scaleXStart, scaleXEnd;
    float scaleYStart, scaleYEnd;
    float transitionXStart, transitionXEnd;
    float transitionYStart, transitionYEnd;

    if (in) {
        rotateStart = 0;
        rotateEnd = 359;
        scaleXStart = 0.66f;
        scaleXEnd = 1;
        scaleYStart = 0.66f;
        scaleYEnd = 1;
        transitionXStart = 60;
        transitionXEnd = 0;
        transitionYStart = 10;
        transitionYEnd = 0;

    } else {
        rotateStart = 359;
        rotateEnd = 0;
        scaleXStart = 1;
        scaleXEnd = 0.66f;
        scaleYStart = 1;
        scaleYEnd = 0.66f;
        transitionXStart = 0;
        transitionXEnd = 60;
        transitionYStart = 0;
        transitionYEnd = 10;
    }
    bt.setTranslationX(transitionXStart);
    bt.setTranslationY(transitionYStart);

    AnimatorSet animSet = new AnimatorSet();
    ObjectAnimator animRotate = ObjectAnimator.ofFloat(bt, "rotation", rotateStart, rotateEnd);
    animRotate.setDuration(animTime);

    ObjectAnimator animScaleX = ObjectAnimator.ofFloat(bt, "scaleX", scaleXStart, scaleXEnd);
    animScaleX.setDuration(animTime);
    animScaleX.setStartDelay(Math.round(delay * 0.66));
    ObjectAnimator animScaleY = ObjectAnimator.ofFloat(bt, "scaleY", scaleYStart, scaleYEnd);
    animScaleY.setDuration(animTime);
    animScaleY.setStartDelay(Math.round(delay * 0.66));

    ObjectAnimator animTrx = ObjectAnimator.ofFloat(bt, "translationX", transitionXStart, transitionXEnd);
    animTrx.setDuration(animTime);
    animTrx.setStartDelay(delay);
    ObjectAnimator animTry = ObjectAnimator.ofFloat(bt, "translationY", transitionYStart, transitionYEnd);
    animTry.setDuration(animTime);
    animTry.setStartDelay(delay);

    animSet.setInterpolator(new BounceInterpolator());
    animSet.playTogether(animRotate, animScaleX, animScaleY, animTrx, animTry);

    animSet.start();
}

From source file:cn.edu.zucc.list.FabAnimation.MorphDialogToFab.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues,
        TransitionValues endValues) {/*ww w. ja va 2 s  .c om*/
    Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues);
    if (startValues == null || endValues == null || changeBounds == null) {
        return null;
    }

    Integer startColor = (Integer) startValues.values.get(PROPERTY_COLOR);
    Integer startCornerRadius = (Integer) startValues.values.get(PROPERTY_CORNER_RADIUS);
    Integer endColor = (Integer) endValues.values.get(PROPERTY_COLOR);
    Integer endCornerRadius = (Integer) endValues.values.get(PROPERTY_CORNER_RADIUS);

    if (startColor == null || startCornerRadius == null || endColor == null || endCornerRadius == null) {
        return null;
    }

    MorphDrawable background = new MorphDrawable(startColor, startCornerRadius);
    endValues.view.setBackground(background);

    Animator color = ObjectAnimator.ofArgb(background, background.COLOR, endColor);
    Animator corners = ObjectAnimator.ofFloat(background, background.CORNER_RADIUS, endCornerRadius);

    // hide child views (offset down & fade out)
    if (endValues.view instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) endValues.view;
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            v.animate().alpha(0f).translationY(v.getHeight() / 3).setStartDelay(0L).setDuration(50L)
                    .setInterpolator(AnimationUtils.loadInterpolator(vg.getContext(),
                            android.R.interpolator.fast_out_linear_in))
                    .start();
        }
    }

    AnimatorSet transition = new AnimatorSet();
    transition.playTogether(changeBounds, corners, color);
    transition.setInterpolator(
            AnimationUtils.loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in));
    transition.setDuration(300);
    return transition;
}