Example usage for android.animation AnimatorSet addListener

List of usage examples for android.animation AnimatorSet addListener

Introduction

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

Prototype

public void addListener(AnimatorListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

From source file:org.telegram.ui.ArticleViewer.java

public void uncollapse() {
    if (parentActivity == null || !isVisible || checkAnimation()) {
        return;//from w  w  w.  ja v a2  s  . c  o  m
    }

    /*windowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
    wm.updateViewLayout(windowView, windowLayoutParams);*/

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationX", 0),
            ObjectAnimator.ofFloat(containerView, "translationY", 0),
            ObjectAnimator.ofFloat(windowView, "alpha", 1.0f), ObjectAnimator.ofFloat(listView, "alpha", 1.0f),
            ObjectAnimator.ofFloat(listView, "translationY", 0),
            ObjectAnimator.ofFloat(headerView, "translationY", 0),

            ObjectAnimator.ofFloat(backButton, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(backButton, "scaleY", 1.0f),
            ObjectAnimator.ofFloat(backButton, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(shareContainer, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleY", 1.0f));
    collapsed = false;
    animationInProgress = 2;
    animationEndRunnable = new Runnable() {
        @Override
        public void run() {
            if (containerView == null) {
                return;
            }
            if (Build.VERSION.SDK_INT >= 18) {
                containerView.setLayerType(View.LAYER_TYPE_NONE, null);
            }
            animationInProgress = 0;
            //onClosed();
        }
    };
    animatorSet.setDuration(250);
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (animationEndRunnable != null) {
                animationEndRunnable.run();
                animationEndRunnable = null;
            }
        }
    });
    transitionAnimationStartTime = System.currentTimeMillis();
    if (Build.VERSION.SDK_INT >= 18) {
        containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    backDrawable.setRotation(0, true);
    animatorSet.start();
}

From source file:org.telegram.ui.ArticleViewer.java

public boolean openPhoto(TLRPC.PageBlock block) {
    if (parentActivity == null || isPhotoVisible || checkPhotoAnimation() || block == null) {
        return false;
    }//w w  w  .j av a 2 s.co m

    final PlaceProviderObject object = getPlaceForPhoto(block);
    if (object == null) {
        return false;
    }

    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileLoadProgressChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);

    if (velocityTracker == null) {
        velocityTracker = VelocityTracker.obtain();
    }

    isPhotoVisible = true;
    toggleActionBar(true, false);
    actionBar.setAlpha(0.0f);
    bottomLayout.setAlpha(0.0f);
    captionTextView.setAlpha(0.0f);
    photoBackgroundDrawable.setAlpha(0);
    disableShowCheck = true;
    photoAnimationInProgress = 1;
    if (block != null) {
        currentAnimation = object.imageReceiver.getAnimation();
    }
    int index = photoBlocks.indexOf(block);

    imagesArr.clear();
    if (!(block instanceof TLRPC.TL_pageBlockVideo) || isVideoBlock(block)) {
        imagesArr.addAll(photoBlocks);
    } else {
        imagesArr.add(block);
        index = 0;
    }

    onPhotoShow(index, object);

    final Rect drawRegion = object.imageReceiver.getDrawRegion();
    int orientation = object.imageReceiver.getOrientation();
    int animatedOrientation = object.imageReceiver.getAnimatedOrientation();
    if (animatedOrientation != 0) {
        orientation = animatedOrientation;
    }

    animatingImageView.setVisibility(View.VISIBLE);
    animatingImageView.setRadius(object.radius);
    animatingImageView.setOrientation(orientation);
    animatingImageView.setNeedRadius(object.radius != 0);
    animatingImageView.setImageBitmap(object.thumb);

    animatingImageView.setAlpha(1.0f);
    animatingImageView.setPivotX(0.0f);
    animatingImageView.setPivotY(0.0f);
    animatingImageView.setScaleX(object.scale);
    animatingImageView.setScaleY(object.scale);
    animatingImageView.setTranslationX(object.viewX + drawRegion.left * object.scale);
    animatingImageView.setTranslationY(object.viewY + drawRegion.top * object.scale);
    final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
    layoutParams.width = (drawRegion.right - drawRegion.left);
    layoutParams.height = (drawRegion.bottom - drawRegion.top);
    animatingImageView.setLayoutParams(layoutParams);

    float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
    float scaleY = (float) (AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight)
            / layoutParams.height;
    float scale = scaleX > scaleY ? scaleY : scaleX;
    float width = layoutParams.width * scale;
    float height = layoutParams.height * scale;
    float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
    if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) {
        xPos += ((WindowInsets) lastInsets).getSystemWindowInsetLeft();
    }
    float yPos = ((AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight) - height) / 2.0f;
    int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
    int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());

    int coords2[] = new int[2];
    object.parentView.getLocationInWindow(coords2);
    int clipTop = coords2[1] - (object.viewY + drawRegion.top) + object.clipTopAddition;
    if (clipTop < 0) {
        clipTop = 0;
    }
    int clipBottom = (object.viewY + drawRegion.top + layoutParams.height)
            - (coords2[1] + object.parentView.getHeight()) + object.clipBottomAddition;
    if (clipBottom < 0) {
        clipBottom = 0;
    }
    clipTop = Math.max(clipTop, clipVertical);
    clipBottom = Math.max(clipBottom, clipVertical);

    animationValues[0][0] = animatingImageView.getScaleX();
    animationValues[0][1] = animatingImageView.getScaleY();
    animationValues[0][2] = animatingImageView.getTranslationX();
    animationValues[0][3] = animatingImageView.getTranslationY();
    animationValues[0][4] = clipHorizontal * object.scale;
    animationValues[0][5] = clipTop * object.scale;
    animationValues[0][6] = clipBottom * object.scale;
    animationValues[0][7] = animatingImageView.getRadius();

    animationValues[1][0] = scale;
    animationValues[1][1] = scale;
    animationValues[1][2] = xPos;
    animationValues[1][3] = yPos;
    animationValues[1][4] = 0;
    animationValues[1][5] = 0;
    animationValues[1][6] = 0;
    animationValues[1][7] = 0;

    photoContainerView.setVisibility(View.VISIBLE);
    photoContainerBackground.setVisibility(View.VISIBLE);
    animatingImageView.setAnimationProgress(0);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
            ObjectAnimator.ofInt(photoBackgroundDrawable, "alpha", 0, 255),
            ObjectAnimator.ofFloat(actionBar, "alpha", 0, 1.0f),
            ObjectAnimator.ofFloat(bottomLayout, "alpha", 0, 1.0f),
            ObjectAnimator.ofFloat(captionTextView, "alpha", 0, 1.0f));

    photoAnimationEndRunnable = new Runnable() {
        @Override
        public void run() {
            if (photoContainerView == null) {
                return;
            }
            if (Build.VERSION.SDK_INT >= 18) {
                photoContainerView.setLayerType(View.LAYER_TYPE_NONE, null);
            }
            photoAnimationInProgress = 0;
            photoTransitionAnimationStartTime = 0;
            setImages();
            photoContainerView.invalidate();
            animatingImageView.setVisibility(View.GONE);
            if (showAfterAnimation != null) {
                showAfterAnimation.imageReceiver.setVisible(true, true);
            }
            if (hideAfterAnimation != null) {
                hideAfterAnimation.imageReceiver.setVisible(false, true);
            }
        }
    };

    animatorSet.setDuration(200);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    NotificationCenter.getInstance().setAnimationInProgress(false);
                    if (photoAnimationEndRunnable != null) {
                        photoAnimationEndRunnable.run();
                        photoAnimationEndRunnable = null;
                    }
                }
            });
        }
    });
    photoTransitionAnimationStartTime = System.currentTimeMillis();
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            NotificationCenter.getInstance()
                    .setAllowedNotificationsDutingAnimation(new int[] { NotificationCenter.dialogsNeedReload,
                            NotificationCenter.closeChats, NotificationCenter.mediaCountDidLoaded,
                            NotificationCenter.mediaDidLoaded, NotificationCenter.dialogPhotosLoaded });
            NotificationCenter.getInstance().setAnimationInProgress(true);
            animatorSet.start();
        }
    });
    if (Build.VERSION.SDK_INT >= 18) {
        photoContainerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    photoBackgroundDrawable.drawRunnable = new Runnable() {
        @Override
        public void run() {
            disableShowCheck = false;
            object.imageReceiver.setVisible(false, true);
        }
    };
    return true;
}

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

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

    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 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 finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f;
    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 (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);
    }

    final CellLayout cl = mWorkspace;
    float initialAlpha = cl.getShortcutsAndWidgets().getAlpha();
    float finalAlpha;
    if (stateIsNormalHidden || stateIsOverviewHidden) {
        finalAlpha = 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) {
                initialAlpha = 0f;
            }
            cl.setShortcutAndWidgetAlpha(initialAlpha);
        }
    }

    float oldAlpha = initialAlpha;
    float newAlpha = finalAlpha;
    if (animated) {
        mOldBackgroundAlpha = cl.getBackgroundAlpha();
        mNewBackgroundAlpha = finalBackgroundAlpha;
    } else {
        cl.setBackgroundAlpha(finalBackgroundAlpha);
        cl.setShortcutAndWidgetAlpha(finalAlpha);
    }

    final View overviewPanel = mLauncher.getOverviewPanel();
    if (animated) {
        LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this);
        scale.scaleX(mNewScale).scaleY(mNewScale).translationY(finalWorkspaceTranslationY).setDuration(duration)
                .setInterpolator(mZoomInInterpolator);
        anim.play(scale);
        float currentAlpha = cl.getShortcutsAndWidgets().getAlpha();
        if (oldAlpha == 0 && newAlpha == 0) {
            cl.setBackgroundAlpha(mNewBackgroundAlpha);
            cl.setShortcutAndWidgetAlpha(newAlpha);
        } else {
            if (layerViews != null) {
                layerViews.add(cl);
            }
            if (oldAlpha != newAlpha || currentAlpha != newAlpha) {
                LauncherViewPropertyAnimator alphaAnim = new LauncherViewPropertyAnimator(
                        cl.getShortcutsAndWidgets());
                alphaAnim.alpha(newAlpha).setDuration(duration).setInterpolator(mZoomInInterpolator);
                anim.play(alphaAnim);
            }
            if (mOldBackgroundAlpha != 0 || mNewBackgroundAlpha != 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 * mOldBackgroundAlpha + b * mNewBackgroundAlpha);
                    }
                });
                anim.play(bgAnim);
            }
        }

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

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

        overviewPanelAlpha.setDuration(duration);

        anim.play(overviewPanelAlpha);
        anim.setStartDelay(delay);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mStateAnimator = null;
            }
        });
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        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:org.telegram.ui.ArticleViewer.java

