Java Code Examples for androidx.recyclerview.widget.RecyclerView#getClipToPadding()

The following examples show how to use androidx.recyclerview.widget.RecyclerView#getClipToPadding() . 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: InstallerXAdapterDividerItemDecoration.java    From SAI with GNU General Public License v3.0 6 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int top;
    final int bottom;
    //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(child.getTranslationX());
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 2
Source File: DividerItemDecorationEx.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    int top;
    int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    int childCount = parent.getChildCount();

    for (int i = 0; i < childCount; ++i) {
        View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        int right = mBounds.right + Math.round(child.getTranslationX());
        int left = right - mDivider.getIntrinsicWidth();
        this.mDivider.setBounds(left, top, right, bottom);
        this.mDivider.draw(canvas);
    }

    canvas.restore();
}
 
Example 3
Source File: SimpleDividerItemDecoration.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    canvas.save();
    final int right;
    //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
    if (parent.getClipToPadding()) {
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(leftPadding, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, bounds);
        final int bottom = bounds.bottom + Math.round(child.getTranslationY());
        final int top = bottom - 1;
        divider.setBounds(leftPadding, top, right, bottom);
        divider.draw(canvas);
    }
    canvas.restore();
}
 
Example 4
Source File: CustomDividerItemDecoration.java    From Android-skin-support with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int top;
    final int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 5
Source File: CustomDividerItemDecoration.java    From Android-skin-support with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 6
Source File: DividerItemDecoration.java    From WidgetCase with Apache License 2.0 6 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int left;
    final int right;
    //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(child.getTranslationY());
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 7
Source File: DividerItemDecoration.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 6 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int top;
    final int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int childCount = parent.getChildCount() - (doNotDrawForLastItem ? 1 : 0);
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(child.getTranslationX());
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 8
Source File: DividerItemDecoration.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 6 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount() - (doNotDrawForLastItem ? 1 : 0);
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(child.getTranslationY());
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 9
Source File: DividerItemDecoration.java    From WidgetCase with Apache License 2.0 6 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int top;
    final int bottom;
    //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(child.getTranslationX());
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 10
Source File: DividerItemDecoration.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    int top;
    int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    int childCount = parent.getChildCount();

    for (int i = 0; i < childCount; ++i) {
        View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, this.mBounds);
        int right = this.mBounds.right + Math.round(child.getTranslationX());
        int left = right - this.mDivider.getIntrinsicWidth();
        this.mDivider.setBounds(left, top, right, bottom);
        this.mDivider.draw(canvas);
    }

    canvas.restore();
}
 
Example 11
Source File: InstallerXAdapterDividerItemDecoration.java    From SAI with GNU General Public License v3.0 5 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int left;
    final int right;
    //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    RecyclerView.Adapter adapter = parent.getAdapter();
    final int itemCount = adapter == null ? -1 : adapter.getItemCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        int adapterPosition = parent.getChildAdapterPosition(child);
        if (adapterPosition == 0 || adapterPosition == itemCount - 1)
            continue;

        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(child.getTranslationY());
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 12
Source File: SelectiveDividerItemDecoration.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();

    int top;
    int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    RecyclerView.LayoutManager lm = parent.getLayoutManager();
    if (lm == null) return;

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        if (isDecorated(i)) {
            View child = parent.getChildAt(i);
            lm.getDecoratedBoundsWithMargins(child, mBounds);
            int right = mBounds.right + Math.round(child.getTranslationX());
            int left = right - mDivider.getIntrinsicWidth();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
    }

    canvas.restore();
}
 
Example 13
Source File: AdvancedDividerItemDecoration.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    canvas.save();
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        if (!hasDivider(parent, child))
            continue;
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.setAlpha((int) (child.getAlpha() * 255));
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 14
Source File: SelectiveDividerItemDecoration.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();

    int left;
    int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        if (isDecorated(i)) {
            View child = parent.getChildAt(i);
            parent.getDecoratedBoundsWithMargins(child, mBounds);
            int bottom = mBounds.bottom + Math.round(child.getTranslationY());
            int top = bottom - mDivider.getIntrinsicHeight();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
    }

    canvas.restore();
}
 
Example 15
Source File: DividerItemDecoration.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int top;
    final int bottom;
    //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(child.getTranslationX());
        final int left = right - mDividerSize;
        mDividerPaint.setColor(mDividerColor);
        mDividerPaint.setStyle(Paint.Style.FILL);
        canvas.drawRect(left + mMarginStart, top + mMarginTop, right - mMarginEnd, bottom - mMarginBottom, mDividerPaint);
    }
    canvas.restore();
}
 
Example 16
Source File: DividerItemDecoration.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int left;
    final int right;
    //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(child.getTranslationY());
        final int top = bottom - mDividerSize;
        mDividerPaint.setColor(mDividerColor);
        mDividerPaint.setStyle(Paint.Style.FILL);
        canvas.drawRect(left + mMarginStart, top + mMarginTop, right - mMarginEnd, bottom - mMarginBottom, mDividerPaint);
    }
    canvas.restore();
}
 
Example 17
Source File: EventItemDecorator.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (parent.getLayoutManager() == null) {
        return;
    }

    c.save();
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        c.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, bounds);

        int position = parent.getChildAdapterPosition(child);
        if (parent.getAdapter().getItemViewType(position) == EventListAdapter.ITEM_TYPE_HEADER ||
            parent.getAdapter().getItemViewType(position + 1) == EventListAdapter.ITEM_TYPE_HEADER ||
            position == state.getItemCount() - 1) {
            continue;
        }

        final int bottom = bounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - divider.getIntrinsicHeight();
        divider.setBounds(left, top, right, bottom);
        divider.draw(c);
    }
    c.restore();
}
 
Example 18
Source File: FlexibleItemDecoration.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
protected void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int itemCount = parent.getChildCount();
    for (int i = 0; i < itemCount - mDividerOnLastItem; i++) {
        final View child = parent.getChildAt(i);
        RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);
        if (shouldDrawDivider(viewHolder)) {
            parent.getDecoratedBoundsWithMargins(child, mBounds);
            final int bottom = mBounds.bottom + Math.round(child.getTranslationY());
            final int top = bottom - mDivider.getIntrinsicHeight();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
    }
    canvas.restore();
}
 
Example 19
Source File: FlexibleItemDecoration.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
protected void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int top;
    final int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int itemCount = parent.getChildCount();
    for (int i = 0; i < itemCount - mDividerOnLastItem; i++) {
        final View child = parent.getChildAt(i);
        RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);
        if (shouldDrawDivider(viewHolder)) {
            parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
            final int right = mBounds.right + Math.round(child.getTranslationX());
            final int left = right - mDivider.getIntrinsicWidth();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
    }
    canvas.restore();
}
 
Example 20
Source File: DividerItemDecorationEx.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    int left;
    int right;
    if (mDividerPadding != 0) {
        left = mDividerPadding;
        right = parent.getWidth() - mDividerPadding;
        canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    int childCount = parent.getChildCount();

    for (int i = 0; i < childCount; ++i) {
        View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, this.mBounds);
        int bottom = this.mBounds.bottom + Math.round(child.getTranslationY());
        int top = bottom - this.mDivider.getIntrinsicHeight();
        this.mDivider.setBounds(left, top, right, bottom);
        this.mDivider.draw(canvas);
    }

    canvas.restore();
}