コード例 #1
0
ファイル: Folder.java プロジェクト: 00zhengfu00/Launcher
 public void onDrop(DragObject d) {
   ShortcutInfo item;
   if (d.dragInfo instanceof ApplicationInfo) {
     // 如果是来自“所有程序”界面,那么复制这个item
     item = ((ApplicationInfo) d.dragInfo).makeShortcut();
     item.spanX = 1;
     item.spanY = 1;
   } else {
     item = (ShortcutInfo) d.dragInfo;
   }
   // Dragged from self onto self, currently this is the only path
   // possible, however
   // we keep this as a distinct code path.
   // 这个判断应该不可能出现别的情况,当前手动对象当然应该是这个d,这是过于谨慎的判断
   if (item == mCurrentDragInfo) {
     ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
     CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
     si.cellX = lp.cellX = mEmptyCell[0];
     si.cellX = lp.cellY = mEmptyCell[1];
     mContent.addViewToCellLayout(mCurrentDragView, -1, (int) item.id, lp, true);
     if (d.dragView.hasDrawn()) {
       mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
     } else {
       d.deferDragViewCleanupPostAnimation = false;
       mCurrentDragView.setVisibility(VISIBLE);
     }
     mItemsInvalidated = true;
     // 拖进来后重新设置Folder的大小
     setupContentDimensions(getItemCount());
     mSuppressOnAdd = true;
   }
   mInfo.add(item);
 }
コード例 #2
0
ファイル: InfoDropTarget.java プロジェクト: flyfire/temp
  @Override
  public boolean acceptDrop(DragObject d) {
    // acceptDrop is called just before onDrop. We do the work here, rather than
    // in onDrop, because it allows us to reject the drop (by returning false)
    // so that the object being dragged isn't removed from the drag source.
    ComponentName componentName = null;
    if (d.dragInfo instanceof ApplicationInfo) {
      componentName = ((ApplicationInfo) d.dragInfo).componentName;
    } else if (d.dragInfo instanceof ShortcutInfo) {
      componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
    } else if (d.dragInfo instanceof PendingAddItemInfo) {
      componentName = ((PendingAddItemInfo) d.dragInfo).componentName;
    }
    if (componentName != null) {
      mLauncher.startApplicationDetailsActivity(componentName);
    }

    // There is no post-drop animation, so clean up the DragView now
    d.deferDragViewCleanupPostAnimation = false;
    return false;
  }
コード例 #3
0
  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;
  }