public void collapse() {
    if (parentActivity == null || !isVisible || checkAnimation()) {
        return;/*from  w w w. ja  va 2s .c o m*/
    }
    if (fullscreenVideoContainer.getVisibility() == View.VISIBLE) {
        if (customView != null) {
            fullscreenVideoContainer.setVisibility(View.INVISIBLE);
            customViewCallback.onCustomViewHidden();
            fullscreenVideoContainer.removeView(customView);
            customView = null;
        } else if (fullscreenedVideo != null) {
            fullscreenedVideo.exitFullscreen();
        }
    }
    if (isPhotoVisible) {
        closePhoto(false);
    }
    try {
        if (visibleDialog != null) {
            visibleDialog.dismiss();
            visibleDialog = null;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(containerView, "translationX",
                    containerView.getMeasuredWidth() - AndroidUtilities.dp(56)),
            ObjectAnimator.ofFloat(containerView, "translationY",
                    ActionBar.getCurrentActionBarHeight()
                            + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)),
            ObjectAnimator.ofFloat(windowView, "alpha", 0.0f), ObjectAnimator.ofFloat(listView, "alpha", 0.0f),
            ObjectAnimator.ofFloat(listView, "translationY", -AndroidUtilities.dp(56)),
            ObjectAnimator.ofFloat(headerView, "translationY", 0),

            ObjectAnimator.ofFloat(backButton, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(backButton, "scaleY", 1.0f),
            ObjectAnimator.ofFloat(backButton, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(shareContainer, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleY", 1.0f));
    collapsed = true;
    animationInProgress = 2;
    animationEndRunnable = new Runnable() {
        @Override
        public void run() {
            if (containerView == null) {
                return;
            }
            if (Build.VERSION.SDK_INT >= 18) {
                containerView.setLayerType(View.LAYER_TYPE_NONE, null);
            }
            animationInProgress = 0;

            //windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
            WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
            wm.updateViewLayout(windowView, windowLayoutParams);

            //onClosed();
            //containerView.setScaleX(1.0f);
            //containerView.setScaleY(1.0f);
        }
    };
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.setDuration(250);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (animationEndRunnable != null) {
                animationEndRunnable.run();
                animationEndRunnable = null;
            }
        }
    });
    transitionAnimationStartTime = System.currentTimeMillis();
    if (Build.VERSION.SDK_INT >= 18) {
        containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    backDrawable.setRotation(1, true);
    animatorSet.start();
}

From source file:org.telegram.ui.PassportActivity.java

public void setPage(int page, boolean animated, Bundle params) {
    if (page == 3) {
        doneItem.setVisibility(View.GONE);
    }/* w w  w.  ja va 2 s  .  c o  m*/
    final SlideView outView = views[currentViewNum];
    final SlideView newView = views[page];
    currentViewNum = page;

    newView.setParams(params, false);
    newView.onShow();

    if (animated) {
        newView.setTranslationX(AndroidUtilities.displaySize.x);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
        animatorSet.setDuration(300);
        animatorSet.playTogether(
                ObjectAnimator.ofFloat(outView, "translationX", -AndroidUtilities.displaySize.x),
                ObjectAnimator.ofFloat(newView, "translationX", 0));
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                newView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                outView.setVisibility(View.GONE);
                outView.setX(0);
            }
        });
        animatorSet.start();
    } else {
        newView.setTranslationX(0);
        newView.setVisibility(View.VISIBLE);
        if (outView != newView) {
            outView.setVisibility(View.GONE);
        }
    }
}

