When an app is chosen in All Apps, tapping a workspace screen adds it to that screen.
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
index 074a098..b1275b8 100644
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ b/src/com/android/launcher2/AllAppsPagedView.java
@@ -93,6 +93,7 @@
@Override
public void setLauncher(Launcher launcher) {
mLauncher = launcher;
+ mLauncher.setAllAppsPagedView(this);
}
@Override
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 53661fa..a6f0a0e 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -213,7 +213,9 @@
private HandleView mHandleView;
private AllAppsView mAllAppsGrid;
private TabHost mHomeCustomizationDrawer;
- private CustomizePagedView mCustomizePagedView;
+
+ private PagedView mAllAppsPagedView = null;
+ private CustomizePagedView mCustomizePagedView = null;
private Bundle mSavedState;
@@ -2404,6 +2406,9 @@
final View fromView =
(fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
+ mCustomizePagedView.endChoiceMode();
+ mAllAppsPagedView.endChoiceMode();
+
setPivotsForZoom(fromView, fromState, scaleFactor);
mWorkspace.unshrink(animated);
@@ -2461,6 +2466,9 @@
final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
+ mCustomizePagedView.endChoiceMode();
+ mAllAppsPagedView.endChoiceMode();
+
if (toState == State.ALL_APPS) {
mWorkspace.shrinkToBottom(animated);
} else {
@@ -2603,13 +2611,28 @@
}
}
- void onWorkspaceUnshrink() {
- final boolean animated = true;
- if (isAllAppsVisible()) {
- closeAllApps(animated);
+ void onWorkspaceClick(CellLayout layout) {
+ Object itemInfo = mAllAppsPagedView.getChosenItem();
+ if (itemInfo == null) {
+ itemInfo = mCustomizePagedView.getChosenItem();
}
- if (isCustomizationDrawerVisible()) {
- hideCustomizationDrawer(animated);
+
+ if (itemInfo == null) {
+ // No items are chosen in All Apps or Customize, so just zoom into the workspace
+ mWorkspace.unshrink(layout);
+ if (isAllAppsVisible()) {
+ closeAllApps(true);
+ } else if (isCustomizationDrawerVisible()) {
+ hideCustomizationDrawer(true);
+ }
+ } else {
+ // Act as if the chosen item was dropped on the given CellLayout
+ if (mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
+ mAllAppsPagedView.endChoiceMode();
+ mCustomizePagedView.endChoiceMode();
+ } else {
+ Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
+ }
}
}
@@ -2800,6 +2823,10 @@
}
}
+ void setAllAppsPagedView(PagedView view) {
+ mAllAppsPagedView = view;
+ }
+
/**
* Refreshes the shortcuts shown on the workspace.
*
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index df3f0cc..c638119 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -1009,7 +1009,7 @@
mChoiceMode = mode;
}
- protected void endChoiceMode() {
+ public void endChoiceMode() {
if (!isChoiceMode(CHOICE_MODE_NONE)) {
mChoiceMode = CHOICE_MODE_NONE;
resetCheckedGrandchildren();
@@ -1059,6 +1059,14 @@
return null;
}
+ public Object getChosenItem() {
+ View checkedView = (View) getSingleCheckedGrandchild();
+ if (checkedView != null) {
+ return checkedView.getTag();
+ }
+ return null;
+ }
+
protected void resetCheckedGrandchildren() {
// loop through children, and set all of their children to _not_ be checked
final ArrayList<Checkable> checked = getCheckedGrandchildren();
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index bb63c08..e0761ff 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -368,8 +368,7 @@
public boolean onTouch(View v, MotionEvent event) {
// this is an intercepted event being forwarded from a cell layout
if (mIsSmall) {
- unshrink((CellLayout)v);
- mLauncher.onWorkspaceUnshrink();
+ mLauncher.onWorkspaceClick((CellLayout) v);
return true;
}
return false;
@@ -630,7 +629,7 @@
}
// We call this when we trigger an unshrink by clicking on the CellLayout cl
- private void unshrink(CellLayout clThatWasClicked) {
+ public void unshrink(CellLayout clThatWasClicked) {
int newCurrentPage = mCurrentPage;
final int screenCount = getChildCount();
for (int i = 0; i < screenCount; i++) {
@@ -974,6 +973,24 @@
onDropExternal(x, y, dragInfo, cellLayout, false);
}
+ /**
+ * Add the item specified by dragInfo to the given layout.
+ * This is basically the equivalent of onDropExternal, except it's not initiated
+ * by drag and drop.
+ * @return true if successful
+ */
+ public boolean addExternalItemToScreen(Object dragInfo, View layout) {
+ CellLayout cl = (CellLayout) layout;
+ ItemInfo info = (ItemInfo) dragInfo;
+
+ final CellLayout.CellInfo cellInfo = cl.updateOccupiedCells(null, null);
+ if (cellInfo.findCellForSpan(mTempEstimate, info.spanX, info.spanY)) {
+ onDropExternal(0, 0, dragInfo, cl, false);
+ return true;
+ }
+ return false;
+ }
+
private void onDropExternal(int x, int y, Object dragInfo,
CellLayout cellLayout, boolean insertAtFirst) {
// Drag from somewhere else