Example usage for android.animation Animator setStartDelay

List of usage examples for android.animation Animator setStartDelay

Introduction

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

Prototype

public abstract void setStartDelay(long startDelay);

Source Link

Document

The amount of time, in milliseconds, to delay processing the animation after #start() is called.

Usage

From source file:com.fairphone.fplauncher3.Folder.java

public void animateOpen() {
    if (!(getParent() instanceof DragLayer)) {
        return;//from  w  ww . j a  v  a 2  s  .  com
    }

    Animator openFolderAnim;
    final Runnable onCompleteRunnable;
    if (!Utilities.isLmpOrAbove()) {
        positionAndSizeAsIcon();
        centerAboutIcon();

        PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1f);
        PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
        PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
        final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
        oa.setDuration(mExpandDuration);
        openFolderAnim = oa;

        setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                setLayerType(LAYER_TYPE_NONE, null);
            }
        };
    } else {
        prepareReveal();
        centerAboutIcon();

        int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
        int height = getFolderHeight();

        float transX = -0.075f * (width / 2 - getPivotX());
        float transY = -0.075f * (height / 2 - getPivotY());
        final float endTransX = 0;
        final float endTransY = 0;

        setTranslationX(transX);
        setTranslationY(transY);
        PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, endTransX);
        PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, endTransY);

        int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX());
        int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY());
        float radius = (float) Math.sqrt(rx * rx + ry * ry);
        AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
        Animator reveal = LauncherAnimUtils.createCircularReveal(this, (int) getPivotX(), (int) getPivotY(), 0,
                radius);
        reveal.setDuration(mMaterialExpandDuration);
        reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));

        View[] alphaViewSet = new View[] { mContent, mFolderName };
        for (View view : alphaViewSet) {
            Animator alphaAnimator = setupAlphaAnimator(view, 0f, 1f, mMaterialExpandDuration,
                    mMaterialExpandStagger);
            anim.play(alphaAnimator);
        }

        /* mContent.setAlpha(0f);
         Animator iconsAlpha = LauncherAnimUtils.ofFloat(mContent, "alpha", 0f, 1f);
         iconsAlpha.setDuration(mMaterialExpandDuration);
         iconsAlpha.setStartDelay(mMaterialExpandStagger);
         iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
                
         mFolderName.setAlpha(0f);
         Animator textAlpha = LauncherAnimUtils.ofFloat(mFolderName, "alpha", 0f, 1f);
         textAlpha.setDuration(mMaterialExpandDuration);
         textAlpha.setStartDelay(mMaterialExpandStagger);
         textAlpha.setInterpolator(new AccelerateInterpolator(1.5f));*/

        Animator drift = LauncherAnimUtils.ofPropertyValuesHolder(this, tx, ty);
        drift.setDuration(mMaterialExpandDuration);
        drift.setStartDelay(mMaterialExpandStagger);
        drift.setInterpolator(new LogDecelerateInterpolator(60, 0));
        drift.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // in low power mode the animation doesn't play, so set the end value here
                Folder.this.setTranslationX(endTransX);
                Folder.this.setTranslationY(endTransY);
            }
        });

        anim.play(drift);
        /* anim.play(iconsAlpha);
         anim.play(textAlpha);*/
        anim.play(reveal);

        openFolderAnim = anim;

        mContent.setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                mContent.setLayerType(LAYER_TYPE_NONE, null);
            }
        };
    }
    openFolderAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    String.format(getContext().getString(R.string.folder_opened), mContent.getCountX(),
                            mContent.getCountY()));
            mState = STATE_ANIMATING;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;

            if (onCompleteRunnable != null) {
                onCompleteRunnable.run();
            }

            setFocusOnFirstChild();
        }
    });
    openFolderAnim.start();

    // Make sure the folder picks up the last drag move even if the finger doesn't move.
    if (mDragController.isDragging()) {
        mDragController.forceTouchMove();
    }
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void showLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float endFabX;
    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        endFabX = rootWidth / 2f + (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 0.98f;
    } else {/*from   w w  w .j  a v a 2 s  .  co m*/
        endFabX = rootWidth / 2f - (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 1.02f;
    }

    /**
     * Animate FAB movement
     */
    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, endFabX, getY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Fade FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration((long) (FAB_MORPH_DURATION / 3f));
        anim.start();
    }

    /**
     * Animate FAB elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, dpToPixels(2));
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Create circular reveal
     */
    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) mFab.getWidth() / 2f, (float) (Math.hypot(getWidth() / 2, getHeight() / 2)));

    toolbarReveal.setDuration(CIRCULAR_REVEAL_DURATION);
    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mFab.setVisibility(View.INVISIBLE);
            setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mMorphing = false;
        }
    });

    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_REVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, dpToPixels(2));
    anim.setDuration(CIRCULAR_REVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_REVEAL_DELAY);
    anim.start();
}

