summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/DeleteDropTarget.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-01-08 16:59:04 -0800
committerSunny Goyal <sunnygoyal@google.com>2015-01-16 17:40:41 -0800
commit71b5c0b988a64b3a0613ded5403749bc537ee8a5 (patch)
treedec5e13b1ef53a7005a9776387fc0a4c1895c39c /src/com/android/launcher3/DeleteDropTarget.java
parent08f7261d11a53ae4b330ad4fa897b8519de3d750 (diff)
downloadandroid_packages_apps_Trebuchet-71b5c0b988a64b3a0613ded5403749bc537ee8a5.tar.gz
android_packages_apps_Trebuchet-71b5c0b988a64b3a0613ded5403749bc537ee8a5.tar.bz2
android_packages_apps_Trebuchet-71b5c0b988a64b3a0613ded5403749bc537ee8a5.zip
Adding accessibility controls
> Adding 'Remove' option to workspace items > Adding 'Add to workspace' to all apps and widget list items, which adds the item to the first available space, giving preference to the current workspace screen > Adding 'App info' and 'Uninstall' options to appropriate items Bug: 18482913 Change-Id: Ifab7423af2d9ba502b5a2771b37bb5436b3df937
Diffstat (limited to 'src/com/android/launcher3/DeleteDropTarget.java')
-rw-r--r--src/com/android/launcher3/DeleteDropTarget.java83
1 files changed, 48 insertions, 35 deletions
diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java
index 5a5c0027e..ebe874f38 100644
--- a/src/com/android/launcher3/DeleteDropTarget.java
+++ b/src/com/android/launcher3/DeleteDropTarget.java
@@ -19,6 +19,7 @@ package com.android.launcher3;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
+import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.res.ColorStateList;
@@ -115,15 +116,6 @@ public class DeleteDropTarget extends ButtonDropTarget {
private boolean isDragSourceWorkspaceOrFolder(DragObject d) {
return (d.dragSource instanceof Workspace) || (d.dragSource instanceof Folder);
}
- private boolean isWorkspaceOrFolderApplication(DragObject d) {
- return isDragSourceWorkspaceOrFolder(d) && (d.dragInfo instanceof ShortcutInfo);
- }
- private boolean isWorkspaceOrFolderWidget(DragObject d) {
- return isDragSourceWorkspaceOrFolder(d) && (d.dragInfo instanceof LauncherAppWidgetInfo);
- }
- private boolean isWorkspaceFolder(DragObject d) {
- return (d.dragSource instanceof Workspace) && (d.dragInfo instanceof FolderInfo);
- }
private void setHoverColor() {
if (mCurrentDrawable != null) {
@@ -177,6 +169,7 @@ public class DeleteDropTarget extends ButtonDropTarget {
return false;
}
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public void onDragStart(DragSource source, Object info, int dragAction) {
boolean isVisible = true;
@@ -284,7 +277,8 @@ public class DeleteDropTarget extends ButtonDropTarget {
}
private boolean isUninstallFromWorkspace(DragObject d) {
- if (LauncherAppState.isDisableAllApps() && isWorkspaceOrFolderApplication(d)) {
+ if (LauncherAppState.isDisableAllApps() && isDragSourceWorkspaceOrFolder(d)
+ && (d.dragInfo instanceof ShortcutInfo)) {
ShortcutInfo shortcut = (ShortcutInfo) d.dragInfo;
// Only allow manifest shortcuts to initiate an un-install.
return !InstallShortcutReceiver.isValidShortcutLaunchIntent(shortcut.intent);
@@ -297,10 +291,7 @@ public class DeleteDropTarget extends ButtonDropTarget {
boolean wasWaitingForUninstall = mWaitingForUninstall;
mWaitingForUninstall = false;
if (isAllAppsApplication(d.dragSource, item)) {
- // Uninstall the application if it is being dragged from AppsCustomize
- AppInfo appInfo = (AppInfo) item;
- mLauncher.startApplicationUninstallActivity(appInfo.componentName, appInfo.flags,
- appInfo.user);
+ uninstallApp(mLauncher, (AppInfo) item);
} else if (isUninstallFromWorkspace(d)) {
ShortcutInfo shortcut = (ShortcutInfo) item;
if (shortcut.intent != null && shortcut.intent.getComponent() != null) {
@@ -329,40 +320,62 @@ public class DeleteDropTarget extends ButtonDropTarget {
mLauncher.addOnResumeCallback(checkIfUninstallWasSuccess);
}
}
- } else if (isWorkspaceOrFolderApplication(d)) {
- LauncherModel.deleteItemFromDatabase(mLauncher, item);
- } else if (isWorkspaceFolder(d)) {
- // Remove the folder from the workspace and delete the contents from launcher model
- FolderInfo folderInfo = (FolderInfo) item;
- mLauncher.removeFolder(folderInfo);
- LauncherModel.deleteFolderContentsFromDatabase(mLauncher, folderInfo);
- } else if (isWorkspaceOrFolderWidget(d)) {
+ } else if (isDragSourceWorkspaceOrFolder(d)) {
+ removeWorkspaceOrFolderItem(mLauncher, item, null);
+ }
+ if (wasWaitingForUninstall && !mWaitingForUninstall) {
+ if (d.dragSource instanceof Folder) {
+ ((Folder) d.dragSource).onUninstallActivityReturned(false);
+ } else if (d.dragSource instanceof Workspace) {
+ ((Workspace) d.dragSource).onUninstallActivityReturned(false);
+ }
+ }
+ }
+
+ public static void uninstallApp(Launcher launcher, AppInfo info) {
+ launcher.startApplicationUninstallActivity(info.componentName, info.flags, info.user);
+ }
+
+ /**
+ * Removes the item from the workspace. If the view is not null, it also removes the view.
+ * @return true if the item was removed.
+ */
+ public static boolean removeWorkspaceOrFolderItem(Launcher launcher, ItemInfo item, View view) {
+ if (item instanceof ShortcutInfo) {
+ LauncherModel.deleteItemFromDatabase(launcher, item);
+ } else if (item instanceof FolderInfo) {
+ FolderInfo folder = (FolderInfo) item;
+ launcher.removeFolder(folder);
+ LauncherModel.deleteFolderContentsFromDatabase(launcher, folder);
+ } else if (item instanceof LauncherAppWidgetInfo) {
+ final LauncherAppWidgetInfo widget = (LauncherAppWidgetInfo) item;
+
// Remove the widget from the workspace
- mLauncher.removeAppWidget((LauncherAppWidgetInfo) item);
- LauncherModel.deleteItemFromDatabase(mLauncher, item);
+ launcher.removeAppWidget(widget);
+ LauncherModel.deleteItemFromDatabase(launcher, widget);
- final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item;
- final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost();
+ final LauncherAppWidgetHost appWidgetHost = launcher.getAppWidgetHost();
- if (appWidgetHost != null && !launcherAppWidgetInfo.isCustomWidget()
- && launcherAppWidgetInfo.isWidgetIdValid()) {
+ if (appWidgetHost != null && !widget.isCustomWidget()
+ && widget.isWidgetIdValid()) {
// Deleting an app widget ID is a void call but writes to disk before returning
// to the caller...
new AsyncTask<Void, Void, Void>() {
public Void doInBackground(Void ... args) {
- appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId);
+ appWidgetHost.deleteAppWidgetId(widget.appWidgetId);
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
+ } else {
+ return false;
}
- if (wasWaitingForUninstall && !mWaitingForUninstall) {
- if (d.dragSource instanceof Folder) {
- ((Folder) d.dragSource).onUninstallActivityReturned(false);
- } else if (d.dragSource instanceof Workspace) {
- ((Workspace) d.dragSource).onUninstallActivityReturned(false);
- }
+
+ if (view != null) {
+ launcher.getWorkspace().removeWorkspaceItem(view);
+ launcher.getWorkspace().stripEmptyScreens();
}
+ return true;
}
public void onDrop(DragObject d) {