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);
  }
  public void onDrop(
      DragSource source,
      int x,
      int y,
      int xOffset,
      int yOffset,
      DragView dragView,
      Object dragInfo) {
    // get workspace
    ViewParent parent = getParent();
    if (parent == null) {
      return;
    }

    Workspace mTargetWorkspace = (Workspace) parent.getParent();

    final int workspaceType = mTargetWorkspace.getType();
    int container = 0;
    switch (workspaceType) {
      case Workspace.WORKSPACE_NAVIGATEBAR:
        container = LauncherSettings.Favorites.CONTAINER_NAVIGATEBAR;
        break;
      case Workspace.WORKSPACE_WORKSPACE:
        container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
        break;
      default:
        return;
    }

    final CellLayout.LayoutParams currentLp = (CellLayout.LayoutParams) getLayoutParams();
    // CellLayout targetCelllayout = (CellLayout) getParent();

    // remove my in parent
    removeSelfInParent(mLauncher.getDragController());
    // clearAnimation();
    // targetCelllayout.removeView(this);

    // make the folder info.

    final UserFolderInfo folderInfo = new UserFolderInfo();
    folderInfo.title = getResources().getText(R.string.folder_name);
    // add folder into db
    LauncherModel.addItemToDatabase(
        getContext(),
        folderInfo,
        container,
        mTargetWorkspace.getCurrentScreen(),
        currentLp.cellX,
        currentLp.cellY,
        true);

    // add into new folder
    // CellLayout.CellInfo cellInfo = mSourceWorkspace.getCurrentDragInfo();

    final ShortcutInfo thisTag = (ShortcutInfo) getTag();
    final ShortcutInfo sourceTag = (ShortcutInfo) dragInfo;
    final int oldSourceScreen = sourceTag.screen;
    folderInfo.add(thisTag);
    folderInfo.add(sourceTag);

    // add folder items into db
    LauncherModel.addOrMoveItemInDatabase(mLauncher, thisTag, folderInfo.id, 0, 0, 0);
    LauncherModel.addOrMoveItemInDatabase(mLauncher, sourceTag, folderInfo.id, 0, 0, 0);

    // Create the view
    final FolderIcon newFolder =
        FolderIcon.fromXml(
            R.layout.folder_icon,
            mLauncher,
            (ViewGroup) mTargetWorkspace.getChildAt(mTargetWorkspace.getCurrentScreen()),
            folderInfo);

    // add into target cell
    mTargetWorkspace.addInCurrentScreen(newFolder, currentLp.cellX, currentLp.cellY, 1, 1, false);

    // start anim
    AnimManager.getInstance().startSingle(newFolder);

    // range cell
    Workspace sourceWorkspace = (Workspace) source;
    CellLayout sourceCellLayout = (CellLayout) sourceWorkspace.getChildAt(oldSourceScreen);
    sourceCellLayout.rangeChilds(false);

    // open folder
    mTargetWorkspace
        .getHandler()
        .postDelayed(
            new Runnable() {
              public void run() {
                mLauncher.handleIphoneFolderClick(folderInfo, newFolder);
              }
            },
            200);
  }
예제 #3
0
 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, Object dragInfo) {
   final ApplicationInfo item = (ApplicationInfo) dragInfo;
   // TODO: update open folder that is looking at this data
   mInfo.add(item);
   LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
 }