List of usage examples for android.graphics Rect Rect
public Rect(int left, int top, int right, int bottom)
From source file:Main.java
/** * Transform source Bitmap to targeted width and height. *//*from w w w . ja va2 s . c om*/ private static Bitmap transform(Matrix scaler, Bitmap source, int targetWidth, int targetHeight, int options) { boolean scaleUp = (options & OPTIONS_SCALE_UP) != 0; boolean recycle = (options & OPTIONS_RECYCLE_INPUT) != 0; int deltaX = source.getWidth() - targetWidth; int deltaY = source.getHeight() - targetHeight; if (!scaleUp && (deltaX < 0 || deltaY < 0)) { /* * In this case the bitmap is smaller, at least in one dimension, * than the target. Transform it by placing as much of the image * as possible into the target and leaving the top/bottom or * left/right (or both) black. */ Bitmap b2 = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b2); int deltaXHalf = Math.max(0, deltaX / 2); int deltaYHalf = Math.max(0, deltaY / 2); Rect src = new Rect(deltaXHalf, deltaYHalf, deltaXHalf + Math.min(targetWidth, source.getWidth()), deltaYHalf + Math.min(targetHeight, source.getHeight())); int dstX = (targetWidth - src.width()) / 2; int dstY = (targetHeight - src.height()) / 2; Rect dst = new Rect(dstX, dstY, targetWidth - dstX, targetHeight - dstY); c.drawBitmap(source, src, dst, null); if (recycle) { source.recycle(); } return b2; } float bitmapWidthF = source.getWidth(); float bitmapHeightF = source.getHeight(); float bitmapAspect = bitmapWidthF / bitmapHeightF; float viewAspect = (float) targetWidth / targetHeight; if (bitmapAspect > viewAspect) { float scale = targetHeight / bitmapHeightF; if (scale < .9F || scale > 1F) { scaler.setScale(scale, scale); } else { scaler = null; } } else { float scale = targetWidth / bitmapWidthF; if (scale < .9F || scale > 1F) { scaler.setScale(scale, scale); } else { scaler = null; } } Bitmap b1; if (scaler != null) { // this is used for minithumb and crop, so we want to filter here. b1 = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), scaler, true); } else { b1 = source; } if (recycle && b1 != source) { source.recycle(); } int dx1 = Math.max(0, b1.getWidth() - targetWidth); int dy1 = Math.max(0, b1.getHeight() - targetHeight); Bitmap b2 = Bitmap.createBitmap(b1, dx1 / 2, dy1 / 2, targetWidth, targetHeight); if (b2 != b1) { if (recycle || b1 != source) { b1.recycle(); } } return b2; }
From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java
/** * Sets the downloaded attached image.//w ww . j av a2 s . c o m * * @param fileName picture file path */ public static Bitmap publishPicture(String fileName) { Bitmap bitmap = null; try { if (!TextUtils.isEmpty(fileName)) { try { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(fileName, opts); //Find the correct scale value. It should be the power of 2. int width = opts.outWidth, height = opts.outHeight; int scale = 1; while (true) { if (width / 2 <= 150 || height / 2 <= 150) { break; } width /= 2; height /= 2; scale *= 2; } BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inSampleSize = scale; bitmap = BitmapFactory.decodeFile(fileName, opt); int size = 0; if (bitmap.getHeight() > bitmap.getWidth()) { size = bitmap.getWidth(); } else { size = bitmap.getHeight(); } Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, size, size); final RectF rectF = new RectF(rect); final float roundPx = 0; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; } catch (Exception e) { Log.w("", ""); } } } catch (Exception ex) { } return null; }
From source file:android.support.v7.widget.BaseRecyclerViewInstrumentationTest.java
public Rect getDecoratedRecyclerViewBounds() { return new Rect(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getWidth() - mRecyclerView.getPaddingRight(), mRecyclerView.getHeight() - mRecyclerView.getPaddingBottom()); }
From source file:android.support.transition.ChangeBounds.java
private void captureValues(TransitionValues values) { View view = values.view;/* ww w . j a v a2s. co m*/ if (ViewCompat.isLaidOut(view) || view.getWidth() != 0 || view.getHeight() != 0) { values.values.put(PROPNAME_BOUNDS, new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())); values.values.put(PROPNAME_PARENT, values.view.getParent()); if (mReparent) { values.view.getLocationInWindow(mTempLocation); values.values.put(PROPNAME_WINDOW_X, mTempLocation[0]); values.values.put(PROPNAME_WINDOW_Y, mTempLocation[1]); } if (mResizeClip) { values.values.put(PROPNAME_CLIP, ViewCompat.getClipBounds(view)); } } }
From source file:de.madvertise.android.sdk.MadvertiseView.java
/** * Constructor/*from w ww . ja va 2s. c o m*/ * * @param context * @param attrs */ public MadvertiseView(final Context context, final AttributeSet attrs) { super(context, attrs); MadvertiseUtil.logMessage(null, Log.DEBUG, "** Constructor for mad view called **"); // We use GONE instead of INVISIBLE because GONE doesn't allocate space // in // the layout. setVisibility(GONE); if (!MadvertiseUtil.checkPermissionGranted(android.Manifest.permission.INTERNET, context)) { MadvertiseUtil.logMessage(null, Log.DEBUG, " *** ----------------------------- *** "); MadvertiseUtil.logMessage(null, Log.DEBUG, " *** Missing internet permissions! *** "); MadvertiseUtil.logMessage(null, Log.DEBUG, " *** ----------------------------- *** "); throw new IllegalArgumentException("Missing internet permission!"); } if (!MadvertiseUtil.checkForBrowserDeclaration(getContext())) { MadvertiseUtil.logMessage(null, Log.DEBUG, " *** ----------------------------- *** "); MadvertiseUtil.logMessage(null, Log.DEBUG, " *** You must declare the activity de.madvertise.android.sdk.MadvertiseActivity in your manifest! *** "); MadvertiseUtil.logMessage(null, Log.DEBUG, " *** ----------------------------- *** "); throw new IllegalArgumentException("Missing Activity declaration!"); } initParameters(attrs); final DisplayMetrics displayMetrics = context.getApplicationContext().getResources().getDisplayMetrics(); MadvertiseUtil.logMessage(null, Log.DEBUG, "Display values: Width = " + displayMetrics.widthPixels + " ; Height = " + displayMetrics.heightPixels); mInitialBackground = this.getBackground(); if (sTextBannerBackground == null) { Rect r = new Rect(0, 0, 1, displayMetrics.heightPixels); sTextBannerBackground = generateBackgroundDrawable(r, mBackgroundColor, 0xffffff); } setClickable(true); setFocusable(true); setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); if (mRequestThread == null || !mRequestThread.isAlive()) { requestNewAd(false); } // no reloads for ads with banner_type = rich_media if (mBannerType.contains(MadvertiseUtil.BANNER_TYPE_RICH_MEDIA) || mBannerType.contains(MadvertiseUtil.BANNER_TYPE_RICH_MEDIA_SHORT)) { this.setFetchingAdsEnabled(false); MadvertiseUtil.logMessage(null, Log.DEBUG, "No ad reloading, since banner_type=[rich_media|rm] was requested"); } // just some testing // MadvertiseUtil.getPackages(context.getApplicationContext()); }
From source file:io.selendroid.server.model.AndroidNativeElement.java
protected void scrollIntoScreenIfNeeded() { Point leftTopLocation = getLocation(); final int left = leftTopLocation.x; final int top = leftTopLocation.y; instrumentation.runOnMainSync(new Runnable() { @Override//from www . java2 s .c o m public void run() { synchronized (syncObject) { Rect r = new Rect(left, top, getView().getWidth(), getView().getHeight()); getView().requestRectangleOnScreen(r); done = true; syncObject.notify(); } } }); long end = System.currentTimeMillis() + instrumentation.getAndroidWait().getTimeoutInMillis(); synchronized (syncObject) { while (!done && System.currentTimeMillis() < end) { try { syncObject.wait(AndroidWait.DEFAULT_SLEEP_INTERVAL); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }
From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java
private Bitmap RenderBarGraph(int CritCount, int ErrCount, int WarnCount) { //Log.i("Counts", Integer.toString(CritCount) + " / " + Integer.toString(ErrCount) + " / " + Integer.toString(WarnCount)); Bitmap emptyBmap = Bitmap.createBitmap(290, 150, Config.ARGB_8888); int width = emptyBmap.getWidth(); int height = emptyBmap.getHeight(); Bitmap charty = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(charty); //final int color = 0xff0B0B61; final Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE);//from ww w . ja v a 2 s . co m //y canvas.drawLine(25, 0, 25, 289, paint); //x canvas.drawLine(25, 149, 289, 149, paint); paint.setAntiAlias(true); int Max = 0; if (CritCount > ErrCount && CritCount > WarnCount) Max = CritCount; else if (ErrCount > CritCount && ErrCount > WarnCount) Max = ErrCount; else if (WarnCount > CritCount && WarnCount > ErrCount) Max = WarnCount; else Max = CritCount; if (Max > 0) canvas.drawText(Integer.toString(Max), 0, 10, paint); if (Max > 1) canvas.drawText(Integer.toString(Max / 2), 0, 75, paint); canvas.drawText("0", 0, 148, paint); double divisor = 148 / (double) Max; paint.setAlpha(128); Rect rect = new Rect(32, (int) (148 - (divisor * CritCount)), 64, 148); paint.setColor(Color.argb(200, 208, 0, 0)); //red if (CritCount > 0) canvas.drawRect(new RectF(rect), paint); rect = new Rect(128, (int) (148 - (divisor * ErrCount)), 160, 148); paint.setColor(Color.argb(200, 255, 102, 0));//orange if (ErrCount > 0) canvas.drawRect(new RectF(rect), paint); rect = new Rect(224, (int) (148 - (divisor * WarnCount)), 256, 148); paint.setColor(Color.argb(200, 255, 224, 57)); //yellow if (WarnCount > 0) canvas.drawRect(new RectF(rect), paint); //Return ByteArrayOutputStream out = new ByteArrayOutputStream(); charty.compress(CompressFormat.PNG, 50, out); return BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size()); }
From source file:com.cellbots.local.EyesView.java
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { // If putUrl is null, it means that only personas overlay was requested. if (putUrl == null) { mCamera.startPreview();//w w w. java 2 s.c o m return; } mHolder.setFixedSize(w, h); // Start the preview Parameters params = mCamera.getParameters(); previewHeight = params.getPreviewSize().height; previewWidth = params.getPreviewSize().width; previewFormat = params.getPreviewFormat(); // Crop the edges of the picture to reduce the image size r = new Rect(80, 20, previewWidth - 80, previewHeight - 20); mCallbackBuffer = new byte[460800]; mCamera.setParameters(params); mCamera.setPreviewCallbackWithBuffer(new PreviewCallback() { public void onPreviewFrame(byte[] imageData, Camera arg1) { final byte[] data = imageData; if (!isUploading) { if (needToTakePicture) { takePicture(imageData, false); } else { isUploading = true; new Thread(new Runnable() { @Override public void run() { uploadImage(data); } }).start(); // appEngineUploadImage(imageData); } } } }); mCamera.addCallbackBuffer(mCallbackBuffer); mCamera.startPreview(); setTorchMode(mTorchMode); }
From source file:org.jared.synodroid.ds.utils.Utils.java
/** * Create a rounded bitmap/*from w ww.jav a2 s . c o m*/ * * @param bitmap * The original bitmap * @return */ public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }