本文整理匯總了Java中android.graphics.Rect.intersects方法的典型用法代碼示例。如果您正苦於以下問題:Java Rect.intersects方法的具體用法?Java Rect.intersects怎麽用?Java Rect.intersects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Rect
的用法示例。
在下文中一共展示了Rect.intersects方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getItemProxies
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public HashMap<Object, FreeFlowItem> getItemProxies(
int viewPortLeft, int viewPortTop) {
Rect viewport = new Rect(viewPortLeft,
viewPortTop,
viewPortLeft + width,
viewPortTop + height);
//Log.d(TAG, "Viewport: "+viewPortLeft+", "+viewPortTop+", "+viewport.width()+","+viewport.height());
HashMap<Object, FreeFlowItem> ret = new HashMap<Object, FreeFlowItem>();
Iterator<Entry<Object, FreeFlowItem>> it = map.entrySet().iterator();
while (it.hasNext()) {
Entry<Object, FreeFlowItem> pairs = it.next();
FreeFlowItem p = (FreeFlowItem) pairs.getValue();
if ( Rect.intersects(p.frame, viewport) ) {
ret.put(pairs.getKey(), p);
}
}
return ret;
}
示例2: getViewsIntersectingRegion
import android.graphics.Rect; //導入方法依賴的package包/類
private void getViewsIntersectingRegion(int cellX, int cellY, int spanX, int spanY,
View dragView, Rect boundingRect, ArrayList<View> intersectingViews) {
if (boundingRect != null) {
boundingRect.set(cellX, cellY, cellX + spanX, cellY + spanY);
}
intersectingViews.clear();
Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
Rect r1 = new Rect();
final int count = mShortcutsAndWidgets.getChildCount();
for (int i = 0; i < count; i++) {
View child = mShortcutsAndWidgets.getChildAt(i);
if (child == dragView) continue;
LayoutParams lp = (LayoutParams) child.getLayoutParams();
r1.set(lp.cellX, lp.cellY, lp.cellX + lp.cellHSpan, lp.cellY + lp.cellVSpan);
if (Rect.intersects(r0, r1)) {
mIntersectingViews.add(child);
if (boundingRect != null) {
boundingRect.union(r1);
}
}
}
}
示例3: addOrRemove
import android.graphics.Rect; //導入方法依賴的package包/類
private void addOrRemove(RecyclerView.Recycler recycler, Rect displayRect, int i) {
View child = recycler.getViewForPosition(i);
Rect rect = getItemFrameByPosition(i);
if (!Rect.intersects(displayRect, rect)) {
removeAndRecycleView(child, recycler); // 回收入暫存區
} else {
addView(child);
measureChildWithMargins(child, mWidthUsed, mHeightUsed);
RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
layoutDecorated(child,
rect.left - mOffsetX + lp.leftMargin,
rect.top - mOffsetY + lp.topMargin,
rect.right - mOffsetX - lp.rightMargin,
rect.bottom - mOffsetY - lp.bottomMargin);
}
}
示例4: fill
import android.graphics.Rect; //導入方法依賴的package包/類
private void fill(RecyclerView.Recycler recycler, RecyclerView.State state) {
if (getItemCount() <= 0 || state.isPreLayout()) {
return;
}
Rect displayRect = new Rect(mHorizontalOffset, mVerticalOffset,
getHorizontalSpace() + mHorizontalOffset,
getVerticalSpace() + mVerticalOffset);
for (int i = 0; i < getItemCount(); i++) {
Rect frame = mItems.get(i);
if (Rect.intersects(displayRect, frame)) {
View scrap = recycler.getViewForPosition(i);
addView(scrap);
measureChildWithMargins(scrap, 0, 0);
layoutDecorated(scrap, frame.left - mHorizontalOffset, frame.top - mVerticalOffset,
frame.right - mHorizontalOffset, frame.bottom - mVerticalOffset);
}
}
}
示例5: updateSubviewClipStatus
import android.graphics.Rect; //導入方法依賴的package包/類
private void updateSubviewClipStatus(Rect clippingRect, int idx, int clippedSoFar) {
View child = Assertions.assertNotNull(mAllChildren)[idx];
sHelperRect.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
boolean intersects = clippingRect
.intersects(sHelperRect.left, sHelperRect.top, sHelperRect.right, sHelperRect.bottom);
boolean needUpdateClippingRecursive = false;
// We never want to clip children that are being animated, as this can easily break layout :
// when layout animation changes size and/or position of views contained inside a listview that
// clips offscreen children, we need to ensure that, when view exits the viewport, final size
// and position is set prior to removing the view from its listview parent.
// Otherwise, when view gets re-attached again, i.e when it re-enters the viewport after scroll,
// it won't be size and located properly.
Animation animation = child.getAnimation();
boolean isAnimating = animation != null && !animation.hasEnded();
if (!intersects && child.getParent() != null && !isAnimating) {
// We can try saving on invalidate call here as the view that we remove is out of visible area
// therefore invalidation is not necessary.
super.removeViewsInLayout(idx - clippedSoFar, 1);
needUpdateClippingRecursive = true;
} else if (intersects && child.getParent() == null) {
super.addViewInLayout(child, idx - clippedSoFar, sDefaultLayoutParam, true);
invalidate();
needUpdateClippingRecursive = true;
} else if (intersects) {
// If there is any intersection we need to inform the child to update its clipping rect
needUpdateClippingRecursive = true;
}
if (needUpdateClippingRecursive) {
if (child instanceof ReactClippingViewGroup) {
// we don't use {@link sHelperRect} until the end of this loop, therefore it's safe
// to call this method that may write to the same {@link sHelperRect} object.
ReactClippingViewGroup clippingChild = (ReactClippingViewGroup) child;
if (clippingChild.getRemoveClippedSubviews()) {
clippingChild.updateClippingRect();
}
}
}
}
示例6: fill
import android.graphics.Rect; //導入方法依賴的package包/類
private void fill(RecyclerView.Recycler recycler, RecyclerView.State state) {
if (getItemCount() <= 0 || state.isPreLayout()) { return;}
Rect displayRect = new Rect(mHorizontalOffset, mVerticalOffset,
getHorizontalSpace() + mHorizontalOffset,
getVerticalSpace() + mVerticalOffset);
// Rect rect = new Rect();
// for (int i = 0; i < getChildCount(); i++) {
// View item = getChildAt(i);
// rect.left = getDecoratedLeft(item);
// rect.top = getDecoratedTop(item);
// rect.right = getDecoratedRight(item);
// rect.bottom = getDecoratedBottom(item);
// if (!Rect.intersects(displayRect, rect)) {
// removeAndRecycleView(item, recycler);
// }
// }
for (int i = 0; i < getItemCount(); i++) {
Rect frame = mItemFrames.get(i);
if (Rect.intersects(displayRect, frame)) {
View scrap = recycler.getViewForPosition(i);
addView(scrap);
measureChildWithMargins(scrap, 0, 0);
layoutDecorated(scrap, frame.left - mHorizontalOffset, frame.top - mVerticalOffset,
frame.right - mHorizontalOffset, frame.bottom - mVerticalOffset);
}
}
}
示例7: fillView
import android.graphics.Rect; //導入方法依賴的package包/類
private void fillView(RecyclerView.Recycler recycler, RecyclerView.State state) {
if (getItemCount() <= 0 || state.isPreLayout()) return;
// the visible area for the RecyclerView
Rect displayArea = new Rect(0, mVerticalOffset, getHorizontalSpace(),
getVerticalSpace() + mVerticalOffset);
// remove invisible child
Rect rect = new Rect();
for (int i = 0; i < getChildCount(); i++) {
View item = getChildAt(i);
rect.set(getDecoratedLeft(item), getDecoratedTop(item),
getDecoratedRight(item), getDecoratedBottom(item));
if (!Rect.intersects(displayArea, rect)) {
removeAndRecycleView(item, recycler);
}
}
// add visible child
for (int i = 0; i < getItemCount(); i++) {
Rect area = mItemAreas.get(i);
if (Rect.intersects(displayArea, area)) {
View child = recycler.getViewForPosition(i);
addView(child);
measureChildWithMargins(child, 0, 0);
Rect childRect = new Rect();
calculateItemDecorationsForChild(child, childRect);
layoutDecorated(child, area.left, area.top - mVerticalOffset,
area.right, area.bottom - mVerticalOffset);
}
}
}
示例8: findResultSelected
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public void findResultSelected(Rect rect) {
super.findResultSelected(rect);
boolean makeRoom = false;
float density = getContext().getResources().getDisplayMetrics().density;
if (rect != null && rect.intersects((int) (getLeft() / density), 0,
(int) (getRight() / density), (int) (getHeight() / density))) {
makeRoom = true;
}
setMakeRoomForResults(makeRoom);
}
示例9: isIntersectWithTrash
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* 削除Viewと重なっているかチェックします。
*
* @return 削除Viewと重なっている場合はtrue
*/
private boolean isIntersectWithTrash() {
// 無効の場合は重なり判定を行わない
if (!mTrashView.isTrashEnabled()) {
return false;
}
// INFO:TrashViewとFloatingViewは同じGravityにする必要があります
mTrashView.getWindowDrawingRect(mTrashViewRect);
mTargetFloatingView.getWindowDrawingRect(mFloatingViewRect);
return Rect.intersects(mTrashViewRect, mFloatingViewRect);
}
示例10: layoutItems
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* 布局Item
* <p>注意:1,先清除已經超出屏幕的item
* <p> 2,再繪製可以顯示在屏幕裏麵的item
*/
private void layoutItems(RecyclerView.Recycler recycler,
RecyclerView.State state, int scrollDirection) {
if (state.isPreLayout()) return;
Rect displayFrame = new Rect(mOffsetAll, 0, mOffsetAll + getHorizontalSpace(), getVerticalSpace());
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
int position = getPosition(child);
if (!Rect.intersects(displayFrame, mAllItemFrames.get(position))) {//Item沒有在顯示區域,就說明需要回收
removeAndRecycleView(child, recycler); //回收滑出屏幕的View
mHasAttachedItems.put(position, false);
} else { //Item還在顯示區域內,更新滑動後Item的位置
layoutItem(child, mAllItemFrames.get(position)); //更新Item位置
mHasAttachedItems.put(position, true);
}
}
for (int i = 0; i < getItemCount(); i++) {
if (Rect.intersects(displayFrame, mAllItemFrames.get(i)) &&
!mHasAttachedItems.get(i)) { //重新加載可見範圍內的Item
View scrap = recycler.getViewForPosition(i);
measureChildWithMargins(scrap, 0, 0);
if (scrollDirection == SCROLL_LEFT || mIsFlatFlow) { //向左滾動,新增的Item需要添加在最前麵
addView(scrap, 0);
} else { //向右滾動,新增的item要添加在最後麵
addView(scrap);
}
layoutItem(scrap, mAllItemFrames.get(i)); //將這個Item布局出來
mHasAttachedItems.put(i, true);
}
}
}
示例11: isViewCovered
import android.graphics.Rect; //導入方法依賴的package包/類
public static boolean isViewCovered(final View view) {
View currentView = view;
Rect currentViewRect = new Rect();
boolean partVisible = currentView.getGlobalVisibleRect(currentViewRect);
boolean totalHeightVisible = (currentViewRect.bottom - currentViewRect.top) >= view.getMeasuredHeight();
boolean totalWidthVisible = (currentViewRect.right - currentViewRect.left) >= view.getMeasuredWidth();
boolean totalViewVisible = partVisible && totalHeightVisible && totalWidthVisible;
if (!totalViewVisible)
return true;
while (currentView.getParent() instanceof ViewGroup) {
ViewGroup currentParent = (ViewGroup) currentView.getParent();
if (currentParent.getVisibility() != View.VISIBLE)
return true;
int start = indexOfViewInParent(currentView, currentParent);
for (int i = start + 1; i < currentParent.getChildCount(); i++) {
Rect viewRect = new Rect();
view.getGlobalVisibleRect(viewRect);
View otherView = currentParent.getChildAt(i);
Rect otherViewRect = new Rect();
otherView.getGlobalVisibleRect(otherViewRect);
if (Rect.intersects(viewRect, otherViewRect))
return true;
}
currentView = currentParent;
}
return false;
}
示例12: draw
import android.graphics.Rect; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
final Rect r = new Rect(getBounds());
if (canvas.getClipBounds(sTempRect) && !Rect.intersects(sTempRect, r)) {
// The draw region has been clipped.
return;
}
if (mIndicatorRectDirty) {
initIndicatorRect();
}
final float iconScale;
if ((mAnimationProgress >= ANIMATION_PROGRESS_STARTED)
&& (mAnimationProgress < ANIMATION_PROGRESS_COMPLETED)) {
mPaint.setAlpha((int) ((1 - mAnimationProgress) * 255));
mBgDrawable.setAlpha(mPaint.getAlpha());
mBgDrawable.draw(canvas);
canvas.drawOval(mIndicatorRect, mPaint);
iconScale = ICON_SCALE_FACTOR + (1 - ICON_SCALE_FACTOR) * mAnimationProgress;
} else if (mAnimationProgress == ANIMATION_PROGRESS_STOPPED) {
mPaint.setAlpha(255);
iconScale = ICON_SCALE_FACTOR;
mBgDrawable.setAlpha(255);
mBgDrawable.draw(canvas);
if (mProgress >= 100) {
canvas.drawOval(mIndicatorRect, mPaint);
} else if (mProgress > 0) {
canvas.drawArc(mIndicatorRect, -90, mProgress * 3.6f, false, mPaint);
}
} else {
iconScale = 1;
}
canvas.save();
canvas.scale(iconScale, iconScale, r.exactCenterX(), r.exactCenterY());
mIcon.draw(canvas);
canvas.restore();
}
示例13: fill
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* 填充方法
*
* @param recycler
* @param state
*/
private void fill(RecyclerView.Recycler recycler, RecyclerView.State state) {
if (getItemCount() <= 0 || state.isPreLayout()) {
return;
}
//考慮到當前RecyclerView會處於滑動的狀態,所以這裏的Rect的作用是展示當前顯示的區域
//需要考慮到RecyclerView的滑動量
//mHorizontalOffset 橫向的滑動偏移量
//mVerticalOffset 縱向的滑動偏移量
Rect displayRect = new Rect(0, mVerticalOffset,
getHorizontalSpace(),
getVerticalSpace() + mVerticalOffset);
/**
* 對這些View進行測量和布局操作
*/
for (int i = 0; i < getItemCount(); i++) {
Rect frame = mItemFrames.get(i);
if (Rect.intersects(displayRect, frame)) {
View scrap = recycler.getViewForPosition(i);
addView(scrap);
//測量子View
measureChildWithMargins(scrap, 0, 0);
//布局方法
layoutDecorated(scrap, frame.left - mHorizontalOffset, frame.top - mVerticalOffset,
frame.right - mHorizontalOffset, frame.bottom - mVerticalOffset);
}
}
}
示例14: layoutItems
import android.graphics.Rect; //導入方法依賴的package包/類
/**
* 擺放當前狀態下要展示的item
* @param recycler Recycler to use for fetching potentially cached views for a
* position
* @param state Transient state of RecyclerView
*/
private void layoutItems(RecyclerView.Recycler recycler, RecyclerView.State state) {
if (state.isPreLayout()) { // 跳過preLayout,preLayout主要用於支持動畫
return;
}
// 當前scroll offset狀態下的顯示區域
Rect displayFrame = new Rect(self.getState().scrolledX, self.getState().scrolledY, self.getState().scrolledX + self.getHorizontalSpace(), self.getState().scrolledY + self.getVerticalSpace());
/**
* 移除已顯示的但在當前scroll offset狀態下處於屏幕外的item
*/
Rect childFrame = new Rect();
for (int i = 0; i < self.getChildCount(); i++) {
View child = self.getChildAt(i);
childFrame.left = self.getDecoratedLeft(child);
childFrame.top = self.getDecoratedTop(child);
childFrame.right = self.getDecoratedRight(child);
childFrame.bottom = self.getDecoratedBottom(child);
if (!Rect.intersects(displayFrame, childFrame)) {
self.getState().itemsAttached.put(self.getPosition(child), false);
self.removeAndRecycleView(child, recycler);
}
}
/**
* 擺放需要顯示的item
* 由於RecyclerView實際上並沒有scroll,也就是說RecyclerView容器的滑動效果是依賴於LayoutManager對item進行平移來實現的
* 故在放置item時要將item的計算位置平移到實際位置
*/
for (int i = 0; i < self.getItemCount(); i++) {
if (Rect.intersects(displayFrame, self.getState().itemsFrames.get(i))) {
/**
* 在onLayoutChildren時由於移除了所有的item view,可以遍曆全部item進行添加
* 在scroll時就不同了,由於scroll時會先將已顯示的item view進行平移,然後移除屏幕外的item view,此時仍然在屏幕內顯示的item view就無需再次添加了
*/
if (!self.getState().itemsAttached.get(i)) {
View scrap = recycler.getViewForPosition(i);
self.measureChildWithMargins(scrap, 0, 0);
self.addView(scrap);
Rect frame = self.getState().itemsFrames.get(i);
self.layoutDecorated(scrap,
frame.left - self.getState().scrolledX,
frame.top - self.getState().scrolledY,
frame.right - self.getState().scrolledX,
frame.bottom - self.getState().scrolledY); // Important!布局到RecyclerView容器中,所有的計算都是為了得出任意position的item的邊界來布局
self.getState().itemsAttached.put(i, true);
}
}
}
}
示例15: drawWheelItems
import android.graphics.Rect; //導入方法依賴的package包/類
private void drawWheelItems(Canvas canvas) {
double angleInRadians = Math.toRadians(mAngle);
double cosAngle = Math.cos(angleInRadians);
double sinAngle = Math.sin(angleInRadians);
float centerX = mWheelBounds.mCenterX;
float centerY = mWheelBounds.mCenterY;
int wheelItemOffset = mItemCount / 2;
int offset = mRawSelectedPosition - wheelItemOffset;
int length = mItemCount + offset;
for (int i = offset; i < length; i++) {
int adapterPosition = rawPositionToAdapterPosition(i);
int wheelItemPosition = rawPositionToWheelPosition(i, adapterPosition);
Circle itemBounds = mWheelItemBounds.get(wheelItemPosition);
float radius = itemBounds.mRadius;
//translate before rotating so that origin is at the wheel's center
float x = itemBounds.mCenterX - centerX;
float y = itemBounds.mCenterY - centerY;
//rotate
float x1 = (float) (x * cosAngle - y * sinAngle);
float y1 = (float) (x * sinAngle + y * cosAngle);
//translate back after rotation
x1 += centerX;
y1 += centerY;
ItemState itemState = mItemStates.get(wheelItemPosition);
updateItemState(itemState, adapterPosition, x1, y1, radius);
mItemTransformer.transform(itemState, sTempRect);
//Empty positions can only occur from having "non repeatable" items
CacheItem cacheItem = getCacheItem(adapterPosition);
//don't draw if outside of the view bounds
if (Rect.intersects(sTempRect, mViewBounds)) {
if (cacheItem.mDirty && !cacheItem.mIsEmpty) {
cacheItem.mDrawable = mAdapter.getDrawable(adapterPosition);
cacheItem.mDirty = false;
}
if (!cacheItem.mIsVisible) {
cacheItem.mIsVisible = true;
if (mOnItemVisibilityChangeListener != null) {
mOnItemVisibilityChangeListener.onItemVisibilityChange(mAdapter, adapterPosition, true);
}
}
if (i == mRawSelectedPosition && mSelectionDrawable != null && !isEmptyItemPosition(i)) {
mSelectionDrawable.setBounds(sTempRect.left - mSelectionPadding, sTempRect.top - mSelectionPadding,
sTempRect.right + mSelectionPadding, sTempRect.bottom + mSelectionPadding);
mSelectionTransformer.transform(mSelectionDrawable, itemState);
mSelectionDrawable.draw(canvas);
}
Drawable drawable = cacheItem.mDrawable;
if (drawable != null) {
drawable.setBounds(sTempRect);
drawable.draw(canvas);
}
} else {
if (cacheItem != null && cacheItem.mIsVisible) {
cacheItem.mIsVisible = false;
if (mOnItemVisibilityChangeListener != null) {
mOnItemVisibilityChangeListener.onItemVisibilityChange(mAdapter, adapterPosition, false);
}
}
}
}
}