From source file:net.bluehack.ui.ChatActivity.java

private void showGifHint() {
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);/*  www . j av a  2  s.  c om*/
    if (preferences.getBoolean("gifhint", false)) {
        return;
    }
    preferences.edit().putBoolean("gifhint", true).commit();

    if (getParentActivity() == null || fragmentView == null || gifHintTextView != null) {
        return;
    }
    if (!allowContextBotPanelSecond) {
        if (chatActivityEnterView != null) {
            chatActivityEnterView.setOpenGifsTabFirst();
        }
        return;
    }
    SizeNotifierFrameLayout frameLayout = (SizeNotifierFrameLayout) fragmentView;
    int index = frameLayout.indexOfChild(chatActivityEnterView);
    if (index == -1) {
        return;
    }
    chatActivityEnterView.setOpenGifsTabFirst();
    emojiButtonRed = new View(getParentActivity());
    emojiButtonRed.setBackgroundResource(R.drawable.redcircle);
    frameLayout.addView(emojiButtonRed, index + 1,
            LayoutHelper.createFrame(10, 10, Gravity.BOTTOM | Gravity.LEFT, 30, 0, 0, 27));

    gifHintTextView = new TextView(getParentActivity());
    gifHintTextView.setBackgroundResource(R.drawable.tooltip);
    gifHintTextView.setTextColor(Theme.CHAT_GIF_HINT_TEXT_COLOR);
    gifHintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    gifHintTextView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
    gifHintTextView.setText(LocaleController.getString("TapHereGifs", R.string.TapHereGifs));
    gifHintTextView.setGravity(Gravity.CENTER_VERTICAL);
    frameLayout.addView(gifHintTextView, index + 1,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32, Gravity.LEFT | Gravity.BOTTOM, 5, 0, 0, 3));

    AnimatorSet AnimatorSet = new AnimatorSet();
    AnimatorSet.playTogether(ObjectAnimator.ofFloat(gifHintTextView, "alpha", 0.0f, 1.0f),
            ObjectAnimator.ofFloat(emojiButtonRed, "alpha", 0.0f, 1.0f));
    AnimatorSet.addListener(new AnimatorListenerAdapterProxy() {
        @Override
        public void onAnimationEnd(Animator animation) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    if (gifHintTextView == null) {
                        return;
                    }
                    AnimatorSet AnimatorSet = new AnimatorSet();
                    AnimatorSet.playTogether(ObjectAnimator.ofFloat(gifHintTextView, "alpha", 0.0f));
                    AnimatorSet.addListener(new AnimatorListenerAdapterProxy() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (gifHintTextView != null) {
                                gifHintTextView.setVisibility(View.GONE);
                            }
                        }
                    });
                    AnimatorSet.setDuration(300);
                    AnimatorSet.start();
                }
            }, 2000);
        }
    });
    AnimatorSet.setDuration(300);
    AnimatorSet.start();
}

