use of android.graphics.Rect in project UltimateAndroid by cymcsg.
the class UiUtils method getStatusBarHeight.
/**
* Get height of status bar
* @param activity
* @return
*/
public static int getStatusBarHeight(Activity activity) {
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
return frame.top;
}
use of android.graphics.Rect 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;
}
use of android.graphics.Rect 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;
}
use of android.graphics.Rect in project UltimateRecyclerView by cymcsg.
the class HeaderRenderer method drawHeader.
/**
* Draws a header to a canvas, offsetting by some x and y amount
*
* @param recyclerView the parent recycler view for drawing the header into
* @param canvas the canvas on which to draw the header
* @param header the view to draw as the header
* @param offset a Rect used to define the x/y offset of the header. Specify x/y offset by setting
* the {@link Rect#left} and {@link Rect#top} properties, respectively.
*/
public void drawHeader(RecyclerView recyclerView, Canvas canvas, View header, Rect offset) {
canvas.save();
if (recyclerView.getLayoutManager().getClipToPadding()) {
// Clip drawing of headers to the padding of the RecyclerView. Avoids drawing in the padding
Rect clipRect = getClipRectForHeader(recyclerView, header);
canvas.clipRect(clipRect);
}
canvas.translate(offset.left, offset.top);
header.draw(canvas);
canvas.restore();
}
use of android.graphics.Rect in project UltimateRecyclerView by cymcsg.
the class SwipeLayout method computeBottomLayoutAreaViaSurface.
private Rect computeBottomLayoutAreaViaSurface(ShowMode mode, Rect surfaceArea) {
Rect rect = surfaceArea;
View bottomView = getCurrentBottomView();
int bl = rect.left, bt = rect.top, br = rect.right, bb = rect.bottom;
if (mode == ShowMode.PullOut) {
if (mCurrentDragEdge == DragEdge.Left)
bl = rect.left - mDragDistance;
else if (mCurrentDragEdge == DragEdge.Right)
bl = rect.right;
else if (mCurrentDragEdge == DragEdge.Top)
bt = rect.top - mDragDistance;
else
bt = rect.bottom;
if (mCurrentDragEdge == DragEdge.Left || mCurrentDragEdge == DragEdge.Right) {
bb = rect.bottom;
br = bl + (bottomView == null ? 0 : bottomView.getMeasuredWidth());
} else {
bb = bt + (bottomView == null ? 0 : bottomView.getMeasuredHeight());
br = rect.right;
}
} else if (mode == ShowMode.LayDown) {
if (mCurrentDragEdge == DragEdge.Left)
br = bl + mDragDistance;
else if (mCurrentDragEdge == DragEdge.Right)
bl = br - mDragDistance;
else if (mCurrentDragEdge == DragEdge.Top)
bb = bt + mDragDistance;
else
bt = bb - mDragDistance;
}
return new Rect(bl, bt, br, bb);
}
Aggregations