Example usage for android.graphics RectF contains

List of usage examples for android.graphics RectF contains

Introduction

In this page you can find the example usage for android.graphics RectF contains.

Prototype

public boolean contains(RectF r) 

Source Link

Document

Returns true iff the specified rectangle r is inside or equal to this rectangle.

Usage

From source file:org.akop.crosswords.view.CrosswordView.java

private void bringIntoView(Crossword.Word word, int selectedCell) {
    if (word == null) {
        return;//from   w w  w .  j a v  a2 s .  c  om
    }

    RectF wordRect = new RectF();

    wordRect.left = word.getStartColumn() * mScaledCellSize - mContentRect.left;
    wordRect.top = word.getStartRow() * mScaledCellSize - mContentRect.top;

    if (word.getDirection() == Crossword.Word.DIR_ACROSS) {
        wordRect.right = wordRect.left + word.getLength() * mScaledCellSize;
        wordRect.bottom = wordRect.top + mScaledCellSize;
    } else if (word.getDirection() == Crossword.Word.DIR_DOWN) {
        wordRect.right = wordRect.left + mScaledCellSize;
        wordRect.bottom = wordRect.top + word.getLength() * mScaledCellSize;
    }

    RectF objectRect = new RectF(wordRect);
    RectF visibleArea = new RectF(-mBitmapOffset.x, -mBitmapOffset.y, -mBitmapOffset.x + mContentRect.width(),
            -mBitmapOffset.y + mContentRect.height());

    if (visibleArea.contains(objectRect)) {
        return; // Already visible
    }

    if (objectRect.width() > visibleArea.width() || objectRect.height() > visibleArea.height()) {
        // Available area isn't large enough to fit the entire word
        // Is the selected cell visible? If not, bring it into view

        CellOffset co = getCellOffset(word, selectedCell);
        RectF cellRect = new RectF();
        cellRect.left = co.mColumn * mScaledCellSize;
        cellRect.top = co.mRow * mScaledCellSize;
        cellRect.right = cellRect.left + mScaledCellSize;
        cellRect.bottom = cellRect.top + mScaledCellSize;

        if (visibleArea.contains(cellRect)) {
            return; // Already visible
        }

        objectRect.set(cellRect);
    }

    // Compute view that includes the object in the center
    PointF end = new PointF((visibleArea.width() - objectRect.width()) / 2.0f - objectRect.left,
            (visibleArea.height() - objectRect.height()) / 2.0f - objectRect.top);

    // Clamp the values
    clampPointF(end, mTranslationBounds);

    // Compute the distance to travel from current location
    float distanceX = end.x - mBitmapOffset.x;
    float distanceY = end.y - mBitmapOffset.y;

    // Scroll the point into view
    mScroller.startScroll((int) mBitmapOffset.x, (int) mBitmapOffset.y, (int) distanceX, (int) distanceY,
            NAVIGATION_SCROLL_DURATION_MS);
}

From source file:org.akop.ararat.view.CrosswordView.java

private void bringIntoView(Selectable sel) {
    if (sel == null) {
        return;/*  w ww.j  a v a2  s.co  m*/
    }

    RectF wordRect = new RectF();

    wordRect.left = sel.getStartColumn() * mScaledCellSize - mContentRect.left;
    wordRect.top = sel.getStartRow() * mScaledCellSize - mContentRect.top;

    if (sel.getDirection() == Crossword.Word.DIR_ACROSS) {
        wordRect.right = wordRect.left + sel.mWord.getLength() * mScaledCellSize;
        wordRect.bottom = wordRect.top + mScaledCellSize;
    } else if (sel.getDirection() == Crossword.Word.DIR_DOWN) {
        wordRect.right = wordRect.left + mScaledCellSize;
        wordRect.bottom = wordRect.top + sel.mWord.getLength() * mScaledCellSize;
    }

    RectF objectRect = new RectF(wordRect);
    RectF visibleArea = new RectF(-mBitmapOffset.x, -mBitmapOffset.y, -mBitmapOffset.x + mContentRect.width(),
            -mBitmapOffset.y + mContentRect.height());

    if (visibleArea.contains(objectRect)) {
        return; // Already visible
    }

    if (objectRect.width() > visibleArea.width() || objectRect.height() > visibleArea.height()) {
        // Available area isn't large enough to fit the entire word
        // Is the selected cell visible? If not, bring it into view

        RectF cellRect = new RectF();
        cellRect.left = sel.getColumn() * mScaledCellSize;
        cellRect.top = sel.getRow() * mScaledCellSize;
        cellRect.right = cellRect.left + mScaledCellSize;
        cellRect.bottom = cellRect.top + mScaledCellSize;

        if (visibleArea.contains(cellRect)) {
            return; // Already visible
        }

        objectRect.set(cellRect);
    }

    // Compute view that includes the object in the center
    PointF end = new PointF((visibleArea.width() - objectRect.width()) / 2.0f - objectRect.left,
            (visibleArea.height() - objectRect.height()) / 2.0f - objectRect.top);

    // Clamp the values
    clampPointF(end, mTranslationBounds);

    // Compute the distance to travel from current location
    float distanceX = end.x - mBitmapOffset.x;
    float distanceY = end.y - mBitmapOffset.y;

    // Scroll the point into view
    mScroller.startScroll((int) mBitmapOffset.x, (int) mBitmapOffset.y, (int) distanceX, (int) distanceY,
            NAVIGATION_SCROLL_DURATION_MS);
}