Example usage for android.graphics Rect set

List of usage examples for android.graphics Rect set

Introduction

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

Prototype

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

Source Link

Document

Set the rectangle's coordinates to the specified values.

Usage

From source file:com.google.android.apps.muzei.NewWallpaperNotificationReceiver.java

public static void maybeShowNewArtworkNotification(Context context, Artwork artwork,
        BitmapRegionLoader bitmapRegionLoader) {
    if (artwork == null || artwork.getImageUri() == null || bitmapRegionLoader == null) {
        return;//from  ww w  .java2s.c o  m
    }

    ArtDetailOpenedClosedEvent adoce = EventBus.getDefault().getStickyEvent(ArtDetailOpenedClosedEvent.class);
    if (adoce != null && adoce.isArtDetailOpened()) {
        return;
    }

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    if (!sp.getBoolean(PREF_ENABLED, true)) {
        return;
    }

    String lastSeenImageUri = sp.getString(PREF_LAST_SEEN_NOTIFICATION_IMAGE_URI, null);
    if (TextUtils.equals(lastSeenImageUri, artwork.getImageUri().toString())) {
        return;
    }

    Rect rect = new Rect();
    int width = bitmapRegionLoader.getWidth();
    int height = bitmapRegionLoader.getHeight();
    if (width > height) {
        rect.set((width - height) / 2, 0, (width + height) / 2, height);
    } else {
        rect.set(0, (height - width) / 2, width, (height + width) / 2);
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = ImageUtil.calculateSampleSize(height, 256);
    Bitmap largeIcon = bitmapRegionLoader.decodeRegion(rect, options);

    NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat_muzei).setPriority(Notification.PRIORITY_MIN).setAutoCancel(true)
            .setContentTitle(artwork.getTitle())
            .setContentText(context.getString(R.string.notification_new_wallpaper)).setLargeIcon(largeIcon)
            .setContentIntent(PendingIntent.getActivity(context, 0,
                    Intent.makeMainActivity(new ComponentName(context, MuzeiActivity.class)),
                    PendingIntent.FLAG_UPDATE_CURRENT))
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0,
                    new Intent(context, NewWallpaperNotificationReceiver.class)
                            .setAction(ACTION_MARK_NOTIFICATION_READ),
                    PendingIntent.FLAG_UPDATE_CURRENT));
    NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle(nb).bigLargeIcon(null)
            .setBigContentTitle(artwork.getTitle()).setSummaryText(artwork.getByline()).bigPicture(largeIcon);
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, style.build());

    // Clear any last-seen notification
    sp.edit().remove(PREF_LAST_SEEN_NOTIFICATION_IMAGE_URI).apply();
}

From source file:Main.java

static void offsetDescendantRect(ViewGroup group, View child, Rect rect) {
    Matrix m = sMatrix.get();// w ww  .  j a  v a 2s  . co  m
    if (m == null) {
        m = new Matrix();
        sMatrix.set(m);
    } else {
        m.set(IDENTITY);
    }

    offsetDescendantMatrix(group, child, m);

    RectF rectF = sRectF.get();
    if (rectF == null) {
        rectF = new RectF();
    }
    rectF.set(rect);
    m.mapRect(rectF);
    rect.set((int) (rectF.left + 0.5f), (int) (rectF.top + 0.5f), (int) (rectF.right + 0.5f),
            (int) (rectF.bottom + 0.5f));
}

From source file:Main.java

public static void offsetDescendantRect(ViewGroup group, View child, Rect rect) {
    Matrix m = sMatrix.get();//from w  w w.ja v  a 2 s.c  o m
    if (m == null) {
        m = new Matrix();
        sMatrix.set(m);
    } else {
        m.set(IDENTITY);
    }

    offsetDescendantMatrix(group, child, m);

    RectF rectF = sRectF.get();
    if (rectF == null) {
        rectF = new RectF();
    }
    rectF.set(rect);
    m.mapRect(rectF);
    rect.set((int) (rectF.left + 0.5f), (int) (rectF.top + 0.5f), (int) (rectF.right + 0.5f),
            (int) (rectF.bottom + 0.5f));
}

From source file:Main.java

public static void mapping(int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, Rect rect) {
    float widthScale = (float) sourceWidth / targetWidth;
    float heightScale = (float) sourceHeight / targetHeight;
    float finalScale = widthScale < heightScale ? widthScale : heightScale;
    int srcWidth = (int) (targetWidth * finalScale);
    int srcHeight = (int) (targetHeight * finalScale);
    int srcLeft = (sourceWidth - srcWidth) / 2;
    int srcTop = (sourceHeight - srcHeight) / 2;
    rect.set(srcLeft, srcTop, srcLeft + srcWidth, srcTop + srcHeight);
}

