Example usage for android.view View setAlpha

List of usage examples for android.view View setAlpha

Introduction

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

Prototype

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

Source Link

Document

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

Usage

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

private void changeState(final State state) {
    if (mState == state)
        return;//ww w  . ja v  a  2s  .c o m

    final View overviewPanel = mLauncher.getOverviewPanel();
    final View hotseat = mLauncher.getHotseat();
    final View pageIndicator = getPageIndicator();

    setState(state);
    if (state == State.OVERVIEW) {
        if (overviewPanel != null) {
            overviewPanel.setVisibility(View.VISIBLE);
            overviewPanel.setAlpha(1f);
        }

        setAlpha(0f);
        if (hotseat != null)
            hotseat.setVisibility(View.GONE);
        if (pageIndicator != null)
            pageIndicator.setVisibility(View.GONE);
    } else {
        if (overviewPanel != null) {
            overviewPanel.setVisibility(View.GONE);
            overviewPanel.setAlpha(0f);
        }

        setAlpha(1f);
        if (hotseat != null)
            hotseat.setVisibility(View.VISIBLE);
        if (pageIndicator != null)
            pageIndicator.setVisibility(View.VISIBLE);
    }
}

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  w  w  . j  av  a  2  s  .c om

    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:com.android.soma.Launcher.java

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *///w ww.j a v  a  2s . c  om
public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
        final boolean forceAnimateIcons) {
    Runnable r = new Runnable() {
        public void run() {
            bindItems(shortcuts, start, end, forceAnimateIcons);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    final Collection<Animator> bounceAnims = new ArrayList<Animator>();
    final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
    Workspace workspace = mWorkspace;
    long newShortcutsScreenId = -1;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            View shortcut = createShortcut(info);

            /*
             * TODO: FIX collision case
             */
            if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
                if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
                    throw new RuntimeException("OCCUPIED");
                }
            }

            workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            if (animateIcons) {
                // Animate all the applications up now
                shortcut.setAlpha(0f);
                shortcut.setScaleX(0f);
                shortcut.setScaleY(0f);
                bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
                newShortcutsScreenId = item.screenId;
            }
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            break;
        default:
            throw new RuntimeException("Invalid Item Type");
        }
    }

    if (animateIcons) {
        // Animate to the correct page
        if (newShortcutsScreenId > -1) {
            long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
            final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
            final Runnable startBounceAnimRunnable = new Runnable() {
                public void run() {
                    anim.playTogether(bounceAnims);
                    anim.start();
                }
            };
            if (newShortcutsScreenId != currentScreenId) {
                // We post the animation slightly delayed to prevent slowdowns
                // when we are loading right after we return to launcher.
                mWorkspace.postDelayed(new Runnable() {
                    public void run() {
                        mWorkspace.snapToPage(newScreenIndex);
                        mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
                    }
                }, NEW_APPS_PAGE_MOVE_DELAY);
            } else {
                mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
            }
        }
    }
    workspace.requestLayout();
}

