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.b44t.ui.ActionBar.BottomSheet.java

@Override
public void dismiss() {
    if (dismissed) {
        return;/*from w  ww  .  java2  s.c  om*/
    }
    dismissed = true;
    cancelSheetAnimation();
    if (!allowCustomAnimation || !onCustomCloseAnimation()) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(
                ObjectAnimator.ofFloat(containerView, "translationY",
                        containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
                ObjectAnimator.ofInt(backDrawable, "alpha", 0));
        if (useFastDismiss) {
            int height = containerView.getMeasuredHeight();
            animatorSet.setDuration(
                    Math.max(60, (int) (180 * (height - containerView.getTranslationY()) / (float) height)));
            useFastDismiss = false;
        } else {
            animatorSet.setDuration(180);
        }
        animatorSet.setInterpolator(new AccelerateInterpolator());
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                dismissInternal();
                            } catch (Exception e) {
                                FileLog.e("messenger", e);
                            }
                        }
                    });
                }
            }

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

From source file:org.michaelbel.bottomsheet.BottomSheet.java

private void dismissWithButtonClick(final int viewId) {
    if (dismissed) {
        return;/*from ww  w  .  j av  a  2  s.com*/
    }

    dismissed = true;
    cancelSheetAnimation();
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(containerView, "translationY",
                    containerView.getMeasuredHeight() + Utils.dp(getContext(), 10)),
            ObjectAnimator.ofInt(backDrawable, "alpha", 0));
    animatorSet.setDuration(180);
    animatorSet.setInterpolator(new AccelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
                if (onClickListener != null) {
                    onClickListener.onClick(BottomSheet.this, viewId);
                }

                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            BottomSheet.super.dismiss();
                        } catch (Exception e) {
                            Log.e(TAG, e.getMessage());
                        }
                    }
                });
            }
        }

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

    animatorSet.start();
    currentSheetAnimation = animatorSet;

    if (bottomSheetCallBack != null) {
        bottomSheetCallBack.onClose();
    }
}

From source file:org.telegram.ui.Components.StickersAlert.java

private void hidePreview() {
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(stickerPreviewLayout, "alpha", 0.0f));
    animatorSet.setDuration(200);//ww  w. jav a 2s.c  o m
    animatorSet.addListener(new AnimatorListenerAdapterProxy() {
        @Override
        public void onAnimationEnd(Animator animation) {
            stickerPreviewLayout.setVisibility(View.GONE);
        }
    });
    animatorSet.start();
}

From source file:com.android.tv.menu.MenuLayoutManager.java

/**
 * Called when the menu row information is updated. The add/remove animation of the row views
 * will be started./*from   w w w .java2  s .  c om*/
 *
 * <p>Note that the current row should not be removed.
 */
public void onMenuRowUpdated() {
    if (mMenuView.getVisibility() != View.VISIBLE) {
        int count = mMenuRowViews.size();
        for (int i = 0; i < count; ++i) {
            mMenuRowViews.get(i).setVisibility(mMenuRows.get(i).isVisible() ? View.VISIBLE : View.GONE);
        }
        return;
    }

    List<Integer> addedRowViews = new ArrayList<>();
    List<Integer> removedRowViews = new ArrayList<>();
    Map<Integer, Integer> offsetsToMove = new HashMap<>();
    int added = 0;
    for (int i = mSelectedPosition - 1; i >= 0; --i) {
        MenuRow row = mMenuRows.get(i);
        MenuRowView view = mMenuRowViews.get(i);
        if (row.isVisible() && (view.getVisibility() == View.GONE || mRemovingRowViews.contains(i))) {
            // Removing rows are still VISIBLE.
            addedRowViews.add(i);
            ++added;
        } else if (!row.isVisible() && view.getVisibility() == View.VISIBLE) {
            removedRowViews.add(i);
            --added;
        } else if (added != 0) {
            offsetsToMove.put(i, -added);
        }
    }
    added = 0;
    int count = mMenuRowViews.size();
    for (int i = mSelectedPosition + 1; i < count; ++i) {
        MenuRow row = mMenuRows.get(i);
        MenuRowView view = mMenuRowViews.get(i);
        if (row.isVisible() && (view.getVisibility() == View.GONE || mRemovingRowViews.contains(i))) {
            // Removing rows are still VISIBLE.
            addedRowViews.add(i);
            ++added;
        } else if (!row.isVisible() && view.getVisibility() == View.VISIBLE) {
            removedRowViews.add(i);
            --added;
        } else if (added != 0) {
            offsetsToMove.put(i, added);
        }
    }
    if (addedRowViews.size() == 0 && removedRowViews.size() == 0) {
        return;
    }

    if (mAnimatorSet != null) {
        // Do not cancel the animation here. The property values should be set to the end values
        // when the animation finishes.
        mAnimatorSet.end();
    }
    if (mTitleFadeOutAnimator != null) {
        mTitleFadeOutAnimator.end();
    }
    mPropertyValuesAfterAnimation.clear();
    List<Animator> animators = new ArrayList<>();
    List<Rect> layouts = getViewLayouts(mMenuView.getLeft(), mMenuView.getTop(), mMenuView.getRight(),
            mMenuView.getBottom(), addedRowViews, removedRowViews);
    for (int position : addedRowViews) {
        MenuRowView view = mMenuRowViews.get(position);
        view.setVisibility(View.VISIBLE);
        Rect rect = layouts.get(position);
        // TODO: The animation is not visible when it is shown for the first time. Need to find
        // a better way to resolve this issue.
        view.layout(rect.left, rect.top, rect.right, rect.bottom);
        View titleView = view.getTitleView();
        MarginLayoutParams params = (MarginLayoutParams) titleView.getLayoutParams();
        titleView.layout(view.getPaddingLeft() + params.leftMargin, view.getPaddingTop() + params.topMargin,
                rect.right - rect.left - view.getPaddingRight() - params.rightMargin,
                rect.bottom - rect.top - view.getPaddingBottom() - params.bottomMargin);
        animators.add(createAlphaAnimator(view, 0.0f, 1.0f, mFastOutLinearIn));
    }
    for (int position : removedRowViews) {
        MenuRowView view = mMenuRowViews.get(position);
        animators.add(createAlphaAnimator(view, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn));
    }
    for (Entry<Integer, Integer> entry : offsetsToMove.entrySet()) {
        MenuRowView view = mMenuRowViews.get(entry.getKey());
        animators.add(createTranslationYAnimator(view, 0, entry.getValue() * mRowTitleHeight));
    }
    // Run animation.
    final List<ViewPropertyValueHolder> propertyValuesAfterAnimation = new ArrayList<>();
    propertyValuesAfterAnimation.addAll(mPropertyValuesAfterAnimation);
    mRemovingRowViews.clear();
    mRemovingRowViews.addAll(removedRowViews);
    mAnimatorSet = new AnimatorSet();
    mAnimatorSet.playTogether(animators);
    mAnimatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mAnimatorSet = null;
            // The property values which are different from the end values and need to be
            // changed after the animation are set here.
            // e.g. setting translationY to 0, alpha of the contents view to 1.
            for (ViewPropertyValueHolder holder : propertyValuesAfterAnimation) {
                holder.property.set(holder.view, holder.value);
            }
            for (int position : mRemovingRowViews) {
                mMenuRowViews.get(position).setVisibility(View.GONE);
            }
            layout(mMenuView.getLeft(), mMenuView.getTop(), mMenuView.getRight(), mMenuView.getBottom());
        }
    });
    mAnimatorSet.start();
    if (DEBUG)
        dumpChildren("onMenuRowUpdated()");
}

From source file:org.telegram.ui.Components.StickersAlert.java

private void runShadowAnimation(final int num, final boolean show) {
    if (stickerSetCovereds != null) {
        return;//from  w  w w . jav a  2 s . co m
    }
    if (show && shadow[num].getTag() != null || !show && shadow[num].getTag() == null) {
        shadow[num].setTag(show ? null : 1);
        if (show) {
            shadow[num].setVisibility(View.VISIBLE);
        }
        if (shadowAnimation[num] != null) {
            shadowAnimation[num].cancel();
        }
        shadowAnimation[num] = new AnimatorSet();
        shadowAnimation[num].playTogether(ObjectAnimator.ofFloat(shadow[num], "alpha", show ? 1.0f : 0.0f));
        shadowAnimation[num].setDuration(150);
        shadowAnimation[num].addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (shadowAnimation[num] != null && shadowAnimation[num].equals(animation)) {
                    if (!show) {
                        shadow[num].setVisibility(View.INVISIBLE);
                    }
                    shadowAnimation[num] = null;
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                if (shadowAnimation[num] != null && shadowAnimation[num].equals(animation)) {
                    shadowAnimation[num] = null;
                }
            }
        });
        shadowAnimation[num].start();
    }
}

From source file:support.plus.reportit.rv.FragmentActivity.java

