Rect contains - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Rect contains method.

This code example shows how to use the following methods:centerX, centerY, contains
        Rect r = computeLayout();
        final float hysteresis = 20F;
        int retval = GROW_NONE;
 
        if (mCircle) {
            float distX = x - r.centerX();
            float distY = y - r.centerY();
            int distanceFromCenter =
                    (int) Math.sqrt(distX * distX + distY * distY);
            int radius  = mDrawRect.width() / 2;
            int delta = distanceFromCenter - radius;
            if (Math.abs(delta) <= hysteresis) {
                if (Math.abs(distY) > Math.abs(distX)) {
                    if (distY < 0) {
                        retval = GROW_TOP_EDGE;
                    } else { 
                        retval = GROW_BOTTOM_EDGE;
                    } 
                } else { 
                    if (distX < 0) {

7
CodeRank
This code example shows how to use the following methods:contains, set
 
			} 
		} 
 
		private boolean isEventWithinView(MotionEvent e, View child) { 
            Rect viewRect = new Rect(); 
            int[] childPosition = new int[2]; 
            child.getLocationOnScreen(childPosition); 
            int left = childPosition[0]; 
            int right = left + child.getWidth(); 
            int top = childPosition[1]; 
            int bottom = top + child.getHeight(); 
            viewRect.set(left, top, right, bottom); 
            return viewRect.contains((int) e.getRawX(), (int) e.getRawY()); 
        } 
	}; 
 
	 
 
} 
7
CodeRank
This code example shows how to use the following methods:contains
        } else if (mDrawIdentifier.equals(FOLDER_PORTRAIT) ||
                   mDrawIdentifier.equals(FOLDER_LANDSCAPE) ||
                   mDrawIdentifier.equals(FOLDER_LARGE)) {
            Folder f = mLauncher.getWorkspace().getOpenFolder();
            if (f != null) {
                Rect r = new Rect();
                f.getHitRect(r);
                if (r.contains((int) event.getX(), (int) event.getY())) {
                    return false; 
                } 
            } 
        } 
        return true; 
    }; 
 
    @Override 
    protected void dispatchDraw(Canvas canvas) {
        if (mIsInitialized) {
            DisplayMetrics metrics = new DisplayMetrics();
            mLauncher.getWindowManager().getDefaultDisplay().getMetrics(metrics);
7
CodeRank
This code example shows how to use the following methods:centerX, centerY, contains
        Rect r = computeLayout();
        final float hysteresis = 20F;
        int retval = GROW_NONE;
 
        if (mCircle) {
            float distX = x - r.centerX();
            float distY = y - r.centerY();
            int distanceFromCenter = (int) Math.sqrt(distX * distX + distY * distY);
            int radius = mDrawRect.width() / 2;
            int delta = distanceFromCenter - radius;
            if (Math.abs(delta) <= hysteresis) {
                if (Math.abs(distY) > Math.abs(distX)) {
                    if (distY < 0) {
                        retval = GROW_TOP_EDGE;
                    } else { 
                        retval = GROW_BOTTOM_EDGE;
                    } 
                } else { 
                    if (distX < 0) {
                        retval = GROW_LEFT_EDGE;

7
CodeRank
This code example shows how to use the following methods:contains
		if ((Math.abs(r.bottom - y) < hysteresis) && horizCheck) {
			retval |= GROW_BOTTOM_EDGE;
		} 
 
		// Not near any edge but inside the rectangle: move. 
		if (retval == GROW_NONE && r.contains((int) x, (int) y)) {
			retval = MOVE;
		} 
 
		return retval;
	} 
 
	public ModifyMode getMode() { 
		return mMode;
	} 
 
	public void invalidate() { 
		mDrawRect = computeLayout();
	} 
 

7
CodeRank
This code example shows how to use the following methods:centerX, centerY, contains
		Rect r = computeLayout();
		final float hysteresis = 20F;
		int retval = GROW_NONE;
 
		if (mCircle) {
			float distX = x - r.centerX();
			float distY = y - r.centerY();
			int distanceFromCenter = (int) android.util.FloatMath.sqrt(distX
					* distX + distY * distY);
			int radius = mDrawRect.width() / 2;
			int delta = distanceFromCenter - radius;
			if (Math.abs(delta) <= hysteresis) {
				if (Math.abs(distY) > Math.abs(distX)) {
					if (distY < 0) {
						retval = GROW_TOP_EDGE;
					} else { 
						retval = GROW_BOTTOM_EDGE;
					} 
				} else { 
					if (distX < 0) {

7
CodeRank
This code example shows how to use the following methods:contains
	public Rect createRect(int containerWidth, int containerHeight) {
		final int x = Math.round(containerWidth * relativeX);
		final int y = Math.round(containerHeight * relativeY);
		final int width = Math.round(containerWidth * relativeWidth);
		final int height = Math.round(containerHeight * relativeHeight);
		final Rect rect = new Rect(x, y, x + width, y + height);
		return rect;
	} 
	 
	public boolean matches(Point p, int containerWidth, int containerHeight) {
		final Rect r = this.createRect(containerWidth, containerHeight);
		return r.contains(p.x, p.y);
	} 
} 
7
CodeRank
This code example shows how to use the following methods:centerX, centerY, contains
        Rect r = computeLayout();
        final float hysteresis = 20F;
        int retval = GROW_NONE;
 
        if (mCircle) {
            float distX = x - r.centerX();
            float distY = y - r.centerY();
            int distanceFromCenter =
                    (int) Math.sqrt(distX * distX + distY * distY);
            int radius  = mDrawRect.width() / 2;
            int delta = distanceFromCenter - radius;
            if (Math.abs(delta) <= hysteresis) {
                if (Math.abs(distY) > Math.abs(distX)) {
                    if (distY < 0) {
                        retval = GROW_TOP_EDGE;
                    } else { 
                        retval = GROW_BOTTOM_EDGE;
                    } 
                } else { 
                    if (distX < 0) {

7
CodeRank
This code example shows how to use the following methods:contains
				mRect.set(getLeft(), getTop(), getRight(), getBottom());
				mIsDown = true;
				invalidate();
				break; 
			case MotionEvent.ACTION_MOVE:
				if (mRect.contains(getLeft() + (int) e.getX(), getTop() + (int) e.getY())) {
					break; 
				} 
				if (mIsDown) {
					mIsDown = false;
					invalidate();
				} 
				break; 
			default: 
				mIsDown = false;
				invalidate();
				break; 
		} 
		return super.onTouchEvent(e);
	} 
6
CodeRank
This code example shows how to use the following methods:centerX, centerY, contains
        Rect r = computeLayout();
        final float hysteresis = 20F;
        int retval = GROW_NONE;
         
        if (mCircle) {
            float distX = x - r.centerX();
            float distY = y - r.centerY();
            int distanceFromCenter = (int) Math.sqrt(distX*distX + distY*distY);
            int radius  = (int) (mDrawRect.width() - getPaddingLeft()) / 2;
            int delta = distanceFromCenter - radius;
            if (Math.abs(delta) <= hysteresis) {
                if (Math.abs(distY) > Math.abs(distX)) {
                    if (distY < 0)
                        retval = GROW_TOP_EDGE;
                    else 
                        retval = GROW_BOTTOM_EDGE;
                } else { 
                    if (distX < 0)
                        retval = GROW_LEFT_EDGE;
                    else 

7
CodeRank

Related Rect contains Questions & Answers:

contains Method Overview
Returns true if (x,y) is inside the rectangle.
See Code Examples for other Android Rect Methods: