Example usage for android.animation ValueAnimator setInterpolator

List of usage examples for android.animation ValueAnimator setInterpolator

Introduction

In this page you can find the example usage for android.animation ValueAnimator setInterpolator.

Prototype

@Override
public void setInterpolator(TimeInterpolator value) 

Source Link

Document

The time interpolator used in calculating the elapsed fraction of this animation.

Usage

From source file:com.aidy.launcher3.ui.workspace.Workspace.java

public Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
    if (mState == state) {
        return null;
    }/*w  w  w  .j  a v  a 2s  . c o  m*/

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

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

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

    boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall);
    boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal);
    boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview);
    boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal);

    mNewScale = 1.0f;

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

    if (state != State.NORMAL) {
        if (stateIsSpringLoaded) {
            mNewScale = mSpringLoadedShrinkFactor;
        } else if (stateIsOverview) {
            mNewScale = mOverviewModeShrinkFactor;
        } else if (stateIsSmall) {
            mNewScale = mOverviewModeShrinkFactor - 0.3f;
        }
        if (workspaceToAllApps) {
            updateChildrenLayersEnabled(false);
        }
    }

    final int duration;
    if (workspaceToAllApps) {
        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);
    }

    for (int i = 0; i < getChildCount(); i++) {
        final CellLayout cl = (CellLayout) getChildAt(i);
        boolean isCurrentPage = (i == getNextPage());
        float initialAlpha = cl.getShortcutsAndWidgets().getAlpha();
        float finalAlpha = stateIsSmall ? 0f : 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();
    if (animated) {
        anim.setDuration(duration);
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY)
                .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 (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) {
                    LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator(
                            cl.getShortcutsAndWidgets());
                    alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator);
                    anim.play(alphaAnim);
                }
                if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) {
                    ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f);
                    bgAnim.setInterpolator(mZoomInInterpolator);
                    bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
                        public void onAnimationUpdate(float a, float b) {
                            cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]);
                        }
                    });
                    anim.play(bgAnim);
                }
            }
        }
        ObjectAnimator pageIndicatorAlpha = null;
        if (getPageIndicator() != null) {
            pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha",
                    finalHotseatAndPageIndicatorAlpha);
        }
        ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(hotseat, "alpha",
                finalHotseatAndPageIndicatorAlpha);
        ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(searchBar, "alpha", finalSearchBarAlpha);
        ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha",
                finalOverviewPanelAlpha);

        overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel));
        hotseatAlpha.addListener(new AlphaUpdateListener(hotseat));
        searchBarAlpha.addListener(new AlphaUpdateListener(searchBar));

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

        if (getPageIndicator() != null) {
            pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator()));
        }

        anim.play(overviewPanelAlpha);
        anim.play(hotseatAlpha);
        anim.play(searchBarAlpha);
        anim.play(pageIndicatorAlpha);
        anim.setStartDelay(delay);
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha);
        AlphaUpdateListener.updateVisibility(hotseat);
        if (getPageIndicator() != null) {
            getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(getPageIndicator());
        }
        searchBar.setAlpha(finalSearchBarAlpha);
        AlphaUpdateListener.updateVisibility(searchBar);
        updateCustomContentVisibility();
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }
    mLauncher.updateVoiceButtonProxyVisible(false);

    if (stateIsSpringLoaded) {
        // Right now we're covered by Apps Customize
        // Show the background gradient immediately, so the gradient will
        // be showing once AppsCustomize disappears
        animateBackgroundGradient(
                getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false);
    } else if (stateIsOverview) {
        animateBackgroundGradient(
                getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true);
    } else {
        // Fade the background gradient away
        animateBackgroundGradient(0f, animated);
    }
    return anim;
}

