Example usage for android.animation AnimatorSet playTogether

List of usage examples for android.animation AnimatorSet playTogether

Introduction

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

Prototype

public void playTogether(Collection<Animator> items) 

Source Link

Document

Sets up this AnimatorSet to play all of the supplied animations at the same time.

Usage

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

private void runImeAnimations(boolean entering) {
    ArrayList<Animator> animators = new ArrayList<Animator>();
    if (entering) {
        mGuidanceStylist.onImeAppearing(animators);
        mActionsStylist.onImeAppearing(animators);
        mButtonActionsStylist.onImeAppearing(animators);
    } else {/*w ww  . j  a  va 2  s . com*/
        mGuidanceStylist.onImeDisappearing(animators);
        mActionsStylist.onImeDisappearing(animators);
        mButtonActionsStylist.onImeDisappearing(animators);
    }
    AnimatorSet set = new AnimatorSet();
    set.playTogether(animators);
    set.start();
}

From source file:com.tmall.wireless.tangram3.ext.SwipeItemTouchListener.java

private void resetViews(RecyclerView recyclerView, final int swipingType, final boolean reachActionEdge,
        final int direction) {
    if (enableAnim) {
        int contentWidth = recyclerView.getWidth();
        AnimatorSet animatorSet = new AnimatorSet();
        List<Animator> list = new ArrayList<>();
        String translation = "translationX";
        if (swipingType == SWIPING_VER) {
            translation = "translationY";
        }//from ww w  .j a  va2  s  .  co m
        for (View view : mChildList) {
            ObjectAnimator animator;
            if (reachActionEdge) {
                animator = ObjectAnimator.ofFloat(view, translation, contentWidth * direction)
                        .setDuration(ANIMATE_DURATION);
                animator.setInterpolator(new AccelerateInterpolator());
            } else {
                animator = ObjectAnimator.ofFloat(view, translation, 0).setDuration(ANIMATE_DURATION);
                animator.setInterpolator(new DecelerateInterpolator());
            }
            list.add(animator);
        }
        animatorSet.playTogether(list);
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (swipingType == SWIPING_HOR && reachActionEdge) {
                    if (mSwipeCardRef != null && mSwipeCardRef.get() != null) {
                        SwipeCard swipeCard = mSwipeCardRef.get();
                        swipeCard.switchTo(swipeCard.getCurrentIndex() - direction);
                    }
                }
                mChildList.clear();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animatorSet.start();
    } else {
        if (swipingType == SWIPING_HOR && reachActionEdge) {
            if (mSwipeCardRef != null && mSwipeCardRef.get() != null) {
                SwipeCard swipeCard = mSwipeCardRef.get();
                swipeCard.switchTo(swipeCard.getCurrentIndex() - direction);
            }
        }
        mChildList.clear();
    }

    if (swipingType == SWIPING_VER) {
        if (pullFromEndListener != null) {
            if (mDistanceY < 0 && (mDistanceY < -pullFromEndListener.getPullEdge())) {
                pullFromEndListener.onAction();
            } else {
                pullFromEndListener.onReset();
            }
        }
    }

    swipeType = SWIPING_NONE;
}

From source file:com.rbware.github.androidcouchpotato.app.GuidedStepFragment.java

void runImeAnimations(boolean entering) {
    ArrayList<Animator> animators = new ArrayList<Animator>();
    if (entering) {
        mGuidanceStylist.onImeAppearing(animators);
        mActionsStylist.onImeAppearing(animators);
        mButtonActionsStylist.onImeAppearing(animators);
    } else {//from   w ww. j  ava  2 s.c o  m
        mGuidanceStylist.onImeDisappearing(animators);
        mActionsStylist.onImeDisappearing(animators);
        mButtonActionsStylist.onImeDisappearing(animators);
    }
    AnimatorSet set = new AnimatorSet();
    set.playTogether(animators);
    set.start();
}

From source file:io.github.sin3hz.wifispinnerview.WifiSpinnerDrawable.java

