List of usage examples for android.graphics Rect Rect
public Rect(int left, int top, int right, int bottom)
From source file:com.cellbots.eyes.EyesActivity.java
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { mHolder.setFixedSize(w, h);//from w ww. ja v a2 s. c o m // 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); } 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:android.support.v7.view.menu.MenuPopupHelper.java
private void showPopup(int xOffset, int yOffset, boolean useOffsets, boolean showTitle) { final MenuPopup popup = getPopup(); popup.setShowTitle(showTitle);//from www.ja v a2 s . c om if (useOffsets) { // If the resolved drop-down gravity is RIGHT, the popup's right // edge will be aligned with the anchor view. Adjust by the anchor // width such that the top-right corner is at the X offset. final int hgrav = GravityCompat.getAbsoluteGravity(mDropDownGravity, ViewCompat.getLayoutDirection(mAnchorView)) & Gravity.HORIZONTAL_GRAVITY_MASK; if (hgrav == Gravity.RIGHT) { xOffset -= mAnchorView.getWidth(); } popup.setHorizontalOffset(xOffset); popup.setVerticalOffset(yOffset); // Set the transition epicenter to be roughly finger (or mouse // cursor) sized and centered around the offset position. This // will give the appearance that the window is emerging from // the touch point. final float density = mContext.getResources().getDisplayMetrics().density; final int halfSize = (int) (TOUCH_EPICENTER_SIZE_DP * density / 2); final Rect epicenter = new Rect(xOffset - halfSize, yOffset - halfSize, xOffset + halfSize, yOffset + halfSize); popup.setEpicenterBounds(epicenter); } popup.show(); }
From source file:com.allthingsgeek.celljoust.MainActivity.java
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { mHolder.setFixedSize(w, h);/*w w w . j av a 2s . com*/ // 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(previewShrink, previewShrink, previewWidth - previewShrink, previewHeight - previewShrink); mCallbackBuffer = new byte[497664]; mCamera.setParameters(params); mCamera.setPreviewCallbackWithBuffer(new PreviewCallback() { public void onPreviewFrame(byte[] imageData, Camera arg1) { convWorker.nextFrame(imageData); } }); mCamera.addCallbackBuffer(mCallbackBuffer); mCamera.startPreview(); setTorchMode(mTorchMode); }
From source file:net.kourlas.voipms_sms.Utils.java
/** * Applies a circular mask to a bitmap.//ww w.j av a2 s.c om * * @param bitmap The bitmap to apply the mask to. */ public static Bitmap applyCircularMask(Bitmap bitmap) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawARGB(0, 0, 0, 0); canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint); paint.setAntiAlias(true); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:ac.robinson.paperchains.PaperChainsActivity.java
@Override protected void onPageIdFound(final String id) { // Toast.makeText(TicQRActivity.this, "Page ID found", Toast.LENGTH_SHORT).show(); new AsyncHttpClient().get(CODE_SERVER_URL, new RequestParams("lookup", id), new JsonHttpResponseHandler() { private void handleFailure(int reason) { // nothing we can do except browse the image switchMode(MODE_IMAGE_ONLY); Toast.makeText(PaperChainsActivity.this, getString(reason), Toast.LENGTH_SHORT).show(); }/*from w w w . j av a 2s. com*/ @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { try { if ("ok".equals(response.getString("status"))) { JSONArray areas = response.getJSONArray("audioAreas"); if (areas != null && !areas.isNull(0)) { for (int i = 0; i < areas.length(); i++) { JSONObject jsonBox = areas.getJSONObject(i); mAudioAreas.add(new AudioAreaHolder(jsonBox.getLong("soundCloudId"), new Rect(jsonBox.getInt("left"), jsonBox.getInt("top"), jsonBox.getInt("right"), jsonBox.getInt("bottom")))); } } mPageId = id; mAudioAreasLoaded = true; if (mImageParsed) { addAudioRects(); switchMode(MODE_LISTEN); } } else { handleFailure(R.string.hint_json_error); } } catch (JSONException e) { handleFailure(R.string.hint_json_error); } } @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { handleFailure(R.string.hint_connection_error); } }); }
From source file:com.lightbox.android.bitmap.BitmapUtils.java
public static Bitmap createScaledBitmap(Bitmap src, int scaledWidth, int scaledHeight) { Bitmap scaledBitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, src.getConfig()); Canvas canvas = new Canvas(scaledBitmap); canvas.drawBitmap(src, new Rect(0, 0, src.getWidth(), src.getHeight()), new Rect(0, 0, scaledWidth, scaledHeight), sScalePaint); return scaledBitmap; }
From source file:ameircom.keymedia.Activity.transition.FabTransform.java
private void captureValues(TransitionValues transitionValues) { final View view = transitionValues.view; if (view == null || view.getWidth() <= 0 || view.getHeight() <= 0) return;// w w w . ja v a2 s . c o m transitionValues.values.put(PROP_BOUNDS, new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())); }
From source file:com.ruesga.rview.misc.BitmapUtils.java
public static Rect calculateSrcRect(int srcWidth, int srcHeight, int dstWidth, int dstHeight, ScalingLogic scalingLogic) {/*w ww.ja va 2s.c o m*/ if (scalingLogic == ScalingLogic.CROP) { final float srcAspect = (float) srcWidth / (float) srcHeight; final float dstAspect = (float) dstWidth / (float) dstHeight; if (srcAspect > dstAspect) { final int srcRectWidth = (int) (srcHeight * dstAspect); final int srcRectLeft = (srcWidth - srcRectWidth) / 2; return new Rect(srcRectLeft, 0, srcRectLeft + srcRectWidth, srcHeight); } else { final int srcRectHeight = (int) (srcWidth / dstAspect); final int scrRectTop = (srcHeight - srcRectHeight) / 2; return new Rect(0, scrRectTop, srcWidth, scrRectTop + srcRectHeight); } } else { return new Rect(0, 0, srcWidth, srcHeight); } }
From source file:com.ruesga.rview.misc.BitmapUtils.java
public static Rect calculateDstRect(int srcWidth, int srcHeight, int dstWidth, int dstHeight, ScalingLogic scalingLogic) {/*from w w w . j a v a2s.c om*/ if (scalingLogic == ScalingLogic.FIT) { final float srcAspect = (float) srcWidth / (float) srcHeight; final float dstAspect = (float) dstWidth / (float) dstHeight; if (srcAspect > dstAspect) { return new Rect(0, 0, dstWidth, (int) (dstWidth / srcAspect)); } else { return new Rect(0, 0, (int) (dstHeight * srcAspect), dstHeight); } } else { return new Rect(0, 0, dstWidth, dstHeight); } }