private void createCustomAnimation() {
    final FloatingActionMenu menu3 = (FloatingActionMenu) findViewById(R.id.menuShareReport);

    AnimatorSet set = new AnimatorSet();

    ObjectAnimator scaleOutX = ObjectAnimator.ofFloat(menu3.getMenuIconView(), "scaleX", 1.0f, 0.2f);
    ObjectAnimator scaleOutY = ObjectAnimator.ofFloat(menu3.getMenuIconView(), "scaleY", 1.0f, 0.2f);

    ObjectAnimator scaleInX = ObjectAnimator.ofFloat(menu3.getMenuIconView(), "scaleX", 0.2f, 1.0f);
    ObjectAnimator scaleInY = ObjectAnimator.ofFloat(menu3.getMenuIconView(), "scaleY", 0.2f, 1.0f);

    scaleOutX.setDuration(50);//from w  ww .ja va  2s . co  m
    scaleOutY.setDuration(50);

    scaleInX.setDuration(150);
    scaleInY.setDuration(150);

    scaleInX.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            menu3.getMenuIconView().setImageResource(
                    menu3.isOpened() ? R.drawable.ic_unarchive_white_24dp : R.drawable.ic_done_white_24dp);
        }
    });

    set.play(scaleOutX).with(scaleOutY);
    set.play(scaleInX).with(scaleInY).after(scaleOutX);
    set.setInterpolator(new OvershootInterpolator(2));

    menu3.setIconToggleAnimatorSet(set);
}

From source file:com.github.shareme.gwsmaterialdrawer.library.DrawerView.java