From source file:com.auratech.launcher.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
    if (mState == state) {
        return null;
    }/*from  w w  w  .jav  a2 s  .co  m*/

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

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

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

    boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall);
    boolean allAppsToWorkspace = (oldStateIsSmall && 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) {
            mNewScale = mOverviewModeShrinkFactor;
        } else if (stateIsSmall) {
            mNewScale = mOverviewModeShrinkFactor - 0.3f;
        }
        if (workspaceToAllApps) {
            updateChildrenLayersEnabled(false);
        }
    }

    final int duration;
    if (workspaceToAllApps) {
        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 (stateIsSmall) {
            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) {
        anim.setDuration(duration);
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY)
                .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 (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) {
                    LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator(
                            cl.getShortcutsAndWidgets());
                    alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator);
                    anim.play(alphaAnim);
                }
                if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) {
                    ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f);
                    bgAnim.setInterpolator(mZoomInInterpolator);
                    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 searchBarAlpha = new LauncherViewPropertyAnimator(searchBar).alpha(finalSearchBarAlpha)
                .withLayer();
        searchBarAlpha.addListener(new AlphaUpdateListener(searchBar));

        Animator overviewPanelAlpha = new LauncherViewPropertyAnimator(overviewPanel)
                .alpha(finalOverviewPanelAlpha).withLayer();
        overviewPanelAlpha.addListener(new AlphaUpdateListener(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));
        }
        searchBarAlpha.setInterpolator(null);

        anim.play(overviewPanelAlpha);
        anim.play(hotseatAlpha);
        anim.play(searchBarAlpha);
        anim.play(pageIndicatorAlpha);
        anim.setStartDelay(delay);
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha);
        AlphaUpdateListener.updateVisibility(hotseat);
        if (pageIndicator != null) {
            pageIndicator.setAlpha(finalHotseatAndPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(pageIndicator);
        }
        searchBar.setAlpha(finalSearchBarAlpha);
        AlphaUpdateListener.updateVisibility(searchBar);
        updateCustomContentVisibility();
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }
    mLauncher.updateVoiceButtonProxyVisible(false);

    if (stateIsSpringLoaded) {
        // Right now we're covered by Apps Customize
        // Show the background gradient immediately, so the gradient will
        // be showing once AppsCustomize disappears
        animateBackgroundGradient(
                getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false);
    } else if (stateIsOverview) {
        animateBackgroundGradient(
                getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true);
    } else {
        // Fade the background gradient away
        animateBackgroundGradient(0f, animated);
    }
    return anim;
}

