Ejemplo n.º 1
0
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
    int height =
        getPaddingTop() + getPaddingBottom() + mContent.getDesiredHeight() + mFolderNameHeight;

    int contentWidthSpec =
        MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(), MeasureSpec.EXACTLY);
    int contentHeightSpec =
        MeasureSpec.makeMeasureSpec(mContent.getDesiredHeight(), MeasureSpec.EXACTLY);
    mContent.measure(contentWidthSpec, contentHeightSpec);

    mFolderName.measure(
        contentWidthSpec, MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
    setMeasuredDimension(width, height);
  }
 private int getContentAreaHeight() {
   LauncherAppState app = LauncherAppState.getInstance();
   DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
   Rect workspacePadding =
       grid.getWorkspacePadding(grid.isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT);
   int maxContentAreaHeight =
       grid.availableHeightPx - workspacePadding.top - workspacePadding.bottom - mFolderNameHeight;
   int height = Math.min(maxContentAreaHeight, mContent.getDesiredHeight());
   return Math.max(height, MIN_CONTENT_DIMEN);
 }
Ejemplo n.º 3
0
  /** 以图标为中心,中心对齐,比如缩放时要以中心对齐 */
  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);

    float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);

    int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
    int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
    int centeredLeft = centerX - width / 2;
    int centeredTop = centerY - height / 2;

    int currentPage = mLauncher.getWorkspace().getCurrentPage();
    // In case the workspace is scrolling, we need to use the final scroll
    // to compute
    // the folders bounds.
    // 如果workspace正在滚动,就强制滚动到最后以计算最终的位置
    mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
    // We first fetch the currently visible CellLayoutChildren
    // 首先获取可见CellLayoutChildren
    CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
    ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
    Rect bounds = new Rect();
    parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
    // We reset the workspaces scroll
    // 强制重置workspace的滚动状态
    mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);

    // 重新调整folder的边界,如果有需要的话,比如实际内容比folder要更大或者更小
    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);
    // 如果实际内容比folder要更大或者更小,那么调整为实际大小
    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);
    // 设置Folder的锚点
    setPivotX(folderPivotX);
    setPivotY(folderPivotY);
    mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width));
    mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height));

    lp.width = width;
    lp.height = height;
    lp.x = left;
    lp.y = top;
  }
Ejemplo n.º 4
0
  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);
    }
  }
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
    int height = getFolderHeight();
    int contentAreaWidthSpec =
        MeasureSpec.makeMeasureSpec(getContentAreaWidth(), MeasureSpec.EXACTLY);
    int contentAreaHeightSpec =
        MeasureSpec.makeMeasureSpec(getContentAreaHeight(), MeasureSpec.EXACTLY);

    if (LauncherAppState.isDisableAllApps() || mScrollingFolders) {
      // Don't cap the height of the content to allow scrolling.
      mContent.setFixedSize(getContentAreaWidth(), mContent.getDesiredHeight());
    } else {
      mContent.setFixedSize(getContentAreaWidth(), getContentAreaHeight());
    }

    mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
    mFolderName.measure(
        contentAreaWidthSpec, MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
    setMeasuredDimension(width, height);
  }