示例#1
0
  void addAllAppsFolder(
      IconCache iconCache,
      ArrayList<AppInfo> allApps,
      ArrayList<ComponentName> onWorkspace,
      Launcher launcher,
      Workspace workspace) {
    if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
      FolderInfo fi = new FolderInfo();

      fi.cellX = getCellXFromOrder(mAllAppsButtonRank);
      fi.cellY = getCellYFromOrder(mAllAppsButtonRank);
      fi.spanX = 1;
      fi.spanY = 1;
      fi.container = LauncherSettings.Favorites.CONTAINER_HOTSEAT;
      fi.screenId = mAllAppsButtonRank;
      fi.itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
      fi.title = "More Apps";
      LauncherModel.addItemToDatabase(
          launcher, fi, fi.container, fi.screenId, fi.cellX, fi.cellY, false);
      FolderIcon folder =
          FolderIcon.fromXml(R.layout.folder_icon, launcher, getLayout(), fi, iconCache);
      workspace.addInScreen(
          folder, fi.container, fi.screenId, fi.cellX, fi.cellY, fi.spanX, fi.spanY);

      for (AppInfo info : allApps) {
        ComponentName cn = info.intent.getComponent();
        if (!onWorkspace.contains(cn)) {
          Log.d(TAG, "Adding to 'more apps': " + info.intent);
          ShortcutInfo si = info.makeShortcut();
          fi.add(si);
        }
      }
    }
  }
  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);
  }