From source file:com.zyk.launcher.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage,
        ArrayList<View> layerViews) {
    System.out.println("workspace getChangeStateAnimation");
    if (mState == state) {
        return null;
    }//ww w .j  ava2  s.co m

    /**
     * Menu??
     * NORMAL_HIDDEN true -1,[]
     */
    // 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 finalHotseatAndPageIndicatorAlpha = 1f;
    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.phonemetra.turbo.launcher.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
    if (mState == state) {
        return null;
    }/*from  www. ja v a  2 s .co  m*/

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

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

    final State oldState = mState;
    final boolean oldStateIsNormal = (oldState == State.NORMAL);
    final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED);
    final boolean oldStateIsSmall = (oldState == State.SMALL);
    final boolean oldStateIsOverview = (oldState == State.OVERVIEW);
    setState(state);
    final boolean stateIsNormal = (state == State.NORMAL);
    final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED);
    final boolean stateIsSmall = (state == State.SMALL);
    final boolean stateIsOverview = (state == State.OVERVIEW);
    float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f;
    float finalBackgroundAlphaMultiplier = (stateIsSpringLoaded || stateIsOverview || mShowOutlines) ? 1.0f
            : 0f;
    float finalHotseatAndPageIndicatorAlpha = (stateIsOverview || stateIsSmall) ? 0f : 1f;
    float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f;
    float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f;
    float finalWorkspaceTranslationY = stateIsOverview ? getOverviewModeTranslationY() : 0;

    boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall);
    boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal);
    boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview);
    boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal);

    mNewScale = 1.0f;

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

    if (state != State.NORMAL) {
        if (stateIsSpringLoaded) {
            mNewScale = mSpringLoadedShrinkFactor;
        } else if (stateIsOverview) {
            mNewScale = getOverviewModeScaleY();
        } else if (stateIsSmall) {
            mNewScale = mOverviewModeShrinkFactor - 0.3f;
        }
        if (workspaceToAllApps) {
            updateChildrenLayersEnabled(false);
        }
    }

    final int duration;
    if (workspaceToAllApps) {
        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 (stateIsSmall) {
            finalAlpha = 0f;
        } else if (stateIsNormal && mWorkspaceFadeInAdjacentScreens) {
            finalAlpha = (i == snapPage || i < numCustomPages()) ? 1f : 0f;
        } else {
            finalAlpha = 1f;
        }

        if (stateIsOverview) {
            cl.setVisibility(VISIBLE);
            cl.setTranslationX(0f);
            cl.setTranslationY(0f);
            cl.setPivotX(cl.getMeasuredWidth() * 0.5f);
            cl.setPivotY(cl.getMeasuredHeight() * 0.5f);
            cl.setRotation(0f);
            cl.setRotationY(0f);
            cl.setRotationX(0f);
            cl.setScaleX(1f);
            cl.setScaleY(1f);
            cl.setShortcutAndWidgetAlpha(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();
            mOldBackgroundAlphaMultipliers[i] = cl.getBackgroundAlphaMultiplier();
            mNewBackgroundAlphas[i] = finalBackgroundAlpha;
            mNewBackgroundAlphaMultipliers[i] = finalBackgroundAlphaMultiplier;
        } else {
            cl.setBackgroundAlpha(finalBackgroundAlpha);
            cl.setBackgroundAlphaMultiplier(finalBackgroundAlphaMultiplier);
            cl.setShortcutAndWidgetAlpha(finalAlpha);
        }
    }

    final View searchBar = mLauncher.getQsbBar();
    final View overviewPanel = mLauncher.getOverviewPanel();
    final View hotseat = mLauncher.getHotseat();
    final View pageIndicator = getPageIndicator();
    if (animated) {
        anim.setDuration(duration);
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY)
                .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 (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) {
                    LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator(
                            cl.getShortcutsAndWidgets());
                    alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator);
                    anim.play(alphaAnim);
                }
                if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) {
                    ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f);
                    bgAnim.setInterpolator(mZoomInInterpolator);
                    bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
                        public void onAnimationUpdate(float a, float b) {
                            cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]);
                            cl.setBackgroundAlphaMultiplier(a * mOldBackgroundAlphaMultipliers[i]
                                    + b * mNewBackgroundAlphaMultipliers[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 searchBarAlpha = new LauncherViewPropertyAnimator(searchBar).alpha(finalSearchBarAlpha)
                .withLayer();
        if (mShowSearchBar)
            searchBarAlpha.addListener(new AlphaUpdateListener(searchBar));

        Animator overviewPanelAlpha = new LauncherViewPropertyAnimator(overviewPanel)
                .alpha(finalOverviewPanelAlpha).withLayer();
        overviewPanelAlpha.addListener(new AlphaUpdateListener(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));
        }
        searchBarAlpha.setInterpolator(null);

        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        Animation animation = AnimationUtils.loadAnimation(mLauncher, R.anim.drop_down);
        overviewPanel.startAnimation(animation);
        anim.play(hotseatAlpha);
        if (mShowSearchBar)
            anim.play(searchBarAlpha);
        anim.play(pageIndicatorAlpha);
        anim.setStartDelay(delay);
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha);
        AlphaUpdateListener.updateVisibility(hotseat);
        if (pageIndicator != null) {
            pageIndicator.setAlpha(finalHotseatAndPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(pageIndicator);
        }
        if (mShowSearchBar) {
            searchBar.setAlpha(finalSearchBarAlpha);
            AlphaUpdateListener.updateVisibility(searchBar);
        }
        updateCustomContentVisibility();
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }
    mLauncher.updateVoiceButtonProxyVisible(false);

    if (stateIsSpringLoaded) {
        // Right now we're covered by Apps Customize
        // Show the background gradient immediately, so the gradient will
        // be showing once AppsCustomize disappears
        animateBackgroundGradient(
                getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false);
    } else if (stateIsOverview) {
        animateBackgroundGradient(
                getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true);
    } else {
        // Fade the background gradient away
        animateBackgroundGradient(0f, animated);
    }
    return anim;
}

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

