Example usage for android.graphics RectF RectF

List of usage examples for android.graphics RectF RectF

Introduction

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

Prototype

public RectF(float left, float top, float right, float bottom) 

Source Link

Document

Create a new rectangle with the specified coordinates.

Usage

From source file:com.qsoft.components.gallery.utils.GalleryUtils.java

public static Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) {
    int sourceWidth = source.getWidth();
    int sourceHeight = source.getHeight();

    // Compute the scaling factors to fit the new height and width, respectively.
    // To cover the final image, the final scaling will be the bigger
    // of these two.
    float xScale = (float) newWidth / sourceWidth;
    float yScale = (float) newHeight / sourceHeight;
    float scale = Math.max(xScale, yScale);

    // Now get the size of the source bitmap when scaled
    float scaledWidth = scale * sourceWidth;
    float scaledHeight = scale * sourceHeight;

    // Let's find out the upper left coordinates if the scaled bitmap
    // should be centered in the new size give by the parameters
    float left = (newWidth - scaledWidth) / 2;
    float top = (newHeight - scaledHeight) / 2;

    // The target rectangle for the new, scaled version of the source bitmap will now
    // be//from w w w.  j  a v a 2 s. co m
    RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);

    // Finally, we create a new bitmap of the specified size and draw our new,
    // scaled bitmap onto it.
    Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
    Canvas canvas = new Canvas(dest);
    canvas.drawBitmap(source, null, targetRect, null);

    return dest;
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.HandleView.java

@Override
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
    if (mOrientation == HandleDirection.UP || mOrientation == HandleDirection.DOWN) {
        mBounds = new RectF(HANDLE_BREADTH / 2, 0, width - 2 - HANDLE_BREADTH / 2, height);
        mHandlePos = mBounds.centerX();//from  www.  j a  v  a 2 s.  co  m
    } else {
        mBounds = new RectF(0, HANDLE_BREADTH / 2, width, height - 2 - HANDLE_BREADTH / 2);
        mHandlePos = mBounds.centerY();

        if (mId == HostView.ID_HANDLE_1)
            mHandlePos -= 50;
        else if (mId == HostView.ID_HANDLE_2)
            mHandlePos += 50;
    }
    makeHandle();
}

From source file:com.example.sergey.currentweather.ui.fragment.MainFragment.java

private void initSwipe() {
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0,
            ItemTouchHelper.LEFT) {//from  w w  w. j av  a 2 s  .  co  m

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            int position = viewHolder.getAdapterPosition();
            if (direction == ItemTouchHelper.LEFT) {
                deleteData(mCityListAdapter.removeItem(position));
            }
        }

        @Override
        public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                float dX, float dY, int actionState, boolean isCurrentlyActive) {
            Bitmap icon;
            if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
                View itemView = viewHolder.itemView;
                float height = (float) itemView.getBottom() - (float) itemView.getTop();
                float width = height / 3;
                if (dX < 0) {
                    mPoint.setColor(Color.parseColor("#D32F2F"));
                    RectF background = new RectF((float) itemView.getRight() + dX, (float) itemView.getTop(),
                            (float) itemView.getRight(), (float) itemView.getBottom());
                    c.drawRect(background, mPoint);
                    icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_delete_white);
                    RectF icon_dest = new RectF((float) itemView.getRight() - 2 * width,
                            (float) itemView.getTop() + width, (float) itemView.getRight() - width,
                            (float) itemView.getBottom() - width);
                    c.drawBitmap(icon, null, icon_dest, mPoint);
                }
            }
            super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void DrawEvents() {
    Bitmap charty = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
    Canvas EventsCanvas = new Canvas(charty);
    final Paint paint = new Paint();

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(getResources().getColor(R.color.DarkBlue));
    paint.setAntiAlias(true);/* ww  w.  j a v a  2  s . c om*/
    EventsCanvas.drawOval(new RectF(1, 1, 199, 199), paint);

    RadialGradient gradient = new RadialGradient(200, 200, 200, 0xFF6b7681, 0xFF000000,
            android.graphics.Shader.TileMode.CLAMP);
    paint.setDither(true);
    paint.setShader(gradient);
    EventsCanvas.drawOval(new RectF(6, 6, 194, 194), paint);

    //Special Bits
    int Scale = 100;

    if (EventCount > 100)
        ;
    Scale = EventCount + 50;

    drawScale(EventsCanvas, true, EventCount, Scale);
    drawGaugeTitle(EventsCanvas, "Events Count");
    drawGaugeNeedle(EventsCanvas, EventCount, Scale);
    //drawGloss(EventsCanvas);

    ((ImageView) findViewById(R.id.EventsGauge)).setImageBitmap(charty);
}

From source file:com.hwqgooo.douknow.view.widget.CircleImageView.java

private RectF calculateBounds() {
    int availableWidth = getWidth() - getPaddingLeft() - getPaddingRight();
    int availableHeight = getHeight() - getPaddingTop() - getPaddingBottom();

    int sideLength = Math.min(availableWidth, availableHeight);

    float left = getPaddingLeft() + (availableWidth - sideLength) / 2f;
    float top = getPaddingTop() + (availableHeight - sideLength) / 2f;

    return new RectF(left, top, left + sideLength, top + sideLength);
}

