List of usage examples for android.graphics Rect set
public void set(int left, int top, int right, int bottom)
From source file:Main.java
static Rect getViewAbsRect(View view, int parentX, int parentY) { int[] loc = new int[2]; view.getLocationInWindow(loc);/* w w w .j av a 2 s . c o m*/ Rect rect = new Rect(); rect.set(loc[0], loc[1], loc[0] + view.getMeasuredWidth(), loc[1] + view.getMeasuredHeight()); rect.offset(-parentX, -parentY); return rect; }
From source file:Main.java
public static Rect rectF2Rect(RectF rectF) { Rect rect = new Rect(); rect.set((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom); return rect;//from w w w.j a va 2 s.c o m }
From source file:Main.java
/** * calculates the approximate height of a text, depending on a demo text * avoid repeated calls (e.g. inside drawing methods) * * @param paint//from w w w. ja v a2s.c om * @param demoText * @return */ public static int calcTextHeight(Paint paint, String demoText) { Rect r = mCalcTextHeightRect; r.set(0, 0, 0, 0); paint.getTextBounds(demoText, 0, demoText.length(), r); return r.height(); }
From source file:Main.java
/** * Honeycomb IMPL borrowed from android.support.design.widget.ViewGroupUtils and * android.support.design.widget.ViewGroupUtilsHoneycomb *//* ww w . java 2 s .c om*/ public static void getDescendantRect(ViewGroup parent, View descendant, Rect out) { out.set(0, 0, descendant.getWidth(), descendant.getHeight()); offsetDescendantRect(parent, descendant, out); }
From source file:Main.java
private static Rect getRectByByte(byte[] org) { Rect rect = new Rect(); ByteBuffer byteBuffer = ByteBuffer.wrap(org).order(ByteOrder.nativeOrder()); rect.set(byteBuffer.getInt(3 * 4), byteBuffer.getInt(5 * 4), byteBuffer.getInt(4 * 4), byteBuffer.getInt(6 * 4));/*from w w w.jav a 2s . com*/ return rect; }
From source file:Main.java
public static Bitmap asBitmap(Drawable drawable, int minWidth, int minHeight) { final Rect tmpRect = new Rect(); drawable.copyBounds(tmpRect);//from ww w . ja v a 2s. c o m if (tmpRect.isEmpty()) { tmpRect.set(0, 0, Math.max(minWidth, drawable.getIntrinsicWidth()), Math.max(minHeight, drawable.getIntrinsicHeight())); drawable.setBounds(tmpRect); } Bitmap bitmap = Bitmap.createBitmap(tmpRect.width(), tmpRect.height(), Bitmap.Config.ARGB_8888); drawable.draw(new Canvas(bitmap)); return bitmap; }
From source file:com.ruesga.rview.fragments.RevealDialogFragment.java
public static Rect computeViewOnScreen(View v) { int[] pos = new int[2]; v.getLocationOnScreen(pos);/* w ww. j a v a2 s .c o m*/ Rect rect = new Rect(); rect.set(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight()); return rect; }
From source file:Main.java
public static Rect getDisplaySize(Context context) { Rect rect = new Rect(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); rect.set(0, 0, display.getWidth(), display.getHeight()); return rect;/*w ww . j a v a2 s. c om*/ }
From source file:com.facebook.litho.utils.IncrementalMountUtils.java
private static void maybePerformIncrementalMountOnView(int scrollingParentWidth, int scrollingParentHeight, View view) {/*from w w w. ja va 2 s . co m*/ final View underlyingView = view instanceof WrapperView ? ((WrapperView) view).getWrappedView() : view; if (!(underlyingView instanceof LithoView)) { return; } final LithoView lithoView = (LithoView) underlyingView; if (!lithoView.isIncrementalMountEnabled()) { return; } if (view != underlyingView && view.getHeight() != underlyingView.getHeight()) { throw new IllegalStateException( "ViewDiagnosticsWrapper must be the same height as the underlying view"); } final int translationX = (int) view.getTranslationX(); final int translationY = (int) view.getTranslationY(); final int top = view.getTop() + translationY; final int bottom = view.getBottom() + translationY; final int left = view.getLeft() + translationX; final int right = view.getRight() + translationX; if (left >= 0 && top >= 0 && right <= scrollingParentWidth && bottom <= scrollingParentHeight && lithoView.getPreviousMountBounds().width() == lithoView.getWidth() && lithoView.getPreviousMountBounds().height() == lithoView.getHeight()) { // View is fully visible, and has already been completely mounted. return; } final Rect rect = acquireRect(); rect.set(Math.max(0, -left), Math.max(0, -top), Math.min(right, scrollingParentWidth) - left, Math.min(bottom, scrollingParentHeight) - top); if (rect.isEmpty()) { // View is not visible at all, nothing to do. release(rect); return; } lithoView.performIncrementalMount(rect); release(rect); }
From source file:Main.java
private static synchronized Bitmap createScaledBitmap(Bitmap bitmap, final int width, final int height, float cornerRadius) { if (bitmap == null) { return null; }//from www . ja v a2 s. com int adjustedWidth = width; int adjustedHeight = height; final int bitmapWidth = bitmap.getWidth(); final int bitmapHeight = bitmap.getHeight(); //int inBytes = bitmap.getByteCount(); if (width >= bitmapWidth && height >= bitmapHeight) return bitmap; if (width > 0 && height > 0) { //if (width < bitmapWidth || height < bitmapHeight) { final float ratio = (float) bitmapWidth / bitmapHeight; if (bitmapWidth > bitmapHeight) { adjustedHeight = (int) (width / ratio); } else if (bitmapHeight > bitmapWidth) { adjustedWidth = (int) (height * ratio); } final Bitmap.Config c = Bitmap.Config.ARGB_8888; final Bitmap thumb = Bitmap.createBitmap(width, height, c); final Canvas canvas = sScaleCanvas; final Paint paint = sPaint; canvas.setBitmap(thumb); paint.setDither(false); paint.setFilterBitmap(true); Rect sBounds = new Rect(); Rect sOldBounds = new Rect(); sBounds.set((width - adjustedWidth) >> 1, (height - adjustedHeight) >> 1, adjustedWidth, adjustedHeight); sOldBounds.set(0, 0, bitmapWidth, bitmapHeight); if (cornerRadius != 0) { //Path p = new Path(); RectF rect = new RectF(sBounds); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.WHITE); canvas.drawRoundRect(rect, cornerRadius, cornerRadius, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); //p.addRoundRect(rect, cornerRadius, cornerRadius, Direction.CCW); //canvas.clipPath(p, Op.REPLACE); } else { paint.setXfermode(null); //canvas.clipRect(0, 0, thumb.getWidth(), thumb.getHeight()); } canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint); canvas.setBitmap(Bitmap.createBitmap(1, 1, Config.ALPHA_8)); return thumb; } return bitmap; }