Example usage for android.graphics Rect set

List of usage examples for android.graphics Rect set

Introduction

In this page you can find the example usage for android.graphics Rect set.

Prototype

public void set(Rect src) 

Source Link

Document

Copy the coordinates from src into this rectangle.

Usage

From source file:Main.java

public static Bitmap duplicateBitmap(Bitmap bmpSrc, int width, int height) {
    if (null == bmpSrc) {
        return null;
    }/*from ww w  .j  av a 2 s.  c o  m*/

    int bmpSrcWidth = bmpSrc.getWidth();
    int bmpSrcHeight = bmpSrc.getHeight();

    Bitmap bmpDest = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    if (null != bmpDest) {
        Canvas canvas = new Canvas(bmpDest);
        Rect viewRect = new Rect();
        final Rect rect = new Rect(0, 0, bmpSrcWidth, bmpSrcHeight);
        if (bmpSrcWidth <= width && bmpSrcHeight <= height) {
            viewRect.set(rect);
        } else if (bmpSrcHeight > height && bmpSrcWidth <= width) {
            viewRect.set(0, 0, bmpSrcWidth, height);
        } else if (bmpSrcHeight <= height && bmpSrcWidth > width) {
            viewRect.set(0, 0, width, bmpSrcWidth);
        } else if (bmpSrcHeight > height && bmpSrcWidth > width) {
            viewRect.set(0, 0, width, height);
        }
        canvas.drawBitmap(bmpSrc, rect, viewRect, null);
    }

    return bmpDest;
}

From source file:com.facebook.litho.stetho.DebugComponentDescriptor.java

@Override
public View getViewAndBoundsForHighlighting(DebugComponent element, Rect bounds) {
    bounds.set(element.getBoundsInLithoView());
    return element.getLithoView();
}

From source file:org.mariotaku.twidere.activity.support.BaseSupportActivity.java

@Override
public boolean getSystemWindowsInsets(Rect insets) {
    if (mSystemWindowsInsets == null)
        return false;
    insets.set(mSystemWindowsInsets);
    return true;//from  w ww.java2  s  . c  o  m
}

From source file:com.android.switchaccess.SwitchAccessNodeCompat.java

/**
 * Get the largest rectangle in the bounds of the View that is not covered by another window.
 *
 * @param visibleBoundsInScreen The rect to return the visible bounds in
 *///from ww w.  jav a 2s .c  o m
public void getVisibleBoundsInScreen(Rect visibleBoundsInScreen) {
    updateVisibility();
    visibleBoundsInScreen.set(mVisibleBoundsInScreen);
}

From source file:com.bottomsheetbehavior.ReactNestedScrollView.java

@Override
public void getClippingRect(Rect outClippingRect) {
    outClippingRect.set(Assertions.assertNotNull(mClippingRect));
}

From source file:com.vincestyling.traversaless_testcase.TopTabIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mViewPager == null)
        return;//from  w w w  .ja  v  a  2 s  .c  o m

    final int count = getCount();
    if (count == 0)
        return;

    Rect areaRect = new Rect();
    areaRect.left = getPaddingLeft();
    areaRect.right = getWidth() - getPaddingRight();
    areaRect.top = getPaddingTop();
    areaRect.bottom = getHeight() - getPaddingBottom();

    int btnWidth = areaRect.width() / count;

    Rect tabRect = new Rect(areaRect);
    tabRect.top = tabRect.height() - mUnderlineHeight;
    tabRect.left += (mScrollingToPage + mPageOffset) * btnWidth;
    tabRect.right = tabRect.left + btnWidth;
    mPaint.setColor(mUnderlineColor);
    canvas.drawRect(tabRect, mPaint);

    mPaint.setColor(mTextColor);
    mPaint.setTextSize(mTextSize);

    for (int pos = 0; pos < count; pos++) {
        tabRect.set(areaRect);
        tabRect.left += pos * btnWidth;
        tabRect.right = tabRect.left + btnWidth;

        String pageTitle = getPageTitle(pos);

        RectF bounds = new RectF(tabRect);
        bounds.right = mPaint.measureText(pageTitle, 0, pageTitle.length());
        bounds.bottom = mPaint.descent() - mPaint.ascent();

        bounds.left += (tabRect.width() - bounds.right) / 2.0f;
        bounds.top += (tabRect.height() - bounds.bottom) / 2.0f;

        canvas.drawText(pageTitle, bounds.left, bounds.top - mPaint.ascent(), mPaint);
    }
}

From source file:com.android.switchaccess.SwitchAccessNodeCompat.java