private void setupAnimators() {
    AnimatorSet set = new AnimatorSet();
    for (int i = 0; i < mSpinnerCount; i++) {
        final int index = i;
        final ValueAnimator sweepAnimator = ValueAnimator.ofFloat(0, MAX_SWEEP_ANGLE);
        sweepAnimator.setInterpolator(SWEEP_ANIMATOR_INTERPOLATOR);
        sweepAnimator.setDuration(mSweepAnimatorDuration);
        sweepAnimator.setRepeatMode(ValueAnimator.RESTART);
        sweepAnimator.setRepeatCount(ValueAnimator.INFINITE);
        sweepAnimator.setStartDelay(index * SWEEP_ANIMATOR_DELAY);
        sweepAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override/*from ww  w.ja va 2  s .com*/
            public void onAnimationUpdate(ValueAnimator animation) {
                mSpinners[index].sweepAngle = (float) animation.getAnimatedValue();
                mSpinners[index].updatePath();
                invalidateSelf();
            }
        });
        sweepAnimator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationRepeat(Animator animation) {
                mSpinners[index].sweepAngleOffset = (mSpinners[index].sweepAngleOffset + MAX_SWEEP_ANGLE) % 360;
                mSpinners[index].updatePath();
            }
        });
        set.playTogether(sweepAnimator);
    }
    mSweepAnimator = set;

    mAngleAnimator = ValueAnimator.ofFloat(0, 360);
    mAngleAnimator.setInterpolator(ANGLE_ANIMATOR_INTERPOLATOR);
    mAngleAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mAngleAnimator.setRepeatMode(ValueAnimator.RESTART);
    mAngleAnimator.setDuration(ANGLE_ANIMATOR_DURATION);
    mAngleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mGlobalAngle = (float) animation.getAnimatedValue();
            updatePath();
            invalidateSelf();
        }
    });
}

From source file:com.viewpagerindicator.TabMovablePageIndicator.java

private void animateScrollWithIndicator(TabView tabView) {
    int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2;

    AnimatorSet as = new AnimatorSet();
    as.setDuration(300);/*w w w  . j a v  a2s  .co m*/

    ArrayList<Animator> animations = new ArrayList<Animator>();

    // scroll
    ObjectAnimator animScrollX = ObjectAnimator.ofInt(TabMovablePageIndicator.this, "scrollX", scrollPos);
    animScrollX.setInterpolator(new AccelerateDecelerateInterpolator());
    animations.add(animScrollX);

    // indicator position
    int left = tabView.getLeft();
    //      int width = tabView.getWidth();
    int textWidth = tabView.wordWidth;
    //      int x = left + (width - textWidth) / 2 - mExtendWidth * 2;
    //      x = x < 0 ? 0 : x;

    ObjectAnimator translateXAnim = ObjectAnimator.ofFloat(mIndicator, "translationX", left);
    translateXAnim.setInterpolator(new OvershootInterpolator(0.8f));
    animations.add(translateXAnim);

    // indicator width
    ValueAnimator animWidth = ValueAnimator.ofInt(mIndicator.getLayoutParams().width,
            textWidth + mExtendWidth * 2);
    animWidth.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mIndicator.getLayoutParams();
            lp.width = (Integer) animation.getAnimatedValue();

            mIndicator.setLayoutParams(lp);
            requestLayout();
        }
    });
    animations.add(animWidth);

    as.playTogether(animations);
    as.start();
}

From source file:kr.wdream.ui.MediaActivity.java

private boolean onItemLongClick(MessageObject item, View view, int a) {
    if (actionBar.isActionModeShowed()) {
        return false;
    }//from  w  w w .  j  a va  2  s .co m
    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
    selectedFiles[item.getDialogId() == dialog_id ? 0 : 1].put(item.getId(), item);
    if (!item.canDeleteMessage(null)) {
        cantDeleteMessagesCount++;
    }
    actionBar.createActionMode().getItem(delete)
            .setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
    selectedMessagesCountTextView.setNumber(1, false);
    AnimatorSet animatorSet = new AnimatorSet();
    ArrayList<Animator> animators = new ArrayList<>();
    for (int i = 0; i < actionModeViews.size(); i++) {
        View view2 = actionModeViews.get(i);
        AndroidUtilities.clearDrawableAnimation(view2);
        animators.add(ObjectAnimator.ofFloat(view2, "scaleY", 0.1f, 1.0f));
    }
    animatorSet.playTogether(animators);
    animatorSet.setDuration(250);
    animatorSet.start();
    scrolling = false;
    if (view instanceof SharedDocumentCell) {
        ((SharedDocumentCell) view).setChecked(true, true);
    } else if (view instanceof SharedPhotoVideoCell) {
        ((SharedPhotoVideoCell) view).setChecked(a, true, true);
    } else if (view instanceof SharedLinkCell) {
        ((SharedLinkCell) view).setChecked(true, true);
    }
    actionBar.showActionMode();
    return true;
}

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

