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.android.systemui.statusbar.phone.NotificationPanelView.java

private void animateKeyguardStatusBarOut() {
    ValueAnimator anim = ValueAnimator.ofFloat(mKeyguardStatusBar.getAlpha(), 0f);
    anim.addUpdateListener(mStatusBarAnimateAlphaListener);
    anim.setStartDelay(mStatusBar.isKeyguardFadingAway() ? mStatusBar.getKeyguardFadingAwayDelay() : 0);
    anim.setDuration(mStatusBar.isKeyguardFadingAway() ? mStatusBar.getKeyguardFadingAwayDuration() / 2
            : StackStateAnimator.ANIMATION_DURATION_STANDARD);
    anim.setInterpolator(mDozeAnimationInterpolator);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override// ww w  .  j a va  2 s  . c  om
        public void onAnimationEnd(Animator animation) {
            mAnimateKeyguardStatusBarInvisibleEndRunnable.run();
        }
    });
    anim.start();
}

From source file:com.heinrichreimersoftware.materialintro.app.IntroActivity.java

private void smoothScrollPagerTo(final int position) {
    if (miPager.isFakeDragging())
        return;//from   w  ww  .j  av a  2 s  . co  m

    ValueAnimator animator = ValueAnimator.ofFloat(miPager.getCurrentItem(), position);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (miPager.isFakeDragging())
                miPager.endFakeDrag();
            miPager.setCurrentItem(position);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (miPager.isFakeDragging())
                miPager.endFakeDrag();
        }
    });
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float position = (Float) animation.getAnimatedValue();

            fakeDragToPosition(position);
        }

        private boolean fakeDragToPosition(float position) {
            // The following mimics the underlying calculations in ViewPager
            float scrollX = miPager.getScrollX();
            int pagerWidth = miPager.getWidth();
            int currentPosition = miPager.getCurrentItem();

            if (position > currentPosition && Math.floor(position) != currentPosition && position % 1 != 0) {
                miPager.setCurrentItem((int) Math.floor(position), false);
            } else if (position < currentPosition && Math.ceil(position) != currentPosition
                    && position % 1 != 0) {
                miPager.setCurrentItem((int) Math.ceil(position), false);
            }

            if (!miPager.isFakeDragging() && !miPager.beginFakeDrag())
                return false;

            miPager.fakeDragBy(scrollX - pagerWidth * position);
            return true;
        }
    });

    int distance = Math.abs(position - miPager.getCurrentItem());

    animator.setInterpolator(pageScrollInterpolator);
    animator.setDuration(calculateScrollDuration(distance));
    animator.start();
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

