Example #1
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // TODO Auto-generated method stub
    int width;
    int height;

    width = MeasureSpec.getSize(widthMeasureSpec);

    // 獲取刻度數字高度
    mTextPaint.getTextBounds(mCalibrationArray[0] + "", 0, 1, mTextBounds);
    // 20默認豎線高度
    int topheight = Math.max(mTextBounds.height() + VERTICALLINEHEIGHT, mBitmap.getHeight());
    height = topheight + mBarHeight + mBitmap.getHeight();
    setMeasuredDimension(width, height);

    // 初始下游標繪製的rect
    mCursorBottomDstRect.set(0, height - mBitmap.getHeight(), mBitmap.getWidth(), height);
    // 初始上游標繪製的rect
    mCursorTopDstRect.set(
        width - mBitmap.getWidth(),
        height - 2 * mBitmap.getHeight() - mBarHeight,
        width,
        height - mBitmap.getHeight() - mBarHeight);
    // 計算bar的寬度
    mBarWidth = MeasureSpec.getSize(widthMeasureSpec) - mBitmap.getWidth();
  }
  public void setAdapter(TaskDescriptionAdapter adapter) {
    Log.d(TAG, "adapter.getCount() = " + adapter.getCount());
    mAdapter = adapter;
    mAdapter.registerDataSetObserver(
        new DataSetObserver() {
          public void onChanged() {
            update();
          }

          public void onInvalidated() {
            update();
          }
        });
    DisplayMetrics dm = getResources().getDisplayMetrics();
    int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(dm.widthPixels, MeasureSpec.AT_MOST);
    int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(dm.heightPixels, MeasureSpec.AT_MOST);
    View child = mAdapter.createView(mLinearLayout);
    child.measure(childWidthMeasureSpec, childheightMeasureSpec);
    mNumItemsInOneScreenful =
        (int) FloatMath.ceil(dm.widthPixels / (float) child.getMeasuredWidth());
    addToRecycledViews(child);

    mCellWidth = child.getMeasuredWidth();

    for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) {
      addToRecycledViews(mAdapter.createView(mLinearLayout));
    }
  }
  /**
   * Determines the width of this view
   *
   * @param measureSpec A measureSpec packed into an int
   * @return The width of the view, honoring constraints from measureSpec
   */
  private int measureLong(int measureSpec) {
    int result = 0;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) {
      // We were told how big to be
      result = specSize;
    } else {
      // Calculate the width according the views count
      final int count = mViewPager.getAdapter().getCount();
      result =
          (int)
              (getPaddingLeft()
                  + getPaddingRight()
                  + (count * 2 * mRadius)
                  + (count - 1) * mRadius
                  + 1);
      // Respect AT_MOST value if that was what is called for by measureSpec
      if (specMode == MeasureSpec.AT_MOST) {
        result = Math.min(result, specSize);
      }
    }
    return result;
  }
  @Override
  public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final boolean lockedExpanded = widthMode == MeasureSpec.EXACTLY;
    setFillViewport(lockedExpanded);

    final int childCount = mTabLayout.getChildCount();
    if (childCount > 1 && (widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST)) {
      if (childCount > 2) {
        //                mMaxTabWidth = (int)(MeasureSpec.getSize(widthMeasureSpec) * 0.4f);
      } else {
        mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2;
      }
    } else {
      mMaxTabWidth = -1;
    }

    final int oldWidth = getMeasuredWidth();
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    final int newWidth = getMeasuredWidth();

    if (lockedExpanded && oldWidth != newWidth) {
      // Recenter the tab display if we're at a new (scrollable) size.
      setCurrentItem(mSelectedTabIndex);
    }
  }
  public int getRowHeight() {
    if (mRowHeight > 0) {
      return mRowHeight;
    }
    ListAdapter adapter = getAdapter();
    int numColumns = getNumColumnsCompatible();

    // adapter has not been set or has no views in it;
    if (adapter == null
        || adapter.getCount() <= numColumns * (mHeaderViewInfos.size() + mFooterViewInfos.size())) {
      return -1;
    }
    int mColumnWidth = getColumnWidthCompatible();
    View view =
        getAdapter().getView(numColumns * mHeaderViewInfos.size(), mViewForMeasureRowHeight, this);
    AbsListView.LayoutParams p = (AbsListView.LayoutParams) view.getLayoutParams();
    if (p == null) {
      p = new AbsListView.LayoutParams(-1, -2, 0);
      view.setLayoutParams(p);
    }
    int childHeightSpec =
        getChildMeasureSpec(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height);
    int childWidthSpec =
        getChildMeasureSpec(
            MeasureSpec.makeMeasureSpec(mColumnWidth, MeasureSpec.EXACTLY), 0, p.width);
    view.measure(childWidthSpec, childHeightSpec);
    mViewForMeasureRowHeight = view;
    mRowHeight = view.getMeasuredHeight();
    return mRowHeight;
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int width;
    int height;

    // Get measureSpec mode and size values.
    final int measureWidthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int measureHeightMode = MeasureSpec.getMode(heightMeasureSpec);
    final int measureWidth = MeasureSpec.getSize(widthMeasureSpec);
    final int measureHeight = MeasureSpec.getSize(heightMeasureSpec);

    // The RangeBar width should be as large as possible.
    if (measureWidthMode == MeasureSpec.AT_MOST) {
      width = measureWidth;
    } else if (measureWidthMode == MeasureSpec.EXACTLY) {
      width = measureWidth;
    } else {
      width = mDefaultWidth;
    }

    // The RangeBar height should be as small as possible.
    if (measureHeightMode == MeasureSpec.AT_MOST) {
      height = Math.min(mDefaultHeight, measureHeight);
    } else if (measureHeightMode == MeasureSpec.EXACTLY) {
      height = measureHeight;
    } else {
      height = mDefaultHeight;
    }

    setMeasuredDimension(width, height);
  }
