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.btmura.android.reddit.app.AbstractBrowserActivity.java

private AnimatorSet newCollapseRightAnimator() {
    ObjectAnimator tcTransX = ObjectAnimator.ofFloat(thingContainer, "translationX", leftWidth, 0);

    AnimatorSet as = new AnimatorSet();
    as.setDuration(durationMs).play(tcTransX);
    as.addListener(new AnimatorListenerAdapter() {
        @Override/*from w ww .j a  va2 s . com*/
        public void onAnimationStart(Animator animation) {
            if (leftContainer != null) {
                leftContainer.setVisibility(View.GONE);
            }
            rightContainer.setVisibility(View.VISIBLE);
            thingContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            thingContainer.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            thingContainer.setLayerType(View.LAYER_TYPE_NONE, null);
        }
    });
    return as;
}

From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java

private Animator createAnimator(View view, boolean fadeIn, int slideDirection, long startDelay) {
    boolean isLtr = getView().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
    boolean slideRight = (isLtr && slideDirection == Gravity.END) || (!isLtr && slideDirection == Gravity.START)
            || slideDirection == Gravity.RIGHT;
    Animator fadeAnimator;/* w  w w.  j a v  a2  s . c o  m*/
    Animator slideAnimator;
    if (fadeIn) {
        fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 0.0f, 1.0f);
        slideAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X,
                slideRight ? sSlideDistance : -sSlideDistance, 0);
        fadeAnimator.setInterpolator(HEADER_APPEAR_INTERPOLATOR);
        slideAnimator.setInterpolator(HEADER_APPEAR_INTERPOLATOR);
    } else {
        fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 1.0f, 0.0f);
        slideAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, 0,
                slideRight ? sSlideDistance : -sSlideDistance);
        fadeAnimator.setInterpolator(HEADER_DISAPPEAR_INTERPOLATOR);
        slideAnimator.setInterpolator(HEADER_DISAPPEAR_INTERPOLATOR);
    }
    fadeAnimator.setDuration(HEADER_ANIMATION_DURATION_MS);
    fadeAnimator.setTarget(view);
    slideAnimator.setDuration(HEADER_ANIMATION_DURATION_MS);
    slideAnimator.setTarget(view);
    AnimatorSet animator = new AnimatorSet();
    animator.playTogether(fadeAnimator, slideAnimator);
    if (startDelay > 0) {
        animator.setStartDelay(startDelay);
    }
    return animator;
}

From source file:com.android.calculator2.Calculator.java

private void reveal(View sourceView, int colorRes, AnimatorListener listener) {
    final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay();

    final Rect displayRect = new Rect();
    mDisplayView.getGlobalVisibleRect(displayRect);

    // Make reveal cover the display and status bar.
    final View revealView = new View(this);
    revealView.setBottom(displayRect.bottom);
    revealView.setLeft(displayRect.left);
    revealView.setRight(displayRect.right);
    revealView.setBackgroundColor(getResources().getColor(colorRes));
    groupOverlay.add(revealView);/*from   ww w. j a  va2  s  . c  om*/

    final int[] clearLocation = new int[2];
    sourceView.getLocationInWindow(clearLocation);
    clearLocation[0] += sourceView.getWidth() / 2;
    clearLocation[1] += sourceView.getHeight() / 2;

    final int revealCenterX = clearLocation[0] - revealView.getLeft();
    final int revealCenterY = clearLocation[1] - revealView.getTop();

    final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
    final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
    final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
    final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

    final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
            revealCenterY, 0.0f, revealRadius);
    revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    revealAnimator.addListener(listener);

    final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(revealAnimator).before(alphaAnimator);
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            groupOverlay.remove(revealView);
            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:com.google.samples.apps.sergio.ui.BaseActivity.java