From source file:com.matthewtamlin.sliding_intro_screen_library.core.IntroActivity.java

/**
 * Enables the supplied button by making it visible and clickable. This method should only be
 * called while the supplied button is disabled (i.e. invisible and un-clickable). The supplied
 * Animator will be used to transition the button.
 *
 * @param buttonAnimator//from  ww w  .j av  a2 s.c o m
 *       the Animator to use when transitioning the button, null to perform no animation
 * @param button
 *       the button to enable, not null
 * @throws IllegalArgumentException
 *       if {@code button} is null
 */
private void enableButton(final Animator buttonAnimator, final IntroButton button) {
    if (button == null) {
        throw new IllegalArgumentException("button cannot be null");
    }

    // Any animations currently affecting the button must be cancelled before new ones start
    if (buttonAnimations.containsKey(button)) {
        buttonAnimations.get(button).cancel();
        buttonAnimations.remove(button);
    }

    if (buttonAnimator != null) {
        buttonAnimations.put(button, buttonAnimator);

        // Give any disable animations time to finish before the enable animation starts
        buttonAnimator.setStartDelay(BUTTON_ANIMATION_DURATION_MS);

        // End/cancel conditions ensure that the UI is not left in a transient state when
        // animations finish
        buttonAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(final Animator animation) {
                button.setVisibility(View.VISIBLE); // Make sure View is visible while animating
                button.setEnabled(true); // Click events should be accepted immediately
            }

            @Override
            public void onAnimationCancel(final Animator animation) {
                // Restore button to disabled mode
                button.setVisibility(View.INVISIBLE);
                button.setEnabled(false);
            }
        });

        buttonAnimator.setDuration(BUTTON_ANIMATION_DURATION_MS);
        buttonAnimator.start();
    } else {
        // If no Animator was supplied, just apply the enabled conditions
        button.setVisibility(View.VISIBLE);
        button.setEnabled(true);
    }
}

From source file:com.android.launcher3.folder.Folder.java