Example #7
0
 // ----------------------------------
 // Setting up stuff
 // ----------------------------------
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   int viewWidth = circleRadius + this.getPaddingLeft() + this.getPaddingRight();
   int viewHeight = circleRadius + this.getPaddingTop() + this.getPaddingBottom();
   int widthMode = MeasureSpec.getMode(widthMeasureSpec);
   int widthSize = MeasureSpec.getSize(widthMeasureSpec);
   int heightMode = MeasureSpec.getMode(heightMeasureSpec);
   int heightSize = MeasureSpec.getSize(heightMeasureSpec);
   int width;
   int height;
   // Measure Width
   if (widthMode == MeasureSpec.EXACTLY) {
     // Must be this size
     width = widthSize;
   } else if (widthMode == MeasureSpec.AT_MOST) {
     // Can't be bigger than...
     width = Math.min(viewWidth, widthSize);
   } else {
     // Be whatever you want
     width = viewWidth;
   }
   // Measure Height
   if (heightMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.EXACTLY) {
     // Must be this size
     height = heightSize;
   } else if (heightMode == MeasureSpec.AT_MOST) {
     // Can't be bigger than...
     height = Math.min(viewHeight, heightSize);
   } else {
     // Be whatever you want
     height = viewHeight;
   }
   setMeasuredDimension(width, height);
 }
Example #8
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // log.dbg (2, "onMeasure", "widthMeasureSpec = " + MeasureSpec.toString(widthMeasureSpec));
    // log.dbg (2, "onMeasure", "heightMeasureSpec = " + MeasureSpec.toString(heightMeasureSpec));

    int specWidth = MeasureSpec.getSize(widthMeasureSpec);
    int specHeight = MeasureSpec.getSize(heightMeasureSpec);

    // log.dbg (2, "onMeasure", "widthMeasureSpec, height = " + widthMeasureSpec + ", " +
    // heightMeasureSpec);

    int maxHeight = 0;
    int maxWidth = 0;

    // Find out how big everyone wants to be
    measureChildren(widthMeasureSpec, heightMeasureSpec);

    Dimensio mini = minimumLayoutSize(0, 0, specWidth, specHeight);
    Dimensio maxi = preferredLayoutSize(0, 0, specWidth, specHeight);

    // Check against minimum height and width
    maxHeight = Math.max(maxi.height, mini.height);
    maxWidth = Math.max(maxi.width, mini.width);

    setMeasuredDimension(
        resolveSize(maxWidth, widthMeasureSpec), resolveSize(maxHeight, heightMeasureSpec));
  }
