Example usage for android.graphics RectF set

List of usage examples for android.graphics RectF set

Introduction

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

Prototype

public void set(float left, float top, float right, float bottom) 

Source Link

Document

Set the rectangle's coordinates to the specified values.

Usage

From source file:uk.co.senab.photoview.PhotoViewAttacher.java

public void renderBitmap() {
    Log.d("RenderBitmap", "Rendering bitmap!!!");
    ImageView iv = getImageView();
    if (iv != null) {
        RectF rect = getDisplayRect();
        if (rect == null || rect.isEmpty()) {
            rect = new RectF(0, 0, originalBitmapSize.x, originalBitmapSize.y);
        }// w  ww  . j  a  v a 2 s.  c om

        float ratioX = originalBitmapSize.x / (float) iv.getWidth();
        float ratioY = originalBitmapSize.y / (float) iv.getHeight();

        rect.set(rect.left * ratioX, rect.top * ratioY, rect.right * ratioX, rect.bottom * ratioY);
        Rect bounds = new Rect();
        rect.round(bounds);

        Bitmap bitmap = Bitmap.createBitmap(originalBitmapSize.x, originalBitmapSize.y,
                Bitmap.Config.ARGB_8888);
        pdfiumCore.renderPageBitmap(pdfDocument, bitmap, pageIndex, bounds.left, bounds.top, bounds.width(),
                bounds.height());
        iv.setImageBitmap(bitmap);
    }
}

From source file:org.stockchart.StockChartView.java

public void getHitTestInfo(HitTestInfo info, float x, float y, int hitTestOptions) {
    info.reset();/*from w  w  w.  j  a v a2 s .  co m*/

    resetPositions();

    for (Area a : fAreas) {
        if (!a.isVisible())
            continue;

        if (a.getAbsoluteBounds().contains(x, y)) {
            if (a.getPlot().getAbsoluteBounds().contains(x, y)) {
                info.element = a.getPlot();
                SeriesPaintInfo pinfo = new SeriesPaintInfo();
                RectF rectF = new RectF();

                if (HIT_TEST_STICKERS == (hitTestOptions & HIT_TEST_STICKERS)) {
                    final float r = AbstractSticker.RADIUS;

                    PointF rel = a.getPlot().getRelativePosition(x, y);

                    for (AbstractSticker s : a.getStickers()) {
                        pinfo.loadFrom(a.getAxis(s.getHorizontalAxis()), a.getAxis(s.getVerticalAxis()));

                        double midX = s.getMidX();
                        double midY = s.getMidY();

                        // mid point
                        rectF.set(pinfo.getX(midX) - r, pinfo.getY(midY) - r, pinfo.getX(midX) + r,
                                pinfo.getY(midY) + r);

                        if (rectF.contains(rel.x, rel.y)) {
                            info.stickerInfo = new StickerInfo(a, s);
                            info.stickerInfo.stickerPoint = STICKER_MID_POINT;
                            break;
                        }

                        // first point
                        rectF.set(pinfo.getX(s.getX1()) - r, pinfo.getY(s.getY1()) - r,
                                pinfo.getX(s.getX1()) + r, pinfo.getY(s.getY1()) + r);

                        if (rectF.contains(rel.x, rel.y)) {
                            info.stickerInfo = new StickerInfo(a, s);
                            info.stickerInfo.stickerPoint = STICKER_FIRST_POINT;
                            break;
                        }

                        // second point
                        rectF.set(pinfo.getX(s.getX2()) - r, pinfo.getY(s.getY2()) - r,
                                pinfo.getX(s.getX2()) + r, pinfo.getY(s.getY2()) + r);

                        if (rectF.contains(rel.x, rel.y)) {
                            info.stickerInfo = new StickerInfo(a, s);
                            info.stickerInfo.stickerPoint = STICKER_SECOND_POINT;
                            break;
                        }
                    }
                }

                if (HIT_TEST_SERIES == (hitTestOptions & HIT_TEST_SERIES)) {

                    for (SeriesBase s : a.getSeries()) {
                        AbstractSeries<?> as = (AbstractSeries<?>) s;

                        pinfo.loadFrom(a.getAxis(as.getXAxisSide()), a.getAxis(as.getYAxisSide()));

                        if (!as.isVisibleOnScreen(pinfo.X.Max, pinfo.X.Min))
                            continue;

                        int index = as.convertToArrayIndexZeroBased(pinfo.X.Min);

                        for (int i = index; i < as.getPointCount(); i++) {
                            AbstractPoint ap = as.getPointAt(i);

                            float scaleIndex = as.convertToScaleIndex(i);

                            if (ap.isVisible()) {
                                double[] maxMin = ap.getMaxMin();
                                float x1 = pinfo.getX(scaleIndex - 0.5f) + 1f;
                                float x2 = pinfo.getX(scaleIndex + 0.5f) - 1f;

                                float max = pinfo.getY(maxMin[0]);
                                float min = pinfo.getY(maxMin[1]);

                                if (maxMin[0] == maxMin[1]) {
                                    float d = (x2 - x1) / 2f;
                                    max -= d;
                                    min += d;
                                }

                                PointF p = a.getPlot().getAbsolutePosition(x1, max);
                                rectF.set(p.x, p.y, p.x + (x2 - x1), p.y + (min - max));

                                if (rectF.contains(x, y)) {
                                    if (null == info.points)
                                        info.points = new TreeMap<String, AbstractPoint>();

                                    info.points.put(s.getName(), ap);
                                    break;
                                }

                            }

                            if (scaleIndex > pinfo.X.Max)
                                break;
                        }
                    }
                }

            } else {
                for (Axis axis : a.getAxes()) {
                    if (axis.getAbsoluteBounds().contains(x, y)) {
                        info.element = axis;
                        break;
                    }
                }
            }

            if (info.element == null)
                info.element = a;

            break;
        }
    }
}

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