public void animateOpen() {
    if (!(getParent() instanceof DragLayer))
        return;// w w  w.  j a v  a2 s.  com

    mContent.completePendingPageChanges();
    if (!mDragInProgress) {
        // Open on the first page.
        mContent.snapToPageImmediately(0);
    }

    // This is set to true in close(), but isn't reset to false until onDropCompleted(). This
    // leads to an inconsistent state if you drag out of the folder and drag back in without
    // dropping. One resulting issue is that replaceFolderWithFinalItem() can be called twice.
    mDeleteFolderOnDropCompleted = false;

    Animator openFolderAnim = null;
    final Runnable onCompleteRunnable;
    if (!Utilities.ATLEAST_LOLLIPOP) {
        positionAndSizeAsIcon();
        centerAboutIcon();

        final ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(this, 1, 1, 1);
        oa.setDuration(mExpandDuration);
        openFolderAnim = oa;

        setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                setLayerType(LAYER_TYPE_NONE, null);
            }
        };
    } else {
        prepareReveal();
        centerAboutIcon();

        AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
        int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
        int height = getFolderHeight();

        float transX = -0.075f * (width / 2 - getPivotX());
        float transY = -0.075f * (height / 2 - getPivotY());
        setTranslationX(transX);
        setTranslationY(transY);
        PropertyValuesHolder tx = PropertyValuesHolder.ofFloat(TRANSLATION_X, transX, 0);
        PropertyValuesHolder ty = PropertyValuesHolder.ofFloat(TRANSLATION_Y, transY, 0);

        Animator drift = ObjectAnimator.ofPropertyValuesHolder(this, tx, ty);
        drift.setDuration(mMaterialExpandDuration);
        drift.setStartDelay(mMaterialExpandStagger);
        drift.setInterpolator(new LogDecelerateInterpolator(100, 0));

        int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX());
        int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY());
        float radius = (float) Math.hypot(rx, ry);

        Animator reveal = new CircleRevealOutlineProvider((int) getPivotX(), (int) getPivotY(), 0, radius)
                .createRevealAnimator(this);
        reveal.setDuration(mMaterialExpandDuration);
        reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));

        mContent.setAlpha(0f);
        Animator iconsAlpha = ObjectAnimator.ofFloat(mContent, "alpha", 0f, 1f);
        iconsAlpha.setDuration(mMaterialExpandDuration);
        iconsAlpha.setStartDelay(mMaterialExpandStagger);
        iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));

        mFooter.setAlpha(0f);
        Animator textAlpha = ObjectAnimator.ofFloat(mFooter, "alpha", 0f, 1f);
        textAlpha.setDuration(mMaterialExpandDuration);
        textAlpha.setStartDelay(mMaterialExpandStagger);
        textAlpha.setInterpolator(new AccelerateInterpolator(1.5f));

        anim.play(drift);
        anim.play(iconsAlpha);
        anim.play(textAlpha);
        anim.play(reveal);

        openFolderAnim = anim;

        mContent.setLayerType(LAYER_TYPE_HARDWARE, null);
        mFooter.setLayerType(LAYER_TYPE_HARDWARE, null);
        onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                mContent.setLayerType(LAYER_TYPE_NONE, null);
                mFooter.setLayerType(LAYER_TYPE_NONE, null);
                mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
            }
        };
    }
    openFolderAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            Utilities.sendCustomAccessibilityEvent(Folder.this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    mContent.getAccessibilityDescription());
            mState = STATE_ANIMATING;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;

            onCompleteRunnable.run();
            mContent.setFocusOnFirstChild();
        }
    });

    // Footer animation
    if (mContent.getPageCount() > 1 && !mInfo.hasOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION)) {
        int footerWidth = mContent.getDesiredWidth() - mFooter.getPaddingLeft() - mFooter.getPaddingRight();

        float textWidth = mFolderName.getPaint().measureText(mFolderName.getText().toString());
        float translation = (footerWidth - textWidth) / 2;
        mFolderName.setTranslationX(mContent.mIsRtl ? -translation : translation);
        mPageIndicator.prepareEntryAnimation();

        // Do not update the flag if we are in drag mode. The flag will be updated, when we
        // actually drop the icon.
        final boolean updateAnimationFlag = !mDragInProgress;
        openFolderAnim.addListener(new AnimatorListenerAdapter() {

            @SuppressLint("InlinedApi")
            @Override
            public void onAnimationEnd(Animator animation) {
                mFolderName.animate().setDuration(FOLDER_NAME_ANIMATION_DURATION).translationX(0)
                        .setInterpolator(Utilities.ATLEAST_LOLLIPOP
                                ? AnimationUtils.loadInterpolator(mLauncher,
                                        android.R.interpolator.fast_out_slow_in)
                                : new LogDecelerateInterpolator(100, 0));
                mPageIndicator.playEntryAnimation();

                if (updateAnimationFlag) {
                    mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher);
                }
            }
        });
    } else {
        mFolderName.setTranslationX(0);
    }

    mPageIndicator.stopAllAnimations();
    openFolderAnim.start();

    // Make sure the folder picks up the last drag move even if the finger doesn't move.
    if (mDragController.isDragging()) {
        mDragController.forceTouchMove();
    }

    mContent.verifyVisibleHighResIcons(mContent.getNextPage());
}

From source file:android.support.transition.Transition.java

/**
 * This is a utility method used by subclasses to handle standard parts of
 * setting up and running an Animator: it sets the {@link #getDuration()
 * duration} and the {@link #getStartDelay() startDelay}, starts the
 * animation, and, when the animator ends, calls {@link #end()}.
 *
 * @param animator The Animator to be run during this transition.
 *
 * @hide//from   w w  w.ja va  2  s.c  o  m
 */
protected void animate(Animator animator) {
    // TODO: maybe pass auto-end as a boolean parameter?
    if (animator == null) {
        end();
    } else {
        if (getDuration() >= 0) {
            animator.setDuration(getDuration());
        }
        if (getStartDelay() >= 0) {
            animator.setStartDelay(getStartDelay());
        }
        if (getInterpolator() != null) {
            animator.setInterpolator(getInterpolator());
        }
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                end();
                animation.removeListener(this);
            }
        });
        animator.start();
    }
}

