コード例 #1
0
  private void replaceFolderWithFinalItem() {
    // Add the last remaining child to the workspace in place of the folder
    Runnable onCompleteRunnable =
        new Runnable() {
          @Override
          public void run() {
            CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);

            View child = null;
            // Move the item from the folder to the workspace, in the position of the folder
            if (getItemCount() == 1) {
              ShortcutInfo finalItem = mInfo.contents.get(0);
              child = mLauncher.createShortcut(R.layout.application, cellLayout, finalItem);
              LauncherModel.addOrMoveItemInDatabase(
                  mLauncher, finalItem, mInfo.container, mInfo.screenId, mInfo.cellX, mInfo.cellY);
            }
            if (getItemCount() <= 1) {
              // Remove the folder
              LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
              if (cellLayout != null) {
                // b/12446428 -- sometimes the cell layout has already gone away?
                cellLayout.removeView(mFolderIcon);
              }
              if (mFolderIcon instanceof DropTarget) {
                mDragController.removeDropTarget((DropTarget) mFolderIcon);
              }
              mLauncher.removeFolder(mInfo);
            }
            // We add the child after removing the folder to prevent both from existing at
            // the same time in the CellLayout.  We need to add the new item with
            // addInScreenFromBind()
            // to ensure that hotseat items are placed correctly.
            if (child != null) {
              mLauncher
                  .getWorkspace()
                  .addInScreenFromBind(
                      child,
                      mInfo.container,
                      mInfo.screenId,
                      mInfo.cellX,
                      mInfo.cellY,
                      mInfo.spanX,
                      mInfo.spanY);
            }
          }
        };
    View finalChild = getItemAt(0);
    if (finalChild != null) {
      mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
    } else {
      onCompleteRunnable.run();
    }
    mDestroyed = true;
  }
コード例 #2
0
ファイル: Folder.java プロジェクト: 00zhengfu00/Launcher
  /** 用最后一个剩余的item代替当前folder显示在桌面上,这发生在Folder里面只有一个item的时候 */
  private void replaceFolderWithFinalItem() {
    Runnable onCompleteRunnable =
        new Runnable() {
          @Override
          public void run() {
            CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screen);

            View child = null;
            // 将最后一个item从Folder移动到桌面上,与Folder一个位置。
            // 但是在这个if块里面并没有实际移动,而仅仅是生成数据并放到了数据库中。
            if (getItemCount() == 1) {
              ShortcutInfo finalItem = mInfo.contents.get(0);
              child = mLauncher.createShortcut(R.layout.application, cellLayout, finalItem);
              LauncherModel.addOrMoveItemInDatabase(
                  mLauncher, finalItem, mInfo.container, mInfo.screen, mInfo.cellX, mInfo.cellY);
            }
            if (getItemCount() <= 1) {
              // 删除Folder
              LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
              cellLayout.removeView(mFolderIcon);
              if (mFolderIcon instanceof DropTarget) {
                mDragController.removeDropTarget((DropTarget) mFolderIcon);
              }
              mLauncher.removeFolder(mInfo);
            }
            // 在删除文件夹后才添加最后一个item到桌面,这是为了防止在同一时间同一位置有两个item
            if (child != null) {
              mLauncher
                  .getWorkspace()
                  .addInScreen(
                      child,
                      mInfo.container,
                      mInfo.screen,
                      mInfo.cellX,
                      mInfo.cellY,
                      mInfo.spanX,
                      mInfo.spanY);
            }
          }
        };
    View finalChild = getItemAt(0);
    if (finalChild != null) {
      // 文件夹销毁动画
      mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
    }
    mDestroyed = true;
  }