From source file:com.fairphone.fplauncher3.Workspace.java

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

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

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

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

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

    mNewScale = 1.0f;

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

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

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

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

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

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

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

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

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

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

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

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

        anim.play(overviewPanelAlpha);
        anim.play(pageIndicatorAlpha);
        anim.setStartDelay(delay);
    } else {
        overviewPanel.setAlpha(finalOverviewPanelAlpha);
        AlphaUpdateListener.updateVisibility(overviewPanel);
        if (pageIndicator != null) {
            pageIndicator.setAlpha(finalHotseatAndPageIndicatorAlpha);
            AlphaUpdateListener.updateVisibility(pageIndicator);
        }
        updateCustomContentVisibility();
        setScaleX(mNewScale);
        setScaleY(mNewScale);
        setTranslationY(finalWorkspaceTranslationY);
    }

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

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

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *///w  ww .j a  va2s  . c o m
public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
        final boolean forceAnimateIcons) {
    Runnable r = new Runnable() {
        public void run() {
            bindItems(shortcuts, start, end, forceAnimateIcons);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    final Collection<Animator> bounceAnims = new ArrayList<Animator>();
    final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
    Workspace workspace = mWorkspace;
    long newShortcutsScreenId = -1;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            View shortcut = createShortcut(info);

            /*
             * TODO: FIX collision case
             */
            if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
                if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
                    View v = cl.getChildAt(item.cellX, item.cellY);
                    Object tag = v.getTag();
                    String desc = "Collision while binding workspace item: " + item + ". Collides with " + tag;
                    if (LauncherAppState.isDogfoodBuild()) {
                        throw (new RuntimeException(desc));
                    } else {
                        Log.d(TAG, desc);
                    }
                }
            }

            workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            if (animateIcons) {
                // Animate all the applications up now
                shortcut.setAlpha(0f);
                shortcut.setScaleX(0f);
                shortcut.setScaleY(0f);
                bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
                newShortcutsScreenId = item.screenId;
            }
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            break;
        default:
            throw new RuntimeException("Invalid Item Type");
        }
    }

    if (animateIcons) {
        // Animate to the correct page
        if (newShortcutsScreenId > -1) {
            long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
            final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
            final Runnable startBounceAnimRunnable = new Runnable() {
                public void run() {
                    anim.playTogether(bounceAnims);
                    anim.start();
                }
            };
            if (newShortcutsScreenId != currentScreenId) {
                // We post the animation slightly delayed to prevent slowdowns
                // when we are loading right after we return to launcher.
                mWorkspace.postDelayed(new Runnable() {
                    public void run() {
                        if (mWorkspace != null) {
                            mWorkspace.snapToPage(newScreenIndex);
                            mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
                        }
                    }
                }, NEW_APPS_PAGE_MOVE_DELAY);
            } else {
                mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
            }
        }
    }
    workspace.requestLayout();
}

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

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

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

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

    final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
    final int itemsAlphaStagger = res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);

    final View fromView = mAppsCustomizeTabHost;
    final View toView = mWorkspace;
    Animator workspaceAnim = null;
    final ArrayList<View> layerViews = new ArrayList<View>();

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

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

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

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

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

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

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

            revealView.setBackgroundColor(getResources().getColor(R.color.widget_text_panel));

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

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

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

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

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

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

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

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

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

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

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

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

            width = revealView.getMeasuredWidth();

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

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

                mStateAnimation.play(reveal);
            }

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

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

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

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

                mAppsCustomizeContent.updateCurrentPageScroll();

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

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

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

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