private ValueAnimator createNewAppBounceAnimation(View v, int i) {
    ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
    bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
    bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
    bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
    return bounceAnim;
}

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

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
    if (mState == state) {
        return null;
    }//from  w  w  w  . j  a va 2s  .c o  m

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

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

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

    boolean workspaceToAllApps = (oldStateIsNormal && stateIsSmall);
    boolean allAppsToWorkspace = (oldStateIsSmall && stateIsNormal);
    boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview);
    boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal);

    mNewScale = 1.0f;

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

    if (state != State.NORMAL) {
        if (stateIsSpringLoaded) {
            mNewScale = mSpringLoadedShrinkFactor;
        } else if (stateIsOverview) {
            mNewScale = mOverviewModeShrinkFactor;
        } else if (stateIsSmall) {
            mNewScale = mOverviewModeShrinkFactor - 0.3f;
        }
        if (workspaceToAllApps) {
            updateChildrenLayersEnabled(false);
        }
    }

    final int duration;
    if (workspaceToAllApps) {
        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);
    }

    for (int i = 0; i < getChildCount(); i++) {
        final CellLayout cl = (CellLayout) getChildAt(i);
        boolean isCurrentPage = (i == getNextPage());
        float initialAlpha = cl.getShortcutsAndWidgets().getAlpha();
        float finalAlpha = stateIsSmall ? 0f : 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();
    if (animated) {
        anim.setDuration(duration);
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY)
                .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 (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) {
                    LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator(
                            cl.getShortcutsAndWidgets());
                    alphaAnim.alpha(mNewAlphas[i]).setInterpolator(mZoomInInterpolator);
                    anim.play(alphaAnim);
                }
                if (mOldBackgroundAlphas[i] != 0 || mNewBackgroundAlphas[i] != 0) {
                    ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(cl, 0f, 1f);
                    bgAnim.setInterpolator(mZoomInInterpolator);
                    bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
                        public void onAnimationUpdate(float a, float b) {
                            cl.setBackgroundAlpha(a * mOldBackgroundAlphas[i] + b * mNewBackgroundAlphas[i]);
                        }
                    });
                    anim.play(bgAnim);
                }
            }
        }
        ObjectAnimator pageIndicatorAlpha = null;
        if (getPageIndicator() != null) {
            pageIndicatorAlpha = ObjectAnimator.ofFloat(getPageIndicator(), "alpha",
                    finalHotseatAndPageIndicatorAlpha);
        }
        ObjectAnimator hotseatAlpha = ObjectAnimator.ofFloat(hotseat, "alpha",
                finalHotseatAndPageIndicatorAlpha);
        ObjectAnimator searchBarAlpha = ObjectAnimator.ofFloat(searchBar, "alpha", finalSearchBarAlpha);
        ObjectAnimator overviewPanelAlpha = ObjectAnimator.ofFloat(overviewPanel, "alpha",
                finalOverviewPanelAlpha);

        overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel));
        hotseatAlpha.addListener(new AlphaUpdateListener(hotseat));
        searchBarAlpha.addListener(new AlphaUpdateListener(searchBar));

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

        if (getPageIndicator() != null) {
            pageIndicatorAlpha.addListener(new AlphaUpdateListener(getPageIndicator()));
        }

        anim.play(overviewPanelAlpha);
        anim.play(hotseatAlpha);
        ///added by zxa for uninstall app
        if (!TydtechConfig.TYDTECH_UNINSTALL_MIUI_FLAG) {
            anim.play(searchBarAlpha);
        }
        ///
        anim.play(pageIndicatorAlpha);
        anim.setStartDelay(delay);
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha);
        AlphaUpdateListener.updateVisibility(hotseat);
        if (getPageIndicator() != null) {
            getPageIndicator().setAlpha(finalHotseatAndPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(getPageIndicator());
        }
        //*/added by zxa for uninstall app
        if (!TydtechConfig.TYDTECH_UNINSTALL_MIUI_FLAG) {
            searchBar.setAlpha(finalSearchBarAlpha);
            AlphaUpdateListener.updateVisibility(searchBar);
        }
        //*/

        updateCustomContentVisibility();
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }
    mLauncher.updateVoiceButtonProxyVisible(false);

    if (stateIsSpringLoaded) {
        // Right now we're covered by Apps Customize
        // Show the background gradient immediately, so the gradient will
        // be showing once AppsCustomize disappears
        animateBackgroundGradient(
                getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false);
    } else if (stateIsOverview) {
        animateBackgroundGradient(
                getResources().getInteger(R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, true);
    } else {
        // Fade the background gradient away
        animateBackgroundGradient(0f, animated);
    }
    return anim;
}

