List of usage examples for android.graphics Rect width
public final int width()
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 a2 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); }
From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java
/** * This function calculates a screen to image Transformation matrix. * * @param reflectRotation/*from w ww .j av a2s. c om*/ * set true if you want the rotation encoded. * TODO useless, to be removed. * @return Screen to Image transformation matrix */ protected Matrix getScreenToImageMatrix(boolean reflectRotation) { Rect originalBounds = mMasterImage.getOriginalBounds(); int imgWidth = originalBounds.width(); int imgHeight = originalBounds.height(); Matrix m = mMasterImage.getImageToScreenMatrix(imgWidth, imgHeight, getWidth(), getHeight()); Matrix invert = new Matrix(); m.invert(invert); return invert; }
From source file:org.caojun.library.cropimage.HighlightView.java
protected void draw(Canvas canvas) { if (mHidden) { return;/*w w w . j a va 2s. c o m*/ } Path path = new Path(); if (!hasFocus()) { mOutlinePaint.setColor(0xFF000000); canvas.drawRect(mDrawRect, mOutlinePaint); } else { Rect viewDrawingRect = new Rect(); mView.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.gruporaido.tasker_library.util.Helper.java
/** * @param drawableId/*from www . j a v a 2 s . c o m*/ * @param text * @param textSize * @param offsetX * @param offsetY * @return */ public Bitmap drawTextOnDrawable(int drawableId, String text, int textSize, int offsetX, int offsetY) { Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true); Typeface tf = Typeface.create("Helvetica", Typeface.BOLD); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE); paint.setTypeface(tf); paint.setTextAlign(Paint.Align.CENTER); paint.setTextSize(dpToPx(textSize)); Rect textRect = new Rect(); paint.getTextBounds(text, 0, text.length(), textRect); Canvas canvas = new Canvas(bm); //If the text is bigger than the canvas , reduce the font size if (textRect.width() >= (canvas.getWidth() - 4)) //the padding on either sides is considered as 4, so as to appropriately fit in the text paint.setTextSize(dpToPx(textSize / 2)); //Scaling needs to be used for different dpi's //Calculate the positions int xPos = (canvas.getWidth() / 2) - 2 + dpToPx(offsetX); //-2 is for regulating the x position offset //"- ((paint.descent() + paint.ascent()) / 2)" is the distance from the baseline to the center. int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)) + dpToPx(offsetY); canvas.drawText(text, xPos, yPos, paint); return bm; }
From source file:com.android.contacts.activities.PhotoSelectionActivity.java
/** * Compute the adjusted expanded photo size to fit within the enclosing view with the same * aspect ratio.//from w ww.j a va 2 s. c om * @param enclosingView This is the view that the photo must fit within. * @param heightOffset This is the amount of height to leave open for the photo action popup. */ private int getAdjustedExpandedPhotoSize(View enclosingView, int heightOffset) { // pull out the bounds of the backdrop final Rect bounds = new Rect(); enclosingView.getDrawingRect(bounds); final int boundsWidth = bounds.width(); final int boundsHeight = bounds.height() - heightOffset; // ensure that the new expanded photo size can fit within the backdrop final float alpha = Math.min((float) boundsHeight / (float) mExpandedPhotoSize, (float) boundsWidth / (float) mExpandedPhotoSize); if (alpha < 1.0f) { // need to shrink width and height while maintaining aspect ratio return (int) (alpha * mExpandedPhotoSize); } else { return mExpandedPhotoSize; } }
From source file:com.vincestyling.traversaless_testcase.TopTabIndicator.java
public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) return true; if (mViewPager == null) return false; final int count = getCount(); if (count == 0) return false; final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX();//from w w w . j a va2 s . c o m break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { mLastMotionX = x; if (isFakeDragging() || beginFakeDrag()) { fakeDragBy(deltaX); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { Rect areaRect = new Rect(); areaRect.left = getPaddingLeft(); areaRect.right = getWidth() - getPaddingRight(); areaRect.top = getPaddingTop(); areaRect.bottom = getHeight() - getPaddingBottom(); int btnWidth = areaRect.width() / count; for (int pos = 0; pos < count; pos++) { RectF tabRect = new RectF(areaRect); tabRect.left += pos * btnWidth; tabRect.right = tabRect.left + btnWidth; if (tabRect.contains(ev.getX(), ev.getY())) { setCurrentItem(pos); return true; } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (isFakeDragging()) endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.mikelau.croperino.HighlightView.java
protected void draw(Canvas canvas) { if (mHidden) { return;// w ww. j a va2 s . c o m } 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 if (mOvalo) { canvas.save(); RectF r = new RectF(mDrawRect.left, mDrawRect.top, mDrawRect.right, mDrawRect.bottom); path.addOval(r, 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.duy.pascal.ui.editor.view.CodeSuggestsEditText.java
/** * this method will be change size of popup window *//* ww w.j av a 2 s .co m*/ protected void onDropdownChangeSize(int w, int h) { Rect rect = new Rect(); getWindowVisibleDisplayFrame(rect); DLog.d(TAG, "onDropdownChangeSize: " + rect); w = rect.width(); h = rect.height(); // 1/2 width of screen setDropDownWidth((int) (w * 0.7f)); // 0.5 height of screen setDropDownHeight((int) (h * 0.5f)); //change position onPopupChangePosition(); }
From source file:com.example.conallcurran.quick_click.English_Infants.java
private void zoomImageFromThumb(final View thumbView, int imageResId) { if (mCurrentAnimator != null) { mCurrentAnimator.cancel();/*from w ww .j av a2 s . com*/ } final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image); expandedImageView.setImageResource(imageResId); final Rect startBounds = new Rect(); final Rect finalBounds = new Rect(); final Point globalOffset = new Point(); thumbView.getGlobalVisibleRect(startBounds); findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset); startBounds.offset(-globalOffset.x, -globalOffset.y); finalBounds.offset(-globalOffset.x, -globalOffset.y); float startScale; if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) { startScale = (float) startBounds.height() / finalBounds.height(); float startWidth = startScale * finalBounds.width(); float deltaWidth = (startWidth - startBounds.width()) / 2; startBounds.left -= deltaWidth; startBounds.right += deltaWidth; } else { // Extend start bounds vertically startScale = (float) startBounds.width() / finalBounds.width(); float startHeight = startScale * finalBounds.height(); float deltaHeight = (startHeight - startBounds.height()) / 2; startBounds.top -= deltaHeight; startBounds.bottom += deltaHeight; } thumbView.setAlpha(0f); expandedImageView.setVisibility(View.VISIBLE); expandedImageView.setPivotX(0f); expandedImageView.setPivotY(0f); AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; final float startScaleFinal = startScale; expandedImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Animate the four positioning/sizing properties in parallel, back to their // original values. AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; } }); }
From source file:de.madvertise.android.sdk.MadView.java
/** * Convenicence method for a shiny background for text ads * /*from www.ja v a2s . c om*/ * @param rect * @param backgroundColor * @param textColor * @return */ private BitmapDrawable generateBackgroundDrawable(Rect rect, int backgroundColor, int shineColor) { try { Bitmap bitmap = Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawTextBannerBackground(canvas, rect, backgroundColor, shineColor); return new BitmapDrawable(bitmap); } catch (Throwable t) { return null; } }