List of usage examples for android.graphics Rect width
public final int width()
From source file:org.adw.library.widgets.discreteseekbar.internal.drawable.AlmostRippleDrawable.java
@Override public void doDraw(Canvas canvas, Paint paint) { Rect bounds = getBounds(); int size = Math.min(bounds.width(), bounds.height()); float scale = mCurrentScale; int rippleColor = mRippleColor; int bgColor = mRippleBgColor; float radius = (size / 2); float radiusAnimated = radius * scale; if (scale > INACTIVE_SCALE) { if (bgColor != 0) { paint.setColor(bgColor);// w ww .j a v a2s.c o m paint.setAlpha(decreasedAlpha(Color.alpha(bgColor))); canvas.drawCircle(bounds.centerX(), bounds.centerY(), radius, paint); } if (rippleColor != 0) { paint.setColor(rippleColor); paint.setAlpha(modulateAlpha(Color.alpha(rippleColor))); canvas.drawCircle(bounds.centerX(), bounds.centerY(), radiusAnimated, paint); } } }
From source file:com.coco.rolldigitaltextview.RollDigitalTextView.java
private boolean isCompleteShown() { if (isShown()) { final Rect visibleRect = new Rect(); if (getLocalVisibleRect(visibleRect) && visibleRect.width() == getWidth() && visibleRect.height() == getHeight()) { return true; }/* w ww .j a v a 2s . c o m*/ } return false; }
From source file:com.jun.elephant.ui.widget.VoteDialog.java
private void initContentView() { View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_vote, null); Rect displayRectangle = new Rect(); Window window = getWindow();//from w ww. j a v a 2 s . c om window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle); view.setMinimumWidth((int) (displayRectangle.width() * 0.8f)); window.setBackgroundDrawableResource(R.color.dialog_bg); setContentView(view); }
From source file:im.neon.util.VectorUtils.java
/** * Create an avatar bitmap from a text.//from ww w . j a v a2s .co m * * @param backgroundColor the background color. * @param text the text to display. * @param pixelsSide the avatar side in pixels * @return the generated bitmap */ private static Bitmap createAvatar(int backgroundColor, String text, int pixelsSide) { android.graphics.Bitmap.Config bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; Bitmap bitmap = Bitmap.createBitmap(pixelsSide, pixelsSide, bitmapConfig); Canvas canvas = new Canvas(bitmap); canvas.drawColor(backgroundColor); // prepare the text drawing Paint textPaint = new Paint(); textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); textPaint.setColor(Color.WHITE); // the text size is proportional to the avatar size. // by default, the avatar size is 42dp, the text size is 28 dp (not sp because it has to be fixed). textPaint.setTextSize(pixelsSide * 2 / 3); // get its size Rect textBounds = new Rect(); textPaint.getTextBounds(text, 0, text.length(), textBounds); // draw the text in center canvas.drawText(text, (canvas.getWidth() - textBounds.width() - textBounds.left) / 2, (canvas.getHeight() + textBounds.height() - textBounds.bottom) / 2, textPaint); // Return the avatar return bitmap; }
From source file:com.tr4android.support.extension.drawable.IndeterminateProgressDrawable.java
/** * Helper that calculates the bounds and the stroke width of the progress arc * * @param bounds the bounds of the drawable *//*from w w w . j a v a 2s . c om*/ private void calculateArcMetrics(Rect bounds) { float size = Math.min(bounds.height(), bounds.width()); float yOffset = (bounds.height() - size) / 2f; float xOffset = (bounds.width() - size) / 2f; float strokeWidth; float padding; if (mArcStrokeWidth == -1f && mArcPadding == -1f) { // auto calculate bounds strokeWidth = 4f / 48f * size; padding = 5f / 48f * size; } else if (mArcStrokeWidth == -1f) { // auto calculate stroke width strokeWidth = 4f / 48f * size; padding = mArcPadding + strokeWidth / 2; } else if (mArcPadding == -1f) { // auto calculate padding strokeWidth = mArcStrokeWidth; padding = 3f / 48f * size + strokeWidth / 2; } else { strokeWidth = mArcStrokeWidth; padding = mArcPadding + strokeWidth / 2; } mArcPaint.setStrokeWidth(strokeWidth); mArcRect.set(bounds.left + padding + xOffset, bounds.top + padding + yOffset, bounds.right - padding - xOffset, bounds.bottom - padding - yOffset); }
From source file:Main.java
/** * Special crop of bitmap rotated by not stright angle, in this case the original crop bitmap contains parts * beyond the required crop area, this method crops the already cropped and rotated bitmap to the final * rectangle.<br>/*from ww w. j ava 2s .co m*/ * Note: rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping. */ private static Bitmap cropForRotatedImage(Bitmap bitmap, float[] points, Rect rect, int degreesRotated, boolean fixAspectRatio, int aspectRatioX, int aspectRatioY) { if (degreesRotated % 90 != 0) { int adjLeft = 0, adjTop = 0, width = 0, height = 0; double rads = Math.toRadians(degreesRotated); int compareTo = degreesRotated < 90 || (degreesRotated > 180 && degreesRotated < 270) ? rect.left : rect.right; for (int i = 0; i < points.length; i += 2) { if (points[i] >= compareTo - 1 && points[i] <= compareTo + 1) { adjLeft = (int) Math.abs(Math.sin(rads) * (rect.bottom - points[i + 1])); adjTop = (int) Math.abs(Math.cos(rads) * (points[i + 1] - rect.top)); width = (int) Math.abs((points[i + 1] - rect.top) / Math.sin(rads)); height = (int) Math.abs((rect.bottom - points[i + 1]) / Math.cos(rads)); break; } } rect.set(adjLeft, adjTop, adjLeft + width, adjTop + height); if (fixAspectRatio) { fixRectForAspectRatio(rect, aspectRatioX, aspectRatioY); } Bitmap bitmapTmp = bitmap; bitmap = Bitmap.createBitmap(bitmap, rect.left, rect.top, rect.width(), rect.height()); if (bitmapTmp != bitmap) { bitmapTmp.recycle(); } } return bitmap; }
From source file:com.sebible.cordova.videosnapshot.VideoSnapshot.java
private void drawTimestamp(Bitmap bm, String prefix, long timeMs, int textSize) { float w = bm.getWidth(), h = bm.getHeight(); float size = (float) (textSize * bm.getWidth()) / 1280; float margin = (float) (w < h ? w : h) * 0.05f; Canvas c = new Canvas(bm); Paint p = new Paint(); p.setColor(Color.WHITE);//from w w w . j a v a 2 s . c om p.setStrokeWidth((int) (size / 10)); p.setTextSize((int) size); // Text Size p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text Overlapping Pattern long second = (timeMs / 1000) % 60; long minute = (timeMs / (1000 * 60)) % 60; long hour = (timeMs / (1000 * 60 * 60)) % 24; String text = String.format("%s %02d:%02d:%02d", prefix, hour, minute, second); Rect r = new Rect(); p.getTextBounds(text, 0, text.length(), r); //c.drawBitmap(originalBitmap, 0, 0, paint); c.drawText(text, bm.getWidth() - r.width() - margin, bm.getHeight() - r.height() - margin, p); }
From source file:com.github.kubatatami.RoundedView.java
private void drawText(Canvas canvas) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(getResources().getDimension(R.dimen.item_circle_text_size)); Rect areaRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); RectF bounds = new RectF(areaRect); bounds.right = paint.measureText(text, 0, text.length()); bounds.bottom = paint.descent() - paint.ascent(); bounds.left += (areaRect.width() - bounds.right) / 2.0f; bounds.top += (areaRect.height() - bounds.bottom) / 2.0f; paint.setColor(Color.WHITE);//from w ww .ja v a 2s . c o m canvas.drawText(text, bounds.left, bounds.top - paint.ascent(), paint); }
From source file:com.callba.phone.widget.refreshlayout.SwipeProgressBar.java
void draw(Canvas canvas) { Rect bounds = mBounds; final int width = bounds.width(); final int height = bounds.height(); final int cx = bounds.centerX(); final int cy = bounds.centerY(); boolean drawTriggerWhileFinishing = false; int restoreCount = canvas.save(); canvas.clipRect(bounds);//from www . java 2 s . c om if (mRunning || (mFinishTime > 0)) { long now = AnimationUtils.currentAnimationTimeMillis(); long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS; long iterations = (now - mStartTime) / ANIMATION_DURATION_MS; float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f)); // If we're not running anymore, that means we're running through // the finish animation. if (!mRunning) { // If the finish animation is done, don't draw anything, and // don't repost. if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) { mFinishTime = 0; return; } // Otherwise, use a 0 opacity alpha layer to clear the animation // from the inside out. This layer will prevent the circles from // drawing within its bounds. long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS; float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f)); float pct = (finishProgress / 100f); // Radius of the community is half of the screen. float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct); mClipRect.set(cx - clearRadius, 0, cx + clearRadius, height); canvas.saveLayerAlpha(mClipRect, 0, 0); // Only draw the trigger if there is a space in the center of // this refreshing view that needs to be filled in by the // trigger. If the progress view is just still animating, let it // continue animating. drawTriggerWhileFinishing = true; } // First fill in with the last color that would have finished drawing. if (iterations == 0) { canvas.drawColor(mColor1); } else { if (rawProgress >= 0 && rawProgress < 25) { canvas.drawColor(mColor4); } else if (rawProgress >= 25 && rawProgress < 50) { canvas.drawColor(mColor1); } else if (rawProgress >= 50 && rawProgress < 75) { canvas.drawColor(mColor2); } else { canvas.drawColor(mColor3); } } // Then draw up to 4 overlapping concentric circles of varying radii, based on how far // along we are in the cycle. // progress 0-50 draw mColor2 // progress 25-75 draw mColor3 // progress 50-100 draw mColor4 // progress 75 (wrap to 25) draw mColor1 if ((rawProgress >= 0 && rawProgress <= 25)) { float pct = (((rawProgress + 25) * 2) / 100f); drawCircle(canvas, cx, cy, mColor1, pct); } if (rawProgress >= 0 && rawProgress <= 50) { float pct = ((rawProgress * 2) / 100f); drawCircle(canvas, cx, cy, mColor2, pct); } if (rawProgress >= 25 && rawProgress <= 75) { float pct = (((rawProgress - 25) * 2) / 100f); drawCircle(canvas, cx, cy, mColor3, pct); } if (rawProgress >= 50 && rawProgress <= 100) { float pct = (((rawProgress - 50) * 2) / 100f); drawCircle(canvas, cx, cy, mColor4, pct); } if ((rawProgress >= 75 && rawProgress <= 100)) { float pct = (((rawProgress - 75) * 2) / 100f); drawCircle(canvas, cx, cy, mColor1, pct); } if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) { // There is some portion of trigger to draw. Restore the canvas, // then draw the trigger. Otherwise, the trigger does not appear // until after the bar has finished animating and appears to // just jump in at a larger width than expected. canvas.restoreToCount(restoreCount); restoreCount = canvas.save(); canvas.clipRect(bounds); drawTrigger(canvas, cx, cy); } // Keep running until we finish out the last cycle. ViewCompat.postInvalidateOnAnimation(mParent, bounds.left, bounds.top, bounds.right, bounds.bottom); } else { // Otherwise if we're in the middle of a trigger, draw that. if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) { drawTrigger(canvas, cx, cy); } } canvas.restoreToCount(restoreCount); }
From source file:com.cyan.widget.refreshlayout.SwipeProgressBar.java
void draw(Canvas canvas) { Rect bounds = mBounds; final int width = bounds.width(); final int height = bounds.height(); final int cx = bounds.centerX(); final int cy = bounds.centerY(); boolean drawTriggerWhileFinishing = false; int restoreCount = canvas.save(); canvas.clipRect(bounds);/* ww w.j a v a 2s. com*/ if (mRunning || (mFinishTime > 0)) { long now = AnimationUtils.currentAnimationTimeMillis(); long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS; long iterations = (now - mStartTime) / ANIMATION_DURATION_MS; float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f)); // If we're not running anymore, that means we're running through // the finish animation. if (!mRunning) { // If the finish animation is done, don't draw anything, and // don't repost. if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) { mFinishTime = 0; return; } // Otherwise, use a 0 opacity alpha layer to clear the animation // from the inside out. This layer will prevent the circles from // drawing within its bounds. long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS; float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f)); float pct = (finishProgress / 100f); // Radius of the circle is half of the screen. float clearRadius = width / 2 * INTERPOLATOR.getInterpolation(pct); mClipRect.set(cx - clearRadius, 0, cx + clearRadius, height); canvas.saveLayerAlpha(mClipRect, 0, 0); // Only draw the trigger if there is a space in the center of // this refreshing view that needs to be filled in by the // trigger. If the progress view is just still animating, let it // continue animating. drawTriggerWhileFinishing = true; } // First fill in with the last color that would have finished drawing. if (iterations == 0) { canvas.drawColor(mColor1); } else { if (rawProgress >= 0 && rawProgress < 25) { canvas.drawColor(mColor4); } else if (rawProgress >= 25 && rawProgress < 50) { canvas.drawColor(mColor1); } else if (rawProgress >= 50 && rawProgress < 75) { canvas.drawColor(mColor2); } else { canvas.drawColor(mColor3); } } // Then draw up to 4 overlapping concentric circles of varying radii, based on how far // along we are in the cycle. // progress 0-50 draw mColor2 // progress 25-75 draw mColor3 // progress 50-100 draw mColor4 // progress 75 (wrap to 25) draw mColor1 if ((rawProgress >= 0 && rawProgress <= 25)) { float pct = (((rawProgress + 25) * 2) / 100f); drawCircle(canvas, cx, cy, mColor1, pct); } if (rawProgress >= 0 && rawProgress <= 50) { float pct = ((rawProgress * 2) / 100f); drawCircle(canvas, cx, cy, mColor2, pct); } if (rawProgress >= 25 && rawProgress <= 75) { float pct = (((rawProgress - 25) * 2) / 100f); drawCircle(canvas, cx, cy, mColor3, pct); } if (rawProgress >= 50 && rawProgress <= 100) { float pct = (((rawProgress - 50) * 2) / 100f); drawCircle(canvas, cx, cy, mColor4, pct); } if ((rawProgress >= 75 && rawProgress <= 100)) { float pct = (((rawProgress - 75) * 2) / 100f); drawCircle(canvas, cx, cy, mColor1, pct); } if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) { // There is some portion of trigger to draw. Restore the canvas, // then draw the trigger. Otherwise, the trigger does not appear // until after the bar has finished animating and appears to // just jump in at a larger width than expected. canvas.restoreToCount(restoreCount); restoreCount = canvas.save(); canvas.clipRect(bounds); drawTrigger(canvas, cx, cy); } // Keep running until we finish out the last cycle. ViewCompat.postInvalidateOnAnimation(mParent, bounds.left, bounds.top, bounds.right, bounds.bottom); } else { // Otherwise if we're in the middle of a trigger, draw that. if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) { drawTrigger(canvas, cx, cy); } } canvas.restoreToCount(restoreCount); }