From source file:com.stanleyidesis.quotograph.ui.activity.LWQSettingsActivity.java

Animator animateFABActions(final boolean dismiss) {
    fabBackground.setVisibility(View.VISIBLE);
    Animator backgroundAnimator;//from  w w w  . java2  s .  co  m

    if (Build.VERSION.SDK_INT >= 21) {
        Rect fabRect = new Rect();
        fabAdd.getGlobalVisibleRect(fabRect);
        final Point realScreenSize = UIUtils.getRealScreenSize();
        int radius = Math.max(realScreenSize.x, realScreenSize.y);
        backgroundAnimator = ViewAnimationUtils.createCircularReveal(fabBackground, fabRect.centerX(),
                fabRect.centerY(), dismiss ? radius : 0, dismiss ? 0 : radius);
    } else {
        backgroundAnimator = ObjectAnimator.ofFloat(fabBackground, "alpha", dismiss ? 1f : 0f,
                dismiss ? 0f : 1f);
    }
    backgroundAnimator.setDuration(300).setInterpolator(new AccelerateDecelerateInterpolator());
    backgroundAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (dismiss) {
                fabBackground.setVisibility(View.GONE);
                // Tell them to swipe again for settings!
                showTutorialTip(TutorialTooltips.SWIPE_AGAIN);
            } else {
                // Tell them about search!
                showTutorialTip(TutorialTooltips.SEARCH);
            }
        }
    });
    final long shortDelay = 50;
    final long longDelay = 100;
    final Animator createAnimator = animateFAB(fabCreate, dismiss);
    final Animator searchAnimator = animateFAB(fabSearch, dismiss);
    createAnimator.setStartDelay(dismiss ? longDelay : shortDelay);
    searchAnimator.setStartDelay(dismiss ? shortDelay : longDelay);
    AnimatorSet allAnimations = new AnimatorSet();
    allAnimations.playTogether(backgroundAnimator, createAnimator, searchAnimator);
    return allAnimations;
}

From source file:com.androidinspain.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java

private Animator createExpandingAnimator(AlarmItemViewHolder oldHolder, long duration) {
    final View oldView = oldHolder.itemView;
    final View newView = itemView;
    final Animator boundsAnimator = AnimatorUtils.getBoundsAnimator(newView, oldView, newView);
    boundsAnimator.setDuration(duration);
    boundsAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    final Animator backgroundAnimator = ObjectAnimator.ofPropertyValuesHolder(newView,
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 0, 255));
    backgroundAnimator.setDuration(duration);

    final View oldArrow = oldHolder.arrow;
    final Rect oldArrowRect = new Rect(0, 0, oldArrow.getWidth(), oldArrow.getHeight());
    final Rect newArrowRect = new Rect(0, 0, arrow.getWidth(), arrow.getHeight());
    ((ViewGroup) newView).offsetDescendantRectToMyCoords(arrow, newArrowRect);
    ((ViewGroup) oldView).offsetDescendantRectToMyCoords(oldArrow, oldArrowRect);
    final float arrowTranslationY = oldArrowRect.bottom - newArrowRect.bottom;

    arrow.setTranslationY(arrowTranslationY);
    arrow.setVisibility(View.VISIBLE);
    clock.setVisibility(View.VISIBLE);
    onOff.setVisibility(View.VISIBLE);

    final long longDuration = (long) (duration * ANIM_LONG_DURATION_MULTIPLIER);
    final Animator repeatAnimation = ObjectAnimator.ofFloat(repeat, View.ALPHA, 1f).setDuration(longDuration);
    final Animator repeatDaysAnimation = ObjectAnimator.ofFloat(repeatDays, View.ALPHA, 1f)
            .setDuration(longDuration);/*from   w  ww .  j a va2 s  .c om*/
    final Animator ringtoneAnimation = ObjectAnimator.ofFloat(ringtone, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator dismissAnimation = ObjectAnimator.ofFloat(preemptiveDismissButton, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator vibrateAnimation = ObjectAnimator.ofFloat(vibrate, View.ALPHA, 1f).setDuration(longDuration);
    final Animator editLabelAnimation = ObjectAnimator.ofFloat(editLabel, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator hairLineAnimation = ObjectAnimator.ofFloat(hairLine, View.ALPHA, 1f)
            .setDuration(longDuration);
    final Animator deleteAnimation = ObjectAnimator.ofFloat(delete, View.ALPHA, 1f).setDuration(longDuration);
    final Animator arrowAnimation = ObjectAnimator.ofFloat(arrow, View.TRANSLATION_Y, 0f).setDuration(duration);
    arrowAnimation.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);

    // Set the stagger delays; delay the first by the amount of time it takes for the collapse
    // to complete, then stagger the expansion with the remaining time.
    long startDelay = (long) (duration * ANIM_STANDARD_DELAY_MULTIPLIER);
    final int numberOfItems = countNumberOfItems();
    final long delayIncrement = (long) (duration * ANIM_SHORT_DELAY_INCREMENT_MULTIPLIER) / (numberOfItems - 1);
    repeatAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    final boolean daysVisible = repeatDays.getVisibility() == View.VISIBLE;
    if (daysVisible) {
        repeatDaysAnimation.setStartDelay(startDelay);
        startDelay += delayIncrement;
    }
    ringtoneAnimation.setStartDelay(startDelay);
    vibrateAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    editLabelAnimation.setStartDelay(startDelay);
    startDelay += delayIncrement;
    hairLineAnimation.setStartDelay(startDelay);
    if (preemptiveDismissButton.getVisibility() == View.VISIBLE) {
        dismissAnimation.setStartDelay(startDelay);
        startDelay += delayIncrement;
    }
    deleteAnimation.setStartDelay(startDelay);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(backgroundAnimator, repeatAnimation, boundsAnimator, repeatDaysAnimation,
            vibrateAnimation, ringtoneAnimation, editLabelAnimation, deleteAnimation, hairLineAnimation,
            dismissAnimation, arrowAnimation);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animator) {
            AnimatorUtils.startDrawableAnimation(arrow);
        }
    });
    return animatorSet;
}

