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
This commit is contained in:
Jon Miranda
2016-10-18 11:47:42 -07:00
parent d2959b9ee7
commit 9485e5f293
4 changed files with 25 additions and 55 deletions

View File

@@ -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.
*/