List of usage examples for android.graphics RectF RectF
public RectF(float left, float top, float right, float bottom)
From source file:com.jaredrummler.android.colorpicker.ColorPanelView.java
private void setUpCenterRect() { final Rect dRect = drawingRect; int left = dRect.left + borderWidthPx; int top = dRect.top + borderWidthPx; int bottom = dRect.bottom - borderWidthPx; int right = dRect.right - borderWidthPx; centerRect = new RectF(left, top, right, bottom); }
From source file:com.bdcorps.videonews.MainActivity.java
public void grabnews(String topicCode) { int pos = article; try {// w ww . j a v a 2s .c o m JSONArray a = Config.initNewsRequest(topicCode); // for (int i = 0; i<json.getInt("num_results");i++) { final JSONObject b = (JSONObject) a.get(article); JSONArray c = b.getJSONArray("multimedia"); if (c.length() > 4) { JSONObject d = (JSONObject) c.get(4); String url = d.getString("url"); final String title = b.getString("title"); try { new DownloadImageTask(new DownloadImageTask.AsyncResponse() { @Override public void processFinish(Bitmap result) { Paint myRectPaint = new Paint(); int x1 = 0; int y1 = 0; int x2 = 500; int y2 = 500; //Create a new image bitmap and attach a brand new canvas to it Bitmap tempBitmap = Bitmap.createBitmap(result.getWidth(), result.getHeight(), Bitmap.Config.RGB_565); Canvas tempCanvas = new Canvas(tempBitmap); //Draw the image bitmap into the cavas tempCanvas.drawBitmap(result, 0, 0, null); //Draw everything else you want into the canvas, in this example a rectangle with rounded edges tempCanvas.drawRoundRect(new RectF(x1, y1, x2, y2), 2, 2, myRectPaint); titleTextView.setText(title); img.setImageBitmap(tempBitmap); } }, img).execute(url).get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } runOnUiThread(new Runnable() { @Override public void run() { try { text.setText(b.getString("abstract")); Log.i("SSS", "abstract is = " + text.getText().toString()); canSpeak = true; } catch (JSONException e) { e.printStackTrace(); } } }); } else { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getBaseContext(), "multimedia does not exist", Toast.LENGTH_LONG).show(); } }); article++; } } } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.cuelogic.android.WheelIndicatorView.java
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); this.viewHeight = getMeasuredHeight(); this.viewWidth = getMeasuredWidth(); this.minDistViewSize = Math.min(getMeasuredWidth(), getMeasuredHeight()); this.maxDistViewSize = Math.max(getMeasuredWidth(), getMeasuredHeight()); if (viewWidth <= viewHeight) { this.traslationX = 0; this.traslationY = (maxDistViewSize - minDistViewSize) / 2; } else {//from www . j a va 2s . c o m this.traslationX = (maxDistViewSize - minDistViewSize) / 2; this.traslationY = 0; } // Adding artificial padding, depending on line width wheelBoundsRectF = new RectF(0 + itemsLineWidth, 0 + itemsLineWidth, minDistViewSize - itemsLineWidth, minDistViewSize - itemsLineWidth); }
From source file:com.microsoft.mimickeralarm.mimics.ProgressButton.java
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mCenterX = w / 2;//from www . ja v a 2 s . c om mCenterY = h / 2; mInitialRadius = Math.min(w, h) / 2 - getContext().getResources().getDimensionPixelSize(R.dimen.progress_button_padding); mRadius = mInitialRadius; prepareDrawText(sWhite); float radius = mInitialRadius / 2f; mLoadingAnimationRect = new RectF(mCenterX - radius, mCenterY - radius, mCenterX + radius, mCenterY + radius); mInteractionHintAnimation = ObjectAnimator.ofFloat(this, "radius", mInitialRadius, mInitialRadius * INTERACTION_HINT_GROW_FACTOR, mInitialRadius); mInteractionHintAnimation.setDuration(INTERACTION_HINT_ANIMATION_DURATION); mInteractionHintAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); mInteractionHintAnimation.setRepeatCount(ValueAnimator.INFINITE); mInteractionHintAnimation.start(); }
From source file:me.lizheng.deckview.helpers.FakeShadowDrawable.java
private void buildShadowCorners() { RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius); RectF outerBounds = new RectF(innerBounds); outerBounds.inset(-mShadowSize, -mShadowSize); if (mCornerShadowPath == null) { mCornerShadowPath = new Path(); } else {/* w w w. j av a 2s.co m*/ mCornerShadowPath.reset(); } mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD); mCornerShadowPath.moveTo(-mCornerRadius, 0); mCornerShadowPath.rLineTo(-mShadowSize, 0); // outer arc mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false); // inner arc mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false); mCornerShadowPath.close(); float startRatio = mCornerRadius / (mCornerRadius + mShadowSize); mCornerShadowPaint.setShader(new RadialGradient(0, 0, mCornerRadius + mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP)); // we offset the content shadowSize/2 pixels up to make it more realistic. // this is why edge shadow shader has some extra space // When drawing bottom edge shadow, we use that extra space. mEdgeShadowPaint.setShader(new LinearGradient(0, -mCornerRadius + mShadowSize, 0, -mCornerRadius - mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, .5f, 1f }, Shader.TileMode.CLAMP)); }
From source file:com.gxy.fastscrollrecyclerview.views.FastScroller.java
public void draw(Canvas canvas) { if (mThumbPosition.x < 0 || mThumbPosition.y < 0) { return;/*from w w w. jav a2 s .c o m*/ } //Background () // canvas.drawRect(mThumbPosition.x + mOffset.x, mThumbHeight / 2 + mOffset.y, mThumbPosition.x + mOffset.x + mWidthBg, mRecyclerView.getHeight() + mOffset.y - mThumbHeight / 2, mTrack); //Handle ? // canvas.drawRect(mThumbPosition.x + mOffset.x, mThumbPosition.y + mOffset.y, mThumbPosition.x + mOffset.x + mWidth, mThumbPosition.y + mOffset.y + mThumbHeight, mThumb); // ? RectF oval3 = new RectF(mThumbPosition.x + mOffset.x, mThumbPosition.y + mOffset.y, mThumbPosition.x + mOffset.x + mWidth, mThumbPosition.y + mOffset.y + mThumbHeight);// canvas.drawRoundRect(oval3, (float) 2.2, 16, mThumb); //Popup mPopup.draw(canvas); }
From source file:de.mrapp.android.util.BitmapUtil.java
/** * Clips the corners of a bitmap in order to transform it into a round shape. Additionally, the * bitmap is resized to a specific size and a border will be added. Bitmaps, whose width and * height are not equal, will be clipped to a square beforehand. * * @param bitmap/*from w w w . j a v a 2 s . c o m*/ * The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The * bitmap may not be null * @param size * The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The * size must be at least 1 * @param borderWidth * The width of the border as an {@link Integer} value in pixels. The width must be at * least 0 * @param borderColor * The color of the border as an {@link Integer} value * @return The clipped bitmap as an instance of the class {@link Bitmap} */ public static Bitmap clipCircle(@NonNull final Bitmap bitmap, final int size, final int borderWidth, @ColorInt final int borderColor) { ensureAtLeast(borderWidth, 0, "The border width must be at least 0"); Bitmap clippedBitmap = clipCircle(bitmap, size); Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); float offset = borderWidth / 2.0f; Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight()); RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset); canvas.drawBitmap(clippedBitmap, src, dst, null); if (borderWidth > 0 && Color.alpha(borderColor) != 0) { Paint paint = new Paint(); paint.setFilterBitmap(false); paint.setAntiAlias(true); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(borderWidth); paint.setColor(borderColor); offset = borderWidth / 2.0f; RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset); canvas.drawArc(bounds, 0, COMPLETE_ARC_ANGLE, false, paint); } return result; }
From source file:com.lovejjfg.blogdemo.ui.indicator.RectPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/*from w w w . ja va 2 s.c om*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } int longSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } final float mHalfRectWidth = mRectWidth / 2.0f; final float rectOffset = mRectWidth * mRadiusRatio; final float shortOffset = shortPaddingBefore + mHalfRectWidth; float longOffset = longPaddingBefore + mHalfRectWidth; if (mCentered) { longOffset += (longSize - longPaddingBefore - longPaddingAfter - (count * mRectWidth) - (count - 1) * rectOffset) / 2.0f; } float dX; float dY; float pageFillRadius = mHalfRectWidth; if (mPaintStroke.getStrokeWidth() > 0) { pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; } //Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * (mRectWidth + rectOffset)); if (mOrientation == HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } RectF rectF = new RectF(dX - pageFillRadius, dY - pageFillRadius, dX + pageFillRadius, dY + pageFillRadius); // Only paint fill if not completely transparent if (mPaintPageFill.getAlpha() > 0) { // canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); canvas.drawRoundRect(rectF, 2, 2, mPaintPageFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != mHalfRectWidth) { rectF.intersect(dX - mHalfRectWidth, dY - mHalfRectWidth, dX + mHalfRectWidth, dY + mHalfRectWidth); canvas.drawRoundRect(rectF, 2, 2, mPaintPageFill); } } //Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * (rectOffset + mRectWidth); if (!mSnap) { cx += mPageOffset * (rectOffset + mRectWidth); } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } RectF rectF = new RectF(dX - mHalfRectWidth, dY - mHalfRectWidth, dX + mHalfRectWidth, dY + mHalfRectWidth); canvas.drawRoundRect(rectF, 2, 2, mPaintFill); }
From source file:com.alimuzaffar.lib.widgets.PinEntryEditText.java
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mOriginalTextColors = getTextColors(); if (mOriginalTextColors != null) { mLastCharPaint.setColor(mOriginalTextColors.getDefaultColor()); mCharPaint.setColor(mOriginalTextColors.getDefaultColor()); }/*from w w w .j a v a 2 s . co m*/ int availableWidth = getWidth() - getPaddingRight() - getPaddingLeft(); if (mSpace < 0) { mCharSize = (availableWidth / (mNumChars * 2 - 1)); } else { mCharSize = (availableWidth - (mSpace * (mNumChars - 1))) / mNumChars; } mLineCoords = new RectF[(int) mNumChars]; mCharBottom = new float[(int) mNumChars]; int startX = getPaddingLeft(); int bottom = getHeight() - getPaddingBottom(); for (int i = 0; i < mNumChars; i++) { mLineCoords[i] = new RectF(startX, bottom, startX + mCharSize, bottom); if (mPinBackground != null) { if (mIsDigitSquare) { mLineCoords[i].top = getPaddingTop(); mLineCoords[i].right = startX + mLineCoords[i].height(); } else { mLineCoords[i].top -= mTextHeight.height() + mTextBottomPadding * 2; } } if (mSpace < 0) { startX += mCharSize * 2; } else { startX += mCharSize + mSpace; } mCharBottom[i] = mLineCoords[i].bottom - mTextBottomPadding; } }
From source file:com.secondhand.view.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;/* w w w .j a va 2s . c o m*/ } final int count = mViewPager.getAdapter().getCount(); if (count == 1) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } int longSize; int longPaddingBefore; int longPaddingAfter; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { longSize = getWidth(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { longSize = getHeight(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } final float threeRadius = mRadius * 2; final float shortOffset = shortPaddingBefore + mRadius; float longOffset = longPaddingBefore + mRadius; if (mCentered) { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } float dX; float dY; float pageFillRadius = mRadius; if (mPaintStroke.getStrokeWidth() > 0) { pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; } // Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } // Only paint fill if not completely transparent if (mPaintPageFill.getAlpha() > 0) { canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != mRadius) { canvas.drawRect(new RectF(dX - mRadius / 2, dY - mRadius / 2, dX + mRadius / 2, dY + mRadius / 2), mPaintStroke); } } // Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap) { cx += mPageOffset * threeRadius; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } canvas.drawRect(new RectF(dX - mRadius / 2, dY - mRadius / 2, dX + mRadius / 2, dY + mRadius / 2), mPaintFill); }