private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
        final AppsCustomizePagedView.ContentType contentType) {
    if (mStateAnimation != null) {
        mStateAnimation.setDuration(0);//ww w .j  a v  a  2 s.  c o m
        mStateAnimation.cancel();
        mStateAnimation = null;
    }

    boolean material = Utilities.isLmpOrAbove();

    final Resources res = getResources();

    final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
    final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
    final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
    final int itemsAlphaStagger = res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);

    final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
    final View fromView = mWorkspace;
    final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;

    final ArrayList<View> layerViews = new ArrayList<View>();

    Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets
            ? Workspace.State.OVERVIEW_HIDDEN
            : Workspace.State.NORMAL_HIDDEN;
    Animator workspaceAnim = mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
    if (!LauncherAppState.isDisableAllApps() || contentType == AppsCustomizePagedView.ContentType.Widgets) {
        // Set the content type for the all apps/widgets space
        mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
    }

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

    if (animated && initialized) {
        mStateAnimation = LauncherAnimUtils.createAnimatorSet();
        final AppsCustomizePagedView content = (AppsCustomizePagedView) toView
                .findViewById(R.id.apps_customize_pane_content);

        final View page = content.getPageAt(content.getCurrentPage());
        final View revealView = toView.findViewById(R.id.fake_page);

        final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
        if (isWidgetTray) {
            revealView.setBackground(ContextCompat.getDrawable(this, R.drawable.quantum_panel_dark));
        } else {
            revealView.setBackground(currentBgDrawable);
        }

        // Hide the real page background, and swap in the fake one
        content.setPageBackgroundsVisible(false);
        revealView.setVisibility(View.VISIBLE);
        // We need to hide this view as the animation start will be posted.
        revealView.setAlpha(0);

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

        revealView.setTranslationY(0);
        revealView.setTranslationX(0);

        // Get the y delta between the center of the page and the center of the all apps button
        int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView, getAllAppsButton(), null);

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

        revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        layerViews.add(revealView);
        PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
        PropertyValuesHolder panelDriftY = PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
        PropertyValuesHolder panelDriftX = PropertyValuesHolder.ofFloat("translationX", xDrift, 0);

        ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView, panelAlpha,
                panelDriftY, panelDriftX);

        panelAlphaAndDrift.setDuration(revealDuration);
        panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));

        mStateAnimation.play(panelAlphaAndDrift);

        if (page != null) {
            page.setVisibility(View.VISIBLE);
            page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            layerViews.add(page);

            ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
            page.setTranslationY(yDrift);
            pageDrift.setDuration(revealDuration);
            pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
            pageDrift.setStartDelay(itemsAlphaStagger);
            mStateAnimation.play(pageDrift);

            page.setAlpha(0f);
            ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
            itemsAlpha.setDuration(revealDuration);
            itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
            itemsAlpha.setStartDelay(itemsAlphaStagger);
            mStateAnimation.play(itemsAlpha);
        }

        View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
        pageIndicators.setAlpha(0.01f);
        ObjectAnimator indicatorsAlpha = ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
        indicatorsAlpha.setDuration(revealDuration);
        mStateAnimation.play(indicatorsAlpha);

        if (material) {
            final View allApps = getAllAppsButton();
            int allAppsButtonSize = LauncherAppState.getInstance().getDynamicGrid()
                    .getDeviceProfile().allAppsButtonVisualSize;
            float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
            Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2, height / 2,
                    startRadius, revealRadius);
            reveal.setDuration(revealDuration);
            reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));

            reveal.addListener(new AnimatorListenerAdapter() {
                public void onAnimationStart(Animator animation) {
                    if (!isWidgetTray) {
                        allApps.setVisibility(View.INVISIBLE);
                    }
                }

                public void onAnimationEnd(Animator animation) {
                    if (!isWidgetTray) {
                        allApps.setVisibility(View.VISIBLE);
                    }
                }
            });
            mStateAnimation.play(reveal);
        }

        mStateAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                dispatchOnLauncherTransitionEnd(fromView, animated, false);
                dispatchOnLauncherTransitionEnd(toView, animated, false);

                revealView.setVisibility(View.INVISIBLE);
                revealView.setLayerType(View.LAYER_TYPE_NONE, null);
                if (page != null) {
                    page.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                content.setPageBackgroundsVisible(true);

                // Hide the search bar
                if (mSearchDropTargetBar != null) {
                    mSearchDropTargetBar.hideSearchBar(false);
                }

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

        });

        if (workspaceAnim != null) {
            mStateAnimation.play(workspaceAnim);
        }

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

                revealView.setAlpha(initAlpha);
                if (Utilities.isLmpOrAbove()) {
                    for (int i = 0; i < layerViews.size(); i++) {
                        View v = layerViews.get(i);
                        if (v != null) {
                            if (Utilities.isViewAttachedToWindow(v))
                                v.buildLayer();
                        }
                    }
                }
                mStateAnimation.start();
            }
        };
        toView.bringToFront();
        toView.setVisibility(View.VISIBLE);
        toView.post(startAnimRunnable);
    } else {
        toView.setTranslationX(0.0f);
        toView.setTranslationY(0.0f);
        toView.setScaleX(1.0f);
        toView.setScaleY(1.0f);
        toView.setVisibility(View.VISIBLE);
        toView.bringToFront();

        if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
            // Hide the search bar
            if (mSearchDropTargetBar != null) {
                mSearchDropTargetBar.hideSearchBar(false);
            }
        }
        dispatchOnLauncherTransitionPrepare(fromView, animated, false);
        dispatchOnLauncherTransitionStart(fromView, animated, false);
        dispatchOnLauncherTransitionEnd(fromView, animated, false);
        dispatchOnLauncherTransitionPrepare(toView, animated, false);
        dispatchOnLauncherTransitionStart(toView, animated, false);
        dispatchOnLauncherTransitionEnd(toView, animated, false);
    }
}

From source file:com.msn.support.gallery.ZoomActivity.java