private void setupAccountBoxToggle() {
    int selfItem = getSelfNavDrawerItem();
    if (mDrawerLayout == null || selfItem == NAVDRAWER_ITEM_INVALID) {
        // this Activity does not have a nav drawer
        return;// ww  w .j  a v  a 2s  .  c  o m
    }
    mExpandAccountBoxIndicator.setImageResource(mAccountBoxExpanded ? R.drawable.ic_drawer_accounts_collapse
            : R.drawable.ic_drawer_accounts_expand);
    int hideTranslateY = -mAccountListContainer.getHeight() / 4; // last 25% of animation
    if (mAccountBoxExpanded && mAccountListContainer.getTranslationY() == 0) {
        // initial setup
        mAccountListContainer.setAlpha(0);
        mAccountListContainer.setTranslationY(hideTranslateY);
    }

    AnimatorSet set = new AnimatorSet();
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mDrawerItemsListContainer.setVisibility(mAccountBoxExpanded ? View.INVISIBLE : View.VISIBLE);
            mAccountListContainer.setVisibility(mAccountBoxExpanded ? View.VISIBLE : View.INVISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            onAnimationEnd(animation);
        }
    });

    if (mAccountBoxExpanded) {
        mAccountListContainer.setVisibility(View.VISIBLE);
        AnimatorSet subSet = new AnimatorSet();
        subSet.playTogether(
                ObjectAnimator.ofFloat(mAccountListContainer, View.ALPHA, 1)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION),
                ObjectAnimator.ofFloat(mAccountListContainer, View.TRANSLATION_Y, 0)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.playSequentially(ObjectAnimator.ofFloat(mDrawerItemsListContainer, View.ALPHA, 0)
                .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), subSet);
        set.start();
    } else {
        mDrawerItemsListContainer.setVisibility(View.VISIBLE);
        AnimatorSet subSet = new AnimatorSet();
        subSet.playTogether(
                ObjectAnimator.ofFloat(mAccountListContainer, View.ALPHA, 0)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION),
                ObjectAnimator.ofFloat(mAccountListContainer, View.TRANSLATION_Y, hideTranslateY)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.playSequentially(subSet, ObjectAnimator.ofFloat(mDrawerItemsListContainer, View.ALPHA, 1)
                .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.start();
    }

    set.start();
}

From source file:com.btmura.android.reddit.app.AbstractBrowserActivity.java

private AnimatorSet newExpandRightAnimator() {
    ObjectAnimator tcTransX = ObjectAnimator.ofFloat(thingContainer, "translationX", 0, leftWidth);

    AnimatorSet as = new AnimatorSet();
    as.setDuration(durationMs).play(tcTransX);
    as.addListener(new AnimatorListenerAdapter() {
        @Override/*  w  ww.j a  va2  s. c o m*/
        public void onAnimationStart(Animator animation) {
            if (leftContainer != null) {
                leftContainer.setVisibility(View.GONE);
            }
            rightContainer.setVisibility(View.VISIBLE);
            thingContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            thingContainer.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            thingContainer.setLayerType(View.LAYER_TYPE_NONE, null);
        }
    });
    return as;
}

From source file:com.b44t.ui.ActionBar.BottomSheet.java

private void startOpenAnimation() {
    containerView.setVisibility(View.VISIBLE);

    if (!onCustomOpenAnimation()) {
        if (Build.VERSION.SDK_INT >= 20) {
            container.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }/*  w w  w  .j  a  v a 2  s  .com*/
        containerView.setTranslationY(containerView.getMeasuredHeight());
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationY", 0),
                ObjectAnimator.ofInt(backDrawable, "alpha", 51));
        animatorSet.setDuration(200);
        animatorSet.setStartDelay(20);
        animatorSet.setInterpolator(new DecelerateInterpolator());
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                    if (delegate != null) {
                        delegate.onOpenAnimationEnd();
                    }
                    container.setLayerType(View.LAYER_TYPE_NONE, null);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                }
            }
        });
        animatorSet.start();
        currentSheetAnimation = animatorSet;
    }
}

