Example usage for android.view View setScaleX

List of usage examples for android.view View setScaleX

Introduction

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

Prototype

public void setScaleX(float scaleX) 

Source Link

Document

Sets the amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width.

Usage

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

@Override
protected void screenScrolled(int screenCenter) {
    super.screenScrolled(screenCenter);

    for (int i = 0; i < getChildCount(); i++) {
        View v = getPageAt(i);
        if (v != null) {
            float scrollProgress = getScrollProgress(screenCenter, v, i);

            float interpolatedProgress = mZInterpolator.getInterpolation(Math.abs(Math.min(scrollProgress, 0)));
            float scale = (1 - interpolatedProgress) + interpolatedProgress * TRANSITION_SCALE_FACTOR;
            float translationX = Math.min(0, scrollProgress) * v.getMeasuredWidth();

            float alpha;

            if (scrollProgress < 0) {
                alpha = scrollProgress < 0 ? mAlphaInterpolator.getInterpolation(1 - Math.abs(scrollProgress))
                        : 1.0f;//from w  w  w .  j a v a2s. c om
            } else {
                // On large screens we need to fade the page as it nears its leftmost position
                alpha = mLeftScreenAlphaInterpolator.getInterpolation(1 - scrollProgress);
            }

            v.setCameraDistance(mDensity * CAMERA_DISTANCE);
            int pageWidth = v.getMeasuredWidth();
            int pageHeight = v.getMeasuredHeight();

            if (PERFORM_OVERSCROLL_ROTATION) {
                if (i == 0 && scrollProgress < 0) {
                    // Overscroll to the left
                    v.setPivotX(TRANSITION_PIVOT * pageWidth);
                    v.setRotationY(-TRANSITION_MAX_ROTATION * scrollProgress);
                    scale = 1.0f;
                    alpha = 1.0f;
                    // On the first page, we don't want the page to have any lateral motion
                    translationX = 0;
                } else if (i == getChildCount() - 1 && scrollProgress > 0) {
                    // Overscroll to the right
                    v.setPivotX((1 - TRANSITION_PIVOT) * pageWidth);
                    v.setRotationY(-TRANSITION_MAX_ROTATION * scrollProgress);
                    scale = 1.0f;
                    alpha = 1.0f;
                    // On the last page, we don't want the page to have any lateral motion.
                    translationX = 0;
                } else {
                    v.setPivotY(pageHeight / 2.0f);
                    v.setPivotX(pageWidth / 2.0f);
                    v.setRotationY(0f);
                }
            }

            v.setTranslationX(translationX);
            v.setScaleX(scale);
            v.setScaleY(scale);
            v.setAlpha(alpha);

            // If the view has 0 alpha, we set it to be invisible so as to prevent
            // it from accepting touches
            if (alpha == 0) {
                v.setVisibility(INVISIBLE);
            } else if (v.getVisibility() != VISIBLE) {
                v.setVisibility(VISIBLE);
            }
        }
    }
}

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

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

    // Get the list of added shortcuts and intersect them with the set of shortcuts here
    Set<String> newApps = new HashSet<String>();
    newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps);

    Workspace workspace = mWorkspace;
    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;
            String uri = info.intent.toUri(0).toString();
            View shortcut = createShortcut(info);
            workspace.addInScreen(shortcut, item.container, item.screen, item.cellX, item.cellY, 1, 1, false);
            boolean animateIconUp = false;
            synchronized (newApps) {
                if (newApps.contains(uri)) {
                    animateIconUp = newApps.remove(uri);
                }
            }
            if (animateIconUp) {
                // Prepare the view to be animated up
                shortcut.setAlpha(0f);
                shortcut.setScaleX(0f);
                shortcut.setScaleY(0f);
                mNewShortcutAnimatePage = item.screen;
                if (!mNewShortcutAnimateViews.contains(shortcut)) {
                    mNewShortcutAnimateViews.add(shortcut);
                }
            }
            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.addInScreen(newFolder, item.container, item.screen, item.cellX, item.cellY, 1, 1, false);
            break;
        }
    }

    workspace.requestLayout();
}

