Example usage for android.view View setAlpha

List of usage examples for android.view View setAlpha

Introduction

In this page you can find the example usage for android.view View setAlpha.

Prototype

public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha) 

Source Link

Document

Sets the opacity of the view to a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

Usage

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Animations to update the views on screen to their new positions.  For new views that aren't
 * currently on screen, animate them in using the specified animationInMode.
 *//*from   w  w  w. j a  v a2  s  . c o m*/
private List<Animator> addUpdateViewPositionsAnimators(List<Animator> animators, boolean cascadeAnimation,
        AnimationIn animationInMode, int startDelay) {
    final int childCount = getChildCount();
    if (childCount == 0) {
        return null;
    }

    if (animators == null) {
        animators = new ArrayList<Animator>();
    }

    int viewsAnimated = 0;
    for (int i = 0; i < childCount; i++) {
        final View childToAnimate = getChildAt(i);

        if (mViewsToAnimateOut.contains(childToAnimate)) {
            // If the stale views are still animating, then they are still laid out, so
            // getChildCount() would've accounted for them.  Since they have their own set
            // of animations to play, we'll skip over them in this loop.
            continue;
        }

        // Use progressive animation delay to create the staggered effect of animating
        // views.  This is done by having each view delay their animation by
        // ANIMATION_DELAY_IN_MS after the animation of the previous view.
        int animationDelay = startDelay + (cascadeAnimation ? viewsAnimated * ANIMATION_DELAY_IN_MS : 0);

        // Figure out whether a view with this item ID existed before
        final LayoutParams lp = (LayoutParams) childToAnimate.getLayoutParams();

        final ViewRectPair viewRectPair = mChildRectsForAnimation.get(lp.id);

        final int xTranslation;
        final int yTranslation;

        // If there is a valid {@link Rect} for the view with this newId, then
        // setup an animation.
        if (viewRectPair != null && viewRectPair.rect != null) {
            // In the special case where the items are explicitly fading, we don't want to do
            // any of the translations.
            if (animationInMode == AnimationIn.FADE) {
                SgvAnimationHelper.addFadeAnimators(animators, childToAnimate, 0 /* start alpha */,
                        1.0f /* end alpha */, animationDelay);
                continue;
            }

            final Rect oldRect = viewRectPair.rect;
            // Since the view already exists, translate it to its new position.
            // Reset the child back to its previous position given by oldRect if the child
            // has not already been translated.  If the child has been translated, use the
            // current translated values, as this child may be in the middle of a previous
            // animation, so we don't want to simply force it to new location.

            xTranslation = oldRect.left - childToAnimate.getLeft();
            yTranslation = oldRect.top - childToAnimate.getTop();
            final float rotation = childToAnimate.getRotation();

            // First set the translation X and Y. The current translation might be out of date.
            childToAnimate.setTranslationX(xTranslation);
            childToAnimate.setTranslationY(yTranslation);

            if (xTranslation == 0 && yTranslation == 0 && rotation == 0) {
                // Bail early if this view doesn't need to be translated.
                continue;
            }

            SgvAnimationHelper.addTranslationRotationAnimators(animators, childToAnimate, xTranslation,
                    yTranslation, rotation, animationDelay);
        } else {
            // If this view was not present before the data updated, rather than just flashing
            // the view into its designated position, fly it up from the bottom.
            xTranslation = 0;
            yTranslation = (animationInMode == AnimationIn.FLY_IN_NEW_VIEWS) ? getHeight() : 0;

            // Since this is a new view coming in, add additional delays so that these IN
            // animations start after all the OUT animations have been played.
            animationDelay += SgvAnimationHelper.getDefaultAnimationDuration();

            childToAnimate.setTranslationX(xTranslation);
            childToAnimate.setTranslationY(yTranslation);

            switch (animationInMode) {
            case FLY_IN_NEW_VIEWS:
                SgvAnimationHelper.addTranslationRotationAnimators(animators, childToAnimate, xTranslation,
                        yTranslation, SgvAnimationHelper.ANIMATION_ROTATION_DEGREES, animationDelay);
                break;

            case SLIDE_IN_NEW_VIEWS:
                // Bias towards sliding right, but depending on the column that this view
                // is laid out in, slide towards the nearest side edge.
                int startTranslation = (int) (childToAnimate.getWidth() * 1.5);
                if (lp.column < (mColCount / 2)) {
                    startTranslation = -startTranslation;
                }

                SgvAnimationHelper.addSlideInFromRightAnimators(animators, childToAnimate, startTranslation,
                        animationDelay);
                break;

            case EXPAND_NEW_VIEWS:
            case EXPAND_NEW_VIEWS_NO_CASCADE:
                if (i == 0) {
                    // Initially set the alpha of this view to be invisible, then fade in.
                    childToAnimate.setAlpha(0);

                    // Create animators that translate the view back to translation = 0
                    // which would be its new layout position
                    final int offset = -1 * childToAnimate.getHeight();
                    SgvAnimationHelper.addXYTranslationAnimators(animators, childToAnimate,
                            0 /* xTranslation */, offset, animationDelay);

                    SgvAnimationHelper.addFadeAnimators(animators, childToAnimate, 0 /* start alpha */,
                            1.0f /* end alpha */, animationDelay);
                } else {
                    SgvAnimationHelper.addExpandInAnimators(animators, childToAnimate, animationDelay);
                }
                break;
            case FADE:
                SgvAnimationHelper.addFadeAnimators(animators, childToAnimate, 0 /* start alpha */,
                        1.0f /* end alpha */, animationDelay);
                break;

            default:
                continue;
            }
        }

        viewsAnimated++;
    }

    return animators;
}