From source file:kr.wdream.ui.ActionBar.BottomSheet.java

private void startOpenAnimation() {
    if (dismissed) {
        return;/*from   ww  w  .  ja  v  a2s. c  o m*/
    }
    containerView.setVisibility(View.VISIBLE);

    if (!onCustomOpenAnimation()) {
        if (Build.VERSION.SDK_INT >= 20) {
            container.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        containerView.setTranslationY(containerView.getMeasuredHeight());
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationY", 0),
                ObjectAnimator.ofInt(backDrawable, "alpha", 51));
        animatorSet.setDuration(200);
        animatorSet.setStartDelay(20);
        animatorSet.setInterpolator(new DecelerateInterpolator());
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                    if (delegate != null) {
                        delegate.onOpenAnimationEnd();
                    }
                    container.setLayerType(View.LAYER_TYPE_NONE, null);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                }
            }
        });
        animatorSet.start();
        currentSheetAnimation = animatorSet;
    }
}

From source file:com.borax12.materialdaterangepicker.single.time.RadialPickerLayout.java

/**
 * Set either seconds, minutes or hours as showing.
 * @param animate True to animate the transition, false to show with no animation.
 *///from   w  w  w  .j  a  va 2 s  .co m
public void setCurrentItemShowing(int index, boolean animate) {
    if (index != HOUR_INDEX && index != MINUTE_INDEX && index != SECOND_INDEX) {
        Log.e(TAG, "TimePicker does not support view at index " + index);
        return;
    }

    int lastIndex = getCurrentItemShowing();
    mCurrentItemShowing = index;

    if (animate && (index != lastIndex)) {
        ObjectAnimator[] anims = new ObjectAnimator[4];
        if (index == MINUTE_INDEX && lastIndex == HOUR_INDEX) {
            anims[0] = mHourRadialTextsView.getDisappearAnimator();
            anims[1] = mHourRadialSelectorView.getDisappearAnimator();
            anims[2] = mMinuteRadialTextsView.getReappearAnimator();
            anims[3] = mMinuteRadialSelectorView.getReappearAnimator();
        } else if (index == HOUR_INDEX && lastIndex == MINUTE_INDEX) {
            anims[0] = mHourRadialTextsView.getReappearAnimator();
            anims[1] = mHourRadialSelectorView.getReappearAnimator();
            anims[2] = mMinuteRadialTextsView.getDisappearAnimator();
            anims[3] = mMinuteRadialSelectorView.getDisappearAnimator();
        } else if (index == MINUTE_INDEX && lastIndex == SECOND_INDEX) {
            anims[0] = mSecondRadialTextsView.getDisappearAnimator();
            anims[1] = mSecondRadialSelectorView.getDisappearAnimator();
            anims[2] = mMinuteRadialTextsView.getReappearAnimator();
            anims[3] = mMinuteRadialSelectorView.getReappearAnimator();
        } else if (index == HOUR_INDEX && lastIndex == SECOND_INDEX) {
            anims[0] = mSecondRadialTextsView.getDisappearAnimator();
            anims[1] = mSecondRadialSelectorView.getDisappearAnimator();
            anims[2] = mHourRadialTextsView.getReappearAnimator();
            anims[3] = mHourRadialSelectorView.getReappearAnimator();
        } else if (index == SECOND_INDEX && lastIndex == MINUTE_INDEX) {
            anims[0] = mSecondRadialTextsView.getReappearAnimator();
            anims[1] = mSecondRadialSelectorView.getReappearAnimator();
            anims[2] = mMinuteRadialTextsView.getDisappearAnimator();
            anims[3] = mMinuteRadialSelectorView.getDisappearAnimator();
        } else if (index == SECOND_INDEX && lastIndex == HOUR_INDEX) {
            anims[0] = mSecondRadialTextsView.getReappearAnimator();
            anims[1] = mSecondRadialSelectorView.getReappearAnimator();
            anims[2] = mHourRadialTextsView.getDisappearAnimator();
            anims[3] = mHourRadialSelectorView.getDisappearAnimator();
        }

        if (mTransition != null && mTransition.isRunning()) {
            mTransition.end();
        }
        mTransition = new AnimatorSet();
        mTransition.playTogether(anims);
        mTransition.start();
    } else {
        int hourAlpha = (index == HOUR_INDEX) ? 1 : 0;
        int minuteAlpha = (index == MINUTE_INDEX) ? 1 : 0;
        int secondAlpha = (index == SECOND_INDEX) ? 1 : 0;
        mHourRadialTextsView.setAlpha(hourAlpha);
        mHourRadialSelectorView.setAlpha(hourAlpha);
        mMinuteRadialTextsView.setAlpha(minuteAlpha);
        mMinuteRadialSelectorView.setAlpha(minuteAlpha);
        mSecondRadialTextsView.setAlpha(secondAlpha);
        mSecondRadialSelectorView.setAlpha(secondAlpha);
    }

}