@TargetApi(16)
private void openCamera() {
    if (cameraView == null) {
        return;//  w w  w  .j a  v  a  2 s  .  c om
    }
    animateCameraValues[0] = 0;
    animateCameraValues[1] = AndroidUtilities.dp(80) - cameraViewOffsetX;
    animateCameraValues[2] = AndroidUtilities.dp(80) - cameraViewOffsetY;
    cameraAnimationInProgress = true;
    cameraPanel.setVisibility(View.VISIBLE);
    cameraPanel.setTag(null);
    ArrayList<Animator> animators = new ArrayList<>();
    animators.add(ObjectAnimator.ofFloat(ChatAttachAlert.this, "cameraOpenProgress", 0.0f, 1.0f));
    animators.add(ObjectAnimator.ofFloat(cameraPanel, "alpha", 1.0f));
    for (int a = 0; a < 2; a++) {
        if (flashModeButton[a].getVisibility() == View.VISIBLE) {
            animators.add(ObjectAnimator.ofFloat(flashModeButton[a], "alpha", 1.0f));
            break;
        }
    }
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(animators);
    animatorSet.setDuration(200);
    animatorSet.addListener(new AnimatorListenerAdapterProxy() {
        @Override
        public void onAnimationEnd(Animator animator) {
            cameraAnimationInProgress = false;
        }
    });
    animatorSet.start();
    if (Build.VERSION.SDK_INT >= 21) {
        cameraView
                .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);
    }
    cameraOpened = true;
}

From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java

private static Animator createAnimatorFromXml(Context context, Resources res, Theme theme, XmlPullParser parser,
        AttributeSet attrs, AnimatorSet parent, int sequenceOrdering, float pixelSize)
        throws XmlPullParserException, IOException {
    Animator anim = null;//from w  w w  .  ja  v a2 s .c o  m
    ArrayList<Animator> childAnims = null;

    // Make sure we are on a start tag.
    int type;
    int depth = parser.getDepth();

    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
            && type != XmlPullParser.END_DOCUMENT) {

        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        String name = parser.getName();
        boolean gotValues = false;

        if (name.equals("objectAnimator")) {
            anim = loadObjectAnimator(context, res, theme, attrs, pixelSize, parser);
        } else if (name.equals("animator")) {
            anim = loadAnimator(context, res, theme, attrs, null, pixelSize, parser);
        } else if (name.equals("set")) {
            anim = new AnimatorSet();
            TypedArray a = TypedArrayUtils.obtainAttributes(res, theme, attrs,
                    AndroidResources.STYLEABLE_ANIMATOR_SET);

            int ordering = TypedArrayUtils.getNamedInt(a, parser, "ordering",
                    AndroidResources.STYLEABLE_ANIMATOR_SET_ORDERING, TOGETHER);

            createAnimatorFromXml(context, res, theme, parser, attrs, (AnimatorSet) anim, ordering, pixelSize);
            a.recycle();
        } else if (name.equals("propertyValuesHolder")) {
            PropertyValuesHolder[] values = loadValues(context, res, theme, parser, Xml.asAttributeSet(parser));
            if (values != null && anim != null && (anim instanceof ValueAnimator)) {
                ((ValueAnimator) anim).setValues(values);
            }
            gotValues = true;
        } else {
            throw new RuntimeException("Unknown animator name: " + parser.getName());
        }

        if (parent != null && !gotValues) {
            if (childAnims == null) {
                childAnims = new ArrayList<Animator>();
            }
            childAnims.add(anim);
        }
    }
    if (parent != null && childAnims != null) {
        Animator[] animsArray = new Animator[childAnims.size()];
        int index = 0;
        for (Animator a : childAnims) {
            animsArray[index++] = a;
        }
        if (sequenceOrdering == TOGETHER) {
            parent.playTogether(animsArray);
        } else {
            parent.playSequentially(animsArray);
        }
    }
    return anim;
}

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