From source file:org.chromium.chrome.browser.toolbar.ToolbarPhone.java

private void populateUrlClearFocusingAnimatorSet(List<Animator> animators) {
    Animator animator = ObjectAnimator.ofFloat(this, mUrlFocusChangePercentProperty, 0f);
    animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);//from w w w .j  av a  2  s.  co m

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, TRANSLATION_X, 0);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 1);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    if (mToggleTabStackButton != null) {
        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, TRANSLATION_X, 0);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setStartDelay(URL_CLEAR_FOCUS_TABSTACK_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);

        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, ALPHA, 1);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setStartDelay(URL_CLEAR_FOCUS_TABSTACK_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);
    }

    for (int i = 0; i < mLocationBar.getChildCount(); i++) {
        View childView = mLocationBar.getChildAt(i);
        if (childView == mLocationBar.getFirstViewVisibleWhenFocused())
            break;
        animator = ObjectAnimator.ofFloat(childView, ALPHA, 1);
        animator.setStartDelay(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setDuration(URL_CLEAR_FOCUS_MENU_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);
    }

    if (isLocationBarShownInNTP() && mNtpSearchBoxScrollPercent == 0f)
        return;

    // The call to getLayout() can return null briefly during text changes, but as it
    // is only needed for RTL calculations, we proceed if the location bar is showing
    // LTR content.
    boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar);
    if (!isLocationBarRtl || mUrlBar.getLayout() != null) {
        int urlBarStartScrollX = 0;
        if (isLocationBarRtl) {
            urlBarStartScrollX = (int) mUrlBar.getLayout().getPrimaryHorizontal(0);
            urlBarStartScrollX -= mUrlBar.getWidth();
        }

        // If the scroll position matches the current scroll position, do not trigger
        // this animation as it will cause visible jumps when going from cleared text
        // back to page URLs (despite it continually calling setScrollX with the same
        // number).
        if (mUrlBar.getScrollX() != urlBarStartScrollX) {
            animator = ObjectAnimator.ofInt(mUrlBar, buildUrlScrollProperty(mLocationBar, isLocationBarRtl),
                    urlBarStartScrollX);
            animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
            animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
            animators.add(animator);
        }
    }
}

From source file:android.transitions.everywhere.Transition.java

/**
 * This is a utility method used by subclasses to handle standard parts of
 * setting up and running an Animator: it sets the {@link #getDuration()
 * duration} and the {@link #getStartDelay() startDelay}, starts the
 * animation, and, when the animator ends, calls {@link #end()}.
 *
 * @param animator The Animator to be run during this transition.
 * @hide//from ww  w  .j  av  a 2  s  . co m
 */