Example #9
0
    public void Layout(int top, int left) {
      // 每行剩余的宽度.
      int FreeWidth = MaxWidth - UsedWidth;

      // 多出来的宽度均分给每个控件
      int avgWidth = (int) (FreeWidth / mView.size() + 0.5f);

      for (int i = 0; i < mView.size(); i++) {
        View view = mView.get(i);
        int vMeasuredWidth = view.getMeasuredWidth();
        int vMeasuredHeight = view.getMeasuredHeight();
        int mHeight = (Height - vMeasuredHeight) / 2; // 有大有小时,让小控件居中显示

        if (avgWidth > 0) {
          // 重新测量
          view.measure(
              MeasureSpec.makeMeasureSpec(vMeasuredWidth + avgWidth, MeasureSpec.EXACTLY),
              MeasureSpec.makeMeasureSpec(vMeasuredHeight, MeasureSpec.EXACTLY));
        }

        vMeasuredWidth = view.getMeasuredWidth();
        vMeasuredHeight = view.getMeasuredHeight();
        int vTop = top + mHeight;
        int vBottom = top + vMeasuredHeight + mHeight;
        int vLeft = left;
        int vRight = left + vMeasuredWidth;

        left += vMeasuredWidth + space;
        view.layout(vLeft, vTop, vRight, vBottom);
      }
    }
  /**
   * Measure a child view to fit within cell-based formatting. The child's width will be measured to
   * a whole multiple of cellSize.
   *
   * <p>
   *
   * <p>Sets the expandable and cellsUsed fields of LayoutParams.
   *
   * @param child Child to measure
   * @param cellSize Size of one cell
   * @param cellsRemaining Number of cells remaining that this view can expand to fill
   * @param parentHeightMeasureSpec MeasureSpec used by the parent view
   * @param parentHeightPadding Padding present in the parent view
   * @return Number of cells this child was measured to occupy
   */
  static int measureChildForCells(
      View child,
      int cellSize,
      int cellsRemaining,
      int parentHeightMeasureSpec,
      int parentHeightPadding) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();

    final int childHeightSize = MeasureSpec.getSize(parentHeightMeasureSpec) - parentHeightPadding;
    final int childHeightMode = MeasureSpec.getMode(parentHeightMeasureSpec);
    final int childHeightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, childHeightMode);

    int cellsUsed = 0;
    if (cellsRemaining > 0) {
      final int childWidthSpec =
          MeasureSpec.makeMeasureSpec(cellSize * cellsRemaining, MeasureSpec.AT_MOST);
      child.measure(childWidthSpec, childHeightSpec);

      final int measuredWidth = child.getMeasuredWidth();
      cellsUsed = measuredWidth / cellSize;
      if (measuredWidth % cellSize != 0) cellsUsed++;
    }

    final ActionMenuItemView itemView =
        child instanceof ActionMenuItemView ? (ActionMenuItemView) child : null;
    final boolean expandable = !lp.isOverflowButton && itemView != null && itemView.hasText();
    lp.expandable = expandable;

    lp.cellsUsed = cellsUsed;
    final int targetWidth = cellsUsed * cellSize;
    child.measure(MeasureSpec.makeMeasureSpec(targetWidth, MeasureSpec.EXACTLY), childHeightSpec);
    return cellsUsed;
  }
Example #11
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY) {
      throw new IllegalStateException("Must measure with an exact size");
    }

    final int width = MeasureSpec.getSize(widthMeasureSpec);
    final int height = MeasureSpec.getSize(heightMeasureSpec);

    if (!mMenuSizeSet) mMenuSize = (int) (height * 0.25f);
    if (mOffsetPixels == -1) openMenu(false);

    final int menuWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, width);
    final int menuHeightMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, mMenuSize);
    mMenuContainer.measure(menuWidthMeasureSpec, menuHeightMeasureSpec);

    final int contentWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, width);
    final int contentHeightMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, height);
    mContentContainer.measure(contentWidthMeasureSpec, contentHeightMeasureSpec);

    setMeasuredDimension(width, height);

    updateTouchAreaSize();
  }
  private void measureFloating(View preview, Rect margins, Rect out) {
    final int marginLeft;
    final int marginTop;
    final int marginRight;
    if (margins == null) {
      marginLeft = 0;
      marginTop = 0;
      marginRight = 0;
    } else {
      marginLeft = margins.left;
      marginTop = margins.top;
      marginRight = margins.right;
    }

    final Rect container = mContainerRect;
    final int containerWidth = container.width();
    final int adjMaxWidth = containerWidth - marginLeft - marginRight;
    final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(adjMaxWidth, MeasureSpec.AT_MOST);
    final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    preview.measure(widthMeasureSpec, heightMeasureSpec);

    // Align at the vertical center, mToastOffset away from this View.
    final int containerHeight = container.height();
    final int width = preview.getMinimumWidth();
    final int top = (containerHeight - width) / 2 + container.top;
    final int bottom = top + preview.getMeasuredHeight();
    final int left = containerWidth - mViewWidth - mToastOffset - width + container.left;
    final int right = left + width;
    out.set(left, top, right, bottom);
  }
Example #13
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthSie = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    setMeasuredDimension(widthSie, heightSize);

    View bottomView = getChildAt(1);
    MarginLayoutParams lp = (MarginLayoutParams) bottomView.getLayoutParams();
    int drawerWidthSpec =
        getChildMeasureSpec(widthMeasureSpec, lp.leftMargin + lp.rightMargin, lp.width);
    int drawerHeightSpec =
        getChildMeasureSpec(heightMeasureSpec, lp.bottomMargin + lp.topMargin, lp.height);

    bottomView.measure(drawerWidthSpec, drawerHeightSpec);

    View contentView = getChildAt(0);
    lp = (MarginLayoutParams) contentView.getLayoutParams();
    int contentWidthSpec =
        MeasureSpec.makeMeasureSpec(widthSie - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
    int contentHeightSpec =
        MeasureSpec.makeMeasureSpec(
            heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
    contentView.measure(contentWidthSpec, contentHeightSpec);

    mBottomMenuView = bottomView;
    mContentView = contentView;
  }
Example #14
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    // setMeasuredDimension(calculateMeasuredWidth(), calculateMeasureHeight());

    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    final int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    LayoutParams lp = getLayoutParams();
    // 获取IndexBar顶部和底部的margin,这里不用关心左右两边的margin
    int margin = 0;
    // 如果布局文件使用了margin属性时,需要根据margin、mAlphabetTextSize、
    if (lp instanceof ViewGroup.MarginLayoutParams) {
      ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) lp;
      margin = mlp.topMargin + mlp.bottomMargin;
    }

    /**
     * 判断IndexBar高度的裁剪模式,如果{@link heightMode} 为{@link MeasureSpec#EXACTLY},
     * 表示用户设置了一个确切的高度值,或者使用了{@link LayoutParams#MATCH_PARENT}属性。 如果{@link heightMode} 为 {@link
     * MeasureSpec#AT_MOST}, 表示用户使用了{@link LayoutParams#WRAP_CONTENT}属性,这时,我们会使用默认的{@link
     * #mAlphabetPadding}, 或者用户设置的值
     */
    if (heightMode == MeasureSpec.EXACTLY) { // 计算mAlphabetPadding
      final int length = mSections.length;
      mAlphabetPadding = (heightSize - length * mAlphabetTextSize - margin) / (length + 1);

      setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    } else {
      setMeasuredDimension(calculateMeasuredWidth(), calculateMeasureHeight());
    }
  }
Example #15
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   int widthSize = MeasureSpec.getSize(widthMeasureSpec);
   int heightSize = MeasureSpec.getSize(heightMeasureSpec);
   int size = Math.min(widthSize, heightSize);
   setMeasuredDimension(size, size);
 }
  private int measureWidth(int measureSpec) {
    int result = 0;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);

    // We were told how big to be
    if (specMode == MeasureSpec.EXACTLY) {
      result = specSize;
    }
    // Calculate the width according the views count
    else {
      int count = 3;
      if (viewFlow != null) {
        count = viewFlow.getViewsCount();
      }
      result =
          (int)
              (getPaddingLeft()
                  + getPaddingRight()
                  + (count * this.perWidth)
                  + (count - 1) * this.perWidth / 2
                  + 1);
      // Respect AT_MOST value if that was what is called for by
      // measureSpec
      if (specMode == MeasureSpec.AT_MOST) {
        result = Math.min(result, specSize);
      }
    }
    return result;
  }
Example #17
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   try {
     Drawable drawable = getDrawable();
     if (drawable == null) {
       setMeasuredDimension(0, 0);
     } else {
       int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
       int measuredHeight = MeasureSpec.getSize(heightMeasureSpec);
       if (measuredHeight == 0 && measuredWidth == 0) { // Height and width set to wrap_content
         setMeasuredDimension(measuredWidth, measuredHeight);
       } else if (measuredHeight == 0) { // Height set to wrap_content
         int width = measuredWidth;
         int height = width * drawable.getIntrinsicHeight() / drawable.getIntrinsicWidth();
         setMeasuredDimension(width, height);
       } else if (measuredWidth == 0) { // Width set to wrap_content
         int height = measuredHeight;
         int width = height * drawable.getIntrinsicWidth() / drawable.getIntrinsicHeight();
         setMeasuredDimension(width, height);
       } else { // Width and height are explicitly set (either to match_parent or to exact value)
         setMeasuredDimension(measuredWidth, measuredHeight);
       }
     }
   } catch (Exception e) {
     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   }
 }
Example #18
0
  protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    // Measure Width
    if (widthMode == MeasureSpec.EXACTLY) {
      // Must be this size
      width = widthSize;
    } else if (widthMode == MeasureSpec.AT_MOST) {
      // Can't be bigger than...
      width = Math.min(50, widthSize);
    } else {
      // Be whatever you want
      width = 100;
    }

    // Measure Height
    if (heightMode == MeasureSpec.EXACTLY) {
      // Must be this size
      height = heightSize;
    } else if (heightMode == MeasureSpec.AT_MOST) {
      // Can't be bigger than...
      height = Math.min(80, heightSize);
    } else {
      // Be whatever you want
      height = 73;
    }

    // Satisfy contract by calling setMeasuredDimension
    setMeasuredDimension(width, height);
  }
Example #19
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (videoAspectRatio == 0) {
      // Aspect ratio not set.
      return;
    }

    int width = getMeasuredWidth();
    int height = getMeasuredHeight();
    float viewAspectRatio = (float) width / height;
    float aspectDeformation = videoAspectRatio / viewAspectRatio - 1;
    if (Math.abs(aspectDeformation) <= MAX_ASPECT_RATIO_DEFORMATION_FRACTION) {
      // We're within the allowed tolerance.
      return;
    }

    if (aspectDeformation > 0) {
      height = (int) (width / videoAspectRatio);
    } else {
      width = (int) (height * videoAspectRatio);
    }
    super.onMeasure(
        MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // If we've been given an exact size to match, apply special formatting during layout.
    final boolean wasFormatted = mFormatItems;
    mFormatItems = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY;

    if (wasFormatted != mFormatItems) {
      mFormatItemsWidth = 0; // Reset this when switching modes
    }

    // Special formatting can change whether items can fit as action buttons.
    // Kick the menu and update presenters when this changes.
    final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    if (mFormatItems && mMenu != null && widthSize != mFormatItemsWidth) {
      mFormatItemsWidth = widthSize;
      mMenu.onItemsChanged(true);
    }

    final int childCount = getChildCount();
    if (mFormatItems && childCount > 0) {
      onMeasureExactFormat(widthMeasureSpec, heightMeasureSpec);
    } else {
      // Previous measurement at exact format may have set margins - reset them.
      for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        lp.leftMargin = lp.rightMargin = 0;
      }
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    if (!mFillViewport) {
      return;
    }

    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    if (heightMode == MeasureSpec.UNSPECIFIED) {
      return;
    }

    if (getChildCount() > 0) {
      final View child = getChildAt(0);
      int height = getMeasuredHeight();
      if (child.getMeasuredHeight() < height) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        int childWidthMeasureSpec =
            getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width);
        height -= getPaddingTop();
        height -= getPaddingBottom();
        int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);

        child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
      }
    }
  }