/**
 * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in"
 * image view and animating its bounds to fit the entire activity content area. More
 * specifically://ww  w. ja v a 2 s  .c  o  m
 * <ol>
 *   <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li>
 *   <li>Calculate the starting and ending bounds for the expanded view.</li>
 *   <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y)
 *       simultaneously, from the starting bounds to the ending bounds.</li>
 *   <li>Zoom back out by running the reverse animation on click.</li>
 * </ol>
 * ??ImageView?
 * Activity
 * <ol>
 *     <li>???ImageView</li>
 *     <li>?ImageView?</li>
 *     <li>??ImageView?/?X, Y, SCALE_X, SCALE_Y
 *     ??</li>
 *     <li>???</li>
 * @param thumbView  The thumbnail view to zoom in. 
 * @param imageResId The high-resolution version of the image represented by the thumbnail.
 *                   
 */
@TargetApi(11)
private void zoomImageFromThumb(final View thumbView, int imageResId) {
    // If there's an animation in progress, cancel it immediately and proceed with this one.
    // ?
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();
    }

    // Load the high-resolution "zoomed-in" image.?ImageView
    final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image);
    expandedImageView.setImageResource(imageResId);

    // Calculate the starting and ending bounds for the zoomed-in image. This step
    // involves lots of math. Yay, math.
    //?ImageView??
    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    // The start bounds are the global visible rectangle of the thumbnail, and the
    // final bounds are the global visible rectangle of the container view. Also
    // set the container view's offset as the origin for the bounds, since that's
    // the origin for the positioning animation properties (X, Y).
    // ?????
    // ????
    thumbView.getGlobalVisibleRect(startBounds);
    findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);
    Log.e("Test", "globalOffset.x=" + globalOffset.x + " globalOffset.y=" + globalOffset.y);
    Log.e("Test", "startBounds.top=" + startBounds.top + " startBounds.left=" + startBounds.left);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    Log.e("Test", "startBounds2.top=" + startBounds.top + " startBounds2.left=" + startBounds.left);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    // Adjust the start bounds to be the same aspect ratio as the final bounds using the
    // "center crop" technique. This prevents undesirable stretching during the animation.
    // Also calculate the start scaling factor (the end scaling factor is always 1.0).
    // ??"center crop"???
    // ????1.0
    float startScale;
    if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width()
            / startBounds.height()) {
        // Extend start bounds horizontally ?
        startScale = (float) startBounds.height() / finalBounds.height();
        float startWidth = startScale * finalBounds.width();
        float deltaWidth = (startWidth - startBounds.width()) / 2;
        startBounds.left -= deltaWidth;
        startBounds.right += deltaWidth;
    } else {
        // Extend start bounds vertically ?
        startScale = (float) startBounds.width() / finalBounds.width();
        float startHeight = startScale * finalBounds.height();
        float deltaHeight = (startHeight - startBounds.height()) / 2;
        startBounds.top -= deltaHeight;
        startBounds.bottom += deltaHeight;
    }

    // Hide the thumbnail and show the zoomed-in view. When the animation begins,
    // it will position the zoomed-in view in the place of the thumbnail.
    //thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);

    // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of
    // the zoomed-in view (the default is the center of the view).
    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);

    // Construct and run the parallel animation of the four translation and scale properties
    // (X, Y, SCALE_X, and SCALE_Y).
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f))
            .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f));
    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
        }
    });
    set.start();
    mCurrentAnimator = set;

    // Upon clicking the zoomed-in image, it should zoom back down to the original bounds
    // and show the thumbnail instead of the expanded image.
    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mCurrentAnimator != null) {
                mCurrentAnimator.cancel();
            }

            // Animate the four positioning/sizing properties in parallel, back to their
            // original values.
            AnimatorSet set = new AnimatorSet();
            set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
                    .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));
            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                }
            });
            set.start();
            mCurrentAnimator = set;
        }
    });
}

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

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *///from   w  ww  .j  av  a 2s. c om
@Override
public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
        final boolean forceAnimateIcons) {
    Runnable r = new Runnable() {
        public void run() {
            bindItems(shortcuts, start, end, forceAnimateIcons);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    final Collection<Animator> bounceAnims = new ArrayList<Animator>();
    final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
    Workspace workspace = mWorkspace;
    long newShortcutsScreenId = -1;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        final View view;
        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
        case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            view = createShortcut(info);
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            view = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            break;
        default:
            throw new RuntimeException("Invalid Item Type");
        }

        /*
        * Remove colliding items.
        */
        if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
            CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
            if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
                View v = cl.getChildAt(item.cellX, item.cellY);
                Object tag = v.getTag();
                String desc = "Collision while binding workspace item: " + item + ". Collides with " + tag;
                if (ProviderConfig.IS_DOGFOOD_BUILD) {
                    throw (new RuntimeException(desc));
                } else {
                    Log.d(TAG, desc);
                    LauncherModel.deleteItemFromDatabase(this, item);
                    continue;
                }
            }
        }
        workspace.addInScreenFromBind(view, item.container, item.screenId, item.cellX, item.cellY, 1, 1);
        if (animateIcons) {
            // Animate all the applications up now
            view.setAlpha(0f);
            view.setScaleX(0f);
            view.setScaleY(0f);
            bounceAnims.add(createNewAppBounceAnimation(view, i));
            newShortcutsScreenId = item.screenId;
        }
    }

    if (animateIcons) {
        // Animate to the correct page
        if (newShortcutsScreenId > -1) {
            long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
            final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
            final Runnable startBounceAnimRunnable = new Runnable() {
                public void run() {
                    anim.playTogether(bounceAnims);
                    anim.start();
                }
            };
            if (newShortcutsScreenId != currentScreenId) {
                // We post the animation slightly delayed to prevent slowdowns
                // when we are loading right after we return to launcher.
                mWorkspace.postDelayed(new Runnable() {
                    public void run() {
                        if (mWorkspace != null) {
                            mWorkspace.snapToPage(newScreenIndex);
                            mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
                        }
                    }
                }, NEW_APPS_PAGE_MOVE_DELAY);
            } else {
                mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
            }
        }
    }
    workspace.requestLayout();
}

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

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *///from ww w  .ja v a  2  s  .  c  o  m
public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
        final boolean forceAnimateIcons) {

    List<ShortcutInfo> shortcutInfos = new ArrayList<>();
    for (ItemInfo itemInfo : shortcuts) {
        if (itemInfo instanceof ShortcutInfo) {
            shortcutInfos.add((ShortcutInfo) itemInfo);
        }
    }
    loadIconPack(shortcutInfos);
    Runnable r = new Runnable() {
        public void run() {
            bindItems(shortcuts, start, end, forceAnimateIcons);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
    final Collection<Animator> bounceAnims = new ArrayList<Animator>();
    final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
    Workspace workspace = mWorkspace;
    long newShortcutsScreenId = -1;
    for (int i = start; i < end; i++) {
        final ItemInfo item = shortcuts.get(i);

        // Short circuit if we are loading dock items for a configuration which has no dock
        if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && mHotseat == null) {
            continue;
        }

        switch (item.itemType) {
        case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
        case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            ShortcutInfo info = (ShortcutInfo) item;
            View shortcut = createShortcut(info);

            /*
             * TODO: FIX collision case
             */
            if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
                if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
                    View v = cl.getChildAt(item.cellX, item.cellY);
                    Object tag = v.getTag();
                    String desc = "Collision while binding workspace item: " + item + ". Collides with " + tag;
                    if (LauncherAppState.isDogfoodBuild()) {
                        throw (new RuntimeException(desc));
                    } else {
                        Log.d(TAG, desc);
                    }
                }
            }

            workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            if (animateIcons) {
                // Animate all the applications up now
                shortcut.setAlpha(0f);
                shortcut.setScaleX(0f);
                shortcut.setScaleY(0f);
                bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
                newShortcutsScreenId = item.screenId;
            }
            break;
        case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
            FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
                    (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), (FolderInfo) item,
                    mIconCache);
            workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX, item.cellY, 1,
                    1);
            break;
        default:
            throw new RuntimeException("Invalid Item Type");
        }
    }

    if (animateIcons) {
        // Animate to the correct page
        if (newShortcutsScreenId > -1) {
            long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
            final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
            final Runnable startBounceAnimRunnable = new Runnable() {
                public void run() {
                    anim.playTogether(bounceAnims);
                    anim.start();
                }
            };
            if (newShortcutsScreenId != currentScreenId) {
                // We post the animation slightly delayed to prevent slowdowns
                // when we are loading right after we return to launcher.
                mWorkspace.postDelayed(new Runnable() {
                    public void run() {
                        if (mWorkspace != null) {
                            mWorkspace.snapToPage(newScreenIndex);
                            mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
                        }
                    }
                }, NEW_APPS_PAGE_MOVE_DELAY);
            } else {
                mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
            }
        }
    }
    workspace.requestLayout();
}