private void startEditFragment(final View view, final int position) {
    sourceList.setOnItemClickListener(null);
    sourceList.setEnabled(false);/* w  w w . j  a va  2s  .  com*/
    listAdapter.saveData();

    Source dataItem = listAdapter.getItem(position);
    final SourceInfoFragment sourceInfoFragment = new SourceInfoFragment();
    sourceInfoFragment.setImageDrawable(((ImageView) view.findViewById(R.id.source_image)).getDrawable());
    Bundle arguments = new Bundle();
    arguments.putInt("position", position);
    arguments.putString("type", dataItem.getType());
    arguments.putString("title", dataItem.getTitle());
    arguments.putString("data", dataItem.getData());
    arguments.putInt("num", dataItem.getNum());
    arguments.putBoolean("use", dataItem.isUse());
    arguments.putBoolean("preview", dataItem.isPreview());
    String imageFileName = dataItem.getImageFile().getAbsolutePath();
    if (imageFileName != null && imageFileName.length() > 0) {
        arguments.putString("image", imageFileName);
    } else {
        arguments.putString("image", "");
    }

    arguments.putBoolean("use_time", dataItem.isUseTime());
    arguments.putString("time", dataItem.getTime());

    sourceInfoFragment.setArguments(arguments);

    final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container);
    final CardView sourceCard = (CardView) view.findViewById(R.id.source_card);
    final View imageOverlay = view.findViewById(R.id.source_image_overlay);
    final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title);
    final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);
    final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container);

    final float cardStartShadow = sourceCard.getPaddingLeft();
    final float viewStartHeight = sourceContainer.getHeight();
    final float viewStartY = view.getY();
    final int viewStartPadding = view.getPaddingLeft();
    final float textStartX = sourceTitle.getX();
    final float textStartY = sourceTitle.getY();
    final float textTranslationY = sourceTitle.getHeight(); /*+ TypedValue.applyDimension(
                                                            TypedValue.COMPLEX_UNIT_DIP,
                                                            8,
                                                            getResources().getDisplayMetrics());*/

    Animation animation = new Animation() {

        private boolean needsFragment = true;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (needsFragment && interpolatedTime >= 1) {
                needsFragment = false;
                getFragmentManager().beginTransaction()
                        .add(R.id.content_frame, sourceInfoFragment, "source_info_fragment")
                        .addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_NONE).commit();
            }
            int newPadding = Math.round(viewStartPadding * (1 - interpolatedTime));
            int newShadowPadding = (int) (cardStartShadow * (1.0f - interpolatedTime));
            sourceCard.setShadowPadding(newShadowPadding, 0, newShadowPadding, 0);
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).topMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).bottomMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).leftMargin = newShadowPadding;
            ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).rightMargin = newShadowPadding;
            view.setPadding(newPadding, 0, newPadding, 0);
            view.setY(viewStartY - interpolatedTime * viewStartY);
            ViewGroup.LayoutParams params = sourceContainer.getLayoutParams();
            params.height = (int) (viewStartHeight + (screenHeight - viewStartHeight) * interpolatedTime);
            sourceContainer.setLayoutParams(params);
            sourceTitle.setY(textStartY + interpolatedTime * textTranslationY);
            sourceTitle.setX(textStartX + viewStartPadding - newPadding);
            deleteButton.setAlpha(1.0f - interpolatedTime);
            viewButton.setAlpha(1.0f - interpolatedTime);
            editButton.setAlpha(1.0f - interpolatedTime);
            sourceExpandContainer.setAlpha(1.0f - interpolatedTime);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getDialogColor(appContext),
            getResources().getColor(AppSettings.getBackgroundColorResource()));
    cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue());
        }

    });

    ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            sourceTitle.getCurrentTextColor(), getResources().getColor(R.color.BLUE_OPAQUE));
    titleColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceTitle.setTextColor((Integer) animation.getAnimatedValue());
        }

    });

    ValueAnimator titleShadowAlphaAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getColorFilterInt(appContext), getResources().getColor(android.R.color.transparent));
    titleShadowAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceTitle.setShadowLayer(4, 0, 0, (Integer) animation.getAnimatedValue());
        }
    });

    ValueAnimator imageOverlayAlphaAnimation = ValueAnimator.ofFloat(imageOverlay.getAlpha(), 0f);
    imageOverlayAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            imageOverlay.setAlpha((Float) animation.getAnimatedValue());
        }
    });

    int transitionTime = INFO_ANIMATION_TIME;

    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);

    animation.setDuration(transitionTime);
    cardColorAnimation.setDuration(transitionTime);
    titleColorAnimation.setDuration(transitionTime);
    titleShadowAlphaAnimation.setDuration(transitionTime);

    animation.setInterpolator(decelerateInterpolator);
    cardColorAnimation.setInterpolator(decelerateInterpolator);
    titleColorAnimation.setInterpolator(decelerateInterpolator);
    titleShadowAlphaAnimation.setInterpolator(decelerateInterpolator);

    if (imageOverlay.getAlpha() > 0) {
        imageOverlayAlphaAnimation.start();
    }

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }
    }, (long) (transitionTime * 1.1f));

    needsListReset = true;
    view.startAnimation(animation);
    cardColorAnimation.start();
    titleColorAnimation.start();
    titleShadowAlphaAnimation.start();
}

From source file:com.gu.swiperefresh.ProgressDrawable.java

