Java Code Examples for org.chromium.base.ApiCompatibilityUtils#getPaddingEnd()

The following examples show how to use org.chromium.base.ApiCompatibilityUtils#getPaddingEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewAnchoredTextBubble.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void refreshAnchorBounds() {
    mAnchorView.getLocationOnScreen(mCachedScreenCoordinates);
    mAnchorRect.left = mCachedScreenCoordinates[0];
    mAnchorRect.top = mCachedScreenCoordinates[1];
    mAnchorRect.right = mAnchorRect.left + mAnchorView.getWidth();
    mAnchorRect.bottom = mAnchorRect.top + mAnchorView.getHeight();

    mAnchorRect.left += mInsetRect.left;
    mAnchorRect.top += mInsetRect.top;
    mAnchorRect.right -= mInsetRect.right;
    mAnchorRect.bottom -= mInsetRect.bottom;

    // Account for the padding.
    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(mAnchorView);
    mAnchorRect.left += isRtl ? ApiCompatibilityUtils.getPaddingEnd(mAnchorView)
                              : ApiCompatibilityUtils.getPaddingStart(mAnchorView);
    mAnchorRect.right -= isRtl ? ApiCompatibilityUtils.getPaddingStart(mAnchorView)
                               : ApiCompatibilityUtils.getPaddingEnd(mAnchorView);
    mAnchorRect.top += mAnchorView.getPaddingTop();
    mAnchorRect.bottom -= mAnchorView.getPaddingBottom();

    // Make sure we still have a valid Rect after applying the inset.
    mAnchorRect.right = Math.max(mAnchorRect.left, mAnchorRect.right);
    mAnchorRect.bottom = Math.max(mAnchorRect.top, mAnchorRect.bottom);

    setAnchorRect(mAnchorRect);
}
 
Example 2
Source File: MostVisitedLayout.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int totalWidth = resolveSize(mMaxWidth, widthMeasureSpec);
    int childCount = getChildCount();
    if (childCount == 0) {
        setMeasuredDimension(totalWidth, resolveSize(0, heightMeasureSpec));
        return;
    }

    // Measure the children.
    for (int i = 0; i < childCount; i++) {
        measureChild(getChildAt(i), MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    }

    // Determine the number of columns that will fit.
    int gridWidth = totalWidth - ApiCompatibilityUtils.getPaddingStart(this)
            - ApiCompatibilityUtils.getPaddingEnd(this);
    int childHeight = getChildAt(0).getMeasuredHeight();
    int childWidth = getChildAt(0).getMeasuredWidth();
    int numColumns = MathUtils.clamp(
            (gridWidth + mMinHorizontalSpacing) / (childWidth + mMinHorizontalSpacing),
            1, MAX_COLUMNS);

    // Ensure column spacing isn't greater than mMaxHorizontalSpacing.
    int gridWidthMinusColumns = Math.max(0, gridWidth - numColumns * childWidth);
    int gridSidePadding = gridWidthMinusColumns - mMaxHorizontalSpacing * (numColumns - 1);

    int gridStart = 0;
    float horizontalSpacing;
    if (gridSidePadding > 0) {
        horizontalSpacing = mMaxHorizontalSpacing;
        gridStart = gridSidePadding / 2;
    } else {
        horizontalSpacing = (float) gridWidthMinusColumns / Math.max(1, numColumns - 1);
    }

    // Limit the number of rows to mMaxRows.
    int visibleChildCount = Math.min(childCount, mMaxRows * numColumns);

    // Arrange the children in a grid.
    int paddingTop = getPaddingTop();
    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
    for (int i = 0; i < visibleChildCount; i++) {
        View child = getChildAt(i);
        child.setVisibility(View.VISIBLE);
        int row = i / numColumns;
        int column = i % numColumns;
        int childTop = row * (childHeight + mVerticalSpacing);
        int childStart = gridStart + Math.round(column * (childWidth + horizontalSpacing));
        MarginLayoutParams layoutParams = (MarginLayoutParams) child.getLayoutParams();
        layoutParams.setMargins(isRtl ? 0 : childStart, childTop, isRtl ? childStart : 0, 0);
        child.setLayoutParams(layoutParams);
    }

    // Hide the last row if it's incomplete.
    for (int i = visibleChildCount; i < childCount; i++) {
        getChildAt(i).setVisibility(View.GONE);
    }

    int numRows = (visibleChildCount + numColumns - 1) / numColumns;
    int totalHeight = paddingTop + getPaddingBottom() + numRows * childHeight
            + (numRows - 1) * mVerticalSpacing;

    setMeasuredDimension(totalWidth, resolveSize(totalHeight, heightMeasureSpec));
}
 
