public void onAdd(ShortcutInfo item) {
   mItemsInvalidated = true;
   // If the item was dropped onto this open folder, we have done the work associated
   // with adding the item to the folder, as indicated by mSuppressOnAdd being set
   if (mSuppressOnAdd) return;
   if (!findAndSetEmptyCells(item)) {
     // The current layout is full, can we expand it?
     setupContentForNumItems(getItemCount() + 1);
     findAndSetEmptyCells(item);
   }
   createAndAddShortcut(item);
   LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
 }
Ejemplo n.º 2
0
 public void onAdd(ShortcutInfo item) {
   mItemsInvalidated = true;
   // If the item was dropped onto this open folder, we have done the work
   // associated
   // with adding the item to the folder, as indicated by mSuppressOnAdd
   // being set
   if (mSuppressOnAdd) return;
   // 如果当前item不在Layout中,添加进来,如果需要,扩张一下Folder
   if (!findAndSetEmptyCells(item)) {
     setupContentForNumItems(getItemCount() + 1);
     findAndSetEmptyCells(item);
   }
   createAndAddShortcut(item);
   LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
 }
Ejemplo n.º 3
0
  private void replaceFolderWithFinalItem() {
    ItemInfo finalItem = null;

    if (getItemCount() == 1) {
      finalItem = mInfo.contents.get(0);
    }

    // Remove the folder completely
    CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screen);
    cellLayout.removeView(mFolderIcon);
    if (mFolderIcon instanceof DropTarget) {
      mDragController.removeDropTarget((DropTarget) mFolderIcon);
    }
    mLauncher.removeFolder(mInfo);

    if (finalItem != null) {
      LauncherModel.addOrMoveItemInDatabase(
          mLauncher, finalItem, mInfo.container, mInfo.screen, mInfo.cellX, mInfo.cellY);
    }
    LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);

    // Add the last remaining child to the workspace in place of the folder
    if (finalItem != null) {
      View child =
          mLauncher.createShortcut(R.layout.application, cellLayout, (ShortcutInfo) finalItem);

      mLauncher
          .getWorkspace()
          .addInScreen(
              child,
              mInfo.container,
              mInfo.screen,
              mInfo.cellX,
              mInfo.cellY,
              mInfo.spanX,
              mInfo.spanY);
    }
  }
  private void arrangeChildren(ArrayList<View> list) {
    int[] vacant = new int[2];
    if (list == null) {
      list = getItemsInReadingOrder();
    }
    mContent.removeAllViews();

    for (int i = 0; i < list.size(); i++) {
      View v = list.get(i);
      mContent.getVacantCell(vacant, 1, 1);
      CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
      lp.cellX = vacant[0];
      lp.cellY = vacant[1];
      ItemInfo info = (ItemInfo) v.getTag();
      if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
        info.cellX = vacant[0];
        info.cellY = vacant[1];
        LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0, info.cellX, info.cellY);
      }
      boolean insert = false;
      mContent.addViewToCellLayout(v, insert ? 0 : -1, (int) info.id, lp, true);
    }
    mItemsInvalidated = true;
  }
  public void onDrop(DragObject d) {
    Runnable cleanUpRunnable = null;

    // If we are coming from All Apps space, we defer removing the extra empty screen
    // until the folder closes
    if (d.dragSource != mLauncher.getWorkspace() && !(d.dragSource instanceof Folder)) {
      cleanUpRunnable =
          new Runnable() {
            @Override
            public void run() {
              mLauncher.exitSpringLoadedDragModeDelayed(
                  true, Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
            }
          };
    }

    View currentDragView;
    ShortcutInfo si = mCurrentDragInfo;
    if (mIsExternalDrag) {
      si.cellX = mEmptyCell[0];
      si.cellY = mEmptyCell[1];

      // Actually move the item in the database if it was an external drag. Call this
      // before creating the view, so that ShortcutInfo is updated appropriately.
      LauncherModel.addOrMoveItemInDatabase(mLauncher, si, mInfo.id, 0, si.cellX, si.cellY);

      // We only need to update the locations if it doesn't get handled in #onDropCompleted.
      if (d.dragSource != this) {
        updateItemLocationsInDatabaseBatch();
      }
      mIsExternalDrag = false;

      currentDragView = createAndAddShortcut(si);
    } else {
      currentDragView = mCurrentDragView;
      CellLayout.LayoutParams lp = (CellLayout.LayoutParams) currentDragView.getLayoutParams();
      si.cellX = lp.cellX = mEmptyCell[0];
      si.cellX = lp.cellY = mEmptyCell[1];
      mContent.addViewToCellLayout(currentDragView, -1, (int) si.id, lp, true);
    }

    if (d.dragView.hasDrawn()) {

      // Temporarily reset the scale such that the animation target gets calculated correctly.
      float scaleX = getScaleX();
      float scaleY = getScaleY();
      setScaleX(1.0f);
      setScaleY(1.0f);
      mLauncher
          .getDragLayer()
          .animateViewIntoPosition(d.dragView, currentDragView, cleanUpRunnable, null);
      setScaleX(scaleX);
      setScaleY(scaleY);
    } else {
      d.deferDragViewCleanupPostAnimation = false;
      currentDragView.setVisibility(VISIBLE);
    }
    mItemsInvalidated = true;
    setupContentDimensions(getItemCount());

    // Temporarily suppress the listener, as we did all the work already here.
    mSuppressOnAdd = true;
    mInfo.add(si);
    mSuppressOnAdd = false;
    // Clear the drag info, as it is no longer being dragged.
    mCurrentDragInfo = null;
  }
Ejemplo n.º 6
0
 public void addItem(ShortcutInfo item) {
   mInfo.add(item);
   LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
 }
  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);
  }
Ejemplo n.º 8
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);
 }