Example usage for android.animation AnimatorSet setStartDelay

List of usage examples for android.animation AnimatorSet setStartDelay

Introduction

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

Prototype

@Override
public void setStartDelay(long startDelay) 

Source Link

Document

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

Usage

From source file:myblog.richard.vewe.launcher3.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage,
        ArrayList<View> layerViews) {
    if (mState == state) {
        return null;
    }//from  w  w  w . j  a  v  a 2s.  c o m
    if (mState == State.OVERVIEW || state == State.OVERVIEW) {
        changeState(state);
        return null;
    }

    // Initialize animation arrays for the first time if necessary
    initAnimationArrays();

    AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null;

    // We only want a single instance of a workspace animation to be running at once, so
    // we cancel any incomplete transition.
    if (mStateAnimator != null) {
        mStateAnimator.cancel();
    }
    mStateAnimator = anim;

    final State oldState = mState;
    final boolean oldStateIsNormal = (oldState == State.NORMAL);
    final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED);
    final boolean oldStateIsNormalHidden = (oldState == State.NORMAL_HIDDEN);
    final boolean oldStateIsOverviewHidden = (oldState == State.OVERVIEW_HIDDEN);
    final boolean oldStateIsOverview = (oldState == State.OVERVIEW);
    setState(state);
    final boolean stateIsNormal = (state == State.NORMAL);
    final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED);
    final boolean stateIsNormalHidden = (state == State.NORMAL_HIDDEN);
    final boolean stateIsOverviewHidden = (state == State.OVERVIEW_HIDDEN);
    final boolean stateIsOverview = (state == State.OVERVIEW);
    float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f;
    float finalHotseatAndPageIndicatorAlpha = (stateIsNormal || stateIsSpringLoaded) ? 1f : 0f;
    float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f;
    float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f;
    float finalWorkspaceTranslationY = stateIsOverview || stateIsOverviewHidden ? getOverviewModeTranslationY()
            : 0;

    boolean workspaceToAllApps = (oldStateIsNormal && stateIsNormalHidden);
    boolean overviewToAllApps = (oldStateIsOverview && stateIsOverviewHidden);
    boolean allAppsToWorkspace = (stateIsNormalHidden && stateIsNormal);
    boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview);
    boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal);

    mNewScale = 1.0f;

    if (oldStateIsOverview) {
        disableFreeScroll();
    } else if (stateIsOverview) {
        enableFreeScroll();
    }

    if (state != State.NORMAL) {
        if (stateIsSpringLoaded) {
            mNewScale = mSpringLoadedShrinkFactor;
        } else if (stateIsOverview || stateIsOverviewHidden) {
            mNewScale = mOverviewModeShrinkFactor;
        }
    }

    final int duration;
    if (workspaceToAllApps || overviewToAllApps) {
        duration = HIDE_WORKSPACE_DURATION; //getResources().getInteger(R.integer.config_workspaceUnshrinkTime);
    } else if (workspaceToOverview || overviewToWorkspace) {
        duration = getResources().getInteger(R.integer.config_overviewTransitionTime);
    } else {
        duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime);
    }

    if (snapPage == -1) {
        snapPage = getPageNearestToCenterOfScreen();
    }
    snapToPage(snapPage, duration, mZoomInInterpolator);

    for (int i = 0; i < getChildCount(); i++) {
        final CellLayout cl = (CellLayout) getChildAt(i);
        boolean isCurrentPage = (i == snapPage);
        float initialAlpha = cl.getShortcutsAndWidgets().getAlpha();
        float finalAlpha;
        if (stateIsNormalHidden || stateIsOverviewHidden) {
            finalAlpha = 0f;
        } else if (stateIsNormal && mWorkspaceFadeInAdjacentScreens) {
            finalAlpha = (i == snapPage || i < numCustomPages()) ? 1f : 0f;
        } else {
            finalAlpha = 1f;
        }

        // If we are animating to/from the small state, then hide the side pages and fade the
        // current page in
        if (!mIsSwitchingState) {
            if (workspaceToAllApps || allAppsToWorkspace) {
                if (allAppsToWorkspace && isCurrentPage) {
                    initialAlpha = 0f;
                } else if (!isCurrentPage) {
                    initialAlpha = finalAlpha = 0f;
                }
                cl.setShortcutAndWidgetAlpha(initialAlpha);
            }
        }

        mOldAlphas[i] = initialAlpha;
        mNewAlphas[i] = finalAlpha;
        if (animated) {
            mOldBackgroundAlphas[i] = cl.getBackgroundAlpha();
            mNewBackgroundAlphas[i] = finalBackgroundAlpha;
        } else {
            cl.setBackgroundAlpha(finalBackgroundAlpha);
            cl.setShortcutAndWidgetAlpha(finalAlpha);
        }
    }

    final View searchBar = mLauncher.getQsbBar();
    final View overviewPanel = mLauncher.getOverviewPanel();
    final View hotseat = mLauncher.getHotseat();
    final View pageIndicator = getPageIndicator();
    if (animated) {
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY).setDuration(duration)
                .setInterpolator(mZoomInInterpolator);
        anim.play(scale);
        for (int index = 0; index < getChildCount(); index++) {
            final int i = index;
            final CellLayout cl = (CellLayout) getChildAt(i);
            float currentAlpha = cl.getShortcutsAndWidgets().getAlpha();
            if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) {
                cl.setBackgroundAlpha(mNewBackgroundAlphas[i]);
                cl.setShortcutAndWidgetAlpha(mNewAlphas[i]);
            } else {
                if (layerViews != null) {
                    layerViews.add(cl);
                }
                if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) {
                    LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator(
                            cl.getShortcutsAndWidgets());
                    alphaAnim.alpha(mNewAlphas[i]).setDuration(duration).setInterpolator(mZoomInInterpolator);
                    anim.play(alphaAnim);
                }
                if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) {
                    ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f);
                    bgAnim.setInterpolator(mZoomInInterpolator);
                    bgAnim.setDuration(duration);
                    bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
                        public void onAnimationUpdate(float a, float b) {
                            cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]);
                        }
                    });
                    anim.play(bgAnim);
                }
            }
        }
        Animator pageIndicatorAlpha = null;
        if (pageIndicator != null) {
            pageIndicatorAlpha = new LauncherViewPropertyAnimator(pageIndicator)
                    .alpha(finalHotseatAndPageIndicatorAlpha).withLayer();
            pageIndicatorAlpha.addListener(new AlphaUpdateListener(pageIndicator));
        } else {
            // create a dummy animation so we don't need to do null checks later
            pageIndicatorAlpha = ValueAnimator.ofFloat(0, 0);
        }

        Animator hotseatAlpha = new LauncherViewPropertyAnimator(hotseat)
                .alpha(finalHotseatAndPageIndicatorAlpha).withLayer();
        hotseatAlpha.addListener(new AlphaUpdateListener(hotseat));

        Animator overviewPanelAlpha = new LauncherViewPropertyAnimator(overviewPanel)
                .alpha(finalOverviewPanelAlpha).withLayer();
        overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel));

        // For animation optimations, we may need to provide the Launcher transition
        // with a set of views on which to force build layers in certain scenarios.
        hotseat.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        overviewPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        if (layerViews != null) {
            layerViews.add(hotseat);
            layerViews.add(overviewPanel);
        }

        if (workspaceToOverview) {
            pageIndicatorAlpha.setInterpolator(new DecelerateInterpolator(2));
            hotseatAlpha.setInterpolator(new DecelerateInterpolator(2));
            overviewPanelAlpha.setInterpolator(null);
        } else if (overviewToWorkspace) {
            pageIndicatorAlpha.setInterpolator(null);
            hotseatAlpha.setInterpolator(null);
            overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2));
        }

        overviewPanelAlpha.setDuration(duration);
        pageIndicatorAlpha.setDuration(duration);
        hotseatAlpha.setDuration(duration);

        if (searchBar != null) {
            Animator searchBarAlpha = new LauncherViewPropertyAnimator(searchBar).alpha(finalSearchBarAlpha)
                    .withLayer();
            searchBarAlpha.addListener(new AlphaUpdateListener(searchBar));
            searchBar.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            if (layerViews != null) {
                layerViews.add(searchBar);
            }
            searchBarAlpha.setDuration(duration);
            anim.play(searchBarAlpha);
        }

        anim.play(overviewPanelAlpha);
        anim.play(hotseatAlpha);
        anim.play(pageIndicatorAlpha);
        anim.setStartDelay(delay);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mStateAnimator = null;
            }
        });
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha);
        AlphaUpdateListener.updateVisibility(hotseat);
        if (pageIndicator != null) {
            pageIndicator.setAlpha(finalHotseatAndPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(pageIndicator);
        }
        if (searchBar != null) {
            searchBar.setAlpha(finalSearchBarAlpha);
            AlphaUpdateListener.updateVisibility(searchBar);
        }
        updateCustomContentVisibility();
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }

    if (stateIsNormal) {
        animateBackgroundGradient(0f, animated);
    } else {
        animateBackgroundGradient(getResources().getInteger(R.integer.config_workspaceScrimAlpha) / 100f,
                animated);
    }
    return anim;
}