private void openProfileList() {
    Log.d(TAG, "openProfileList()");
    if (!profileListOpen) {
        AnimatorSet set = new AnimatorSet();
        set.playTogether(ObjectAnimator.ofFloat(linearListView, "alpha", 1, 0f, 0f, 0f),
                ObjectAnimator.ofFloat(linearListView, "translationY", 0,
                        getResources().getDimensionPixelSize(R.dimen.md_list_item_height) / 4),
                ObjectAnimator.ofFloat(linearListViewProfileList, "alpha", 0, 1),
                ObjectAnimator.ofFloat(linearListViewProfileList, "translationY",
                        -getResources().getDimensionPixelSize(R.dimen.md_list_item_height) / 2, 0),
                ObjectAnimator.ofInt(imageViewOpenProfileListIcon.getDrawable(), PROPERTY_LEVEL, 0, 10000),
                ObjectAnimator.ofInt(scrollView, PROPERTY_SCROLL_POSITION, 0));
        set.setDuration(getResources().getInteger(R.integer.md_profile_list_open_anim_time));
        set.addListener(new Animator.AnimatorListener() {
            @Override/*from  w ww .  jav a 2s.  c o  m*/
            public void onAnimationStart(Animator animation) {
                linearListViewProfileList.setVisibility(VISIBLE);

                imageViewOpenProfileListIcon.setClickable(false);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                imageViewOpenProfileListIcon.setClickable(true);

                profileListOpen = true;

                updateListVisibility();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        set.start();
    } else {
        updateListVisibility();
    }
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void startHoursToMinutesAnimation() {
    if (mHoursToMinutesAnims.size() == 0) {
        mHoursToMinutesAnims.add(/*from   www.j a  v  a  2 s  .  c  o  m*/
                getFadeOutAnimator(mAlpha[HOURS], ALPHA_OPAQUE, ALPHA_TRANSPARENT, mInvalidateUpdateListener));
        mHoursToMinutesAnims.add(
                getFadeInAnimator(mAlpha[MINUTES], ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
    }

    if (mTransition != null && mTransition.isRunning()) {
        mTransition.end();
    }
    mTransition = new AnimatorSet();
    mTransition.playTogether(mHoursToMinutesAnims);
    mTransition.start();
}

From source file:graphic.expand_graphic.ExpandingListView.java

/**
 * This method collapses the view that was clicked and animates all the
 * views around it to close around the collapsing view. There are several
 * steps required to do this which are outlined below.
 * <p/>/*from w  w  w.  ja v a 2s .  c o m*/
 * 1. Update the layout parameters of the view clicked so as to minimize its
 * height to the original collapsed (default) state. 2. After invoking a
 * layout, the listview will shift all the cells so as to display them most
 * efficiently. Therefore, during the first predraw pass, the listview must
 * be offset by some amount such that given the custom bound change upon
 * collapse, all the cells that need to be on the screen after the layout
 * are rendered by the listview. 3. On the second predraw pass, all the
 * items are first returned to their original location (before the first
 * layout). 4. The collapsing view's bounds are animated to what the final
 * values should be. 5. The bounds above the collapsing view are animated
 * downwards while the bounds below the collapsing view are animated
 * upwards. 6. The extra text is faded out as its contents become visible
 * throughout the animation process.
 */

private void collapseView(final View view) {

    /* Store the original top and bottom bounds of all the cells. */
    final int oldTop = view.getTop();
    final int oldBottom = view.getBottom();

    final HashMap<View, int[]> oldCoordinates = new HashMap<View, int[]>();

    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View v = getChildAt(i);
        ViewCompat.setHasTransientState(v, true);
        oldCoordinates.put(v, new int[] { v.getTop(), v.getBottom() });
    }

    /* Update the layout so the extra content becomes invisible. */
    view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, viewObject.mCollapsedHeight));

    /* Add an onPreDraw listener. */
    final ViewTreeObserver observer = getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {

            if (!mShouldRemoveObserver) {
                /*
                 * Same as for expandingView, the parameters for
                 * setSelectionFromTop must be determined such that the
                 * necessary cells of the ListView are rendered and added to
                 * it.
                 */
                mShouldRemoveObserver = true;

                int newTop = view.getTop();
                int newBottom = view.getBottom();

                int newHeight = newBottom - newTop;
                int oldHeight = oldBottom - oldTop;
                int deltaHeight = oldHeight - newHeight;

                mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, deltaHeight, false);

                int currentTop = view.getTop();
                int futureTop = oldTop + mTranslate[0];

                int firstChildStartTop = getChildAt(0).getTop();
                int firstVisiblePosition = getFirstVisiblePosition();
                int deltaTop = currentTop - futureTop;

                int i;
                int childCount = getChildCount();
                for (i = 0; i < childCount; i++) {
                    View v = getChildAt(i);
                    int height = v.getBottom() - Math.max(0, v.getTop());
                    if (deltaTop - height > 0) {
                        firstVisiblePosition++;
                        deltaTop -= height;
                    } else {
                        break;
                    }
                }

                if (i > 0) {
                    firstChildStartTop = 0;
                }

                setSelectionFromTop(firstVisiblePosition, firstChildStartTop - deltaTop);

                requestLayout();

                return false;
            }

            mShouldRemoveObserver = false;
            observer.removeOnPreDrawListener(this);

            int yTranslateTop = mTranslate[0];
            int yTranslateBottom = mTranslate[1];

            int index = indexOfChild(view);
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View v = getChildAt(i);
                int[] old = oldCoordinates.get(v);
                if (old != null) {
                    /*
                     * If the cell was present in the ListView before the
                     * collapse and after the collapse then the bounds are
                     * reset to their old values.
                     */
                    v.setTop(old[0]);
                    v.setBottom(old[1]);
                    ViewCompat.setHasTransientState(v, false);
                } else {
                    /*
                     * If the cell is present in the ListView after the
                     * collapse but not before the collapse then the bounds
                     * are calculated using the bottom and top translation
                     * of the collapsing cell.
                     */
                    int delta = i > index ? yTranslateBottom : -yTranslateTop;
                    v.setTop(v.getTop() + delta);
                    v.setBottom(v.getBottom() + delta);
                }
            }

            final View expandingLayout = view.findViewById(R.id.expanding_layout);

            /*
             * Animates all the cells present on the screen after the
             * collapse.
             */
            ArrayList<Animator> animations = new ArrayList<Animator>();
            for (int i = 0; i < childCount; i++) {
                View v = getChildAt(i);
                if (v != view) {
                    float diff = i > index ? -yTranslateBottom : yTranslateTop;
                    animations.add(getAnimation(v, diff, diff));
                }
            }

            /* Adds animation for collapsing the cell that was clicked. */
            animations.add(getAnimation(view, yTranslateTop, -yTranslateBottom));

            /* Adds an animation for fading out the extra content. */
            animations.add(ObjectAnimator.ofFloat(expandingLayout, View.ALPHA, 1, 0));

            /* Disabled the ListView for the duration of the animation. */
            setEnabled(false);
            setClickable(false);

            /*
             * Play all the animations created above together at the same
             * time.
             */
            AnimatorSet s = new AnimatorSet();
            s.playTogether(animations);
            s.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    expandingLayout.setVisibility(View.GONE);
                    view.setLayoutParams(
                            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
                    viewObject.setExpanded(false);
                    setEnabled(true);
                    setClickable(true);
                    /*
                     * Note that alpha must be set back to 1 in case this
                     * view is reused by a cell that was expanded, but not
                     * yet collapsed, so its state should persist in an
                     * expanded state with the extra content visible.
                     */
                    expandingLayout.setAlpha(1);
                }
            });
            s.start();

            return true;
        }
    });
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void startMinutesToHoursAnimation() {
    if (mMinuteToHoursAnims.size() == 0) {
        mMinuteToHoursAnims.add(getFadeOutAnimator(mAlpha[MINUTES], ALPHA_OPAQUE, ALPHA_TRANSPARENT,
                mInvalidateUpdateListener));
        mMinuteToHoursAnims.add(//w w w.  j  a v  a  2 s .  c o  m
                getFadeInAnimator(mAlpha[HOURS], ALPHA_TRANSPARENT, ALPHA_OPAQUE, mInvalidateUpdateListener));
    }

    if (mTransition != null && mTransition.isRunning()) {
        mTransition.end();
    }
    mTransition = new AnimatorSet();
    mTransition.playTogether(mMinuteToHoursAnims);
    mTransition.start();
}