Example usage for android.animation AnimatorSet playSequentially

List of usage examples for android.animation AnimatorSet playSequentially

Introduction

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

Prototype

public void playSequentially(List<Animator> items) 

Source Link

Document

Sets up this AnimatorSet to play each of the supplied animations when the previous animation ends.

Usage

From source file:Main.java

public static AnimatorSet playSequentially(Animator... animators) {
    AnimatorSet set = new AnimatorSet();
    set.playSequentially(animators);

    return set;//from   w  ww. j av  a2 s.c  o m
}

From source file:org.deviceconnect.android.deviceplugin.linking.setting.fragment.LinkingHelpFragment.java

private void createAnimation(final View v) {
    float size = 12.0f * getResources().getDisplayMetrics().density;
    long time = 1000;

    List<Animator> animatorList = new ArrayList<>();

    ObjectAnimator fadeIn = ObjectAnimator.ofFloat(v, "translationY", -size, 0);
    fadeIn.setDuration(time);//  www .  j  a v a 2 s .c o  m
    animatorList.add(fadeIn);

    ObjectAnimator fadeOut = ObjectAnimator.ofFloat(v, "translationY", 0, -size);
    fadeOut.setDuration(time);
    animatorList.add(fadeOut);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playSequentially(animatorList);
    animatorSet.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (!mDestroy) {
                animation.start();
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    animatorSet.start();
}

From source file:com.angelatech.yeyelive.view.PeriscopeLayout.java

private Animator getAnimator(View target) {
    AnimatorSet set = getEnterAnimtor(target);
    ValueAnimator bezierValueAnimator = getBezierValueAnimator(target);
    AnimatorSet finalSet = new AnimatorSet();
    finalSet.playSequentially(set);
    finalSet.playSequentially(set, bezierValueAnimator);
    finalSet.setInterpolator(interpolators[random.nextInt(4)]);
    finalSet.setTarget(target);//  w  w  w .ja  v a 2 s.  c om
    return finalSet;
}

From source file:org.amahi.anywhere.tv.fragment.IntroFragment.java

@Override
protected void onPageChanged(final int newPage, int previousPage) {
    if (mContentAnimator != null) {
        mContentAnimator.end();// ww w. j  a v a  2s.  co  m
    }

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

    Animator fadeOut = createFadeOutAnimator(mContentView);

    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            Log.d(getClass().getName(), String.valueOf(newPage));
            mContentView.setImageResource(CONTENT_IMAGES[newPage]);
            switch (newPage) {
            case 0:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            case 1:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            case 2:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            case 3:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            case 4:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            case 5:
                mBackgroundView.setBackground(new ColorDrawable(mColors.get(newPage)));
                break;
            }
        }
    });

    animators.add(fadeOut);

    animators.add(createFadeInAnimator(mContentView));

    AnimatorSet set = new AnimatorSet();

    set.playSequentially(animators);

    set.start();

    mContentAnimator = set;
}

From source file:me.hammarstrom.imagerecognition.activities.MainActivity.java

private void convertResponseToString(BatchAnnotateImagesResponse response) {
    Log.d(TAG, ":: " + response.getResponses().toString());
    List<FaceAnnotation> faces = response.getResponses().get(0).getFaceAnnotations();
    List<EntityAnnotation> labels = response.getResponses().get(0).getLabelAnnotations();

    // Label string to be populated with data for TextToSpeech
    String label = "";
    if (labels != null && labels.size() > 0) {
        label = "The image may contain ";
        List<Animator> scoreViewAnimations = new ArrayList<>();
        List<Animator> scoreAlphaAnimations = new ArrayList<>();
        List<Animator> showScoreAnimations = new ArrayList<>();

        for (EntityAnnotation l : labels) {
            if (l.getScore() < 0.6f) {
                continue;
            }/* ww  w  . ja  v  a  2s  .  c  om*/

            // Add label description (ex. laptop, desk, person, etc.)
            label += l.getDescription() + ", ";

            /**
             * Create a new {@link ScoreView} and populate it with label description and score
             */
            ScoreView scoreView = new ScoreView(MainActivity.this);
            int padding = (int) DeviceDimensionsHelper.convertDpToPixel(8, this);
            scoreView.setPadding(padding, padding, padding, padding);
            scoreView.setScore(l.getScore());
            scoreView.setLabelPosition(ScoreView.LABEL_POSITION_RIGHT);
            scoreView.setLabelText(l.getDescription());
            scoreView.setAlpha(0f);
            scoreView.setTranslationX((DeviceDimensionsHelper.getDisplayWidth(this) / 2) * -1);

            // Add ScoreView to result layout
            mScoreResultLayout.addView(scoreView);

            // Create animations to used to show the ScoreView in a nice way
            ObjectAnimator animator = ObjectAnimator.ofFloat(scoreView, "translationX",
                    (DeviceDimensionsHelper.getDisplayWidth(this) / 2) * -1, 0f);
            animator.setInterpolator(new OvershootInterpolator());
            scoreViewAnimations.add(animator);

            ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(scoreView, "alpha", 0f, 1f);
            scoreAlphaAnimations.add(alphaAnimator);

            // Get the animation to show the actual score from ScoreView object
            showScoreAnimations.addAll(scoreView.getShowScoreAnimationsList());
        }

        // Set reset button visibility to visible
        mButtonReset.setVisibility(View.VISIBLE);

        // Setup and play the animations
        AnimatorSet translationSet = new AnimatorSet();
        translationSet.playSequentially(scoreViewAnimations);
        translationSet.setDuration(300);

        AnimatorSet alphaSet = new AnimatorSet();
        alphaSet.playSequentially(scoreAlphaAnimations);
        alphaSet.setDuration(300);

        AnimatorSet showScoreSet = new AnimatorSet();
        showScoreSet.playTogether(showScoreAnimations);

        showLoading(false);

        AnimatorSet set = new AnimatorSet();
        set.play(translationSet).with(alphaSet).before(showScoreSet);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mButtonReset.animate().alpha(1f).start();
            }
        });
        set.start();
    } else {
        // Set reset button visibility to visible
        mButtonReset.setVisibility(View.VISIBLE);
        mButtonReset.setAlpha(1f);
    }

    // Handle detected faces
    String facesFound = "";
    if (faces != null && faces.size() > 0) {
        FaceGraphicOverlay faceGraphicOverlay = new FaceGraphicOverlay(MainActivity.this);
        faceGraphicOverlay.addFaces(faces);
        faceGraphicOverlay.setTag("faceOverlay");
        mCameraPreviewLayout.addView(faceGraphicOverlay);

        facesFound = FaceFoundHelper.getFacesFoundString(this, faces);
    }

    // Add the detected image data to TTS engine
    mTts.speak(label, TextToSpeech.QUEUE_FLUSH, null);
    mTts.speak(facesFound, TextToSpeech.QUEUE_ADD, null);
}

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);
            }//from   w w  w .  ja  va  2 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();
        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.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;//w w w  .  ja v a2  s .  c  om
    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;
}