コード例 #1
0
ファイル: Folder.java プロジェクト: FutureHax/Hax-Launcher
  private void centerAboutIcon() {
    DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();

    int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
    int height =
        getPaddingTop() + getPaddingBottom() + mContent.getDesiredHeight() + mFolderNameHeight;
    DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);

    parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);

    int centerX = mTempRect.centerX();
    int centerY = mTempRect.centerY();
    int centeredLeft = centerX - width / 2;
    int centeredTop = centerY - height / 2;

    // We first fetch the currently visible CellLayoutChildren
    CellLayout currentPage = mLauncher.getWorkspace().getCurrentDropLayout();
    CellLayoutChildren boundingLayout = currentPage.getChildrenLayout();
    Rect bounds = new Rect();
    parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);

    // We need to bound the folder to the currently visible CellLayoutChildren
    int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width);
    int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height);
    // If the folder doesn't fit within the bounds, center it about the desired bounds
    if (width >= bounds.width()) {
      left = bounds.left + (bounds.width() - width) / 2;
    }
    if (height >= bounds.height()) {
      top = bounds.top + (bounds.height() - height) / 2;
    }

    int folderPivotX = width / 2 + (centeredLeft - left);
    int folderPivotY = height / 2 + (centeredTop - top);
    setPivotX(folderPivotX);
    setPivotY(folderPivotY);
    int folderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width));
    int folderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height));
    mFolderIcon.setPivotX(folderIconPivotX);
    mFolderIcon.setPivotY(folderIconPivotY);

    if (mMode == PARTIAL_GROW) {
      lp.width = width;
      lp.height = height;
      lp.x = left;
      lp.y = top;
    } else {
      mNewSize.set(left, top, left + width, top + height);
    }
  }