summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2015-09-18 18:53:48 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-09-18 18:53:48 +0000
commit26bfdd9d5a0cc590d78a849d3401b52c02494a2c (patch)
treebb44dbd8614569a078fb89f11ee1be7edadab6a1
parent8580dd584a59b8895db0f4603321346ffe3ecd26 (diff)
parenta3c9fb125c7449df5add990e91e0e3471e3cc776 (diff)
downloadandroid_packages_apps_Trebuchet-26bfdd9d5a0cc590d78a849d3401b52c02494a2c.tar.gz
android_packages_apps_Trebuchet-26bfdd9d5a0cc590d78a849d3401b52c02494a2c.tar.bz2
android_packages_apps_Trebuchet-26bfdd9d5a0cc590d78a849d3401b52c02494a2c.zip
am a3c9fb12: Merge "Requiring key chord to delete icons and folders on the workspace" into ub-launcher3-burnaby-polish
* commit 'a3c9fb125c7449df5add990e91e0e3471e3cc776': Requiring key chord to delete icons and folders on the workspace
-rw-r--r--res/layout/all_apps_search_market.xml2
-rw-r--r--src/com/android/launcher3/DeleteDropTarget.java6
-rw-r--r--src/com/android/launcher3/FocusHelper.java46
-rw-r--r--src/com/android/launcher3/Folder.java29
-rw-r--r--src/com/android/launcher3/Launcher.java19
-rw-r--r--src/com/android/launcher3/Workspace.java4
6 files changed, 74 insertions, 32 deletions
diff --git a/res/layout/all_apps_search_market.xml b/res/layout/all_apps_search_market.xml
index 1ed508890..a2bb2e779 100644
--- a/res/layout/all_apps_search_market.xml
+++ b/res/layout/all_apps_search_market.xml
@@ -25,5 +25,5 @@
android:textSize="14sp"
android:textColor="@color/launcher_accent_color"
android:textAllCaps="true"
- android:focusable="false"
+ android:focusable="true"
android:background="@drawable/all_apps_search_market_bg" />
diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java
index 6d8fa6bd0..76e14f51c 100644
--- a/src/com/android/launcher3/DeleteDropTarget.java
+++ b/src/com/android/launcher3/DeleteDropTarget.java
@@ -70,8 +70,10 @@ public class DeleteDropTarget extends ButtonDropTarget {
* @return true if the item was removed.
*/
public static boolean removeWorkspaceOrFolderItem(Launcher launcher, ItemInfo item, View view) {
- // Remove the item from launcher and the db
- launcher.removeItem(view, item, true /* deleteFromDb */);
+ // Remove the item from launcher and the db, we can ignore the containerInfo in this call
+ // because we already remove the drag view from the folder (if the drag originated from
+ // a folder) in Folder.beginDrag()
+ launcher.removeItem(view, null, item, true /* deleteFromDb */);
launcher.getWorkspace().stripEmptyScreens();
return true;
}
diff --git a/src/com/android/launcher3/FocusHelper.java b/src/com/android/launcher3/FocusHelper.java
index 6f345875a..be4d04f93 100644
--- a/src/com/android/launcher3/FocusHelper.java
+++ b/src/com/android/launcher3/FocusHelper.java
@@ -73,7 +73,6 @@ public class FocusHelper {
KeyEvent.keyCodeToString(keyCode)));
}
-
if (!(v.getParent() instanceof ShortcutAndWidgetContainer)) {
if (ProviderConfig.IS_DOGFOOD_BUILD) {
throw new IllegalStateException("Parent of the focused item is not supported.");
@@ -196,10 +195,11 @@ public class FocusHelper {
}
// Initialize the variables.
+ final Workspace workspace = (Workspace) v.getRootView().findViewById(R.id.workspace);
final ShortcutAndWidgetContainer hotseatParent = (ShortcutAndWidgetContainer) v.getParent();
final CellLayout hotseatLayout = (CellLayout) hotseatParent.getParent();
- Workspace workspace = (Workspace) v.getRootView().findViewById(R.id.workspace);
+ final ItemInfo itemInfo = (ItemInfo) v.getTag();
int pageIndex = workspace.getNextPage();
int pageCount = workspace.getChildCount();
int countX = -1;
@@ -241,9 +241,14 @@ public class FocusHelper {
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT &&
profile.isVerticalBarLayout()) {
keyCode = KeyEvent.KEYCODE_PAGE_DOWN;
- } else if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) {
- ItemInfo info = (ItemInfo) v.getTag();
- launcher.removeItem(v, info, true /* deleteFromDb */);
+ } else if (isUninstallKeyChord(e)) {
+ matrix = FocusLogic.createSparseMatrix(iconLayout);
+ if (UninstallDropTarget.supportsDrop(launcher, itemInfo)) {
+ UninstallDropTarget.startUninstallActivity(launcher, itemInfo);
+ }
+ } else if (isDeleteKeyChord(e)) {
+ matrix = FocusLogic.createSparseMatrix(iconLayout);
+ launcher.removeItem(v, null, itemInfo, true /* deleteFromDb */);
} else {
// For other KEYCODE_DPAD_LEFT and KEYCODE_DPAD_RIGHT navigation, do not use the
// matrix extended with hotseat.
@@ -305,6 +310,7 @@ public class FocusHelper {
final ViewGroup tabs = (ViewGroup) dragLayer.findViewById(R.id.search_drop_target_bar);
final Hotseat hotseat = (Hotseat) dragLayer.findViewById(R.id.hotseat);
+ final ItemInfo itemInfo = (ItemInfo) v.getTag();
final int iconIndex = parent.indexOfChild(v);
final int pageIndex = workspace.indexOfChild(iconLayout);
final int pageCount = workspace.getChildCount();
@@ -329,10 +335,14 @@ public class FocusHelper {
profile.inv.hotseatAllAppsRank,
!hotseat.hasIcons() /* ignore all apps icon, unless there are no other icons */);
countX = countX + 1;
- } else if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) {
- ItemInfo info = (ItemInfo) v.getTag();
- launcher.removeItem(v, info, true /* deleteFromDb */);
- return consume;
+ } else if (isUninstallKeyChord(e)) {
+ matrix = FocusLogic.createSparseMatrix(iconLayout);
+ if (UninstallDropTarget.supportsDrop(launcher, itemInfo)) {
+ UninstallDropTarget.startUninstallActivity(launcher, itemInfo);
+ }
+ } else if (isDeleteKeyChord(e)) {
+ matrix = FocusLogic.createSparseMatrix(iconLayout);
+ launcher.removeItem(v, null, itemInfo, true /* deleteFromDb */);
} else {
matrix = FocusLogic.createSparseMatrix(iconLayout);
}
@@ -462,4 +472,22 @@ public class FocusHelper {
break;
}
}
+
+ /**
+ * Returns whether the key event represents a valid uninstall key chord.
+ */
+ private static boolean isUninstallKeyChord(KeyEvent event) {
+ int keyCode = event.getKeyCode();
+ return (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) &&
+ event.hasModifiers(KeyEvent.META_CTRL_ON | KeyEvent.META_SHIFT_ON);
+ }
+
+ /**
+ * Returns whether the key event represents a valid delete key chord.
+ */
+ private static boolean isDeleteKeyChord(KeyEvent event) {
+ int keyCode = event.getKeyCode();
+ return (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) &&
+ event.hasModifiers(KeyEvent.META_CTRL_ON);
+ }
}
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index ff21be218..ff65d3098 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -1123,26 +1123,29 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
public void run() {
CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
- View child = null;
- // Move the item from the folder to the workspace, in the position of the folder
- if (getItemCount() == 1) {
- ShortcutInfo finalItem = mInfo.contents.get(0);
- child = mLauncher.createShortcut(cellLayout, finalItem);
- LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
- mInfo.screenId, mInfo.cellX, mInfo.cellY);
- }
+ // Remove the folder
if (getItemCount() <= 1) {
- mLauncher.removeItem(mFolderIcon, mInfo, true /* deleteFromDb */);
+ mLauncher.removeItem(mFolderIcon, null, mInfo, true /* deleteFromDb */);
if (mFolderIcon instanceof DropTarget) {
mDragController.removeDropTarget((DropTarget) mFolderIcon);
}
}
- // We add the child after removing the folder to prevent both from existing at
- // the same time in the CellLayout. We need to add the new item with addInScreenFromBind()
- // to ensure that hotseat items are placed correctly.
- if (child != null) {
+
+ // Move the item from the folder to the workspace, in the position of the folder
+ if (getItemCount() == 1) {
+ ShortcutInfo finalItem = mInfo.contents.get(0);
+ View child = mLauncher.createShortcut(cellLayout, finalItem);
+ LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
+ mInfo.screenId, mInfo.cellX, mInfo.cellY);
+
+ // We add the child after removing the folder to prevent both from existing at
+ // the same time in the CellLayout. We need to add the new item with addInScreenFromBind()
+ // to ensure that hotseat items are placed correctly.
mLauncher.getWorkspace().addInScreenFromBind(child, mInfo.container, mInfo.screenId,
mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
+
+ // Focus the newly created child
+ child.requestFocus();
}
}
};
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 11869d9e6..d695e347d 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2326,13 +2326,22 @@ public class Launcher extends Activity
}
/**
- * Unbinds the view for the specified item, and removes the item and all its children items
- * from the database. For folders, this incl udes the folder contents. AppWidgets will also
- * have their widget ids deleted.
+ * Unbinds the view for the specified item, and removes the item and all its children.
+ *
+ * @param v the view being removed.
+ * @param containerInfo the {@link FolderInfo} container of this view (can be null).
+ * @param itemInfo the {@link ItemInfo} for this view.
+ * @param deleteFromDb whether or not to delete this item from the db.
*/
- public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
+ public boolean removeItem(View v, FolderInfo containerInfo, ItemInfo itemInfo,
+ boolean deleteFromDb) {
if (itemInfo instanceof ShortcutInfo) {
- mWorkspace.removeWorkspaceItem(v);
+ // Remove the shortcut from the folder before removing it from launcher
+ if (containerInfo != null) {
+ containerInfo.remove((ShortcutInfo) itemInfo);
+ } else {
+ mWorkspace.removeWorkspaceItem(v);
+ }
if (deleteFromDb) {
LauncherModel.deleteItemFromDatabase(this, itemInfo);
}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index b59d85dd5..778bff7b6 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1105,7 +1105,7 @@ public class Workspace extends PagedView
if (lahv != null && lahv.isReinflateRequired()) {
// Remove and rebind the current widget (which was inflated in the wrong
// orientation), but don't delete it from the database
- mLauncher.removeItem(lahv, info, false /* deleteFromDb */);
+ mLauncher.removeItem(lahv, null, info, false /* deleteFromDb */);
mLauncher.bindAppWidget(info);
}
}
@@ -4441,7 +4441,7 @@ public class Workspace extends PagedView
if (info.hostView instanceof PendingAppWidgetHostView) {
// Remove and rebind the current widget, but don't delete it from the database
PendingAppWidgetHostView view = (PendingAppWidgetHostView) info.hostView;
- mLauncher.removeItem(view, info, false /* deleteFromDb */);
+ mLauncher.removeItem(view, null, info, false /* deleteFromDb */);
mLauncher.bindAppWidget(info);
}
}