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:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java

private void calculateItemSize(int w, int h) {

    int items = mSideItems * 2 + 1;
    int totalPadding = ((int) mDividerSize * (items - 1));
    mItemWidth = (w - totalPadding) / items;

    mItemClipBounds = new RectF(0, 0, mItemWidth, h);
    mItemClipBoundsOffser = new RectF(mItemClipBounds);

    scrollToItem(mSelectedItem);//from  ww w .  j  a  va 2  s. c  o m

    remakeLayout();
    startMarqueeIfNeeded();

}

From source file:nautilus.writingpane.CameraActivity.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *//*w ww.j av  a 2 s  .  c o m*/
private void configureTransform(int viewWidth, int viewHeight) {
    if (null == mTextureView || null == mPreviewSize) {
        return;
    }
    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}

From source file:com.iwuvhugs.seekgame.PhotoFragment.java

/**
 * Configures the necessary {@link Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *///from   w  w  w .j  a  v  a2s . c om
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();

    if (Surface.ROTATION_0 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = (float) (viewWidth / mPreviewSize.getWidth() + 0.6);
        matrix.postScale(scale, scale, centerX, centerY);
    }

    mTextureView.setTransform(matrix);
}

From source file:org.mozilla.gecko.GeckoAppShell.java

static private Bitmap getLauncherIcon(Bitmap aSource) {
    final int kOffset = 6;
    final int kRadius = 5;
    int kIconSize;
    int kOverlaySize;
    switch (getDpi()) {
    case DisplayMetrics.DENSITY_MEDIUM:
        kIconSize = 48;/*from w  w w. j  av a 2s  .c om*/
        kOverlaySize = 32;
        break;
    case DisplayMetrics.DENSITY_XHIGH:
        kIconSize = 96;
        kOverlaySize = 48;
        break;
    case DisplayMetrics.DENSITY_HIGH:
    default:
        kIconSize = 72;
        kOverlaySize = 32;
    }

    Bitmap bitmap = Bitmap.createBitmap(kIconSize, kIconSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    // draw a base color
    Paint paint = new Paint();

    if (aSource == null) {
        float[] hsv = new float[3];
        hsv[0] = 32.0f;
        hsv[1] = 1.0f;
        hsv[2] = 1.0f;
        paint.setColor(Color.HSVToColor(hsv));
        canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius,
                kRadius, paint);
    } else {
        int color = BitmapUtils.getDominantColor(aSource);
        paint.setColor(color);
        canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius,
                kRadius, paint);
        paint.setColor(Color.argb(100, 255, 255, 255));
        canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius,
                kRadius, paint);
    }

    // draw the overlay
    Bitmap overlay = BitmapFactory.decodeResource(GeckoApp.mAppContext.getResources(), R.drawable.home_bg);
    canvas.drawBitmap(overlay, null, new Rect(0, 0, kIconSize, kIconSize), null);

    // draw the bitmap
    if (aSource == null)
        aSource = BitmapFactory.decodeResource(GeckoApp.mAppContext.getResources(), R.drawable.home_star);

    if (aSource.getWidth() < kOverlaySize || aSource.getHeight() < kOverlaySize) {
        canvas.drawBitmap(aSource, null,
                new Rect(kIconSize / 2 - kOverlaySize / 2, kIconSize / 2 - kOverlaySize / 2,
                        kIconSize / 2 + kOverlaySize / 2, kIconSize / 2 + kOverlaySize / 2),
                null);
    } else {
        canvas.drawBitmap(aSource, null,
                new Rect(kIconSize / 2 - aSource.getWidth() / 2, kIconSize / 2 - aSource.getHeight() / 2,
                        kIconSize / 2 + aSource.getWidth() / 2, kIconSize / 2 + aSource.getHeight() / 2),
                null);
    }

    return bitmap;
}

From source file:com.android.ex.chips.RecipientEditTextView.java