From source file:com.jrummyapps.android.widget.AnimatedSvgView.java

/**
 * If you set the SVG data paths more than once using {@link #setGlyphStrings(String...)} you should call this method
 * before playing the animation./*from   ww  w  .  j a  v a  2 s .co m*/
 */
@SuppressWarnings("SuspiciousNameCombination")
public void rebuildGlyphData() {

    float X = mWidth / mViewport.x;
    float Y = mHeight / mViewport.y;

    Matrix scaleMatrix = new Matrix();
    RectF outerRect = new RectF(X, X, Y, Y);
    scaleMatrix.setScale(X, Y, outerRect.centerX(), outerRect.centerY());

    mGlyphData = new GlyphData[mGlyphStrings.length];
    for (int i = 0; i < mGlyphStrings.length; i++) {
        mGlyphData[i] = new GlyphData();
        try {
            mGlyphData[i].path = ExposedPathParser.createPathFromPathData(mGlyphStrings[i]);
            mGlyphData[i].path.transform(scaleMatrix);
        } catch (Exception e) {
            mGlyphData[i].path = new Path();
            Log.e(TAG, "Couldn't parse path", e);
        }
        PathMeasure pm = new PathMeasure(mGlyphData[i].path, true);
        while (true) {
            mGlyphData[i].length = Math.max(mGlyphData[i].length, pm.getLength());
            if (!pm.nextContour()) {
                break;
            }
        }
        mGlyphData[i].paint = new Paint();
        mGlyphData[i].paint.setStyle(Paint.Style.STROKE);
        mGlyphData[i].paint.setAntiAlias(true);
        mGlyphData[i].paint.setColor(Color.WHITE);
        mGlyphData[i].paint.setStrokeWidth(
                TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    }
}

From source file:de.wikilab.android.friendica01.Max.java

public static void resizeImage(String pathOfInputImage, String pathOfOutputImage, int dstWidth, int dstHeight) {
    try {//  w  ww.  j  a  va2 s  . c o  m
        int inWidth = 0;
        int inHeight = 0;

        InputStream in = new FileInputStream(pathOfInputImage);

        // decode image size (decode metadata only, not the whole image)
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(in, null, options);
        in.close();
        in = null;

        // save width and height
        inWidth = options.outWidth;
        inHeight = options.outHeight;

        // decode full image pre-resized
        in = new FileInputStream(pathOfInputImage);
        options = new BitmapFactory.Options();
        // calc rought re-size (this is no exact resize)
        options.inSampleSize = Math.max(inWidth / dstWidth, inHeight / dstHeight);
        // decode full image
        Bitmap roughBitmap = BitmapFactory.decodeStream(in, null, options);

        // calc exact destination size
        Matrix m = new Matrix();
        RectF inRect = new RectF(0, 0, roughBitmap.getWidth(), roughBitmap.getHeight());
        RectF outRect = new RectF(0, 0, dstWidth, dstHeight);
        m.setRectToRect(inRect, outRect, Matrix.ScaleToFit.CENTER);
        float[] values = new float[9];
        m.getValues(values);

        // resize bitmap
        Bitmap resizedBitmap = Bitmap.createScaledBitmap(roughBitmap,
                (int) (roughBitmap.getWidth() * values[0]), (int) (roughBitmap.getHeight() * values[4]), true);

        // save image
        try {
            FileOutputStream out = new FileOutputStream(pathOfOutputImage);
            resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);
        } catch (Exception e) {
            Log.e("Image", e.getMessage(), e);
        }
    } catch (IOException e) {
        Log.e("Image", e.getMessage(), e);
    }
}

From source file:com.microblink.ocr.ScanActivity.java

@Override
public void onCameraPreviewStarted() {
    // this method is called when camera preview has started
    // camera is being initialized in background thread and when
    // it is ready, this method is called.
    // You can use it to check camera properties, such as whether
    // torch is supported and then show/hide torch button.
    if (mRecognizerView != null && mRecognizerView.isCameraTorchSupported()) {
        mFlashButton.setVisibility(View.VISIBLE);
        mFlashButton.setImageResource(R.drawable.flashlight);
        mTorchOn = false;/*w  w  w.j a va 2 s .c o m*/
    }

    // after camera is started, we can set the metering area for autofocus, white balance
    // and auto exposure measurements
    // we set the same rectangle as for scanning region
    // we also define that this metering area will not follow device orientation changes because
    // we have set non rotatable scanning region
    mRecognizerView.setMeteringAreas(new RectF[] { new RectF(0.1f, 0.34f, 0.1f + 0.8f, 0.34f + 0.13f) }, false);
}

From source file:com.ymt.demo1.customViews.widget.GuideTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;//from www.j a va2  s.  c  om
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    //
    RectF rectF = new RectF(lineLeft, 0, lineRight, height);
    canvas.drawRoundRect(rectF, 45, 45, rectPaint);

}

From source file:com.ymt.demo1.customViews.widget.PagerSlidingTabStrip.java

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

    if (isInEditMode() || tabCount == 0) {
        return;/*from   w w w  .  j  a va2  s .  com*/
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    //
    RectF rectF = new RectF(lineLeft + 28, 28, lineRight - 28, height - 28);
    canvas.drawRoundRect(rectF, 45, 45, rectPaint);

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}