Search in sources :

Example 6 with GridOccupancy

use of com.android.launcher3.util.GridOccupancy in project android_packages_apps_Launcher3 by crdroidandroid.

the class CellLayout method animateChildToPosition.

public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay, boolean permanent, boolean adjustOccupied) {
    ShortcutAndWidgetContainer clc = getShortcutsAndWidgets();
    if (clc.indexOfChild(child) != -1 && (child instanceof Reorderable)) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final ItemInfo info = (ItemInfo) child.getTag();
        final Reorderable item = (Reorderable) child;
        // We cancel any existing animations
        if (mReorderAnimators.containsKey(lp)) {
            mReorderAnimators.get(lp).cancel();
            mReorderAnimators.remove(lp);
        }
        if (adjustOccupied) {
            GridOccupancy occupied = permanent ? mOccupied : mTmpOccupied;
            occupied.markCells(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, false);
            occupied.markCells(cellX, cellY, lp.cellHSpan, lp.cellVSpan, true);
        }
        // Compute the new x and y position based on the new cellX and cellY
        // We leverage the actual layout logic in the layout params and hence need to modify
        // state and revert that state.
        final int oldX = lp.x;
        final int oldY = lp.y;
        lp.isLockedToGrid = true;
        if (permanent) {
            lp.cellX = info.cellX = cellX;
            lp.cellY = info.cellY = cellY;
        } else {
            lp.tmpCellX = cellX;
            lp.tmpCellY = cellY;
        }
        clc.setupLp(child);
        final int newX = lp.x;
        final int newY = lp.y;
        lp.x = oldX;
        lp.y = oldY;
        lp.isLockedToGrid = false;
        // End compute new x and y
        item.getReorderPreviewOffset(mTmpPointF);
        final float initPreviewOffsetX = mTmpPointF.x;
        final float initPreviewOffsetY = mTmpPointF.y;
        final float finalPreviewOffsetX = newX - oldX;
        final float finalPreviewOffsetY = newY - oldY;
        // Exit early if we're not actually moving the view
        if (finalPreviewOffsetX == 0 && finalPreviewOffsetY == 0 && initPreviewOffsetX == 0 && initPreviewOffsetY == 0) {
            lp.isLockedToGrid = true;
            return true;
        }
        ValueAnimator va = ValueAnimator.ofFloat(0f, 1f);
        va.setDuration(duration);
        mReorderAnimators.put(lp, va);
        va.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float r = (Float) animation.getAnimatedValue();
                float x = (1 - r) * initPreviewOffsetX + r * finalPreviewOffsetX;
                float y = (1 - r) * initPreviewOffsetY + r * finalPreviewOffsetY;
                item.setReorderPreviewOffset(x, y);
            }
        });
        va.addListener(new AnimatorListenerAdapter() {

            boolean cancelled = false;

            public void onAnimationEnd(Animator animation) {
                // place just yet.
                if (!cancelled) {
                    lp.isLockedToGrid = true;
                    item.setReorderPreviewOffset(0, 0);
                    child.requestLayout();
                }
                if (mReorderAnimators.containsKey(lp)) {
                    mReorderAnimators.remove(lp);
                }
            }

            public void onAnimationCancel(Animator animation) {
                cancelled = true;
            }
        });
        va.setStartDelay(delay);
        va.start();
        return true;
    }
    return false;
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) GridOccupancy(com.android.launcher3.util.GridOccupancy) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 7 with GridOccupancy

use of com.android.launcher3.util.GridOccupancy in project android_packages_apps_Launcher3 by crdroidandroid.

the class CellLayout method addViewsToTempLocation.