private Bitmap createUnselectedChip(final RecipientEntry contact, final TextPaint paint,
        final boolean leaveBlankIconSpacer) {
    // Ellipsize the text so that it takes AT MOST the entire width of the
    // autocomplete text entry area. Make sure to leave space for padding
    // on the sides.
    final int height = (int) mChipHeight;
    int iconWidth = height;
    final float[] widths = new float[1];
    paint.getTextWidths(" ", widths);
    final float availableWidth = calculateAvailableWidth();
    final String chipDisplayText = createChipDisplayText(contact);
    final CharSequence ellipsizedText = ellipsizeText(chipDisplayText, paint,
            availableWidth - iconWidth - widths[0]);
    // Make sure there is a minimum chip width so the user can ALWAYS
    // tap a chip without difficulty.
    final int width = Math.max(iconWidth * 2,
            (int) Math.floor(paint.measureText(ellipsizedText, 0, ellipsizedText.length())) + mChipPadding * 2
                    + iconWidth);/*from   w  w  w. java  2 s.  c o  m*/
    // Create the background of the chip.
    final Bitmap tmpBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(tmpBitmap);
    final Drawable background = getChipBackground(contact);
    if (background != null) {
        background.setBounds(0, 0, width, height);
        background.draw(canvas);
        // Don't draw photos for recipients that have been typed in OR generated on the fly.
        final long contactId = contact.getContactId();
        final boolean drawPhotos = isPhoneQuery() ? contactId != RecipientEntry.INVALID_CONTACT
                : contactId != RecipientEntry.INVALID_CONTACT && contactId != RecipientEntry.GENERATED_CONTACT
                        && !TextUtils.isEmpty(contact.getDisplayName());
        if (drawPhotos) {
            byte[] photoBytes = contact.getPhotoBytes();
            // There may not be a photo yet if anything but the first contact address
            // was selected.
            if (photoBytes == null && contact.getPhotoThumbnailUri() != null) {
                // TODO: cache this in the recipient entry?
                getAdapter().fetchPhoto(contact, contact.getPhotoThumbnailUri());
                photoBytes = contact.getPhotoBytes();
            }
            Bitmap photo;
            if (photoBytes != null)
                photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length);
            else // TODO: can the scaled down default photo be cached?
                photo = mDefaultContactPhoto;
            // Draw the photo on the left side.
            if (photo != null) {
                final RectF src = new RectF(0, 0, photo.getWidth(), photo.getHeight());
                final Rect backgroundPadding = new Rect();
                mChipBackground.getPadding(backgroundPadding);
                final RectF dst = new RectF(width - iconWidth + backgroundPadding.left,
                        0 + backgroundPadding.top, width - backgroundPadding.right,
                        height - backgroundPadding.bottom);
                final Matrix matrix = new Matrix();
                matrix.setRectToRect(src, dst, Matrix.ScaleToFit.FILL);
                canvas.drawBitmap(photo, matrix, paint);
            }
        } else if (!leaveBlankIconSpacer || isPhoneQuery())
            iconWidth = 0;
        paint.setColor(ContextCompat.getColor(getContext(), android.R.color.black));
        // Vertically center the text in the chip.
        canvas.drawText(ellipsizedText, 0, ellipsizedText.length(), mChipPadding,
                getTextYOffset((String) ellipsizedText, paint, height), paint);
    } else
        Log.w(TAG, "Unable to draw a background for the chips as it was never set");
    return tmpBitmap;
}

From source file:io.digibyte.presenter.activities.camera.CameraActivity.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */// ww w .jav a2 s  .  co  m
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = CameraActivity.this;
    if (null == mTextureView || null == mPreviewSize) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}

From source file:camera2basic.Camera2BasicFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *//* www.j  a  v a  2 s. co  m*/
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}

From source file:com.example.joshf.conc.CameraFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *///w  ww  .j  ava2 s.  c  o  m
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        Log.e("rotate", "90");
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        Log.e("rotate", "180");
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}

From source file:com.mylikes.likes.etchasketch.Slate.java

public void paintBitmap(Bitmap b) {
    if (mTiledCanvas == null) {
        mPendingPaintBitmap = b;/*from   w  w w  . ja  v a  2 s  . co m*/
        return;
    }

    commitStroke();

    Matrix m = new Matrix();
    RectF s = new RectF(0, 0, b.getWidth(), b.getHeight());
    RectF d = new RectF(0, 0, mTiledCanvas.getWidth(), mTiledCanvas.getHeight());
    m.setRectToRect(s, d, Matrix.ScaleToFit.CENTER);

    if (DEBUG) {
        Log.v(TAG, "paintBitmap: drawing new bits into current canvas");
    }
    mTiledCanvas.drawBitmap(b, m, sBitmapPaint);
    invalidate();

    if (DEBUG)
        Log.d(TAG, String.format("paintBitmap(%s, %dx%d): canvas=%s", b.toString(), b.getWidth(), b.getHeight(),
                mTiledCanvas.toString()));
}

From source file:com.lab47billion.appchooser.HorizontalPicker.java

private void calculateItemSize(int w, int h) {

    int items = mSideItems * 2 + 1;
    int totalPadding = ((int) mDividerSize * (items - 1));
    mItemWidth = (w - totalPadding) / items;

    mItemClipBounds = new RectF(0, 0, mItemWidth, h);
    mItemClipBoundsOffser = new RectF(mItemClipBounds);

    scrollToItem(mSelectedItem);/* ww  w .  java  2 s.  c  o m*/
    remakeLayout();
}