From source file:com.google.samples.apps.iosched.ui.BaseActivity.java

private void setupAccountBoxToggle() {
    int selfItem = getSelfNavDrawerItem();
    if (mDrawerLayout == null || selfItem == NAVDRAWER_ITEM_INVALID) {
        // this Activity does not have a nav drawer
        return;//  w  ww. java2  s  . c o m
    }
    mExpandAccountBoxIndicator.setImageResource(mAccountBoxExpanded ? R.drawable.ic_navview_accounts_collapse
            : R.drawable.ic_navview_accounts_expand);
    int hideTranslateY = -mAccountListContainer.getHeight() / 4; // last 25% of animation
    if (mAccountBoxExpanded && mAccountListContainer.getTranslationY() == 0) {
        // initial setup
        mAccountListContainer.setAlpha(0);
        mAccountListContainer.setTranslationY(hideTranslateY);
    }

    AnimatorSet set = new AnimatorSet();
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mDrawerItemsListContainer.setVisibility(mAccountBoxExpanded ? View.INVISIBLE : View.VISIBLE);
            mAccountListContainer.setVisibility(mAccountBoxExpanded ? View.VISIBLE : View.INVISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            onAnimationEnd(animation);
        }
    });

    if (mAccountBoxExpanded) {
        mAccountListContainer.setVisibility(View.VISIBLE);
        AnimatorSet subSet = new AnimatorSet();
        subSet.playTogether(
                ObjectAnimator.ofFloat(mAccountListContainer, View.ALPHA, 1)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION),
                ObjectAnimator.ofFloat(mAccountListContainer, View.TRANSLATION_Y, 0)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.playSequentially(ObjectAnimator.ofFloat(mDrawerItemsListContainer, View.ALPHA, 0)
                .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), subSet);
        set.start();
    } else {
        mDrawerItemsListContainer.setVisibility(View.VISIBLE);
        AnimatorSet subSet = new AnimatorSet();
        subSet.playTogether(
                ObjectAnimator.ofFloat(mAccountListContainer, View.ALPHA, 0)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION),
                ObjectAnimator.ofFloat(mAccountListContainer, View.TRANSLATION_Y, hideTranslateY)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.playSequentially(subSet, ObjectAnimator.ofFloat(mDrawerItemsListContainer, View.ALPHA, 1)
                .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.start();
    }

    set.start();
}

From source file:com.android.tv.settings.dialog.DialogFragment.java

private Animator createTranslateAlphaAnimator(View v, float fromTranslateX, float toTranslateX, float fromAlpha,
        float toAlpha) {
    ObjectAnimator translateAnimator = ObjectAnimator.ofFloat(v, "translationX", fromTranslateX, toTranslateX);
    translateAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    Animator alphaAnimator = createAlphaAnimator(v, fromAlpha, toAlpha);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(translateAnimator).with(alphaAnimator);
    return animatorSet;
}