use of android.graphics.Rect in project actor-platform by actorapp.
the class AvatarPlaceholderDrawable method draw.
@Override
public void draw(Canvas canvas) {
Rect bounds = getBounds();
CIRCLE_PAINT.setColor(color);
canvas.drawCircle(bounds.centerX(), bounds.centerY(), bounds.width() / 2, CIRCLE_PAINT);
if (TEXT_SIZE != selfTextSize) {
TEXT_PAINT.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, selfTextSize, ctx.getResources().getDisplayMetrics()));
TEXT_SIZE = selfTextSize;
}
canvas.drawText(title, textX, textY, (TEXT_PAINT));
}
use of android.graphics.Rect in project actor-platform by actorapp.
the class CoverOverlayDrawable method draw.
@Override
public void draw(Canvas canvas) {
Rect rect = getBounds();
bottomShadow.setBounds(rect.left, rect.bottom - Screen.dp(64), rect.right, rect.bottom);
bottomShadow.draw(canvas);
}
use of android.graphics.Rect in project actor-platform by actorapp.
the class BaseKeyboard method getViewInset.
public static int getViewInset(View view, int statusBarHeight) {
if (view == null || view.getRootView() == null) {
return 0;
}
view = view.getRootView();
if (Build.VERSION.SDK_INT < 21 || view.getHeight() == Screen.getHeight() || view.getHeight() == Screen.getHeight() - statusBarHeight) {
return 0;
}
try {
Field mAttachInfoField = View.class.getDeclaredField("mAttachInfo");
mAttachInfoField.setAccessible(true);
Object mAttachInfo = mAttachInfoField.get(view);
if (mAttachInfo != null) {
Field mStableInsetsField = mAttachInfo.getClass().getDeclaredField("mStableInsets");
mStableInsetsField.setAccessible(true);
Rect insets = (Rect) mStableInsetsField.get(mAttachInfo);
return insets.bottom;
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
use of android.graphics.Rect in project Reader by TheKeeperOfPie.
the class CustomItemTouchHelper method scrollIfNecessary.
/**
* If user drags the view to the edge, trigger a scroll if necessary.
*/
private boolean scrollIfNecessary() {
if (mSelected == null) {
mDragScrollStartTimeInMs = Long.MIN_VALUE;
return false;
}
final long now = System.currentTimeMillis();
final long scrollDuration = mDragScrollStartTimeInMs == Long.MIN_VALUE ? 0 : now - mDragScrollStartTimeInMs;
RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager();
if (mTmpRect == null) {
mTmpRect = new Rect();
}
int scrollX = 0;
int scrollY = 0;
lm.calculateItemDecorationsForChild(mSelected.itemView, mTmpRect);
if (lm.canScrollHorizontally()) {
int curX = (int) (mSelectedStartX + mDx);
final int leftDiff = curX - mTmpRect.left - mRecyclerView.getPaddingLeft();
if (mDx < 0 && leftDiff < 0) {
scrollX = leftDiff;
} else if (mDx > 0) {
final int rightDiff = curX + mSelected.itemView.getWidth() + mTmpRect.right - (mRecyclerView.getWidth() - mRecyclerView.getPaddingRight());
if (rightDiff > 0) {
scrollX = rightDiff;
}
}
}
if (lm.canScrollVertically()) {
int curY = (int) (mSelectedStartY + mDy);
final int topDiff = curY - mTmpRect.top - mRecyclerView.getPaddingTop();
if (mDy < 0 && topDiff < 0) {
scrollY = topDiff;
} else if (mDy > 0) {
final int bottomDiff = curY + mSelected.itemView.getHeight() + mTmpRect.bottom - (mRecyclerView.getHeight() - mRecyclerView.getPaddingBottom());
if (bottomDiff > 0) {
scrollY = bottomDiff;
}
}
}
if (scrollX != 0) {
scrollX = mCallback.interpolateOutOfBoundsScroll(mRecyclerView, mSelected.itemView.getWidth(), scrollX, mRecyclerView.getWidth(), scrollDuration);
}
if (scrollY != 0) {
scrollY = mCallback.interpolateOutOfBoundsScroll(mRecyclerView, mSelected.itemView.getHeight(), scrollY, mRecyclerView.getHeight(), scrollDuration);
}
if (scrollX != 0 || scrollY != 0) {
if (mDragScrollStartTimeInMs == Long.MIN_VALUE) {
mDragScrollStartTimeInMs = now;
}
mRecyclerView.scrollBy(scrollX, scrollY);
return true;
}
mDragScrollStartTimeInMs = Long.MIN_VALUE;
return false;
}
use of android.graphics.Rect in project SuperSLiM by TonicArtos.
the class LayoutManager method layoutHeaderTowardsStart.
/**
* Layout header towards start edge.
*
* @param header Header to be laid out.
* @param leadingEdge Leading edge to align sticky headers against.
* @param markerLine Bottom edge of the header.
* @param sd Section data.
* @param state Layout state.
* @return Top of the section including the header.
*/
private int layoutHeaderTowardsStart(View header, int leadingEdge, int markerLine, int offset, int sectionBottom, SectionData sd, LayoutState state) {
Rect r = setHeaderRectSides(mRect, sd, state);
if (sd.headerParams.isHeaderInline() && !sd.headerParams.isHeaderOverlay()) {
r.bottom = markerLine;
r.top = r.bottom - sd.headerHeight;
} else if (offset <= 0) {
r.top = markerLine + offset;
r.bottom = r.top + sd.headerHeight;
} else {
r.bottom = leadingEdge;
r.top = r.bottom - sd.headerHeight;
}
if (sd.headerParams.isHeaderSticky() && r.top < leadingEdge && sd.firstPosition != state.getRecyclerState().getTargetScrollPosition()) {
r.top = leadingEdge;
r.bottom = r.top + sd.headerHeight;
if (sd.headerParams.isHeaderInline() && !sd.headerParams.isHeaderOverlay()) {
markerLine -= sd.headerHeight;
}
}
if (r.bottom > sectionBottom) {
r.bottom = sectionBottom;
r.top = r.bottom - sd.headerHeight;
}
layoutDecorated(header, r.left, r.top, r.right, r.bottom);
return Math.min(r.top, markerLine);
}
Aggregations