@TargetApi(16)
public void closeCamera(boolean animated) {
    if (takingPhoto || cameraView == null) {
        return;//from  w  ww . j  a v a 2  s  .  co m
    }
    animateCameraValues[1] = AndroidUtilities.dp(80) - cameraViewOffsetX;
    animateCameraValues[2] = AndroidUtilities.dp(80) - cameraViewOffsetY;
    if (animated) {
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) cameraView.getLayoutParams();
        animateCameraValues[0] = layoutParams.topMargin = (int) cameraView.getTranslationY();
        cameraView.setLayoutParams(layoutParams);
        cameraView.setTranslationY(0);

        cameraAnimationInProgress = true;
        ArrayList<Animator> animators = new ArrayList<>();
        animators.add(ObjectAnimator.ofFloat(ChatAttachAlert.this, "cameraOpenProgress", 0.0f));
        animators.add(ObjectAnimator.ofFloat(cameraPanel, "alpha", 0.0f));
        for (int a = 0; a < 2; a++) {
            if (flashModeButton[a].getVisibility() == View.VISIBLE) {
                animators.add(ObjectAnimator.ofFloat(flashModeButton[a], "alpha", 0.0f));
                break;
            }
        }
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(animators);
        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animator) {
                cameraAnimationInProgress = false;
                cameraPanel.setVisibility(View.GONE);
                cameraOpened = false;
                if (Build.VERSION.SDK_INT >= 21) {
                    cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
                }
            }
        });
        animatorSet.start();
    } else {
        animateCameraValues[0] = 0;
        setCameraOpenProgress(0);
        cameraPanel.setAlpha(0);
        cameraPanel.setVisibility(View.GONE);
        for (int a = 0; a < 2; a++) {
            if (flashModeButton[a].getVisibility() == View.VISIBLE) {
                flashModeButton[a].setAlpha(0.0f);
                break;
            }
        }
        cameraOpened = false;
        if (Build.VERSION.SDK_INT >= 21) {
            cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
    }
}

From source file:io.plaidapp.core.ui.transitions.ReflowText.java

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {

    if (startValues == null || endValues == null)
        return null;

    final View view = endValues.view;
    AnimatorSet transition = new AnimatorSet();
    ReflowData startData = (ReflowData) startValues.values.get(PROPNAME_DATA);
    ReflowData endData = (ReflowData) endValues.values.get(PROPNAME_DATA);
    duration = calculateDuration(startData.bounds, endData.bounds);

    // create layouts & capture a bitmaps of the text in both states
    // (with max lines variants where needed)
    Layout startLayout = createLayout(startData, sceneRoot.getContext(), false);
    Layout endLayout = createLayout(endData, sceneRoot.getContext(), false);
    Layout startLayoutMaxLines = null;//w  w  w  .j  a va 2s  .c  o m
    Layout endLayoutMaxLines = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // StaticLayout maxLines support
        if (startData.maxLines != -1) {
            startLayoutMaxLines = createLayout(startData, sceneRoot.getContext(), true);
        }
        if (endData.maxLines != -1) {
            endLayoutMaxLines = createLayout(endData, sceneRoot.getContext(), true);
        }
    }
    final Bitmap startText = createBitmap(startData,
            startLayoutMaxLines != null ? startLayoutMaxLines : startLayout);
    final Bitmap endText = createBitmap(endData, endLayoutMaxLines != null ? endLayoutMaxLines : endLayout);

    // temporarily turn off clipping so we can draw outside of our bounds don't draw
    view.setWillNotDraw(true);
    ((ViewGroup) view.getParent()).setClipChildren(false);

    // calculate the runs of text to move together
    List<Run> runs = getRuns(startData, startLayout, startLayoutMaxLines, endData, endLayout,
            endLayoutMaxLines);

    // create animators for moving, scaling and fading each run of text
    transition.playTogether(createRunAnimators(view, startData, endData, startText, endText, runs));

    if (!freezeFrame) {
        transition.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // clean up
                view.setWillNotDraw(false);
                view.getOverlay().clear();
                ((ViewGroup) view.getParent()).setClipChildren(true);
                startText.recycle();
                endText.recycle();
            }
        });
    }
    return transition;
}