private void renderSelection(Canvas canvas, boolean clearSelection) {
    if (mSelectedWord == null) {
        return;//from  ww w . jav a  2s . c  o  m
    }

    int startRow = mSelectedWord.getStartRow();
    int endRow = startRow;
    int startColumn = mSelectedWord.getStartColumn();
    int endColumn = startColumn;
    RectF cellRect = new RectF();

    canvas.save();
    canvas.scale(mRenderScale, mRenderScale);

    if (mSelectedWord.getDirection() == Crossword.Word.DIR_ACROSS) {
        endColumn += mSelectedWord.getLength() - 1;
    } else {
        endRow += mSelectedWord.getLength() - 1;
    }

    float top = mSelectedWord.getStartRow() * mCellSize;
    for (int row = startRow, index = 0; row <= endRow; row++, top += mCellSize) {
        float left = mSelectedWord.getStartColumn() * mCellSize;
        for (int column = startColumn; column <= endColumn; column++, left += mCellSize) {
            Cell cell = mPuzzleCells[row][column];
            if (cell != null) {
                // Draw the unselected cell
                Paint paint;
                if (clearSelection) {
                    paint = mCellFillPaint;
                } else {
                    if (index == mSelectedCell) {
                        paint = mSelectedCellFillPaint;
                    } else {
                        paint = mSelectedWordFillPaint;
                    }
                }

                cellRect.set(left, top, left + mCellSize, top + mCellSize);
                renderCell(canvas, cell, cellRect, paint);
            }

            index++;
        }
    }

    canvas.restore();
}

From source file:com.pdftron.pdf.tools.Tool.java

/**
 * Computes the page bounding box in the client space.
 *//*from   w w  w  .j a  va  2s.  com*/
protected RectF buildPageBoundBoxOnClient(int page_num) {
    RectF rect = null;
    if (page_num >= 1) {
        try {
            mPDFView.docLockRead();
            Page page = mPDFView.getDoc().getPage(page_num);
            if (page != null) {
                rect = new RectF();
                com.pdftron.pdf.Rect r = page.getBox(mPDFView.getPageBox());

                double x1 = r.getX1();
                double y1 = r.getY1();
                double x2 = r.getX2();
                double y2 = r.getY2();
                double[] pts1, pts2, pts3, pts4;

                // Need to compute the transformed coordinates for the four
                // corners of the page bounding box, since a page can be rotated.
                pts1 = mPDFView.convPagePtToScreenPt(x1, y1, page_num);
                pts2 = mPDFView.convPagePtToScreenPt(x2, y1, page_num);
                pts3 = mPDFView.convPagePtToScreenPt(x2, y2, page_num);
                pts4 = mPDFView.convPagePtToScreenPt(x1, y2, page_num);

                double min_x = Math.min(Math.min(Math.min(pts1[0], pts2[0]), pts3[0]), pts4[0]);
                double max_x = Math.max(Math.max(Math.max(pts1[0], pts2[0]), pts3[0]), pts4[0]);
                double min_y = Math.min(Math.min(Math.min(pts1[1], pts2[1]), pts3[1]), pts4[1]);
                double max_y = Math.max(Math.max(Math.max(pts1[1], pts2[1]), pts3[1]), pts4[1]);

                float sx = mPDFView.getScrollX();
                float sy = mPDFView.getScrollY();
                rect = new RectF();
                rect.set((float) min_x + sx, (float) min_y + sy, (float) max_x + sx, (float) max_y + sy);
            }

        } catch (Exception e) {

        } finally {
            mPDFView.docUnlockRead();
        }
    }
    return rect;
}

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

protected void editWidget(final View widget) {
    if (mWorkspace != null) {
        mIsWidgetEditMode = true;/*from   w  w  w.j  a v  a2  s . 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");
                                }
                            }
                        }
                    });
        }
    }
}