Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9485e5f2 authored by Jon Miranda's avatar Jon Miranda
Browse files

Show error toast messages when there is no room for the item when icon is not...

Show error toast messages when there is no room for the item when icon is not to be added to folder.

* when user tries to add item to full hot seat from workspace.
* when user tries to add item to full home screen from workspace.
* refactored so that Workspace handles displaying error messages.

Bug: 15574422
Change-Id: Ibc98c7f45bc0c646dc4636660fba62be9db22ac0
parent d2959b9e
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -1466,7 +1466,7 @@ public class Launcher extends Activity
        }

        if (!foundCellSpan) {
            showOutOfSpaceMessage(isHotseatLayout(layout));
            mWorkspace.onNoCellFound(layout);
            return;
        }

@@ -1612,11 +1612,6 @@ public class Launcher extends Activity
        }
    }

    public void showOutOfSpaceMessage(boolean isHotseatLayout) {
        int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
        Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
    }

    public DragLayer getDragLayer() {
        return mDragLayer;
    }
+24 −12
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.view.accessibility.AccessibilityManager;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.TextView;
import android.widget.Toast;

import com.android.launcher3.Launcher.CustomContentCallbacks;
import com.android.launcher3.Launcher.LauncherOverlay;
@@ -2406,18 +2407,7 @@ public class Workspace extends PagedView

            // Don't accept the drop if there's no room for the item
            if (!foundCell) {
                // Don't show the message if we are dropping on the AllApps button and the hotseat
                // is full
                boolean isHotseat = mLauncher.isHotseatLayout(dropTargetLayout);
                if (mTargetCell != null && isHotseat && !FeatureFlags.NO_ALL_APPS_ICON) {
                    Hotseat hotseat = mLauncher.getHotseat();
                    if (mLauncher.getDeviceProfile().inv.isAllAppsButtonRank(
                            hotseat.getOrderInHotseat(mTargetCell[0], mTargetCell[1]))) {
                        return false;
                    }
                }

                mLauncher.showOutOfSpaceMessage(isHotseat);
                onNoCellFound(dropTargetLayout);
                return false;
            }
        }
@@ -2703,6 +2693,8 @@ public class Workspace extends PagedView
                    LauncherModel.modifyItemInDatabase(mLauncher, info, container, screenId, lp.cellX,
                            lp.cellY, item.spanX, item.spanY);
                } else {
                    onNoCellFound(dropTargetLayout);

                    // If we can't find a drop location, we return the item to its original position
                    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
                    mTargetCell[0] = lp.cellX;
@@ -2748,6 +2740,26 @@ public class Workspace extends PagedView
        }
    }

    public void onNoCellFound(View dropTargetLayout) {
        if (mLauncher.isHotseatLayout(dropTargetLayout)) {
            Hotseat hotseat = mLauncher.getHotseat();
            boolean droppedOnAllAppsIcon = !FeatureFlags.NO_ALL_APPS_ICON
                    && mTargetCell != null && !mLauncher.getDeviceProfile().inv.isAllAppsButtonRank(
                    hotseat.getOrderInHotseat(mTargetCell[0], mTargetCell[1]));
            if (!droppedOnAllAppsIcon) {
                // Only show message when hotseat is full and drop target was not AllApps button
                showOutOfSpaceMessage(true);
            }
        } else {
            showOutOfSpaceMessage(false);
        }
    }

    private void showOutOfSpaceMessage(boolean isHotseatLayout) {
        int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
        Toast.makeText(mLauncher, mLauncher.getString(strId), Toast.LENGTH_SHORT).show();
    }

    /**
     * Computes the area relative to dragLayer which is used to display a page.
     */
+0 −19
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.view.ViewGroup;

import com.android.launcher3.AppInfo;
import com.android.launcher3.BaseContainerView;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeleteDropTarget;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DragSource;
@@ -44,7 +43,6 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherTransitionable;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragOptions;
@@ -419,24 +417,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
        }
        mLauncher.unlockScreenOrientation(false);

        // Display an error message if the drag failed due to there not being enough space on the
        // target layout we were dropping on.
        if (!success) {
            boolean showOutOfSpaceMessage = false;
            if (target instanceof Workspace) {
                int currentScreen = mLauncher.getCurrentWorkspaceScreen();
                Workspace workspace = (Workspace) target;
                CellLayout layout = (CellLayout) workspace.getChildAt(currentScreen);
                ItemInfo itemInfo = d.dragInfo;
                if (layout != null) {
                    showOutOfSpaceMessage =
                            !layout.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY);
                }
            }
            if (showOutOfSpaceMessage) {
                mLauncher.showOutOfSpaceMessage(false);
            }

            d.deferDragViewCleanupPostAnimation = false;
        }
    }
+0 −18
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.view.ViewGroup;
import android.widget.Toast;

import com.android.launcher3.BaseContainerView;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeleteDropTarget;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget.DragObject;
@@ -42,7 +41,6 @@ import com.android.launcher3.PendingAddItemInfo;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.WidgetPreviewLoader;
import com.android.launcher3.Workspace;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.model.WidgetsModel;
@@ -291,23 +289,7 @@ public class WidgetsContainerView extends BaseContainerView
        }
        mLauncher.unlockScreenOrientation(false);

        // Display an error message if the drag failed due to there not being enough space on the
        // target layout we were dropping on.
        if (!success) {
            boolean showOutOfSpaceMessage = false;
            if (target instanceof Workspace) {
                int currentScreen = mLauncher.getCurrentWorkspaceScreen();
                Workspace workspace = (Workspace) target;
                CellLayout layout = (CellLayout) workspace.getChildAt(currentScreen);
                ItemInfo itemInfo = d.dragInfo;
                if (layout != null) {
                    showOutOfSpaceMessage =
                            !layout.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY);
                }
            }
            if (showOutOfSpaceMessage) {
                mLauncher.showOutOfSpaceMessage(false);
            }
            d.deferDragViewCleanupPostAnimation = false;
        }
    }