/**
 * Find the largest sub-rectangle that doesn't intersect a specified one.
 *
 * @param rectToModify The rect that may be modified to avoid intersections
 * @param otherRect The rect that should be avoided
 *///from  w  w  w . j av a 2  s  .com
private static void adjustRectToAvoidIntersection(Rect rectToModify, Rect otherRect) {
    /*
     * Some rectangles are flipped around (left > right). Make sure we have two Rects free of
     * such pathologies.
     */
    rectToModify.sort();
    otherRect.sort();
    /*
     * Intersect rectToModify with four rects that represent cuts of the entire space along
     * lines defined by the otherRect's edges
     */
    Rect[] cuts = { new Rect(Integer.MIN_VALUE, Integer.MIN_VALUE, otherRect.left, Integer.MAX_VALUE),
            new Rect(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, otherRect.top),
            new Rect(otherRect.right, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE),
            new Rect(Integer.MIN_VALUE, otherRect.bottom, Integer.MAX_VALUE, Integer.MAX_VALUE) };

    int maxIntersectingRectArea = 0;
    int indexOfLargestIntersection = -1;
    for (int i = 0; i < cuts.length; i++) {
        if (cuts[i].intersect(rectToModify)) {
            /* Reassign this cut to its intersection with rectToModify */
            int visibleRectArea = cuts[i].width() * cuts[i].height();
            if (visibleRectArea > maxIntersectingRectArea) {
                maxIntersectingRectArea = visibleRectArea;
                indexOfLargestIntersection = i;
            }
        }
    }
    if (maxIntersectingRectArea <= 0) {
        // The rectToModify isn't within any of our cuts, so it's entirely occuled by otherRect.
        rectToModify.setEmpty();
        return;
    }
    rectToModify.set(cuts[indexOfLargestIntersection]);
}

From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java

private void drawHighresImage(Canvas canvas, Bitmap fullHighres) {
    Matrix originalToScreen = MasterImage.getImage().originalImageToScreen();
    if (fullHighres != null && originalToScreen != null) {
        Matrix screenToOriginal = new Matrix();
        originalToScreen.invert(screenToOriginal);
        Rect rBounds = new Rect();
        rBounds.set(MasterImage.getImage().getPartialBounds());
        if (fullHighres != null) {
            originalToScreen.preTranslate(rBounds.left, rBounds.top);
            canvas.clipRect(mImageBounds);
            canvas.drawBitmap(fullHighres, originalToScreen, mPaint);
        }/*from w  w  w.  j ava  2 s.  co m*/
    }
}

From source file:codetail.graphics.drawables.LayerDrawable.java

public void getHotspotBounds(Rect outRect) {
    if (mHotspotBounds != null) {
        outRect.set(mHotspotBounds);
    }
}

From source file:com.android.utils.traversal.DirectionalTraversalStrategy.java

public AccessibilityNodeInfoCompat findFocus(AccessibilityNodeInfoCompat focused, Rect focusedRect,
        int direction) {
    // Using roughly the same algorithm as
    // frameworks/base/core/java/android/view/FocusFinder.java#findNextFocusInAbsoluteDirection

    Rect bestCandidateRect = new Rect(focusedRect);
    switch (direction) {
    case TraversalStrategy.SEARCH_FOCUS_LEFT:
        bestCandidateRect.offset(focusedRect.width() + 1, 0);
        break;//from ww w .  j a v a 2  s .c o  m
    case TraversalStrategy.SEARCH_FOCUS_RIGHT:
        bestCandidateRect.offset(-(focusedRect.width() + 1), 0);
        break;
    case TraversalStrategy.SEARCH_FOCUS_UP:
        bestCandidateRect.offset(0, focusedRect.height() + 1);
        break;
    case TraversalStrategy.SEARCH_FOCUS_DOWN:
        bestCandidateRect.offset(0, -(focusedRect.height() + 1));
        break;
    }

    AccessibilityNodeInfoCompat closest = null;
    for (AccessibilityNodeInfoCompat focusable : mFocusables) {
        // Skip the currently-focused view.
        if (focusable.equals(focused) || focusable.equals(mRoot)) {
            continue;
        }

        Rect otherRect = new Rect();
        getAssumedRectInScreen(focusable, otherRect);

        if (isBetterCandidate(direction, focusedRect, otherRect, bestCandidateRect)) {
            bestCandidateRect.set(otherRect);
            closest = focusable;
        }
    }

    if (closest != null) {
        return AccessibilityNodeInfoCompat.obtain(closest);
    }

    return null;
}