protected void animate(Animator animator) {
    // TODO: maybe pass auto-end as a boolean parameter?
    if (animator == null) {
        end();
    } else {
        if (getDuration() >= 0) {
            animator.setDuration(getDuration());
        }
        if (getStartDelay() >= 0) {
            animator.setStartDelay(getStartDelay() + animator.getStartDelay());
        }
        if (getInterpolator() != null) {
            animator.setInterpolator(getInterpolator());
        }
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                end();
                animation.removeListener(this);
            }
        });
        animator.start();
    }
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

/**
 * Zoom the camera back into the workspace, hiding 'fromView'.
 * This is the opposite of showAppsCustomizeHelper.
 *
 * @param animated If true, the transition will be animated.
 *///w  ww.  ja  va2s  .  c om
private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
        final boolean springLoaded, final Runnable onCompleteRunnable) {

    if (mStateAnimation != null) {
        mStateAnimation.setDuration(0);
        mStateAnimation.cancel();
        mStateAnimation = null;
    }

    boolean material = Utilities.isLmpOrAbove();
    Resources res = getResources();

    final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
    final int itemsAlphaStagger = res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);

    final View fromView = mAppsCustomizeTabHost;
    final View toView = mWorkspace;
    Animator workspaceAnim = null;
    final ArrayList<View> layerViews = new ArrayList<View>();

    if (toState == Workspace.State.NORMAL) {
        workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated, layerViews);
    } else if (toState == Workspace.State.SPRING_LOADED || toState == Workspace.State.OVERVIEW) {
        workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated, layerViews);
    }

    // If for some reason our views aren't initialized, don't animate
    boolean initialized = getAllAppsButton() != null;

    if (animated && initialized) {
        mStateAnimation = LauncherAnimUtils.createAnimatorSet();
        if (workspaceAnim != null) {
            mStateAnimation.play(workspaceAnim);
        }

        final AppsCustomizePagedView content = (AppsCustomizePagedView) fromView
                .findViewById(R.id.apps_customize_pane_content);

        final View page = content.getPageAt(content.getNextPage());

        // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
        int count = content.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = content.getChildAt(i);
            if (child != page) {
                child.setVisibility(View.INVISIBLE);
            }
        }
        final View revealView = fromView.findViewById(R.id.fake_page);

        // hideAppsCustomizeHelper is called in some cases when it is already hidden
        // don't perform all these no-op animations. In particularly, this was causing
        // the all-apps button to pop in and out.
        if (fromView.getVisibility() == View.VISIBLE) {
            AppsCustomizePagedView.ContentType contentType = content.getContentType();
            final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;

            revealView.setBackgroundColor(getResources().getColor(R.color.widget_text_panel));

            int width = revealView.getMeasuredWidth();
            int height = revealView.getMeasuredHeight();
            float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);

            // Hide the real page background, and swap in the fake one
            revealView.setVisibility(View.VISIBLE);
            content.setPageBackgroundsVisible(false);

            final View allAppsButton = getAllAppsButton();
            revealView.setTranslationY(0);
            int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, allAppsButton, null);

            float xDrift = 0;
            float yDrift = 0;
            if (material) {
                yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
                xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
            } else {
                yDrift = 2 * height / 3;
                xDrift = 0;
            }

            revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            TimeInterpolator decelerateInterpolator = material ? new LogDecelerateInterpolator(100, 0)
                    : new DecelerateInterpolator(1f);

            // The vertical motion of the apps panel should be delayed by one frame
            // from the conceal animation in order to give the right feel. We correpsondingly
            // shorten the duration so that the slide and conceal end at the same time.
            ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY", 0, yDrift);
            panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
            panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
            panelDriftY.setInterpolator(decelerateInterpolator);
            mStateAnimation.play(panelDriftY);

            ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX", 0, xDrift);
            panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
            panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
            panelDriftX.setInterpolator(decelerateInterpolator);
            mStateAnimation.play(panelDriftX);

            if (isWidgetTray || !material) {
                float finalAlpha = material ? 0.4f : 0f;
                revealView.setAlpha(1f);
                ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha", 1f, finalAlpha);
                panelAlpha.setDuration(material ? revealDuration : 150);
                panelAlpha.setInterpolator(decelerateInterpolator);
                panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY);
                mStateAnimation.play(panelAlpha);
            }

            if (page != null) {
                page.setLayerType(View.LAYER_TYPE_HARDWARE, null);

                ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY", 0, yDrift);
                page.setTranslationY(0);
                pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
                pageDrift.setInterpolator(decelerateInterpolator);
                pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
                mStateAnimation.play(pageDrift);

                page.setAlpha(1f);
                ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
                itemsAlpha.setDuration(100);
                itemsAlpha.setInterpolator(decelerateInterpolator);
                mStateAnimation.play(itemsAlpha);
            }

            View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
            pageIndicators.setAlpha(1f);
            ObjectAnimator indicatorsAlpha = LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
            indicatorsAlpha.setDuration(revealDuration);
            indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
            mStateAnimation.play(indicatorsAlpha);

            width = revealView.getMeasuredWidth();

            if (material) {
                if (!isWidgetTray) {
                    allAppsButton.setVisibility(View.INVISIBLE);
                }
                int allAppsButtonSize = LauncherAppState.getInstance().getDynamicGrid()
                        .getDeviceProfile().allAppsButtonVisualSize;
                float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
                Animator reveal = LauncherAnimUtils.createCircularReveal(revealView, width / 2, height / 2,
                        revealRadius, finalRadius);
                reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
                reveal.setDuration(revealDuration);
                reveal.setStartDelay(itemsAlphaStagger);

                reveal.addListener(new AnimatorListenerAdapter() {
                    public void onAnimationEnd(Animator animation) {
                        revealView.setVisibility(View.INVISIBLE);
                        if (!isWidgetTray) {
                            allAppsButton.setVisibility(View.VISIBLE);
                        }
                    }
                });

                mStateAnimation.play(reveal);
            }

            dispatchOnLauncherTransitionPrepare(fromView, animated, true);
            dispatchOnLauncherTransitionPrepare(toView, animated, true);
            mAppsCustomizeContent.stopScrolling();
        }

        mStateAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                fromView.setVisibility(View.GONE);
                dispatchOnLauncherTransitionEnd(fromView, animated, true);
                dispatchOnLauncherTransitionEnd(toView, animated, true);
                if (onCompleteRunnable != null) {
                    onCompleteRunnable.run();
                }

                revealView.setLayerType(View.LAYER_TYPE_NONE, null);
                if (page != null) {
                    page.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                content.setPageBackgroundsVisible(true);
                // Unhide side pages
                int count = content.getChildCount();
                for (int i = 0; i < count; i++) {
                    View child = content.getChildAt(i);
                    child.setVisibility(View.VISIBLE);
                }

                // Reset page transforms
                if (page != null) {
                    page.setTranslationX(0);
                    page.setTranslationY(0);
                    page.setAlpha(1);
                }
                content.setCurrentPage(content.getNextPage());

                mAppsCustomizeContent.updateCurrentPageScroll();

                // This can hold unnecessary references to views.
                mStateAnimation = null;
            }
        });

        final AnimatorSet stateAnimation = mStateAnimation;
        final Runnable startAnimRunnable = new Runnable() {
            public void run() {
                // Check that mStateAnimation hasn't changed while
                // we waited for a layout/draw pass
                if (mStateAnimation != stateAnimation)
                    return;
                dispatchOnLauncherTransitionStart(fromView, animated, false);
                dispatchOnLauncherTransitionStart(toView, animated, false);

                if (Utilities.isLmpOrAbove()) {
                    for (int i = 0; i < layerViews.size(); i++) {
                        View v = layerViews.get(i);
                        if (v != null) {
                            if (Utilities.isViewAttachedToWindow(v))
                                v.buildLayer();
                        }
                    }
                }
                mStateAnimation.start();
            }
        };
        fromView.post(startAnimRunnable);
    } else {
        fromView.setVisibility(View.GONE);
        dispatchOnLauncherTransitionPrepare(fromView, animated, true);
        dispatchOnLauncherTransitionStart(fromView, animated, true);
        dispatchOnLauncherTransitionEnd(fromView, animated, true);
        dispatchOnLauncherTransitionPrepare(toView, animated, true);
        dispatchOnLauncherTransitionStart(toView, animated, true);
        dispatchOnLauncherTransitionEnd(toView, animated, true);
    }
}