当前位置: 首页>>代码示例>>Java>>正文


Java Rect.intersects方法代码示例

本文整理汇总了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;
	
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ArtbookLayout.java

示例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);
            }
        }
    }
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:23,代码来源:CellLayout.java

示例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);
    }
}
 
开发者ID:GcsSloop,项目名称:pager-layoutmanager,代码行数:17,代码来源:PagerGridLayoutManager.java

示例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);
        }
    }
}
 
开发者ID:doitlite,项目名称:TagLayoutManager,代码行数:21,代码来源:TagLayoutManager.java

示例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();
      }
    }
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:39,代码来源:ReactViewGroup.java

示例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);
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:CardLayoutManager.java

示例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);
            }
        }
    }
 
开发者ID:devilist,项目名称:RecyclerWheelPicker,代码行数:34,代码来源:WheelPickerLayoutManager.java

示例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);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:15,代码来源:FindToolbarTablet.java

示例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);
}
 
开发者ID:cheenid,项目名称:FLFloatingButton,代码行数:16,代码来源:FloatingViewManager.java

示例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);
        }
    }
}
 
开发者ID:ChenLittlePing,项目名称:RecyclerCoverFlow,代码行数:40,代码来源:CoverFlowLayoutManger.java

示例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;
}
 
开发者ID:warkiz,项目名称:IndicatorSeekBar,代码行数:31,代码来源:IndicatorUtils.java

示例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();
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:41,代码来源:PreloadIconDrawable.java

示例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);
        }
    }
}
 
开发者ID:Vander-liu,项目名称:HexagonRecyclerView,代码行数:35,代码来源:PolygonLayoutManager.java

示例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);
            }
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:60,代码来源:CustomLayoutManager.java

示例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);
                }
            }
        }
    }
}
 
开发者ID:adithya321,项目名称:Instincts-2k17,代码行数:73,代码来源:WheelView.java


注:本文中的android.graphics.Rect.intersects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。