From source file:kr.wdream.ui.ChatActivity.java

private void showGifHint() {
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
            Activity.MODE_PRIVATE);//ww w  . j a  v a  2s .  c  om
    if (preferences.getBoolean("gifhint", false)) {
        return;
    }
    preferences.edit().putBoolean("gifhint", true).commit();

    if (getParentActivity() == null || fragmentView == null || gifHintTextView != null) {
        return;
    }
    if (!allowContextBotPanelSecond) {
        if (chatActivityEnterView != null) {
            chatActivityEnterView.setOpenGifsTabFirst();
        }
        return;
    }
    SizeNotifierFrameLayout frameLayout = (SizeNotifierFrameLayout) fragmentView;
    int index = frameLayout.indexOfChild(chatActivityEnterView);
    if (index == -1) {
        return;
    }
    chatActivityEnterView.setOpenGifsTabFirst();
    emojiButtonRed = new View(getParentActivity());
    emojiButtonRed.setBackgroundResource(kr.wdream.storyshop.R.drawable.redcircle);
    frameLayout.addView(emojiButtonRed, index + 1,
            LayoutHelper.createFrame(10, 10, Gravity.BOTTOM | Gravity.LEFT, 30, 0, 0, 27));

    gifHintTextView = new TextView(getParentActivity());
    gifHintTextView.setBackgroundResource(kr.wdream.storyshop.R.drawable.tooltip);
    gifHintTextView.setTextColor(Theme.CHAT_GIF_HINT_TEXT_COLOR);
    gifHintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    gifHintTextView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
    gifHintTextView
            .setText(LocaleController.getString("TapHereGifs", kr.wdream.storyshop.R.string.TapHereGifs));
    gifHintTextView.setGravity(Gravity.CENTER_VERTICAL);
    frameLayout.addView(gifHintTextView, index + 1,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32, Gravity.LEFT | Gravity.BOTTOM, 5, 0, 0, 3));

    AnimatorSet AnimatorSet = new AnimatorSet();
    AnimatorSet.playTogether(ObjectAnimator.ofFloat(gifHintTextView, "alpha", 0.0f, 1.0f),
            ObjectAnimator.ofFloat(emojiButtonRed, "alpha", 0.0f, 1.0f));
    AnimatorSet.addListener(new AnimatorListenerAdapterProxy() {
        @Override
        public void onAnimationEnd(Animator animation) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    if (gifHintTextView == null) {
                        return;
                    }
                    AnimatorSet AnimatorSet = new AnimatorSet();
                    AnimatorSet.playTogether(ObjectAnimator.ofFloat(gifHintTextView, "alpha", 0.0f));
                    AnimatorSet.addListener(new AnimatorListenerAdapterProxy() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (gifHintTextView != null) {
                                gifHintTextView.setVisibility(View.GONE);
                            }
                        }
                    });
                    AnimatorSet.setDuration(300);
                    AnimatorSet.start();
                }
            }, 2000);
        }
    });
    AnimatorSet.setDuration(300);
    AnimatorSet.start();
}