From source file:com.deepak.myclock.widget.sgv.StaggeredGridView.java

/**
 * Animations to update the views on screen to their new positions.  For new views that aren't
 * currently on screen, animate them in using the specified animationInMode.
 *//*from  w w w  .  j a  v  a  2s  .c  om*/
private List<Animator> addUpdateViewPositionsAnimators(List<Animator> animators, boolean cascadeAnimation,
        SgvAnimationHelper.AnimationIn animationInMode, int startDelay) {
    final int childCount = getChildCount();
    if (childCount == 0) {
        return null;
    }

    if (animators == null) {
        animators = new ArrayList<Animator>();
    }

    int viewsAnimated = 0;
    for (int i = 0; i < childCount; i++) {
        final View childToAnimate = getChildAt(i);

        if (mViewsToAnimateOut.contains(childToAnimate)) {
            // If the stale views are still animating, then they are still laid out, so
            // getChildCount() would've accounted for them.  Since they have their own set
            // of animations to play, we'll skip over them in this loop.
            continue;
        }

        // Use progressive animation delay to create the staggered effect of animating
        // views.  This is done by having each view delay their animation by
        // ANIMATION_DELAY_IN_MS after the animation of the previous view.
        int animationDelay = startDelay + (cascadeAnimation ? viewsAnimated * ANIMATION_DELAY_IN_MS : 0);

        // Figure out whether a view with this item ID existed before
        final LayoutParams lp = (LayoutParams) childToAnimate.getLayoutParams();

        final ViewRectPair viewRectPair = mChildRectsForAnimation.get(lp.id);

        final int xTranslation;
        final int yTranslation;

        // If there is a valid {@link Rect} for the view with this newId, then
        // setup an animation.
        if (viewRectPair != null && viewRectPair.rect != null) {
            // In the special case where the items are explicitly fading, we don't want to do
            // any of the translations.
            if (animationInMode == SgvAnimationHelper.AnimationIn.FADE) {
                SgvAnimationHelper.addFadeAnimators(animators, childToAnimate, 0 /* start alpha */,
                        1.0f /* end alpha */, animationDelay);
                continue;
            }

            final Rect oldRect = viewRectPair.rect;
            // Since the view already exists, translate it to its new position.
            // Reset the child back to its previous position given by oldRect if the child
            // has not already been translated.  If the child has been translated, use the
            // current translated values, as this child may be in the middle of a previous
            // animation, so we don't want to simply force it to new location.

            xTranslation = oldRect.left - childToAnimate.getLeft();
            yTranslation = oldRect.top - childToAnimate.getTop();
            final float rotation = childToAnimate.getRotation();

            // First set the translation X and Y. The current translation might be out of date.
            childToAnimate.setTranslationX(xTranslation);
            childToAnimate.setTranslationY(yTranslation);

            if (xTranslation == 0 && yTranslation == 0 && rotation == 0) {
                // Bail early if this view doesn't need to be translated.
                continue;
            }

            SgvAnimationHelper.addTranslationRotationAnimators(animators, childToAnimate, xTranslation,
                    yTranslation, rotation, animationDelay);
        } else {
            // If this view was not present before the data updated, rather than just flashing
            // the view into its designated position, fly it up from the bottom.
            xTranslation = 0;
            yTranslation = (animationInMode == SgvAnimationHelper.AnimationIn.FLY_IN_NEW_VIEWS) ? getHeight()
                    : 0;

            // Since this is a new view coming in, add additional delays so that these IN
            // animations start after all the OUT animations have been played.
            animationDelay += SgvAnimationHelper.getDefaultAnimationDuration();

            childToAnimate.setTranslationX(xTranslation);
            childToAnimate.setTranslationY(yTranslation);

            switch (animationInMode) {
            case FLY_IN_NEW_VIEWS:
                SgvAnimationHelper.addTranslationRotationAnimators(animators, childToAnimate, xTranslation,
                        yTranslation, SgvAnimationHelper.ANIMATION_ROTATION_DEGREES, animationDelay);
                break;

            case SLIDE_IN_NEW_VIEWS:
                // Bias towards sliding right, but depending on the column that this view
                // is laid out in, slide towards the nearest side edge.
                int startTranslation = (int) (childToAnimate.getWidth() * 1.5);
                if (lp.column < (mColCount / 2)) {
                    startTranslation = -startTranslation;
                }

                SgvAnimationHelper.addSlideInFromRightAnimators(animators, childToAnimate, startTranslation,
                        animationDelay);
                break;

            case EXPAND_NEW_VIEWS:
            case EXPAND_NEW_VIEWS_NO_CASCADE:
                if (i == 0) {
                    // Initially set the alpha of this view to be invisible, then fade in.
                    childToAnimate.setAlpha(0);

                    // Create animators that translate the view back to translation = 0
                    // which would be its new layout position
                    final int offset = -1 * childToAnimate.getHeight();
                    SgvAnimationHelper.addXYTranslationAnimators(animators, childToAnimate,
                            0 /* xTranslation */, offset, animationDelay);

                    SgvAnimationHelper.addFadeAnimators(animators, childToAnimate, 0 /* start alpha */,
                            1.0f /* end alpha */, animationDelay);
                } else {
                    SgvAnimationHelper.addExpandInAnimators(animators, childToAnimate, animationDelay);
                }
                break;
            case FADE:
                SgvAnimationHelper.addFadeAnimators(animators, childToAnimate, 0 /* start alpha */,
                        1.0f /* end alpha */, animationDelay);
                break;

            default:
                continue;
            }
        }

        viewsAnimated++;
    }

    return animators;
}