private void setupAnimators() {
    final Ring ring = mRing;
    final ValueAnimator animator = ObjectAnimator.ofFloat(0f, 1f);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from  ww w . j  ava 2s .  co  m
        public void onAnimationUpdate(ValueAnimator animation) {
            float interpolatedTime = Float.valueOf(animation.getAnimatedValue().toString());
            if (mFinishing) {
                applyFinishTranslation(interpolatedTime, ring);
            } else {
                // The minProgressArc is calculated from 0 to create an
                // angle that matches the stroke width.
                final float minProgressArc = getMinProgressArc(ring);
                final float startingEndTrim = ring.getStartingEndTrim();
                final float startingTrim = ring.getStartingStartTrim();
                final float startingRotation = ring.getStartingRotation();

                updateRingColor(interpolatedTime, ring);

                // Moving the start trim only occurs in the first 50% of a
                // single ring animation
                if (interpolatedTime <= START_TRIM_DURATION_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float scaledTime = (interpolatedTime) / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float startTrim = startingTrim + ((MAX_PROGRESS_ARC - minProgressArc)
                            * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setStartTrim(startTrim);
                }

                // Moving the end trim starts after 50% of a single ring
                // animation completes
                if (interpolatedTime > END_TRIM_START_DELAY_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float minArc = MAX_PROGRESS_ARC - minProgressArc;
                    float scaledTime = (interpolatedTime - START_TRIM_DURATION_OFFSET)
                            / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float endTrim = startingEndTrim
                            + (minArc * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setEndTrim(endTrim);
                }

                final float rotation = startingRotation + (0.25f * interpolatedTime);
                ring.setRotation(rotation);

                float groupRotation = ((FULL_ROTATION / NUM_POINTS) * interpolatedTime)
                        + (FULL_ROTATION * (mRotationCount / NUM_POINTS));
                setRotation(groupRotation);
            }
        }
    });
    animator.setRepeatCount(Animation.INFINITE);
    animator.setRepeatMode(ValueAnimator.RESTART);
    animator.setInterpolator(LINEAR_INTERPOLATOR);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {

        }

        @Override
        public void onAnimationStart(Animator animation) {
            mRotationCount = 0;
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            if (mFinishing) {
                // finished closing the last ring from the swipe gesture; go
                // into progress mode
                mFinishing = false;
                animation.setDuration(ANIMATION_DURATION);
                ring.setShowArrow(false);
            } else {
                mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
            }
        }
    });
    mAnimation = animator;
}

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

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

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

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

    // Stop any scrolling, move to the current page right away
    setCurrentPage(getNextPage());

    final State oldState = mState;
    final boolean oldStateIsNormal = (oldState == State.NORMAL);
    final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED);
    final boolean oldStateIsSmall = (oldState == State.SMALL);
    mState = state;
    final boolean stateIsNormal = (state == State.NORMAL);
    final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED);
    final boolean stateIsSmall = (state == State.SMALL);
    float finalScaleFactor = 1.0f;
    float finalBackgroundAlpha = stateIsSpringLoaded ? 1.0f : 0f;
    float translationX = 0;
    float translationY = 0;
    boolean zoomIn = true;

    if (state != State.NORMAL) {
        finalScaleFactor = mSpringLoadedShrinkFactor - (stateIsSmall ? 0.1f : 0);
        setPageSpacing(mSpringLoadedPageSpacing);
        if (oldStateIsNormal && stateIsSmall) {
            zoomIn = false;
            setLayoutScale(finalScaleFactor);
            updateChildrenLayersEnabled(false);
        } else {
            finalBackgroundAlpha = 1.0f;
            setLayoutScale(finalScaleFactor);
        }
    } else {
        setPageSpacing(mOriginalPageSpacing);
        setLayoutScale(1.0f);
    }

    final int duration = zoomIn ? getResources().getInteger(R.integer.config_workspaceUnshrinkTime)
            : getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime);
    for (int i = 0; i < getChildCount(); i++) {
        final CellLayout cl = (CellLayout) getChildAt(i);
        float finalAlpha = (!mWorkspaceFadeInAdjacentScreens || stateIsSpringLoaded || (i == mCurrentPage)) ? 1f
                : 0f;
        float currentAlpha = cl.getShortcutsAndWidgets().getAlpha();
        float initialAlpha = currentAlpha;

        // Determine the pages alpha during the state transition
        if ((oldStateIsSmall && stateIsNormal) || (oldStateIsNormal && stateIsSmall)) {
            // To/from workspace - only show the current page unless the transition is not
            //                     animated and the animation end callback below doesn't run;
            //                     or, if we're in spring-loaded mode
            if (i == mCurrentPage || !animated || oldStateIsSpringLoaded) {
                finalAlpha = 1f;
            } else {
                initialAlpha = 0f;
                finalAlpha = 0f;
            }
        }

        mOldAlphas[i] = initialAlpha;
        mNewAlphas[i] = finalAlpha;
        if (animated) {
            mOldTranslationXs[i] = cl.getTranslationX();
            mOldTranslationYs[i] = cl.getTranslationY();
            mOldScaleXs[i] = cl.getScaleX();
            mOldScaleYs[i] = cl.getScaleY();
            mOldBackgroundAlphas[i] = cl.getBackgroundAlpha();

            mNewTranslationXs[i] = translationX;
            mNewTranslationYs[i] = translationY;
            mNewScaleXs[i] = finalScaleFactor;
            mNewScaleYs[i] = finalScaleFactor;
            mNewBackgroundAlphas[i] = finalBackgroundAlpha;
        } else {
            cl.setTranslationX(translationX);
            cl.setTranslationY(translationY);
            cl.setScaleX(finalScaleFactor);
            cl.setScaleY(finalScaleFactor);
            cl.setBackgroundAlpha(finalBackgroundAlpha);
            cl.setShortcutAndWidgetAlpha(finalAlpha);
        }
    }

    if (animated) {
        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.setTranslationX(mNewTranslationXs[i]);
                cl.setTranslationY(mNewTranslationYs[i]);
                cl.setScaleX(mNewScaleXs[i]);
                cl.setScaleY(mNewScaleYs[i]);
                cl.setBackgroundAlpha(mNewBackgroundAlphas[i]);
                cl.setShortcutAndWidgetAlpha(mNewAlphas[i]);
                cl.setRotationY(mNewRotationYs[i]);
            } else {
                LauncherViewPropertyAnimator a = new LauncherViewPropertyAnimator(cl);
                a.translationX(mNewTranslationXs[i]).translationY(mNewTranslationYs[i]).scaleX(mNewScaleXs[i])
                        .scaleY(mNewScaleYs[i]).setDuration(duration).setInterpolator(mZoomInInterpolator);
                anim.play(a);

                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(0f, 1f).setDuration(duration);
                    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);
                }
            }
        }
        buildPageHardwareLayers();
        anim.setStartDelay(delay);
    }

    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 {
        // Fade the background gradient away
        animateBackgroundGradient(0f, true);
    }
    return anim;
}

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

