Search in sources :

Example 91 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.

the class VerticalDividerItemDecoration method getDividerBound.

@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top = parent.getPaddingTop() + mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom = parent.getHeight() - parent.getPaddingBottom() - mMarginProvider.dividerBottomMargin(position, parent) + transitionY;
    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE) {
        bounds.left = child.getRight() + params.leftMargin + transitionX;
        bounds.right = bounds.left + dividerSize;
    } else {
        bounds.left = child.getRight() + params.leftMargin + dividerSize / 2 + transitionX;
        bounds.right = bounds.left;
    }
    return bounds;
}
Also used : Rect(android.graphics.Rect) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 92 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.

the class HeaderPositionCalculator method itemIsObscuredByHeader.

/**
 * Determines if an item is obscured by a header
 *
 * @param parent
 * @param item        to determine if obscured by header
 * @param header      that might be obscuring the item
 * @param orientation of the {@link RecyclerView}
 * @return true if the item view is obscured by the header view
 */
private boolean itemIsObscuredByHeader(RecyclerView parent, View item, View header, int orientation) {
    RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) item.getLayoutParams();
    Rect headerMargins = mDimensionCalculator.getMargins(header);
    int adapterPosition = parent.getChildAdapterPosition(item);
    if (adapterPosition == RecyclerView.NO_POSITION || mHeaderProvider.getHeader(parent, adapterPosition) != header) {
        // Handles an edge case where a trailing header is smaller than the current sticky header.
        return false;
    }
    if (orientation == LinearLayoutManager.VERTICAL) {
        int itemTop = item.getTop() - layoutParams.topMargin;
        int headerBottom = header.getBottom() + headerMargins.bottom + headerMargins.top;
        if (itemTop > headerBottom) {
            return false;
        }
    } else {
        int itemLeft = item.getLeft() - layoutParams.leftMargin;
        int headerRight = header.getRight() + headerMargins.right + headerMargins.left;
        if (itemLeft > headerRight) {
            return false;
        }
    }
    return true;
}
Also used : Rect(android.graphics.Rect) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 93 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.

the class HeaderPositionCalculator method getHeaderBounds.

public Rect getHeaderBounds(RecyclerView recyclerView, View header, View firstView, boolean firstHeader) {
    int orientation = mOrientationProvider.getOrientation(recyclerView);
    Rect bounds = getDefaultHeaderOffset(recyclerView, header, firstView, orientation);
    if (firstHeader && isStickyHeaderBeingPushedOffscreen(recyclerView, header)) {
        View viewAfterNextHeader = getFirstViewUnobscuredByHeader(recyclerView, header);
        int firstViewUnderHeaderPosition = recyclerView.getChildAdapterPosition(viewAfterNextHeader);
        View secondHeader = mHeaderProvider.getHeader(recyclerView, firstViewUnderHeaderPosition);
        translateHeaderWithNextHeader(recyclerView, mOrientationProvider.getOrientation(recyclerView), bounds, header, viewAfterNextHeader, secondHeader);
    }
    return bounds;
}
Also used : Rect(android.graphics.Rect) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 94 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.

the class StickyRecyclerHeadersDecoration method getItemOffsets.

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    int itemPosition = parent.getChildAdapterPosition(view);
    if (itemPosition == RecyclerView.NO_POSITION) {
        return;
    }
    if (mHeaderPositionCalculator.hasNewHeader(itemPosition)) {
        View header = getHeaderView(parent, itemPosition);
        setItemOffsetsForHeader(outRect, header, mOrientationProvider.getOrientation(parent));
    }
}
Also used : View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 95 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.

the class SimpleItemTouchHelperCallback method onChildDraw.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    // Fade out the view as it is swiped out of the parent's bounds
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        View itemView = viewHolder.itemView;
        final float alpha = ALPHA_FULL - Math.abs(dX) / (float) itemView.getWidth();
        itemView.setAlpha(alpha);
    }
}
Also used : View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TargetApi(android.annotation.TargetApi)

Aggregations

RecyclerView (androidx.recyclerview.widget.RecyclerView)272 View (android.view.View)174 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)115 TextView (android.widget.TextView)32 Test (org.junit.Test)24 Nullable (androidx.annotation.Nullable)22 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)22 ImageView (android.widget.ImageView)18 Toolbar (androidx.appcompat.widget.Toolbar)18 NonNull (androidx.annotation.NonNull)16 Bundle (android.os.Bundle)15 ViewGroup (android.view.ViewGroup)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)14 Rect (android.graphics.Rect)13 LayoutInflater (android.view.LayoutInflater)11 SuppressLint (android.annotation.SuppressLint)10 Context (android.content.Context)10 ContextualCard (com.android.settings.homepage.contextualcards.ContextualCard)10 List (java.util.List)9