Esempio n. 1
0
  private void deleteFromWorkspace(DragSource source, ItemInfo item) {
    // TODO Auto-generated method stub
    if (item.container == Favorites.CONTAINER_DESKTOP) {
      if (item instanceof LauncherAppWidgetInfo) {
        mLauncher.removeAppWidget((LauncherAppWidgetInfo) item);
      } else if (item instanceof CustomAppWidgetInfo) {
        if (((CustomAppWidgetInfo) item).itemType == Favorites.ITEM_TYPE_WIDGET_LOCK_SCREEN) {
          final ContentResolver cr = mLauncher.getContentResolver();
          final String where =
              BaseLauncherColumns.ITEM_TYPE + "=" + Favorites.ITEM_TYPE_WIDGET_LOCK_SCREEN;
          Cursor c = cr.query(Favorites.CONTENT_URI, null, where, null, null);
          // should remove administration when no more LOCK_SCREEN
          // widget displayed in launcher
          if (c.getCount() <= 1) {
            LockScreenUtil.getInstance(mLauncher).removeAdmin();
          }
        }
      }
    } else {
      if (source instanceof UserFolder) {
        final UserFolder userFolder = (UserFolder) source;
        final FolderInfo folderInfo = userFolder.getInfo();
        if (folderInfo instanceof UserFolderInfo) {
          // Item must be a ShortcutInfo otherwise it couldn't have
          // been in the folder
          // in the first place.
          if (item instanceof ShortcutInfo && item.container == folderInfo.id) {
            mLauncher.removeItemFromFolder((ShortcutInfo) item);
          }
        }
      }
    }
    if (item instanceof UserFolderInfo) {
      final UserFolderInfo userFolderInfo = (UserFolderInfo) item;
      if (userFolderInfo.contents.size() > 0) {
        Toast.makeText(mLauncher, R.string.folder_is_not_empty, Toast.LENGTH_SHORT).show();
        return;
      }

      LauncherModel.deleteUserFolderContentsFromDatabase(mLauncher, userFolderInfo);
      mLauncher.removeFolder(userFolderInfo);
    } else if (item instanceof LauncherAppWidgetInfo) {
      final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item;
      final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost();
      if (appWidgetHost != null) {
        appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId);
      }
      mLauncher.getWorkspace().forceToDeleteWidget((long) launcherAppWidgetInfo.appWidgetId);
    } else if (item instanceof CustomAppWidgetInfo) {
      mLauncher.getWorkspace().forceToDeleteWidget(((CustomAppWidgetInfo) item).id);
    }
    LauncherModel.deleteItemFromDatabase(mLauncher, item);
  }
  public void onDrop(
      DragSource source,
      int x,
      int y,
      int xOffset,
      int yOffset,
      DragView dragView,
      Object dragInfo) {
    final ItemInfo item = (ItemInfo) dragInfo;

    if (item.container == -1) return;

    if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
      if (item instanceof LauncherAppWidgetInfo) {
        mLauncher.removeAppWidget((LauncherAppWidgetInfo) item);
      }
    } else {
      if (source instanceof UserFolder) {
        final UserFolder userFolder = (UserFolder) source;
        final UserFolderInfo userFolderInfo = (UserFolderInfo) userFolder.getInfo();
        // Item must be a ShortcutInfo otherwise it couldn't have been in the folder
        // in the first place.
        userFolderInfo.remove((ShortcutInfo) item);
      }
    }
    if (item instanceof UserFolderInfo) {
      final UserFolderInfo userFolderInfo = (UserFolderInfo) item;
      LauncherModel.deleteUserFolderContentsFromDatabase(mLauncher, userFolderInfo);
      mLauncher.removeFolder(userFolderInfo);
    } else if (item instanceof LauncherAppWidgetInfo) {
      final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item;
      final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost();
      if (appWidgetHost != null) {
        appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId);
      }
    }
    LauncherModel.deleteItemFromDatabase(mLauncher, item);
  }
Esempio n. 3
0
  public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
    final ItemInfo item = (ItemInfo) dragInfo;

    // dismiss popup to avoid an ugly bug when the qaw is triggered directly on top of the delete
    // zone
    mLauncher.dismissQuickActionWindow();

    if (item.container == -1) return;

    final LauncherModel model = Launcher.getLauncherModel();
    if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
      if (item instanceof LauncherAppWidgetInfo) {
        model.removeDesktopAppWidget((LauncherAppWidgetInfo) item);
      } else {
        model.removeDesktopItem(item);
      }
    } else {
      if (source instanceof UserFolder) {
        final UserFolder userFolder = (UserFolder) source;
        final UserFolderInfo userFolderInfo = (UserFolderInfo) userFolder.getInfo();
        model.removeUserFolderItem(userFolderInfo, item);
      }
    }
    if (item instanceof UserFolderInfo) {
      final UserFolderInfo userFolderInfo = (UserFolderInfo) item;
      LauncherModel.deleteUserFolderContentsFromDatabase(mLauncher, userFolderInfo);
      model.removeUserFolder(userFolderInfo);
    } else if (item instanceof LauncherAppWidgetInfo) {
      final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item;
      final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost();
      mLauncher.getWorkspace().unbindWidgetScrollableId(launcherAppWidgetInfo.appWidgetId);
      if (appWidgetHost != null) {
        appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId);
      }
    }
    LauncherModel.deleteItemFromDatabase(mLauncher, item);
  }