Example 3
Source File: MostVisitedLayout.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int totalWidth = resolveSize(mMaxWidth, widthMeasureSpec);
    int childCount = getChildCount();
    if (childCount == 0) {
        setMeasuredDimension(totalWidth, resolveSize(0, heightMeasureSpec));
        return;
    }

    // Measure the children.
    for (int i = 0; i < childCount; i++) {
        measureChild(getChildAt(i), MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    }

    // Determine the number of columns that will fit.
    int gridWidth = totalWidth - ApiCompatibilityUtils.getPaddingStart(this)
            - ApiCompatibilityUtils.getPaddingEnd(this);
    int childHeight = getChildAt(0).getMeasuredHeight();
    int childWidth = getChildAt(0).getMeasuredWidth();
    int numColumns = MathUtils.clamp(
            (gridWidth + mMinHorizontalSpacing) / (childWidth + mMinHorizontalSpacing),
            1, MAX_COLUMNS);

    // Ensure column spacing isn't greater than mMaxHorizontalSpacing.
    int gridWidthMinusColumns = Math.max(0, gridWidth - numColumns * childWidth);
    int gridSidePadding = gridWidthMinusColumns - mMaxHorizontalSpacing * (numColumns - 1);

    int gridStart = 0;
    float horizontalSpacing;
    if (gridSidePadding > 0) {
        horizontalSpacing = mMaxHorizontalSpacing;
        gridStart = gridSidePadding / 2;
    } else {
        horizontalSpacing = (float) gridWidthMinusColumns / Math.max(1, numColumns - 1);
    }

    // Limit the number of rows to mMaxRows.
    int visibleChildCount = Math.min(childCount, mMaxRows * numColumns);

    // Arrange the visible children in a grid.
    int numRows = (visibleChildCount + numColumns - 1) / numColumns;
    int paddingTop = getPaddingTop();
    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
    for (int i = 0; i < visibleChildCount; i++) {
        View child = getChildAt(i);
        child.setVisibility(View.VISIBLE);
        int row = i / numColumns;
        int column = i % numColumns;
        int verticalOffset = Math.round(mExtraVerticalSpacing * ((float) (row + 1) / numRows));
        int childTop = row * (childHeight + mVerticalSpacing) + verticalOffset;
        int childStart = gridStart + Math.round(column * (childWidth + horizontalSpacing));
        MarginLayoutParams layoutParams = (MarginLayoutParams) child.getLayoutParams();
        layoutParams.setMargins(isRtl ? 0 : childStart, childTop, isRtl ? childStart : 0, 0);
        child.setLayoutParams(layoutParams);
    }

    // Hide any extra children in case there are more than needed for the maximum number of
    // rows.
    for (int i = visibleChildCount; i < childCount; i++) {
        getChildAt(i).setVisibility(View.GONE);
    }

    int totalHeight = paddingTop + getPaddingBottom() + numRows * childHeight
            + (numRows - 1) * mVerticalSpacing + mExtraVerticalSpacing;

    setMeasuredDimension(totalWidth, resolveSize(totalHeight, heightMeasureSpec));
}
 
Example 4
Source File: TileGridLayout.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int totalWidth = resolveSize(mMaxWidth, widthMeasureSpec);
    int childCount = getChildCount();
    if (childCount == 0) {
        setMeasuredDimension(totalWidth, resolveSize(0, heightMeasureSpec));
        return;
    }

    // Measure the children.
    for (int i = 0; i < childCount; i++) {
        measureChild(getChildAt(i), MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    }

    // Determine the number of columns that will fit.
    int gridWidth = totalWidth - ApiCompatibilityUtils.getPaddingStart(this)
            - ApiCompatibilityUtils.getPaddingEnd(this);
    int childHeight = getChildAt(0).getMeasuredHeight();
    int childWidth = getChildAt(0).getMeasuredWidth();
    int numColumns = MathUtils.clamp(
            (gridWidth + mMinHorizontalSpacing) / (childWidth + mMinHorizontalSpacing), 1,
            mMaxColumns);

    // Ensure column spacing isn't greater than mMaxHorizontalSpacing.
    int gridWidthMinusColumns = Math.max(0, gridWidth - numColumns * childWidth);
    int gridSidePadding = gridWidthMinusColumns - mMaxHorizontalSpacing * (numColumns - 1);

    int gridStart = 0;
    float horizontalSpacing;
    if (gridSidePadding > 0) {
        horizontalSpacing = mMaxHorizontalSpacing;
        gridStart = gridSidePadding / 2;
    } else {
        horizontalSpacing = (float) gridWidthMinusColumns / Math.max(1, numColumns - 1);
    }

    // Limit the number of rows to mMaxRows.
    int visibleChildCount = Math.min(childCount, mMaxRows * numColumns);

    // Arrange the visible children in a grid.
    int numRows = (visibleChildCount + numColumns - 1) / numColumns;
    int paddingTop = getPaddingTop();
    boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this);
    for (int i = 0; i < visibleChildCount; i++) {
        View child = getChildAt(i);
        child.setVisibility(View.VISIBLE);
        int row = i / numColumns;
        int column = i % numColumns;
        int verticalOffset = Math.round(mExtraVerticalSpacing * ((float) (row + 1) / numRows));
        int childTop = row * (childHeight + mVerticalSpacing) + verticalOffset;
        int childStart = gridStart + Math.round(column * (childWidth + horizontalSpacing));
        MarginLayoutParams layoutParams = (MarginLayoutParams) child.getLayoutParams();
        layoutParams.setMargins(isRtl ? 0 : childStart, childTop, isRtl ? childStart : 0, 0);
        child.setLayoutParams(layoutParams);
    }

    // Hide any extra children in case there are more than needed for the maximum number of
    // rows.
    for (int i = visibleChildCount; i < childCount; i++) {
        getChildAt(i).setVisibility(View.GONE);
    }

    int totalHeight = paddingTop + getPaddingBottom() + numRows * childHeight
            + (numRows - 1) * mVerticalSpacing + mExtraVerticalSpacing;

    setMeasuredDimension(totalWidth, resolveSize(totalHeight, heightMeasureSpec));
}