From source file:g7.bluesky.launcher3.Launcher.java

/**
 * Zoom the camera back into the workspace, hiding 'fromView'.
 * This is the opposite of showAppsCustomizeHelper.
 * @param animated If true, the transition will be animated.
 *///from  w  w w  .  j  a v  a2s .c  o m
private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
        final boolean springLoaded, final Runnable onCompleteRunnable) {

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

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

    final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
    final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
    final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
    final int itemsAlphaStagger = res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);

    final float scaleFactor = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
    final View fromView = mAppsCustomizeTabHost;
    final View toView = mWorkspace;
    Animator workspaceAnim = null;
    final ArrayList<View> layerViews = new ArrayList<View>();

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

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

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

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

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

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

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

            if (isWidgetTray) {
                revealView.setBackground(ContextCompat.getDrawable(this, R.drawable.quantum_panel_dark));
            } else {
                revealView.setBackground(currentBgDrawable);
            }

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

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

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

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

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

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

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

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

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

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

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

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

            width = revealView.getMeasuredWidth();

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

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

                mStateAnimation.play(reveal);
            }

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

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

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

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

                mAppsCustomizeContent.updateCurrentPageScroll();

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

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

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

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;
    }/*w  w  w. ja  va2  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;
}

From source file:io.github.runassudo.launchert.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage,
        ArrayList<View> layerViews) {
    if (mState == state) {
        return null;
    }//  ww  w .j ava  2 s.com

    // 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);

        //(LauncherT) Custom search bar visibility
        if (SettingsData.desktopShowSearchbar)
            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);
        }

        //(LauncherT) Custom search bar visibility
        if (SettingsData.desktopShowSearchbar) {
            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;
}

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;
    }//w w  w . j a  v a2  s .  c  o 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.android.launcher4.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.  java 2s . 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: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;
    }// ww w  .j a  va  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;
    }/*  w ww .  j ava2 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);
        }
    }

    // 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;
}