private boolean addViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop, int[] direction, View dragView, ItemConfiguration currentState) {
    if (views.size() == 0)
        return true;
    boolean success = false;
    Rect boundingRect = new Rect();
    // We construct a rect which represents the entire group of views passed in
    currentState.getBoundingRectForViews(views, boundingRect);
    // Mark the occupied state as false for the group of views we want to move.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        mTmpOccupied.markCells(c, false);
    }
    GridOccupancy blockOccupied = new GridOccupancy(boundingRect.width(), boundingRect.height());
    int top = boundingRect.top;
    int left = boundingRect.left;
    // for interlocking.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        blockOccupied.markCells(c.cellX - left, c.cellY - top, c.spanX, c.spanY, true);
    }
    mTmpOccupied.markCells(rectOccupiedByPotentialDrop, true);
    findNearestArea(boundingRect.left, boundingRect.top, boundingRect.width(), boundingRect.height(), direction, mTmpOccupied.cells, blockOccupied.cells, mTempLocation);
    // If we successfuly found a location by pushing the block of views, we commit it
    if (mTempLocation[0] >= 0 && mTempLocation[1] >= 0) {
        int deltaX = mTempLocation[0] - boundingRect.left;
        int deltaY = mTempLocation[1] - boundingRect.top;
        for (View v : views) {
            CellAndSpan c = currentState.map.get(v);
            c.cellX += deltaX;
            c.cellY += deltaY;
        }
        success = true;
    }
    // In either case, we set the occupied array as marked for the location of the views
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        mTmpOccupied.markCells(c, true);
    }
    return success;
}
Also used : Rect(android.graphics.Rect) CellAndSpan(com.android.launcher3.util.CellAndSpan) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) GridOccupancy(com.android.launcher3.util.GridOccupancy) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 8 with GridOccupancy

use of com.android.launcher3.util.GridOccupancy in project android_packages_apps_Launcher3 by crdroidandroid.

the class AddWorkspaceItemsTask method findNextAvailableIconSpaceInScreen.

private boolean findNextAvailableIconSpaceInScreen(LauncherAppState app, ArrayList<ItemInfo> occupiedPos, int[] xy, int spanX, int spanY) {
    InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
    GridOccupancy occupied = new GridOccupancy(profile.numColumns, profile.numRows);
    if (occupiedPos != null) {
        for (ItemInfo r : occupiedPos) {
            occupied.markCells(r, true);
        }
    }
    return occupied.findVacantCell(xy, spanX, spanY);
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) GridOccupancy(com.android.launcher3.util.GridOccupancy)

Example 9 with GridOccupancy

use of com.android.launcher3.util.GridOccupancy in project android_packages_apps_Launcher3 by crdroidandroid.

the class CellLayout method cloneGridOccupancy.

/**
 * returns a copy of cell layout's grid occupancy
 */
public GridOccupancy cloneGridOccupancy() {
    GridOccupancy occupancy = new GridOccupancy(mCountX, mCountY);
    mOccupied.copyTo(occupancy);
    return occupancy;
}
Also used : GridOccupancy(com.android.launcher3.util.GridOccupancy)

Example 10 with GridOccupancy

use of com.android.launcher3.util.GridOccupancy in project android_packages_apps_Launcher3 by crdroidandroid.

the class CellLayout method setGridSize.

public void setGridSize(int x, int y) {
    mCountX = x;
    mCountY = y;
    mOccupied = new GridOccupancy(mCountX, mCountY);
    mTmpOccupied = new GridOccupancy(mCountX, mCountY);
    mTempRectStack.clear();
    mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mCountX, mCountY, mBorderSpacing);
    requestLayout();
}
Also used : GridOccupancy(com.android.launcher3.util.GridOccupancy)

Aggregations

GridOccupancy (com.android.launcher3.util.GridOccupancy)12 Point (android.graphics.Point)5 SuppressLint (android.annotation.SuppressLint)3 Paint (android.graphics.Paint)3 Rect (android.graphics.Rect)2 View (android.view.View)2 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)2 Utilities.parsePoint (com.android.launcher3.Utilities.parsePoint)2 ItemInfo (com.android.launcher3.model.data.ItemInfo)2 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)2 CellAndSpan (com.android.launcher3.util.CellAndSpan)2 IntSparseArrayMap (com.android.launcher3.util.IntSparseArrayMap)2 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)1 Intent (android.content.Intent)1 Workspace (com.android.launcher3.Workspace)1