From source file:kr.wdream.ui.PhotoViewer.java

public void closePhoto(boolean animated, boolean fromEditMode) {
    if (!fromEditMode && currentEditMode != 0) {
        if (currentEditMode == 3 && photoPaintView != null) {
            photoPaintView.maybeShowDismissalAlert(this, parentActivity, new Runnable() {
                @Override/*  w  ww . ja va  2s  . c  om*/
                public void run() {
                    switchToEditMode(0);
                }
            });
            return;
        }

        if (currentEditMode == 1) {
            photoCropView.cancelAnimationRunnable();
        }
        switchToEditMode(0);
        return;
    }
    try {
        if (visibleDialog != null) {
            visibleDialog.dismiss();
            visibleDialog = null;
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    if (currentEditMode != 0) {
        if (currentEditMode == 2) {
            photoFilterView.shutdown();
            containerView.removeView(photoFilterView);
            photoFilterView = null;
        } else if (currentEditMode == 1) {
            editorDoneLayout.setVisibility(View.GONE);
            photoCropView.setVisibility(View.GONE);
        }
        currentEditMode = 0;
    }

    if (parentActivity == null || !isVisible || checkAnimation() || placeProvider == null) {
        return;
    }
    if (captionEditText.hideActionMode() && !fromEditMode) {
        return;
    }

    releasePlayer();
    captionEditText.onDestroy();
    parentChatActivity = null;
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileLoadProgressChanged);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaCountDidLoaded);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaDidLoaded);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.dialogPhotosLoaded);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
    ConnectionsManager.getInstance().cancelRequestsForGuid(classGuid);

    isActionBarVisible = false;

    if (velocityTracker != null) {
        velocityTracker.recycle();
        velocityTracker = null;
    }
    ConnectionsManager.getInstance().cancelRequestsForGuid(classGuid);

    final PlaceProviderObject object = placeProvider.getPlaceForPhoto(currentMessageObject, currentFileLocation,
            currentIndex);

    if (animated) {
        animationInProgress = 1;
        animatingImageView.setVisibility(View.VISIBLE);
        containerView.invalidate();

        AnimatorSet animatorSet = new AnimatorSet();

        final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
        Rect drawRegion = null;
        int orientation = centerImage.getOrientation();
        int animatedOrientation = 0;
        if (object != null && object.imageReceiver != null) {
            animatedOrientation = object.imageReceiver.getAnimatedOrientation();
        }
        if (animatedOrientation != 0) {
            orientation = animatedOrientation;
        }
        animatingImageView.setOrientation(orientation);
        if (object != null) {
            animatingImageView.setNeedRadius(object.radius != 0);
            drawRegion = object.imageReceiver.getDrawRegion();
            layoutParams.width = drawRegion.right - drawRegion.left;
            layoutParams.height = drawRegion.bottom - drawRegion.top;
            animatingImageView.setImageBitmap(object.thumb);
        } else {
            animatingImageView.setNeedRadius(false);
            layoutParams.width = centerImage.getImageWidth();
            layoutParams.height = centerImage.getImageHeight();
            animatingImageView.setImageBitmap(centerImage.getBitmap());
        }
        animatingImageView.setLayoutParams(layoutParams);

        float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
        float scaleY = (float) (AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / layoutParams.height;
        float scale2 = scaleX > scaleY ? scaleY : scaleX;
        float width = layoutParams.width * scale * scale2;
        float height = layoutParams.height * scale * scale2;
        float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
        float yPos = ((AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) - height) / 2.0f;
        animatingImageView.setTranslationX(xPos + translationX);
        animatingImageView.setTranslationY(yPos + translationY);
        animatingImageView.setScaleX(scale * scale2);
        animatingImageView.setScaleY(scale * scale2);

        if (object != null) {
            object.imageReceiver.setVisible(false, true);
            int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
            int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());

            int coords2[] = new int[2];
            object.parentView.getLocationInWindow(coords2);
            int clipTop = coords2[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight)
                    - (object.viewY + drawRegion.top) + object.clipTopAddition;
            if (clipTop < 0) {
                clipTop = 0;
            }
            int clipBottom = (object.viewY + drawRegion.top + (drawRegion.bottom - drawRegion.top))
                    - (coords2[1] + object.parentView.getHeight()
                            - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight))
                    + object.clipBottomAddition;
            if (clipBottom < 0) {
                clipBottom = 0;
            }

            clipTop = Math.max(clipTop, clipVertical);
            clipBottom = Math.max(clipBottom, clipVertical);

            animationValues[0][0] = animatingImageView.getScaleX();
            animationValues[0][1] = animatingImageView.getScaleY();
            animationValues[0][2] = animatingImageView.getTranslationX();
            animationValues[0][3] = animatingImageView.getTranslationY();
            animationValues[0][4] = 0;
            animationValues[0][5] = 0;
            animationValues[0][6] = 0;
            animationValues[0][7] = 0;

            animationValues[1][0] = object.scale;
            animationValues[1][1] = object.scale;
            animationValues[1][2] = object.viewX + drawRegion.left * object.scale;
            animationValues[1][3] = object.viewY + drawRegion.top * object.scale;
            animationValues[1][4] = clipHorizontal * object.scale;
            animationValues[1][5] = clipTop * object.scale;
            animationValues[1][6] = clipBottom * object.scale;
            animationValues[1][7] = object.radius;

            animatorSet.playTogether(
                    ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
                    ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
                    ObjectAnimator.ofFloat(containerView, "alpha", 0.0f));
        } else {
            int h = (AndroidUtilities.displaySize.y
                    + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0));
            animatorSet.playTogether(ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
                    ObjectAnimator.ofFloat(animatingImageView, "alpha", 0.0f),
                    ObjectAnimator.ofFloat(animatingImageView, "translationY", translationY >= 0 ? h : -h),
                    ObjectAnimator.ofFloat(containerView, "alpha", 0.0f));
        }

        animationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= 18) {
                    containerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                animationInProgress = 0;
                onPhotoClosed(object);
            }
        };

        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        if (animationEndRunnable != null) {
                            animationEndRunnable.run();
                            animationEndRunnable = null;
                        }
                    }
                });
            }
        });
        transitionAnimationStartTime = System.currentTimeMillis();
        if (Build.VERSION.SDK_INT >= 18) {
            containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        animatorSet.start();
    } else {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "scaleX", 0.9f),
                ObjectAnimator.ofFloat(containerView, "scaleY", 0.9f),
                ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
                ObjectAnimator.ofFloat(containerView, "alpha", 0.0f));
        animationInProgress = 2;
        animationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (containerView == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT >= 18) {
                    containerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                animationInProgress = 0;
                onPhotoClosed(object);
                containerView.setScaleX(1.0f);
                containerView.setScaleY(1.0f);
            }
        };
        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (animationEndRunnable != null) {
                    animationEndRunnable.run();
                    animationEndRunnable = null;
                }
            }
        });
        transitionAnimationStartTime = System.currentTimeMillis();
        if (Build.VERSION.SDK_INT >= 18) {
            containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        animatorSet.start();
    }
    if (currentAnimation != null) {
        currentAnimation.setSecondParentView(null);
        currentAnimation = null;
        centerImage.setImageBitmap((Drawable) null);
    }
    if (placeProvider instanceof EmptyPhotoViewerProvider) {
        placeProvider.cancelButtonPressed();
    }
}