From source file:com.android.launcher3.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage,
        ArrayList<View> layerViews) {
    if (mState == state) {
        return null;
    }//from ww  w .j  av  a2  s .c  o m

    // Initialize animation arrays for the first time if necessary
    initAnimationArrays();

    AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null;

    // We only want a single instance of a workspace animation to be running at once, so
    // we cancel any incomplete transition.
    if (mStateAnimator != null) {
        mStateAnimator.cancel();
    }
    mStateAnimator = anim;

    final State oldState = mState;
    final boolean oldStateIsNormal = (oldState == State.NORMAL);
    final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED);
    final boolean oldStateIsNormalHidden = (oldState == State.NORMAL_HIDDEN);
    final boolean oldStateIsOverviewHidden = (oldState == State.OVERVIEW_HIDDEN);
    final boolean oldStateIsOverview = (oldState == State.OVERVIEW);
    setState(state);
    final boolean stateIsNormal = (state == State.NORMAL);
    final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED);
    final boolean stateIsNormalHidden = (state == State.NORMAL_HIDDEN);
    final boolean stateIsOverviewHidden = (state == State.OVERVIEW_HIDDEN);
    final boolean stateIsOverview = (state == State.OVERVIEW);
    float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f;
    float finalHotseatAndPageIndicatorAlpha = (stateIsNormal || stateIsSpringLoaded) ? 1f : 0f;
    float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f;
    float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f;
    float finalWorkspaceTranslationY = stateIsOverview || stateIsOverviewHidden ? getOverviewModeTranslationY()
            : 0;

    boolean workspaceToAllApps = (oldStateIsNormal && stateIsNormalHidden);
    boolean overviewToAllApps = (oldStateIsOverview && stateIsOverviewHidden);
    boolean allAppsToWorkspace = (stateIsNormalHidden && stateIsNormal);
    boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview);
    boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal);

    mNewScale = 1.0f;

    if (oldStateIsOverview) {
        disableFreeScroll();
    } else if (stateIsOverview) {
        enableFreeScroll();
    }

    if (state != State.NORMAL) {
        if (stateIsSpringLoaded) {
            mNewScale = mSpringLoadedShrinkFactor;
        } else if (stateIsOverview || stateIsOverviewHidden) {
            mNewScale = mOverviewModeShrinkFactor;
        }
    }

    final int duration;
    if (workspaceToAllApps || overviewToAllApps) {
        duration = HIDE_WORKSPACE_DURATION; //getResources().getInteger(R.integer.config_workspaceUnshrinkTime);
    } else if (workspaceToOverview || overviewToWorkspace) {
        duration = getResources().getInteger(R.integer.config_overviewTransitionTime);
    } else {
        duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime);
    }

    if (snapPage == -1) {
        snapPage = getPageNearestToCenterOfScreen();
    }
    snapToPage(snapPage, duration, mZoomInInterpolator);

    for (int i = 0; i < getChildCount(); i++) {
        final CellLayout cl = (CellLayout) getChildAt(i);
        boolean isCurrentPage = (i == snapPage);
        float initialAlpha = cl.getShortcutsAndWidgets().getAlpha();
        float finalAlpha;
        if (stateIsNormalHidden || stateIsOverviewHidden) {
            finalAlpha = 0f;
        } else if (stateIsNormal && mWorkspaceFadeInAdjacentScreens) {
            finalAlpha = (i == snapPage || i < numCustomPages()) ? 1f : 0f;
        } else {
            finalAlpha = 1f;
        }

        // If we are animating to/from the small state, then hide the side pages and fade the
        // current page in
        if (!mIsSwitchingState) {
            if (workspaceToAllApps || allAppsToWorkspace) {
                if (allAppsToWorkspace && isCurrentPage) {
                    initialAlpha = 0f;
                } else if (!isCurrentPage) {
                    initialAlpha = finalAlpha = 0f;
                }
                cl.setShortcutAndWidgetAlpha(initialAlpha);
            }
        }

        mOldAlphas[i] = initialAlpha;
        mNewAlphas[i] = finalAlpha;
        if (animated) {
            mOldBackgroundAlphas[i] = cl.getBackgroundAlpha();
            mNewBackgroundAlphas[i] = finalBackgroundAlpha;
        } else {
            cl.setBackgroundAlpha(finalBackgroundAlpha);
            cl.setShortcutAndWidgetAlpha(finalAlpha);
        }
    }

    // SPRD: bug371310 2014-11-19 Feature circular sliding.
    final View circularSlidingPanel = mLauncher.getCircularSlidingPanel();
    final View searchBar = mLauncher.getQsbBar();
    final View overviewPanel = mLauncher.getOverviewPanel();
    final View hotseat = mLauncher.getHotseat();
    final View pageIndicator = getPageIndicator();
    if (animated) {
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY).setDuration(duration)
                .setInterpolator(mZoomInInterpolator);
        anim.play(scale);
        for (int index = 0; index < getChildCount(); index++) {
            final int i = index;
            final CellLayout cl = (CellLayout) getChildAt(i);
            float currentAlpha = cl.getShortcutsAndWidgets().getAlpha();
            if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) {
                cl.setBackgroundAlpha(mNewBackgroundAlphas[i]);
                cl.setShortcutAndWidgetAlpha(mNewAlphas[i]);
            } else {
                if (layerViews != null) {
                    layerViews.add(cl);
                }
                if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) {
                    LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator(
                            cl.getShortcutsAndWidgets());
                    alphaAnim.alpha(mNewAlphas[i]).setDuration(duration).setInterpolator(mZoomInInterpolator);
                    anim.play(alphaAnim);
                }
                if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) {
                    ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f);
                    bgAnim.setInterpolator(mZoomInInterpolator);
                    bgAnim.setDuration(duration);
                    bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
                        public void onAnimationUpdate(float a, float b) {
                            cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]);
                        }
                    });
                    anim.play(bgAnim);
                }
            }
        }
        Animator pageIndicatorAlpha = null;
        if (pageIndicator != null) {
            pageIndicatorAlpha = new LauncherViewPropertyAnimator(pageIndicator)
                    .alpha(finalHotseatAndPageIndicatorAlpha).withLayer();
            pageIndicatorAlpha.addListener(new AlphaUpdateListener(pageIndicator));
        } else {
            // create a dummy animation so we don't need to do null checks later
            pageIndicatorAlpha = ValueAnimator.ofFloat(0, 0);
        }

        Animator hotseatAlpha = new LauncherViewPropertyAnimator(hotseat)
                .alpha(finalHotseatAndPageIndicatorAlpha).withLayer();
        hotseatAlpha.addListener(new AlphaUpdateListener(hotseat));

        Animator overviewPanelAlpha = new LauncherViewPropertyAnimator(overviewPanel)
                .alpha(finalOverviewPanelAlpha).withLayer();
        overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel));

        /* SPRD: bug371310 2014-11-19 Feature circular sliding. @{ */
        Animator circularSlidingPanelAlpha = new LauncherViewPropertyAnimator(circularSlidingPanel)
                .alpha(finalOverviewPanelAlpha).withLayer();
        circularSlidingPanelAlpha.addListener(new AlphaUpdateListener(circularSlidingPanel));
        /* SPRD: bug371310 2014-11-19 Feature circular sliding. @} */

        // For animation optimations, we may need to provide the Launcher transition
        // with a set of views on which to force build layers in certain scenarios.
        hotseat.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        overviewPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        // SPRD: bug371310 2014-11-19 Feature circular sliding.
        circularSlidingPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        if (layerViews != null) {
            layerViews.add(hotseat);
            layerViews.add(overviewPanel);
            // SPRD: bug371310 2014-11-19 Feature circular sliding.
            layerViews.add(circularSlidingPanel);
        }

        if (workspaceToOverview) {
            pageIndicatorAlpha.setInterpolator(new DecelerateInterpolator(2));
            hotseatAlpha.setInterpolator(new DecelerateInterpolator(2));
            overviewPanelAlpha.setInterpolator(null);
            // SPRD: bug371310 2014-11-19 Feature circular sliding.
            circularSlidingPanelAlpha.setInterpolator(null);
        } else if (overviewToWorkspace) {
            pageIndicatorAlpha.setInterpolator(null);
            hotseatAlpha.setInterpolator(null);
            overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2));
            // SPRD: bug371310 2014-11-19 Feature circular sliding.
            circularSlidingPanelAlpha.setInterpolator(new DecelerateInterpolator(2));
        }

        // SPRD: bug371310 2014-11-19 Feature circular sliding.
        circularSlidingPanelAlpha.setDuration(duration);
        overviewPanelAlpha.setDuration(duration);
        pageIndicatorAlpha.setDuration(duration);
        hotseatAlpha.setDuration(duration);

        if (searchBar != null) {
            Animator searchBarAlpha = new LauncherViewPropertyAnimator(searchBar).alpha(finalSearchBarAlpha)
                    .withLayer();
            searchBarAlpha.addListener(new AlphaUpdateListener(searchBar));
            searchBar.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            if (layerViews != null) {
                layerViews.add(searchBar);
            }
            searchBarAlpha.setDuration(duration);
            anim.play(searchBarAlpha);
        }

        // SPRD: bug371310 2014-11-19 Feature circular sliding.
        anim.play(circularSlidingPanelAlpha);
        anim.play(overviewPanelAlpha);
        anim.play(hotseatAlpha);
        anim.play(pageIndicatorAlpha);
        anim.setStartDelay(delay);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mStateAnimator = null;
            }
        });
    } else {
        /* SPRD: bug371310 2014-11-19 Feature circular sliding. @{ */
        circularSlidingPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(circularSlidingPanel);
        /* SPRD: bug371310 2014-11-19 Feature circular sliding. @} */

        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha);
        AlphaUpdateListener.updateVisibility(hotseat);
        if (pageIndicator != null) {
            pageIndicator.setAlpha(finalHotseatAndPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(pageIndicator);
        }
        if (searchBar != null) {
            searchBar.setAlpha(finalSearchBarAlpha);
            AlphaUpdateListener.updateVisibility(searchBar);
        }
        updateCustomContentVisibility();
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }

    if (stateIsNormal) {
        animateBackgroundGradient(0f, animated);
    } else {
        animateBackgroundGradient(getResources().getInteger(R.integer.config_workspaceScrimAlpha) / 100f,
                animated);
    }
    return anim;
}