List of usage examples for android.graphics Rect height
public final int height()
From source file:andoridhost.imczy.com.activitymaterial.custom.ReturnChangePosition.java
@Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { if (null == startValues || null == endValues) { return null; }//from w w w. j a v a 2 s . c om if (startValues.view.getId() > 0) { Rect startRect = (Rect) startValues.values.get(PROPNAME_POSITION); Rect endRect = (Rect) endValues.values.get(PROPNAME_POSITION); final View view = endValues.view; Log.e(TAG, "createAnimator: startRect = " + startRect + " , endRect = " + endRect); Path changePosPath = getPathMotion().getPath(startRect.centerX(), startRect.centerY(), endRect.centerX(), endRect.centerY() - endRect.height() / 2); int radius = startRect.centerY() - endRect.centerY(); Log.e(TAG, "createAnimator: startRect center x = " + startRect.centerX() + " , centerY= " + startRect.centerY()); Log.w(TAG, "createAnimator: end rect center x = " + endRect.centerX() + " , centerY= " + endRect.centerY()); ObjectAnimator objectAnimator = ObjectAnimator.ofObject(view, new PropPosition(PointF.class, "position", new PointF(startRect.centerX(), startRect.centerY())), null, changePosPath); objectAnimator.setInterpolator(new FastOutSlowInInterpolator()); return objectAnimator; } return null; }
From source file:com.example.carlitos.swipeitemrecycler.view.animation.swipe_item.swipeable.RemovingItemDecorator.java
private void fillSwipingItemBackground(Canvas c, Drawable drawable, float scale) { final Rect bounds = mSwipingItemBounds; final int translationX = mTranslationX; final int translationY = mTranslationY; final float hScale = (mHorizontal) ? 1.0f : scale; final float vScale = (mHorizontal) ? scale : 1.0f; int width = (int) (hScale * bounds.width() + 0.5f); int height = (int) (vScale * bounds.height() + 0.5f); if ((height == 0) || (width == 0) || (drawable == null)) { return;/*w ww . ja va 2s. com*/ } final int savedCount = c.save(); c.clipRect(bounds.left + translationX, bounds.top + translationY, bounds.left + translationX + width, bounds.top + translationY + height); // c.drawColor(0xffff0000); // <-- debug c.translate(bounds.left + translationX - (bounds.width() - width) / 2, bounds.top + translationY - (bounds.height() - height) / 2); drawable.setBounds(0, 0, bounds.width(), bounds.height()); drawable.draw(c); c.restoreToCount(savedCount); }
From source file:ch.carteggio.ui.ConversationIconLoader.java
/** * Calculates a bitmap with a color and a capital letter for contacts without picture. *//*from w w w . jav a 2 s .c o m*/ private Bitmap calculateFallbackBitmap(String emails[]) { Bitmap result = Bitmap.createBitmap(mPictureSizeInPx, mPictureSizeInPx, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); int rgb = CONTACT_DUMMY_COLORS_ARGB[0]; if (emails.length > 0) { calcUnknownContactColor(emails[0]); } result.eraseColor(rgb); String letter = FALLBACK_CONTACT_LETTER; Paint paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL); paint.setARGB(255, 255, 255, 255); paint.setTextSize(mPictureSizeInPx * 3 / 4); // just scale this down a bit Rect rect = new Rect(); paint.getTextBounds(letter, 0, 1, rect); float width = paint.measureText(letter); canvas.drawText(letter, (mPictureSizeInPx / 2f) - (width / 2f), (mPictureSizeInPx / 2f) + (rect.height() / 2f), paint); return result; }
From source file:com.android.gallery3d.data.UriImage.java
public Bitmap drawTextToBitmap(Context gContext, String gText, Bitmap bitmap) { Resources resources = gContext.getResources(); float scale = resources.getDisplayMetrics().density; android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }/* w ww . jav a 2s .c o m*/ // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(Color.rgb(61, 61, 61)); // text size in pixels paint.setTextSize((int) (25 * scale)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); // draw text to the Canvas center Rect bounds = new Rect(); paint.setTextAlign(Align.CENTER); paint.getTextBounds(gText, 0, gText.length(), bounds); int x = (bitmap.getWidth() - bounds.width()) / 2; int y = (bitmap.getHeight() + bounds.height()) / 2; canvas.drawText(gText, x * scale, y * scale, paint); return bitmap; }
From source file:com.dastanapps.camera2.view.Cam2AutoFitTextureView.java
@Nullable private Boolean touchTofocus2(MotionEvent event) { MotionEvent motionEvent = event;/*from www .j a va2s . com*/ final int actionMasked = motionEvent.getActionMasked(); if (actionMasked != MotionEvent.ACTION_DOWN) { return false; } if (mManualFocusEngaged) { Log.d(TAG, "Manual focus already engaged"); return true; } final Rect sensorArraySize = mCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); //TODO: here I just flip x,y, but this needs to correspond with the sensor orientation (via SENSOR_ORIENTATION) final int y = (int) ((motionEvent.getX() / (float) getWidth()) * (float) sensorArraySize.height()); final int x = (int) ((motionEvent.getY() / (float) getHeight()) * (float) sensorArraySize.width()); final int halfTouchWidth = 150; //(int)motionEvent.getTouchMajor(); //TODO: this doesn't represent actual touch size in pixel. Values range in [3, 10]... final int halfTouchHeight = 150; //(int)motionEvent.getTouchMinor(); MeteringRectangle focusAreaTouch = new MeteringRectangle(Math.max(x - halfTouchWidth, 0), Math.max(y - halfTouchHeight, 0), halfTouchWidth * 2, halfTouchHeight * 2, MeteringRectangle.METERING_WEIGHT_MAX - 1); CameraCaptureSession.CaptureCallback captureCallbackHandler = new CameraCaptureSession.CaptureCallback() { @Override public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { super.onCaptureCompleted(session, request, result); mManualFocusEngaged = false; if (request.getTag() == "FOCUS_TAG") { //the focus trigger is complete - //resume repeating (preview surface will get frames), clear AF trigger mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, null); try { mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), null, null); } catch (CameraAccessException e) { e.printStackTrace(); } } } @Override public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure) { super.onCaptureFailed(session, request, failure); Log.e(TAG, "Manual AF failure: " + failure); mManualFocusEngaged = false; } }; //first stop the existing repeating request try { mPreviewSession.stopRepeating(); } catch (CameraAccessException e) { e.printStackTrace(); } //cancel any existing AF trigger (repeated touches, etc.) mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF); try { mPreviewSession.capture(mPreviewBuilder.build(), captureCallbackHandler, null); } catch (CameraAccessException e) { e.printStackTrace(); } //Now add a new AF trigger with focus region if (isMeteringAreaAFSupported()) { mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[] { focusAreaTouch }); } mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO); mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START); mPreviewBuilder.setTag("FOCUS_TAG"); //we'll capture this later for resuming the preview // //then we ask for a single request (not repeating!) // mPreviewSession.capture(mPreviewBuilder.build(), captureCallbackHandler, mBackgroundHandler); return null; }
From source file:com.android.camera.HighlightView.java
void handleMotion(int edge, float dx, float dy) { Rect r = computeLayout(); if (edge == GROW_NONE) { return;//from w ww .j av a2 s. c om } else if (edge == MOVE) { // Convert to image space before sending to moveBy(). moveBy(dx * (mCropRect.width() / r.width()), dy * (mCropRect.height() / r.height())); } else { if (((GROW_LEFT_EDGE | GROW_RIGHT_EDGE) & edge) == 0) { dx = 0; } if (((GROW_TOP_EDGE | GROW_BOTTOM_EDGE) & edge) == 0) { dy = 0; } // Convert to image space before sending to growBy(). float xDelta = dx * (mCropRect.width() / r.width()); float yDelta = dy * (mCropRect.height() / r.height()); growBy((((edge & GROW_LEFT_EDGE) != 0) ? -1 : 1) * xDelta, (((edge & GROW_TOP_EDGE) != 0) ? -1 : 1) * yDelta); } }
From source file:com.facebook.imagepipeline.platform.DefaultDecoder.java
/** * Create a bitmap from an input stream. * * @param inputStream the InputStream/* w w w. j a v a 2 s. c o m*/ * @param options the {@link android.graphics.BitmapFactory.Options} used to decode the stream * @param regionToDecode optional image region to decode or null to decode the whole image * @param transformToSRGB whether to allow color space transformation to sRGB at load time * @return the bitmap */ private CloseableReference<Bitmap> decodeFromStream(InputStream inputStream, BitmapFactory.Options options, @Nullable Rect regionToDecode, final boolean transformToSRGB) { Preconditions.checkNotNull(inputStream); int targetWidth = options.outWidth; int targetHeight = options.outHeight; if (regionToDecode != null) { targetWidth = regionToDecode.width() / options.inSampleSize; targetHeight = regionToDecode.height() / options.inSampleSize; } int sizeInBytes = getBitmapSize(targetWidth, targetHeight, options); final Bitmap bitmapToReuse = mBitmapPool.get(sizeInBytes); if (bitmapToReuse == null) { throw new NullPointerException("BitmapPool.get returned null"); } options.inBitmap = bitmapToReuse; // Performs transformation at load time to sRGB. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && transformToSRGB) { options.inPreferredColorSpace = ColorSpace.get(ColorSpace.Named.SRGB); } Bitmap decodedBitmap = null; ByteBuffer byteBuffer = mDecodeBuffers.acquire(); if (byteBuffer == null) { byteBuffer = ByteBuffer.allocate(DECODE_BUFFER_SIZE); } try { options.inTempStorage = byteBuffer.array(); if (regionToDecode != null) { BitmapRegionDecoder bitmapRegionDecoder = null; try { bitmapToReuse.reconfigure(targetWidth, targetHeight, options.inPreferredConfig); bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, true); decodedBitmap = bitmapRegionDecoder.decodeRegion(regionToDecode, options); } catch (IOException e) { FLog.e(TAG, "Could not decode region %s, decoding full bitmap instead.", regionToDecode); } finally { if (bitmapRegionDecoder != null) { bitmapRegionDecoder.recycle(); } } } if (decodedBitmap == null) { decodedBitmap = BitmapFactory.decodeStream(inputStream, null, options); } } catch (IllegalArgumentException e) { mBitmapPool.release(bitmapToReuse); // This is thrown if the Bitmap options are invalid, so let's just try to decode the bitmap // as-is, which might be inefficient - but it works. try { // We need to reset the stream first inputStream.reset(); Bitmap naiveDecodedBitmap = BitmapFactory.decodeStream(inputStream); if (naiveDecodedBitmap == null) { throw e; } return CloseableReference.of(naiveDecodedBitmap, SimpleBitmapReleaser.getInstance()); } catch (IOException re) { // We throw the original exception instead since it's the one causing this workaround in the // first place. throw e; } } catch (RuntimeException re) { mBitmapPool.release(bitmapToReuse); throw re; } finally { mDecodeBuffers.release(byteBuffer); } if (bitmapToReuse != decodedBitmap) { mBitmapPool.release(bitmapToReuse); decodedBitmap.recycle(); throw new IllegalStateException(); } return CloseableReference.of(decodedBitmap, mBitmapPool); }
From source file:com.example.gatsu.theevent.HighlightView.java
protected void draw(Canvas canvas) { if (mHidden) { return;// w w w . j av a2 s. c om } Path path = new Path(); if (!hasFocus()) { mOutlinePaint.setColor(0xFF000000); canvas.drawRect(mDrawRect, mOutlinePaint); } else { Rect viewDrawingRect = new Rect(); mContext.getDrawingRect(viewDrawingRect); if (mCircle) { canvas.save(); float width = mDrawRect.width(); float height = mDrawRect.height(); path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2, Path.Direction.CW); mOutlinePaint.setColor(0xFFEF04D6); canvas.clipPath(path, Region.Op.DIFFERENCE); canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint); canvas.restore(); } else { Rect topRect = new Rect(viewDrawingRect.left, viewDrawingRect.top, viewDrawingRect.right, mDrawRect.top); if (topRect.width() > 0 && topRect.height() > 0) { canvas.drawRect(topRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect bottomRect = new Rect(viewDrawingRect.left, mDrawRect.bottom, viewDrawingRect.right, viewDrawingRect.bottom); if (bottomRect.width() > 0 && bottomRect.height() > 0) { canvas.drawRect(bottomRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect leftRect = new Rect(viewDrawingRect.left, topRect.bottom, mDrawRect.left, bottomRect.top); if (leftRect.width() > 0 && leftRect.height() > 0) { canvas.drawRect(leftRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } Rect rightRect = new Rect(mDrawRect.right, topRect.bottom, viewDrawingRect.right, bottomRect.top); if (rightRect.width() > 0 && rightRect.height() > 0) { canvas.drawRect(rightRect, hasFocus() ? mFocusPaint : mNoFocusPaint); } path.addRect(new RectF(mDrawRect), Path.Direction.CW); mOutlinePaint.setColor(0xFFFF8A00); } canvas.drawPath(path, mOutlinePaint); if (mMode == ModifyMode.Grow) { if (mCircle) { int width = mResizeDrawableDiagonal.getIntrinsicWidth(); int height = mResizeDrawableDiagonal.getIntrinsicHeight(); int d = (int) Math.round(Math.cos(/*45deg*/Math.PI / 4D) * (mDrawRect.width() / 2D)); int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2; int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2; mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(), y + mResizeDrawableDiagonal.getIntrinsicHeight()); mResizeDrawableDiagonal.draw(canvas); } else { int left = mDrawRect.left + 1; int right = mDrawRect.right + 1; int top = mDrawRect.top + 4; int bottom = mDrawRect.bottom + 3; int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2; int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2; int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2; int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2; int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2); int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2); mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth, yMiddle + widthHeight); mResizeDrawableWidth.draw(canvas); mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth, yMiddle + widthHeight); mResizeDrawableWidth.draw(canvas); mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight, xMiddle + heightWidth, top + heightHeight); mResizeDrawableHeight.draw(canvas); mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight, xMiddle + heightWidth, bottom + heightHeight); mResizeDrawableHeight.draw(canvas); } } } }
From source file:com.raulh82vlc.face_detection_sample.camera2.presentation.FDCamera2Presenter.java
/** * Maps {@link Rect} face bounds from Camera 2 API towards the model used throughout the samples * then passes the RecognisedFace object back * @param faceBounds/*from www.j a v a2 s . co m*/ * @param leftEyePosition * @param rightEyePosition */ private Face mapCameraFaceToCanvas(Rect faceBounds, Point leftEyePosition, Point rightEyePosition) { if (isViewAvailable()) { int w = faceBounds.width(); int h = faceBounds.height(); Face face = new Face(faceBounds.centerX() - w, faceBounds.centerY(), w, h); if (leftEyePosition != null) { face.setIrisLeft(leftEyePosition.x, leftEyePosition.y); } return face; } return new Face(); }
From source file:com.huahcoding.metrojam.BackTrackActivity.java
/** * This is where we can add markers or lines, add listeners or move the camera. In this case, we * just add a marker near Africa.// w w w . j a v a 2 s .co m * <p> * This should only be called once and when we are sure that {@link #mMap} is not null. */ private void setUpMap() { mMap.getUiSettings().setZoomControlsEnabled(false); // Show Lima mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(chileLatLng, 15)); mMap.setOnMapLongClickListener(this); mMap.setMyLocationEnabled(true); mMap.setTrafficEnabled(true); // Instantiates a new Polyline object and adds points to define a rectangle PolylineOptions rectOptions = new PolylineOptions(); double[] route = RouteTestData.getChilePoints3(); for (int i = 0; i < route.length - 1; i += 2) { LatLng ll = new LatLng(route[i], route[i + 1]); if (i > 1) { double lat = (route[i] + route[i - 2]) / 2.0; double lng = (route[i + 1] + route[i + 1 - 2]) / 2.0; double dist = distance(route[i], route[i + 1], route[i - 2], route[i + 1 - 2]); String pretty = getPrettyDistance(dist); LatLng ll2 = new LatLng(lat, lng); String strText = pretty; Rect boundsText = new Rect(); Paint textPaint = new Paint(); textPaint.setTextSize(18); textPaint.getTextBounds(strText, 0, strText.length(), boundsText); textPaint.setColor(Color.RED); Bitmap.Config conf = Bitmap.Config.ARGB_8888; Bitmap bmpText = Bitmap.createBitmap(boundsText.width() * 3, boundsText.height(), conf); Canvas canvasText = new Canvas(bmpText); canvasText.drawText(strText, canvasText.getWidth() / 2, canvasText.getHeight(), textPaint); MarkerOptions markerOptions = new MarkerOptions().position(ll2) .icon(BitmapDescriptorFactory.fromBitmap(bmpText)).anchor(0.5f, 1); mMap.addMarker(markerOptions); } rectOptions.add(ll); } // rectOptions. // Get back the mutable Polyline mMap.addPolyline(rectOptions); }