本文整理匯總了Java中android.graphics.Rect.setEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Java Rect.setEmpty方法的具體用法?Java Rect.setEmpty怎麽用?Java Rect.setEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Rect
的用法示例。
在下文中一共展示了Rect.setEmpty方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calculateClippingRect
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* Can be used by view that support {@code removeClippedSubviews} property to calculate area that
* given {@param view} should be clipped to based on the clipping rectangle of it's parent in
* case when parent is also set to clip it's children.
*
* @param view view that we want to calculate clipping rect for
* @param outputRect where the calculated rectangle will be written
*/
public static void calculateClippingRect(View view, Rect outputRect) {
ViewParent parent = view.getParent();
if (parent == null) {
outputRect.setEmpty();
return;
} else if (parent instanceof ReactClippingViewGroup) {
ReactClippingViewGroup clippingViewGroup = (ReactClippingViewGroup) parent;
if (clippingViewGroup.getRemoveClippedSubviews()) {
clippingViewGroup.getClippingRect(sHelperRect);
// Intersect the view with the parent's rectangle
// This will result in the overlap with coordinates in the parent space
if (!sHelperRect.intersect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())) {
outputRect.setEmpty();
return;
}
// Now we move the coordinates to the View's coordinate space
sHelperRect.offset(-view.getLeft(), -view.getTop());
sHelperRect.offset(view.getScrollX(), view.getScrollY());
outputRect.set(sHelperRect);
return;
}
}
view.getDrawingRect(outputRect);
}
示例2: getItemOffsets
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (parent.getChildAdapterPosition(view) < mColumns) {
if (mHorizontal) {
if (mView.getMeasuredWidth() <= 0) {
mView.measure(View.MeasureSpec.makeMeasureSpec(parent.getMeasuredWidth(), View.MeasureSpec.AT_MOST),
View.MeasureSpec.makeMeasureSpec(parent.getMeasuredHeight(), View.MeasureSpec.AT_MOST));
}
outRect.set(mView.getMeasuredWidth(), 0, 0, 0);
} else {
if (mView.getMeasuredHeight() <= 0) {
mView.measure(View.MeasureSpec.makeMeasureSpec(parent.getMeasuredWidth(), View.MeasureSpec.AT_MOST),
View.MeasureSpec.makeMeasureSpec(parent.getMeasuredHeight(), View.MeasureSpec.AT_MOST));
}
outRect.set(0, mView.getMeasuredHeight(), 0, 0);
}
} else {
outRect.setEmpty();
}
}
示例3: onItemClicked
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public void onItemClicked(MotionEvent event, View v, Object dataObject) {
if (v.getTag() instanceof ViewHolder) {
int x = (int) event.getRawX();
int y = (int) event.getRawY();
ViewHolder vh = (ViewHolder) v.getTag();
View child = vh.portraitView;
Rect outRect = new Rect();
child.getGlobalVisibleRect(outRect);
if (outRect.contains(x, y)) {
AppToast.show(this, "click 大圖");
} else {
outRect.setEmpty();
child = vh.collectView;
child.getGlobalVisibleRect(outRect);
if (outRect.contains(x, y)) {
AppToast.show(this, "click 關注");
}
}
}
}
示例4: getChildRect
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* Get the position rect for the given child. If the child has currently requested layout
* or has a visibility of GONE.
*
* @param child child view to check
* @param transform true to include transformation in the output rect, false to
* only account for the base position
* @param out rect to set to the output values
*/
void getChildRect(View child, boolean transform, Rect out) {
if (child.isLayoutRequested() || child.getVisibility() == View.GONE) {
out.setEmpty();
return;
}
if (transform) {
getDescendantRect(child, out);
} else {
out.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
}
}
示例5: adjustLayout
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public void adjustLayout(int startPosition, int endPosition, LayoutManagerHelper helper) {
if (requireLayoutView()) {
View refer = null;
Rect tempRect = new Rect();
final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
for (int i = 0; i < helper.getChildCount(); i++) {
refer = helper.getChildAt(i);
int anchorPos = helper.getPosition(refer);
if (getRange().contains(anchorPos)) {
if (refer.getVisibility() == View.GONE) {
tempRect.setEmpty();
} else {
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)
refer.getLayoutParams();
if (helper.getOrientation() == VirtualLayoutManager.VERTICAL) {
tempRect.union(helper.getDecoratedLeft(refer) - params.leftMargin,
orientationHelper.getDecoratedStart(refer),
helper.getDecoratedRight(refer) + params.rightMargin,
orientationHelper.getDecoratedEnd(refer));
} else {
tempRect.union(orientationHelper.getDecoratedStart(refer),
helper.getDecoratedTop(refer) - params.topMargin, orientationHelper.getDecoratedEnd(refer),
helper.getDecoratedBottom(refer) + params.bottomMargin);
}
}
}
}
if (!tempRect.isEmpty()) {
mLayoutRegion.set(tempRect.left - mPaddingLeft, tempRect.top - mPaddingTop,
tempRect.right + mPaddingRight, tempRect.bottom + mPaddingBottom);
} else {
mLayoutRegion.setEmpty();
}
if (mLayoutView != null) {
mLayoutView.layout(mLayoutRegion.left, mLayoutRegion.top, mLayoutRegion.right, mLayoutRegion.bottom);
}
}
}
示例6: adjustLayout
import android.graphics.Rect; //導入方法依賴的package包/類
public void adjustLayout(int startPosition, int endPosition, LayoutManagerHelper helper) {
if (!isChildrenEmpty()) {
for (int i = 0, size = mChildren.size(); i < size; i++) {
RangeStyle rangeStyle = mChildren.valueAt(i);
rangeStyle.adjustLayout(startPosition, endPosition, helper);
}
}
if (requireLayoutView()) {
View refer = null;
Rect tempRect = new Rect();
final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
for (int i = 0; i < helper.getChildCount(); i++) {
refer = helper.getChildAt(i);
int anchorPos = helper.getPosition(refer);
if (getRange().contains(anchorPos)) {
if (refer.getVisibility() == View.GONE) {
tempRect.setEmpty();
} else {
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)
refer.getLayoutParams();
if (helper.getOrientation() == VirtualLayoutManager.VERTICAL) {
tempRect.union(helper.getDecoratedLeft(refer) - params.leftMargin,
orientationHelper.getDecoratedStart(refer),
helper.getDecoratedRight(refer) + params.rightMargin,
orientationHelper.getDecoratedEnd(refer));
} else {
tempRect.union(orientationHelper.getDecoratedStart(refer),
helper.getDecoratedTop(refer) - params.topMargin, orientationHelper.getDecoratedEnd(refer),
helper.getDecoratedBottom(refer) + params.bottomMargin);
}
}
}
}
if (!tempRect.isEmpty()) {
mLayoutRegion.set(tempRect.left - mPaddingLeft, tempRect.top - mPaddingTop,
tempRect.right + mPaddingRight, tempRect.bottom + mPaddingBottom);
} else {
mLayoutRegion.setEmpty();
}
if (mLayoutView != null) {
mLayoutView.layout(mLayoutRegion.left, mLayoutRegion.top, mLayoutRegion.right, mLayoutRegion.bottom);
}
}
}
示例7: getItemOffsets
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
outRect.setEmpty();
}
示例8: onMeasure
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final Rect padding = mTempRect;
int thumbWidth;
int thumbHeight;
if (mThumbDrawable != null) {
mThumbDrawable.getPadding(padding);
thumbWidth = mThumbDrawable.getIntrinsicWidth() - padding.left - padding.right;
thumbHeight = mThumbDrawable.getIntrinsicHeight();
} else {
thumbWidth = 0;
thumbHeight = 0;
}
mThumbWidth = thumbWidth;
int trackHeight;
if (mTrackDrawable != null) {
mTrackDrawable.getPadding(padding);
trackHeight = mTrackDrawable.getIntrinsicHeight();
} else {
padding.setEmpty();
trackHeight = 0;
}
int paddingLeft = padding.left;
int paddingRight = padding.right;
if (mThumbDrawable != null) {
final Insets inset = Insets.NONE;
paddingLeft = Math.max(paddingLeft, inset.left);
paddingRight = Math.max(paddingRight, inset.right);
}
final int switchWidth = Math.max(mSwitchMinWidth, 2 * mThumbWidth + paddingLeft + paddingRight);
final int switchHeight = Math.max(trackHeight, thumbHeight);
mSwitchWidth = switchWidth;
mSwitchHeight = switchHeight;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final int measuredHeight = getMeasuredHeight();
if (measuredHeight < switchHeight) {
setMeasuredDimension(switchWidth, switchHeight);
}
}
示例9: onLayout
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
wasLayout = true;
int opticalInsetLeft = 0;
int opticalInsetRight = 0;
if (mThumbDrawable != null) {
final Rect trackPadding = mTempRect;
if (mTrackDrawable != null) {
mTrackDrawable.getPadding(trackPadding);
} else {
trackPadding.setEmpty();
}
final Insets insets = Insets.NONE;
opticalInsetLeft = Math.max(0, insets.left - trackPadding.left);
opticalInsetRight = Math.max(0, insets.right - trackPadding.right);
}
final int switchRight;
final int switchLeft;
if (LocaleController.isRTL) {
switchLeft = getPaddingLeft() + opticalInsetLeft;
switchRight = switchLeft + mSwitchWidth - opticalInsetLeft - opticalInsetRight;
} else {
switchRight = getWidth() - getPaddingRight() - opticalInsetRight;
switchLeft = switchRight - mSwitchWidth + opticalInsetLeft + opticalInsetRight;
}
final int switchTop;
final int switchBottom;
switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) {
default:
case Gravity.TOP:
switchTop = getPaddingTop();
switchBottom = switchTop + mSwitchHeight;
break;
case Gravity.CENTER_VERTICAL:
switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 - mSwitchHeight / 2;
switchBottom = switchTop + mSwitchHeight;
break;
case Gravity.BOTTOM:
switchBottom = getHeight() - getPaddingBottom();
switchTop = switchBottom - mSwitchHeight;
break;
}
mSwitchLeft = switchLeft;
mSwitchTop = switchTop;
mSwitchBottom = switchBottom;
mSwitchRight = switchRight;
}
示例10: getItemOffsets
import android.graphics.Rect; //導入方法依賴的package包/類
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) {
outRect.setEmpty();
}
示例11: releaseTempRect
import android.graphics.Rect; //導入方法依賴的package包/類
private static void releaseTempRect(@NonNull Rect rect) {
rect.setEmpty();
sRectPool.release(rect);
}
示例12: onMeasure
import android.graphics.Rect; //導入方法依賴的package包/類
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int thumbWidth;
int thumbHeight;
int maxTextWidth;
int trackHeight;
if (this.mShowText) {
if (this.mOnLayout == null) {
this.mOnLayout = makeLayout(this.mTextOn);
}
if (this.mOffLayout == null) {
this.mOffLayout = makeLayout(this.mTextOff);
}
}
Rect padding = this.mTempRect;
if (this.mThumbDrawable != null) {
this.mThumbDrawable.getPadding(padding);
thumbWidth = (this.mThumbDrawable.getIntrinsicWidth() - padding.left) - padding.right;
thumbHeight = this.mThumbDrawable.getIntrinsicHeight();
} else {
thumbWidth = 0;
thumbHeight = 0;
}
if (this.mShowText) {
maxTextWidth = Math.max(this.mOnLayout.getWidth(), this.mOffLayout.getWidth()) + (this.mThumbTextPadding * 2);
} else {
maxTextWidth = 0;
}
this.mThumbWidth = Math.max(maxTextWidth, thumbWidth);
if (this.mTrackDrawable != null) {
this.mTrackDrawable.getPadding(padding);
trackHeight = this.mTrackDrawable.getIntrinsicHeight();
} else {
padding.setEmpty();
trackHeight = 0;
}
int paddingLeft = padding.left;
int paddingRight = padding.right;
if (this.mThumbDrawable != null) {
Rect inset = DrawableUtils.getOpticalBounds(this.mThumbDrawable);
paddingLeft = Math.max(paddingLeft, inset.left);
paddingRight = Math.max(paddingRight, inset.right);
}
int switchWidth = Math.max(this.mSwitchMinWidth, ((this.mThumbWidth * 2) + paddingLeft) + paddingRight);
int switchHeight = Math.max(trackHeight, thumbHeight);
this.mSwitchWidth = switchWidth;
this.mSwitchHeight = switchHeight;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (getMeasuredHeight() < switchHeight) {
setMeasuredDimension(ViewCompat.getMeasuredWidthAndState(this), switchHeight);
}
}
示例13: onLayout
import android.graphics.Rect; //導入方法依賴的package包/類
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int switchLeft;
int switchRight;
int switchTop;
int switchBottom;
super.onLayout(changed, left, top, right, bottom);
int opticalInsetLeft = 0;
int opticalInsetRight = 0;
if (this.mThumbDrawable != null) {
Rect trackPadding = this.mTempRect;
if (this.mTrackDrawable != null) {
this.mTrackDrawable.getPadding(trackPadding);
} else {
trackPadding.setEmpty();
}
Rect insets = DrawableUtils.getOpticalBounds(this.mThumbDrawable);
opticalInsetLeft = Math.max(0, insets.left - trackPadding.left);
opticalInsetRight = Math.max(0, insets.right - trackPadding.right);
}
if (ViewUtils.isLayoutRtl(this)) {
switchLeft = getPaddingLeft() + opticalInsetLeft;
switchRight = ((this.mSwitchWidth + switchLeft) - opticalInsetLeft) - opticalInsetRight;
} else {
switchRight = (getWidth() - getPaddingRight()) - opticalInsetRight;
switchLeft = ((switchRight - this.mSwitchWidth) + opticalInsetLeft) + opticalInsetRight;
}
switch (getGravity() & 112) {
case 16:
switchTop = (((getPaddingTop() + getHeight()) - getPaddingBottom()) / 2) - (this.mSwitchHeight / 2);
switchBottom = switchTop + this.mSwitchHeight;
break;
case 80:
switchBottom = getHeight() - getPaddingBottom();
switchTop = switchBottom - this.mSwitchHeight;
break;
default:
switchTop = getPaddingTop();
switchBottom = switchTop + this.mSwitchHeight;
break;
}
this.mSwitchLeft = switchLeft;
this.mSwitchTop = switchTop;
this.mSwitchBottom = switchBottom;
this.mSwitchRight = switchRight;
}
示例14: onDraw
import android.graphics.Rect; //導入方法依賴的package包/類
protected void onDraw(Canvas canvas) {
int saveCount;
Layout switchText;
super.onDraw(canvas);
Rect padding = this.mTempRect;
Drawable trackDrawable = this.mTrackDrawable;
if (trackDrawable != null) {
trackDrawable.getPadding(padding);
} else {
padding.setEmpty();
}
int switchTop = this.mSwitchTop;
int switchInnerTop = switchTop + padding.top;
int switchInnerBottom = this.mSwitchBottom - padding.bottom;
Drawable thumbDrawable = this.mThumbDrawable;
if (trackDrawable != null) {
if (!this.mSplitTrack || thumbDrawable == null) {
trackDrawable.draw(canvas);
} else {
Rect insets = DrawableUtils.getOpticalBounds(thumbDrawable);
thumbDrawable.copyBounds(padding);
padding.left += insets.left;
padding.right -= insets.right;
saveCount = canvas.save();
canvas.clipRect(padding, Op.DIFFERENCE);
trackDrawable.draw(canvas);
canvas.restoreToCount(saveCount);
}
}
saveCount = canvas.save();
if (thumbDrawable != null) {
thumbDrawable.draw(canvas);
}
if (getTargetCheckedState()) {
switchText = this.mOnLayout;
} else {
switchText = this.mOffLayout;
}
if (switchText != null) {
int cX;
int[] drawableState = getDrawableState();
if (this.mTextColors != null) {
this.mTextPaint.setColor(this.mTextColors.getColorForState(drawableState, 0));
}
this.mTextPaint.drawableState = drawableState;
if (thumbDrawable != null) {
Rect bounds = thumbDrawable.getBounds();
cX = bounds.left + bounds.right;
} else {
cX = getWidth();
}
canvas.translate((float) ((cX / 2) - (switchText.getWidth() / 2)), (float) (((switchInnerTop + switchInnerBottom) / 2) - (switchText.getHeight() / 2)));
switchText.draw(canvas);
}
canvas.restoreToCount(saveCount);
}