From source file:com.github.songnick.viewgroup.ScaleViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    final int scrollX = getScrollX();

    int decorCount = 0;

    // First pass - decor views. We need to do this in two passes so that
    // we have the proper offsets for non-decor views later.
    for (int i = 0; i < count; i++) {
        Log.e(TAG, " layout child is  " + i);
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int childLeft = 100;
            int childTop = 0;
            if (lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                }/*from w ww.j av a2  s .  c om*/
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                }
                childLeft += scrollX;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
                decorCount++;
            }
        }
    }

    final int childWidth = width - paddingLeft - paddingRight;
    // Page views. Do this once we have the right padding offsets from above.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        Log.e(TAG, " second layout child is  " + i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            child.setScaleX(.8f);
            child.setScaleY(.8f);
            if (!lp.isDecor && (ii = infoForChild(child)) != null) {
                Log.e(TAG, " layout child is off set ==  " + ii.offset);
                int loff = (int) (childWidth * ii.offset);
                int childLeft = paddingLeft + loff;
                int childTop = paddingTop;
                int childRight = childLeft + child.getMeasuredWidth();
                int childBottom = childTop + child.getMeasuredHeight();

                if (lp.needsMeasure) {
                    // This was added during layout and needs measurement.
                    // Do it now that we know what we're working with.
                    lp.needsMeasure = false;
                    final int widthSpec = MeasureSpec.makeMeasureSpec((int) (childWidth * lp.widthFactor),
                            MeasureSpec.EXACTLY);
                    final int heightSpec = MeasureSpec
                            .makeMeasureSpec((int) (height - paddingTop - paddingBottom), MeasureSpec.EXACTLY);
                    child.measure(widthSpec, heightSpec);
                }
                if (DEBUG)
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                if (i == 1) {
                    childLeft = childLeft - 100;
                }
                child.layout(childLeft, childTop, childRight, childBottom);
            }
        }
    }
    mTopPageBounds = paddingTop;
    mBottomPageBounds = height - paddingBottom;
    mDecorChildCount = decorCount;

    if (mFirstLayout) {
        scrollToItem(mCurItem, false, 0, false);
    }
    mFirstLayout = false;
    //        int childSize = getChildCount();
    //        for (int i = 0; i < childSize; i++) {
    //
    //            getChildAt(i).setScaleX(.8f);
    //            getChildAt(i).setScaleY(.8f);
    //        }
}

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  a2s .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)) {
                    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.kozhevin.example.carousel.CarouselLayoutManager.java

/**
 * The magic functions :). Scaled all item of ChildView array.
 * //from www. j  av a2 s  .  c o  m
 * @param renderState
 *
 */
private void makeScaleView(RenderState renderState) {

    updateCenter();

    if (mIsEnabledCalulateLappingItem) {
        if (renderState.mLayoutDirection == RenderState.LAYOUT_START) {
            // from left to right
            if (IS_DEBUG && IS_DEBUG_SCALE) {
                Log.w(TAG, "Scroll from left to right");
            }
            if (getmOffsetForSmoothController() < 0) {
                setOffsetForSmoothController(-getmOffsetForSmoothController());
            }
            mMinLappingValue = getWidth();
        } else {

            mMinLappingValue = -getWidth();
            if (IS_DEBUG && IS_DEBUG_SCALE) {
                Log.w(TAG, "Scroll from right to left");
            }
            if (getmOffsetForSmoothController() > 0) {
                setOffsetForSmoothController(-getmOffsetForSmoothController());
            }
        }

        mMinLappingItemIndex = 0;
    }
    float lCenterChild = 0;
    float lDeltaXCenterChild = 0;
    float lScaleValue = 0;
    for (int i = 0; i < getChildCount(); ++i) {
        View child = getChildAt(i);
        lCenterChild = child.getRight() - child.getPivotX();
        lDeltaXCenterChild = mCenterScreen - lCenterChild;
        if (mIsEnabledCalulateLappingItem) {
            if (renderState.mLayoutDirection == RenderState.LAYOUT_START) {
                // from left to right

                if (lDeltaXCenterChild > 0 && mMinLappingValue > lDeltaXCenterChild) {
                    mMinLappingValue = lDeltaXCenterChild;
                    if (getPosition(child) > 0) {
                        mMinLappingItemIndex = getPosition(child); // + 1;
                    } else {
                        mMinLappingItemIndex = 1;
                    }
                    if (IS_DEBUG && IS_DEBUG_SCALE) {
                        Log.w(TAG,
                                "mMinLappingValue = " + mMinLappingValue + " index = " + mMinLappingItemIndex);
                    }
                } else if (lDeltaXCenterChild < 0 && mMinLappingItemIndex == getPosition(child) /*+ 1*/) {
                    mMinLappingValue = getWidth();
                    if (IS_DEBUG && IS_DEBUG_SCALE) {
                        Log.w(TAG,
                                "mMinLappingValue = " + mMinLappingValue + " index = " + mMinLappingItemIndex);
                    }

                }
            } else {
                if (lDeltaXCenterChild < 0 && mMinLappingValue < lDeltaXCenterChild) {
                    mMinLappingValue = lDeltaXCenterChild;
                    if (getPosition(child) < getItemCount() - 1) {
                        mMinLappingItemIndex = getPosition(child);
                    } else {
                        if (IS_DEBUG && IS_DEBUG_SCALE) {
                            Log.w(TAG, "Scrolled last position = " + getPosition(child)
                                    + ", set the penultimate position.");
                        }

                        mMinLappingItemIndex = getItemCount() - 2;
                    }

                    if (IS_DEBUG && IS_DEBUG_SCALE) {
                        Log.w(TAG,
                                "mMinLappingValue = " + mMinLappingValue + " index = " + mMinLappingItemIndex);
                    }
                } else if (lDeltaXCenterChild > 0 && mMinLappingItemIndex == getPosition(child) + 1) {
                    mMinLappingValue = -getWidth();
                    if (IS_DEBUG && IS_DEBUG_SCALE) {
                        Log.w(TAG,
                                "mMinLappingValue = " + mMinLappingValue + " index = " + mMinLappingItemIndex);
                    }

                }
            }
        }
        if (IS_DEBUG && IS_DEBUG_SCALE) {
            Log.d(TAG, "lDeltaXCenterChild value = " + lDeltaXCenterChild);
        }

        /*
         * scale = a + b * cos(w / pi * dx) a = (max + min) / 2 b = (max -
         * min) / 2 dx - shift from the center max - the maximum value of
         * scale (1) min - the minimum value of scale w - When dx = 0, the
         * value of scale will be max, when dx = +w or -w, the value will be
         * min pi - math PI constant
         * 
         * assume max = 1, min = 0.4; then a = 0.7, b = 0.3
         */
        lScaleValue = (float) (0.7 + 0.3 * Math.cos(lDeltaXCenterChild * Math.PI / getWidth() / 2));
        if (IS_DEBUG) {
            Log.d(TAG, "scale value = " + lScaleValue);
        }
        if (lScaleValue < 0) {
            lScaleValue = 0;
        }
        if (lScaleValue > 1) {
            Log.e(TAG, "scale value = " + lScaleValue);
        }
        child.setScaleY(lScaleValue);
        child.setScaleX(lScaleValue);

        if (IS_DEBUG && IS_DEBUG_SCALE) {
            Log.d(TAG, "child index = " + i + " centerX = " + (child.getRight() - child.getPivotX()));
        }

    }

}

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  w w  .j  a v a2s .  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.launcher3.Launcher.java

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 */// w ww  .j  a va  2 s .c o  m
@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  w w  w. j  av a2s. 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();
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

/**
 * Bind the items start-end from the list.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 *//*  w  w  w  .j  ava  2  s .c o m*/
@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:
            ShortcutInfo info = (ShortcutInfo) item;
            view = 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);
                    }
                }
            }
            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");
        }

        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();
}