From source file:com.fairphone.fplauncher3.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  ava  2s. c  o  m

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

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

    final State oldState = mState;
    final boolean oldStateIsNormal = (oldState == State.NORMAL);
    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;
    final 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 overviewPanel = mLauncher.getOverviewPanel();
    final View pageIndicator = getPageIndicator();
    if (animated) {
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY).setDuration(duration)
                .setInterpolator(mZoomInInterpolator);
        scale.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                // in low power mode the animation doesn't play, so set the end value here
                setScaleX(mNewScale);
                setScaleY(mNewScale);
                setTranslationY(finalWorkspaceTranslationY);
            }
        });
        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]) {
                    final View shortcutAndWidgets = cl.getShortcutsAndWidgets();
                    LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator(
                            shortcutAndWidgets);
                    alphaAnim.alpha(mNewAlphas[i]).setDuration(duration).setInterpolator(mZoomInInterpolator);
                    alphaAnim.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            // in low power mode the animation doesn't play,
                            // so set the end value here
                            shortcutAndWidgets.setAlpha(mNewAlphas[i]);
                        }
                    });
                    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;
        if (pageIndicator != null) {
            pageIndicatorAlpha = new LauncherViewPropertyAnimator(pageIndicator)
                    .alpha(finalHotseatAndPageIndicatorAlpha).withLayer();
            pageIndicatorAlpha
                    .addListener(new AlphaUpdateListener(pageIndicator, finalHotseatAndPageIndicatorAlpha));
        } else {
            // create a dummy animation so we don't need to do null checks later
            pageIndicatorAlpha = ValueAnimator.ofFloat(0, 0);
        }

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

        // 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.
        overviewPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        if (layerViews != null) {
            layerViews.add(overviewPanel);
        }

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

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

        anim.play(overviewPanelAlpha);
        anim.play(pageIndicatorAlpha);
        anim.setStartDelay(delay);
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        if (pageIndicator != null) {
            pageIndicator.setAlpha(finalHotseatAndPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(pageIndicator);
        }
        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.launcher4.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  a v  a 2 s  . c om*/

    // 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.klinker.android.launcher.launcher3.Launcher.java

private ValueAnimator createNewAppBounceAnimation(View v, int i) {
    ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
            PropertyValuesHolder.ofFloat("alpha", 1f), PropertyValuesHolder.ofFloat("scaleX", 1f),
            PropertyValuesHolder.ofFloat("scaleY", 1f));
    bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
    bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
    bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));
    return bounceAnim;
}

From source file:com.upchannel.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  om

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

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

    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 searchBarAlpha = new LauncherViewPropertyAnimator(searchBar).alpha(finalSearchBarAlpha)
                .withLayer();
        searchBarAlpha.addListener(new AlphaUpdateListener(searchBar));

        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);
        searchBar.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        overviewPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        if (layerViews != null) {
            layerViews.add(hotseat);
            layerViews.add(searchBar);
            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);
        searchBarAlpha.setDuration(duration);

        anim.play(overviewPanelAlpha);
        anim.play(hotseatAlpha);
        anim.play(searchBarAlpha);
        anim.play(pageIndicatorAlpha);
        anim.setStartDelay(delay);
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha);
        AlphaUpdateListener.updateVisibility(hotseat);
        if (pageIndicator != null) {
            pageIndicator.setAlpha(finalHotseatAndPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(pageIndicator);
        }
        searchBar.setAlpha(finalSearchBarAlpha);
        AlphaUpdateListener.updateVisibility(searchBar);
        updateCustomContentVisibility();
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }
    mLauncher.updateVoiceButtonProxyVisible(false);

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