From source file:Main.java

@SuppressWarnings("unused")
@Deprecated/*w  w  w .jav a  2 s  . com*/
public static void mapping(int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, Rect rect) {
    float widthScale = (float) sourceWidth / targetWidth;
    float heightScale = (float) sourceHeight / targetHeight;
    float finalScale = widthScale < heightScale ? widthScale : heightScale;
    int srcWidth = (int) (targetWidth * finalScale);
    int srcHeight = (int) (targetHeight * finalScale);
    int srcLeft = (sourceWidth - srcWidth) / 2;
    int srcTop = (sourceHeight - srcHeight) / 2;
    rect.set(srcLeft, srcTop, srcLeft + srcWidth, srcTop + srcHeight);
}

From source file:Main.java

public static void offsetDescendantRect(ViewGroup group, View child, Rect rect) {
    Matrix m = sMatrix.get();/*  w  w w.jav a2s .c om*/
    if (m == null) {
        m = new Matrix();
        sMatrix.set(m);
    } else {
        m.reset();
    }

    offsetDescendantMatrix(group, child, m);

    RectF rectF = sRectF.get();
    if (rectF == null) {
        rectF = new RectF();
        sRectF.set(rectF);
    }
    rectF.set(rect);
    m.mapRect(rectF);
    rect.set((int) (rectF.left + 0.5f), (int) (rectF.top + 0.5f), (int) (rectF.right + 0.5f),
            (int) (rectF.bottom + 0.5f));
}

From source file:Main.java

public static void drawToCenterOfCanvas(Canvas canvas, Bitmap bp, int max_width, int max_height,
        Rect cacheRect) {
    final int b_w = bp.getWidth();
    final int b_h = bp.getHeight();
    if (b_w <= max_width && b_h <= max_height) { // center aligned
        canvas.drawBitmap(bp, (max_width - b_w) / 2, (max_height - b_h) / 2, null);
    } else { // scaled fix given rect size
        final float s_w = 1.0f * max_width / b_w;
        final float s_h = 1.0f * max_height / b_h;
        final float f_s = Math.min(s_w, s_h);
        final int f_w = (int) (b_w * f_s);
        final int f_h = (int) (b_h * f_s);
        cacheRect.set(0, 0, f_w, f_h);
        cacheRect.offset((max_width - f_w) / 2, (max_height - f_h) / 2);
        canvas.drawBitmap(bp, null, cacheRect, null);
    }/*w  w  w  . j a  v a2  s.c  om*/
}

From source file:Main.java

/**
 * Special crop of bitmap rotated by not stright angle, in this case the original crop bitmap contains parts
 * beyond the required crop area, this method crops the already cropped and rotated bitmap to the final
 * rectangle.<br>//  www . j a  va2 s. co m
 * Note: rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping.
 */
private static Bitmap cropForRotatedImage(Bitmap bitmap, float[] points, Rect rect, int degreesRotated,
        boolean fixAspectRatio, int aspectRatioX, int aspectRatioY) {
    if (degreesRotated % 90 != 0) {

        int adjLeft = 0, adjTop = 0, width = 0, height = 0;
        double rads = Math.toRadians(degreesRotated);
        int compareTo = degreesRotated < 90 || (degreesRotated > 180 && degreesRotated < 270) ? rect.left
                : rect.right;
        for (int i = 0; i < points.length; i += 2) {
            if (points[i] >= compareTo - 1 && points[i] <= compareTo + 1) {
                adjLeft = (int) Math.abs(Math.sin(rads) * (rect.bottom - points[i + 1]));
                adjTop = (int) Math.abs(Math.cos(rads) * (points[i + 1] - rect.top));
                width = (int) Math.abs((points[i + 1] - rect.top) / Math.sin(rads));
                height = (int) Math.abs((rect.bottom - points[i + 1]) / Math.cos(rads));
                break;
            }
        }

        rect.set(adjLeft, adjTop, adjLeft + width, adjTop + height);
        if (fixAspectRatio) {
            fixRectForAspectRatio(rect, aspectRatioX, aspectRatioY);
        }

        Bitmap bitmapTmp = bitmap;
        bitmap = Bitmap.createBitmap(bitmap, rect.left, rect.top, rect.width(), rect.height());
        if (bitmapTmp != bitmap) {
            bitmapTmp.recycle();
        }
    }
    return bitmap;
}

From source file:com.cundong.recyclerview.MarginDecoration.java

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    outRect.set(margin, margin, margin, margin);
}

From source file:com.ahamed.sample.common.decorator.ArticleItemDecorator.java

@Override
public void getItemOffsets(Rect outRect, int position, int positionType) {
    outRect.set(0, 0, 0, 16);
}