Example #22
0
  /**
   * Calculates control width and creates text layouts
   *
   * @param widthSize the input layout width
   * @param mode the layout mode
   * @return the calculated control width
   */
  private int calculateLayoutWidth(int widthSize, int mode) {
    initResourcesIfNecessary();

    // TODO: make it static
    itemsLayout.setLayoutParams(
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    itemsLayout.measure(
        MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.UNSPECIFIED),
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int width = itemsLayout.getMeasuredWidth();

    if (mode == MeasureSpec.EXACTLY) {
      width = widthSize;
    } else {
      width += 2 * PADDING;

      // Check against our minimum width
      width = Math.max(width, getSuggestedMinimumWidth());

      if (mode == MeasureSpec.AT_MOST && widthSize < width) {
        width = widthSize;
      }
    }

    itemsLayout.measure(
        MeasureSpec.makeMeasureSpec(width - 2 * PADDING, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

    return width;
  }
Example #23
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int intrinsicSize = mPreferredBarLength + (mBarPointerHaloRadius * 2);

    // Variable orientation
    int measureSpec;
    if (mOrientation == ORIENTATION_HORIZONTAL) {
      measureSpec = widthMeasureSpec;
    } else {
      measureSpec = heightMeasureSpec;
    }
    int lengthMode = MeasureSpec.getMode(measureSpec);
    int lengthSize = MeasureSpec.getSize(measureSpec);

    int length;
    if (lengthMode == MeasureSpec.EXACTLY) {
      length = lengthSize;
    } else if (lengthMode == MeasureSpec.AT_MOST) {
      length = Math.min(intrinsicSize, lengthSize);
    } else {
      length = intrinsicSize;
    }

    int barPointerHaloRadiusx2 = mBarPointerHaloRadius * 2;
    mBarLength = length - barPointerHaloRadiusx2;
    if (mOrientation == ORIENTATION_VERTICAL) {
      setMeasuredDimension(barPointerHaloRadiusx2, (mBarLength + barPointerHaloRadiusx2));
    } else {
      setMeasuredDimension((mBarLength + barPointerHaloRadiusx2), barPointerHaloRadiusx2);
    }
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);

    switch (widthMode) {
      case MeasureSpec.AT_MOST:
        // If there is an upper limit, don't exceed maximum width (explicit
        // or implicit)
        if (mMaxWidth > 0) {
          width = Math.min(mMaxWidth, width);
        } else {
          width = Math.min(getPreferredWidth(), width);
        }
        break;
      case MeasureSpec.EXACTLY:
        // If an exact width is specified, still don't exceed any specified
        // maximum width
        if (mMaxWidth > 0) {
          width = Math.min(mMaxWidth, width);
        }
        break;
      case MeasureSpec.UNSPECIFIED:
        // Use maximum width, if specified, else preferred width
        width = mMaxWidth > 0 ? mMaxWidth : getPreferredWidth();
        break;
    }
    widthMode = MeasureSpec.EXACTLY;
    super.onMeasure(MeasureSpec.makeMeasureSpec(width, widthMode), heightMeasureSpec);
  }
Example #25
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(
       MeasureSpec.makeMeasureSpec(
           AndroidUtilities.dp(76) + getPaddingLeft() + getPaddingRight(), MeasureSpec.EXACTLY),
       MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(78), MeasureSpec.EXACTLY));
 }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    rebuildItems(); // rebuilding before measuring

    int height = calculateLayoutHeight(heightSize, heightMode);

    int width;
    if (widthMode == MeasureSpec.EXACTLY) {
      width = widthSize;
    } else {
      width =
          Math.max(
              getItemDimension() * (mVisibleItems - mItemOffsetPercent / 100),
              getSuggestedMinimumWidth());

      if (widthMode == MeasureSpec.AT_MOST) {
        width = Math.min(width, widthSize);
      }
    }
    setMeasuredDimension(width, height);
  }
  public void measureChild(View child) {
    final LauncherAppState app = LauncherAppState.getInstance();
    final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    final int cellWidth = mCellWidth;
    final int cellHeight = mCellHeight;
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
    if (!lp.isFullscreen) {
      lp.setup(cellWidth, cellHeight, mWidthGap, mHeightGap, invertLayoutHorizontally(), mCountX);

      if (child instanceof LauncherAppWidgetHostView) {
        // Widgets have their own padding, so skip
      } else {
        // Otherwise, center the icon
        int cHeight = getCellContentHeight();
        int cellPaddingY = (int) Math.max(0, ((lp.height - cHeight) / 2f));
        int cellPaddingX = (int) (grid.edgeMarginPx / 2f);
        child.setPadding(cellPaddingX, cellPaddingY, cellPaddingX, 0);
      }
    } else {
      lp.x = 0;
      lp.y = 0;
      lp.width = getMeasuredWidth();
      lp.height = getMeasuredHeight();
    }
    int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
    int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
    child.measure(childWidthMeasureSpec, childheightMeasureSpec);
  }
  /**
   * Calculates control height and creates text layouts
   *
   * @param heightSize the input layout height
   * @param mode the layout mode
   * @return the calculated control height
   */
  private int calculateLayoutHeight(int heightSize, int mode) {
    mItemsLayout.setLayoutParams(
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    mItemsLayout.measure(
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
        MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.UNSPECIFIED));
    int height = mItemsLayout.getMeasuredHeight();

    if (mode == MeasureSpec.EXACTLY) {
      height = heightSize;
    } else {
      height += 2 * mItemsPadding;

      // Check against our minimum width
      height = Math.max(height, getSuggestedMinimumHeight());

      if (mode == MeasureSpec.AT_MOST && heightSize < height) {
        height = heightSize;
      }
    }
    // forcing recalculating
    mItemsLayout.measure(
        // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
        MeasureSpec.makeMeasureSpec(400, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(height - 2 * mItemsPadding, MeasureSpec.EXACTLY));

    return height;
  }
Example #29
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    Drawable drawable = getDrawable();
    if (drawable == null
        || drawable.getIntrinsicWidth() == 0
        || drawable.getIntrinsicHeight() == 0) {
      setMeasuredDimension(0, 0);
      return;
    }

    int drawableWidth = drawable.getIntrinsicWidth();
    int drawableHeight = drawable.getIntrinsicHeight();
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    viewWidth = setViewSize(widthMode, widthSize, drawableWidth);
    viewHeight = setViewSize(heightMode, heightSize, drawableHeight);

    //
    // Set view dimensions
    //
    setMeasuredDimension(viewWidth, viewHeight);

    //
    // Fit content within view
    //
    fitImageToView();
  }
  @Override
  protected void onMeasure(int widthSpec, int heightSpec) {
    int previewWidth = MeasureSpec.getSize(widthSpec);
    int previewHeight = MeasureSpec.getSize(heightSpec);

    // Get the padding of the border background.
    int hPadding = mPaddingLeft + mPaddingRight;
    int vPadding = mPaddingTop + mPaddingBottom;

    // Resize the preview frame with correct aspect ratio.
    previewWidth -= hPadding;
    previewHeight -= vPadding;
    if (previewWidth > previewHeight * mAspectRatio) {
      previewWidth = (int) (previewHeight * mAspectRatio + .5);
    } else {
      previewHeight = (int) (previewWidth / mAspectRatio + .5);
    }

    // Add the padding of the border.
    previewWidth += hPadding;
    previewHeight += vPadding;

    // Ask children to follow the new preview dimension.
    super.onMeasure(
        MeasureSpec.makeMeasureSpec(previewWidth, MeasureSpec.EXACTLY),
        MeasureSpec.makeMeasureSpec(previewHeight, MeasureSpec.EXACTLY));
  }