/**
 * Runs a new animation that scales up icons that were added while Launcher was in the
 * background.//from www.jav  a 2 s  .  c  o  m
 *
 * @param immediate whether to run the animation or show the results immediately
 */
private void runNewAppsAnimation(boolean immediate) {
    AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    Collection<Animator> bounceAnims = new ArrayList<Animator>();

    // Order these new views spatially so that they animate in order
    Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() {
        @Override
        public int compare(View a, View b) {
            CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams();
            CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams();
            int cellCountX = LauncherModel.getCellCountX();
            return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX);
        }
    });

    // Animate each of the views in place (or show them immediately if requested)
    if (immediate) {
        for (View v : mNewShortcutAnimateViews) {
            v.setAlpha(1f);
            v.setScaleX(1f);
            v.setScaleY(1f);
        }
    } else {
        for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) {
            View v = mNewShortcutAnimateViews.get(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 SmoothPagedView.OvershootInterpolator());
            bounceAnims.add(bounceAnim);
        }
        anim.playTogether(bounceAnims);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (mWorkspace != null) {
                    mWorkspace.postDelayed(mBuildLayersRunnable, 500);
                }
            }
        });
        anim.start();
    }

    // Clean up
    mNewShortcutAnimatePage = -1;
    mNewShortcutAnimateViews.clear();
    new Thread("clearNewAppsThread") {
        public void run() {
            mSharedPrefs.edit().putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1)
                    .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null).commit();
        }
    }.start();
}

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

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
    if (mState == state) {
        return null;
    }//from   w ww  .  j a  v a 2  s. 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:cc.flydev.launcher.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
    if (mState == state) {
        return null;
    }//  www.  j ava  2 s  .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:us.shandian.launcher.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
    if (mState == state) {
        return null;
    }// w w  w  . ja 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);
        if (searchBar.getVisibility() != View.GONE) {
            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.example.launcher3.Workspace.java

Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
    if (mState == state) {
        return null;
    }//from  w w  w .  java  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 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;
}