From source file:org.telegram.ui.ArticleViewer.java

public void closePhoto(boolean animated) {
    if (parentActivity == null || !isPhotoVisible || checkPhotoAnimation()) {
        return;/*from ww w .j  av a 2s  . c  o  m*/
    }

    releasePlayer();
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileLoadProgressChanged);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);

    isActionBarVisible = false;

    if (velocityTracker != null) {
        velocityTracker.recycle();
        velocityTracker = null;
    }

    final PlaceProviderObject object = getPlaceForPhoto(currentMedia);

    if (animated) {
        photoAnimationInProgress = 1;
        animatingImageView.setVisibility(View.VISIBLE);
        photoContainerView.invalidate();

        AnimatorSet animatorSet = new AnimatorSet();

        final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
        Rect drawRegion = null;
        int orientation = centerImage.getOrientation();
        int animatedOrientation = 0;
        if (object != null && object.imageReceiver != null) {
            animatedOrientation = object.imageReceiver.getAnimatedOrientation();
        }
        if (animatedOrientation != 0) {
            orientation = animatedOrientation;
        }
        animatingImageView.setOrientation(orientation);
        if (object != null) {
            animatingImageView.setNeedRadius(object.radius != 0);
            drawRegion = object.imageReceiver.getDrawRegion();
            layoutParams.width = drawRegion.right - drawRegion.left;
            layoutParams.height = drawRegion.bottom - drawRegion.top;
            animatingImageView.setImageBitmap(object.thumb);
        } else {
            animatingImageView.setNeedRadius(false);
            layoutParams.width = centerImage.getImageWidth();
            layoutParams.height = centerImage.getImageHeight();
            animatingImageView.setImageBitmap(centerImage.getBitmap());
        }
        animatingImageView.setLayoutParams(layoutParams);

        float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
        float scaleY = (float) (AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight)
                / layoutParams.height;
        float scale2 = scaleX > scaleY ? scaleY : scaleX;
        float width = layoutParams.width * scale * scale2;
        float height = layoutParams.height * scale * scale2;
        float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
        if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) {
            xPos += ((WindowInsets) lastInsets).getSystemWindowInsetLeft();
        }
        float yPos = (AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight - height) / 2.0f;
        animatingImageView.setTranslationX(xPos + translationX);
        animatingImageView.setTranslationY(yPos + translationY);
        animatingImageView.setScaleX(scale * scale2);
        animatingImageView.setScaleY(scale * scale2);

        if (object != null) {
            object.imageReceiver.setVisible(false, true);
            int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
            int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());

            int coords2[] = new int[2];
            object.parentView.getLocationInWindow(coords2);
            int clipTop = coords2[1] - (object.viewY + drawRegion.top) + object.clipTopAddition;
            if (clipTop < 0) {
                clipTop = 0;
            }
            int clipBottom = (object.viewY + drawRegion.top + (drawRegion.bottom - drawRegion.top))
                    - (coords2[1] + object.parentView.getHeight()) + object.clipBottomAddition;
            if (clipBottom < 0) {
                clipBottom = 0;
            }

            clipTop = Math.max(clipTop, clipVertical);
            clipBottom = Math.max(clipBottom, clipVertical);

            animationValues[0][0] = animatingImageView.getScaleX();
            animationValues[0][1] = animatingImageView.getScaleY();
            animationValues[0][2] = animatingImageView.getTranslationX();
            animationValues[0][3] = animatingImageView.getTranslationY();
            animationValues[0][4] = 0;
            animationValues[0][5] = 0;
            animationValues[0][6] = 0;
            animationValues[0][7] = 0;

            animationValues[1][0] = object.scale;
            animationValues[1][1] = object.scale;
            animationValues[1][2] = object.viewX + drawRegion.left * object.scale;
            animationValues[1][3] = object.viewY + drawRegion.top * object.scale;
            animationValues[1][4] = clipHorizontal * object.scale;
            animationValues[1][5] = clipTop * object.scale;
            animationValues[1][6] = clipBottom * object.scale;
            animationValues[1][7] = object.radius;

            animatorSet.playTogether(
                    ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
                    ObjectAnimator.ofInt(photoBackgroundDrawable, "alpha", 0),
                    ObjectAnimator.ofFloat(actionBar, "alpha", 0),
                    ObjectAnimator.ofFloat(bottomLayout, "alpha", 0),
                    ObjectAnimator.ofFloat(captionTextView, "alpha", 0));
        } else {
            int h = AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight;
            animatorSet.playTogether(ObjectAnimator.ofInt(photoBackgroundDrawable, "alpha", 0),
                    ObjectAnimator.ofFloat(animatingImageView, "alpha", 0.0f),
                    ObjectAnimator.ofFloat(animatingImageView, "translationY", translationY >= 0 ? h : -h),
                    ObjectAnimator.ofFloat(actionBar, "alpha", 0),
                    ObjectAnimator.ofFloat(bottomLayout, "alpha", 0),
                    ObjectAnimator.ofFloat(captionTextView, "alpha", 0));
        }

        photoAnimationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= 18) {
                    photoContainerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                photoContainerView.setVisibility(View.INVISIBLE);
                photoContainerBackground.setVisibility(View.INVISIBLE);
                photoAnimationInProgress = 0;
                onPhotoClosed(object);
            }
        };

        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        if (photoAnimationEndRunnable != null) {
                            photoAnimationEndRunnable.run();
                            photoAnimationEndRunnable = null;
                        }
                    }
                });
            }
        });
        photoTransitionAnimationStartTime = System.currentTimeMillis();
        if (Build.VERSION.SDK_INT >= 18) {
            photoContainerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        animatorSet.start();
    } else {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(photoContainerView, "scaleX", 0.9f),
                ObjectAnimator.ofFloat(photoContainerView, "scaleY", 0.9f),
                ObjectAnimator.ofInt(photoBackgroundDrawable, "alpha", 0),
                ObjectAnimator.ofFloat(actionBar, "alpha", 0), ObjectAnimator.ofFloat(bottomLayout, "alpha", 0),
                ObjectAnimator.ofFloat(captionTextView, "alpha", 0));
        photoAnimationInProgress = 2;
        photoAnimationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (photoContainerView == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT >= 18) {
                    photoContainerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                photoContainerView.setVisibility(View.INVISIBLE);
                photoContainerBackground.setVisibility(View.INVISIBLE);
                photoAnimationInProgress = 0;
                onPhotoClosed(object);
                photoContainerView.setScaleX(1.0f);
                photoContainerView.setScaleY(1.0f);
            }
        };
        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (photoAnimationEndRunnable != null) {
                    photoAnimationEndRunnable.run();
                    photoAnimationEndRunnable = null;
                }
            }
        });
        photoTransitionAnimationStartTime = System.currentTimeMillis();
        if (Build.VERSION.SDK_INT >= 18) {
            photoContainerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        animatorSet.start();
    }
    if (currentAnimation != null) {
        currentAnimation.setSecondParentView(null);
        currentAnimation = null;
        centerImage.setImageBitmap((Drawable) null);
    }
}

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;
    }/*from www  .  j a v a 2  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;
}