Example usage for android.graphics RectF width

List of usage examples for android.graphics RectF width

Introduction

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

Prototype

public final float width() 

Source Link

Usage

From source file:com.iiordanov.bVNC.RemoteCanvas.java

/**
 * Moves soft cursor into a particular location.
 * @param x//from   w  w  w .  j  a v a 2 s  .co m
 * @param y
 */
synchronized void softCursorMove(int x, int y) {
    if (bitmapData.isNotInitSoftCursor()) {
        initializeSoftCursor();
    }

    if (!inScrolling) {
        pointer.setX(x);
        pointer.setY(y);
        RectF prevR = new RectF(bitmapData.getCursorRect());
        // Move the cursor.
        bitmapData.moveCursorRect(x, y);
        // Show the cursor.
        RectF r = bitmapData.getCursorRect();
        reDraw(r.left, r.top, r.width(), r.height());
        reDraw(prevR.left, prevR.top, prevR.width(), prevR.height());
    }
}

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

private void bringIntoView(Crossword.Word word, int selectedCell) {
    if (word == null) {
        return;/*  w ww .j  av a 2 s . c o  m*/
    }

    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;//  www . j  av a2  s  .  c  o  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);
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

protected void editWidget(final View widget) {
    if (mWorkspace != null) {
        mIsWidgetEditMode = true;/*ww  w.j av a 2s  .  c o  m*/
        final PersonaCellLayout screen = (PersonaCellLayout) mWorkspace
                .getChildAt(mWorkspace.getCurrentScreen());
        if (screen != null) {
            mlauncherAppWidgetInfo = (PersonaLauncherAppWidgetInfo) widget.getTag();

            final Intent motosize = new Intent("com.motorola.blur.home.ACTION_SET_WIDGET_SIZE");
            final int appWidgetId = ((AppWidgetHostView) widget).getAppWidgetId();
            final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
            if (appWidgetInfo != null) {
                motosize.setComponent(appWidgetInfo.provider);
            }
            motosize.putExtra("appWidgetId", appWidgetId);
            motosize.putExtra("com.motorola.blur.home.EXTRA_NEW_WIDGET", true);
            final int minw = (mWorkspace.getWidth() - screen.getLeftPadding() - screen.getRightPadding())
                    / screen.getCountX();
            final int minh = (mWorkspace.getHeight() - screen.getBottomPadding() - screen.getTopPadding())
                    / screen.getCountY();
            mScreensEditor = new PersonaResizeViewHandler(this);
            // Create a default HightlightView if we found no face in the
            // picture.
            int width = (mlauncherAppWidgetInfo.spanX * minw);
            int height = (mlauncherAppWidgetInfo.spanY * minh);

            final Rect screenRect = new Rect(0, 0, mWorkspace.getWidth() - screen.getRightPadding(),
                    mWorkspace.getHeight() - screen.getBottomPadding());
            final int x = mlauncherAppWidgetInfo.cellX * minw;
            final int y = mlauncherAppWidgetInfo.cellY * minh;
            final int[] spans = new int[] { 1, 1 };
            final int[] position = new int[] { 1, 1 };
            final PersonaCellLayout.LayoutParams lp = (PersonaCellLayout.LayoutParams) widget.getLayoutParams();
            RectF widgetRect = new RectF(x, y, x + width, y + height);
            ((PersonaResizeViewHandler) mScreensEditor).setup(null, screenRect, widgetRect, false, false,
                    minw - 10, minh - 10);
            mDragLayer.addView(mScreensEditor);
            ((PersonaResizeViewHandler) mScreensEditor)
                    .setOnValidateSizingRect(new PersonaResizeViewHandler.OnSizeChangedListener() {

                        @Override
                        public void onTrigger(RectF r) {
                            if (r != null) {
                                final float left = Math.round(r.left / minw) * minw;
                                final float top = Math.round(r.top / minh) * minh;
                                final float right = left + (Math.max(Math.round(r.width() / (minw)), 1) * minw);
                                final float bottom = top
                                        + (Math.max(Math.round(r.height() / (minh)), 1) * minh);

                                r.set(left, top, right, bottom);
                            }
                        }
                    });
            final Rect checkRect = new Rect();
            ((PersonaResizeViewHandler) mScreensEditor)
                    .setOnSizeChangedListener(new PersonaResizeViewHandler.OnSizeChangedListener() {
                        @Override
                        public void onTrigger(RectF r) {
                            int[] tmpspans = { Math.max(Math.round(r.width() / (minw)), 1),
                                    Math.max(Math.round(r.height() / (minh)), 1) };
                            int[] tmpposition = { Math.round(r.left / minw), Math.round(r.top / minh) };
                            checkRect.set(tmpposition[0], tmpposition[1], tmpposition[0] + tmpspans[0],
                                    tmpposition[1] + tmpspans[1]);
                            boolean ocupada = getModel().ocuppiedArea(screen.getScreen(), appWidgetId,
                                    checkRect);
                            if (!ocupada) {
                                ((PersonaResizeViewHandler) mScreensEditor).setColliding(false);
                            } else {
                                ((PersonaResizeViewHandler) mScreensEditor).setColliding(true);
                            }
                            if (tmpposition[0] != position[0] || tmpposition[1] != position[1]
                                    || tmpspans[0] != spans[0] || tmpspans[1] != spans[1]) {
                                if (!ocupada) {
                                    position[0] = tmpposition[0];
                                    position[1] = tmpposition[1];
                                    spans[0] = tmpspans[0];
                                    spans[1] = tmpspans[1];
                                    lp.cellX = position[0];
                                    lp.cellY = position[1];
                                    lp.cellHSpan = spans[0];
                                    lp.cellVSpan = spans[1];
                                    widget.setLayoutParams(lp);
                                    mlauncherAppWidgetInfo.cellX = lp.cellX;
                                    mlauncherAppWidgetInfo.cellY = lp.cellY;
                                    mlauncherAppWidgetInfo.spanX = lp.cellHSpan;
                                    mlauncherAppWidgetInfo.spanY = lp.cellVSpan;
                                    widget.setTag(mlauncherAppWidgetInfo);
                                    // send the broadcast
                                    motosize.putExtra("spanX", spans[0]);
                                    motosize.putExtra("spanY", spans[1]);
                                    PersonaLauncher.this.sendBroadcast(motosize);
                                    PersonaLog.d("RESIZEHANDLER", "sent resize broadcast");
                                }
                            }
                        }
                    });
        }
    }
}