summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/Launcher.java
diff options
context:
space:
mode:
authorWinson <winsonc@google.com>2015-09-09 16:38:15 -0700
committerWinson <winsonc@google.com>2015-09-10 14:55:17 -0700
commitc0b52fefbc11531d560359c093484099f9d1298e (patch)
tree0ac56dcb6819e6e314438d7bc535ef39dbbbfc99 /src/com/android/launcher3/Launcher.java
parent01251b0dc4c302a8b9eb6ef6797c8e33eebab139 (diff)
downloadandroid_packages_apps_Trebuchet-c0b52fefbc11531d560359c093484099f9d1298e.tar.gz
android_packages_apps_Trebuchet-c0b52fefbc11531d560359c093484099f9d1298e.tar.bz2
android_packages_apps_Trebuchet-c0b52fefbc11531d560359c093484099f9d1298e.zip
Refactoring to ensure item deletion always removes from the DB.
- Routing the various places where we call through to delete from LauncherModel through Launcher, which will delegate the removal of the icon from the workspace, and properly handle the removal of all items and their contents from the db. Bug: 23944119 Change-Id: I022fe2b3e79da16b5af87505c4362490b8422686
Diffstat (limited to 'src/com/android/launcher3/Launcher.java')
-rw-r--r--src/com/android/launcher3/Launcher.java64
1 files changed, 56 insertions, 8 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index c017dc05a..65aa68ab5 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1787,7 +1787,7 @@ public class Launcher extends Activity
}
});
- void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
+ private void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
if (v instanceof Advanceable) {
@@ -1797,18 +1797,13 @@ public class Launcher extends Activity
}
}
- void removeWidgetToAutoAdvance(View hostView) {
+ private void removeWidgetToAutoAdvance(View hostView) {
if (mWidgetsToAdvance.containsKey(hostView)) {
mWidgetsToAdvance.remove(hostView);
updateAutoAdvanceState();
}
}
- public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
- removeWidgetToAutoAdvance(launcherInfo.hostView);
- launcherInfo.hostView = null;
- }
-
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();
@@ -2394,10 +2389,63 @@ public class Launcher extends Activity
return newFolder;
}
- void removeFolder(FolderInfo folder) {
+ /**
+ * 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.
+ */
+ public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) {
+ if (itemInfo instanceof ShortcutInfo) {
+ mWorkspace.removeWorkspaceItem(v);
+ if (deleteFromDb) {
+ LauncherModel.deleteItemFromDatabase(this, itemInfo);
+ }
+ } else if (itemInfo instanceof FolderInfo) {
+ final FolderInfo folderInfo = (FolderInfo) itemInfo;
+ unbindFolder(folderInfo);
+ mWorkspace.removeWorkspaceItem(v);
+ if (deleteFromDb) {
+ LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo);
+ }
+ } else if (itemInfo instanceof LauncherAppWidgetInfo) {
+ final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
+ unbindAppWidget(widgetInfo, deleteFromDb);
+ if (deleteFromDb) {
+ LauncherModel.deleteItemFromDatabase(this, widgetInfo);
+ }
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Unbinds any launcher references to the folder.
+ */
+ private void unbindFolder(FolderInfo folder) {
sFolders.remove(folder.id);
}
+ /**
+ * Unbinds any launcher references to the widget and deletes the app widget id.
+ */
+ private void unbindAppWidget(final LauncherAppWidgetInfo widgetInfo, boolean deleteAppWidgetId) {
+ final LauncherAppWidgetHost appWidgetHost = getAppWidgetHost();
+ if (deleteAppWidgetId && appWidgetHost != null &&
+ !widgetInfo.isCustomWidget() && widgetInfo.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(widgetInfo.appWidgetId);
+ return null;
+ }
+ }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ }
+ removeWidgetToAutoAdvance(widgetInfo.hostView);
+ widgetInfo.hostView = null;
+ }
+
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {