use of android.graphics.RectF in project WaveLoadingView by tangqi92.
the class WaveLoadingView method onDraw.
@Override
public void onDraw(Canvas canvas) {
mCanvasSize = canvas.getWidth();
if (canvas.getHeight() < mCanvasSize) {
mCanvasSize = canvas.getHeight();
}
// Modify paint shader according to mShowWave state.
if (mWaveShader != null) {
// First call after mShowWave, assign it to our paint.
if (mWavePaint.getShader() == null) {
mWavePaint.setShader(mWaveShader);
}
// Sacle shader according to waveLengthRatio and amplitudeRatio.
// This decides the size(waveLengthRatio for width, amplitudeRatio for height) of waves.
mShaderMatrix.setScale(1, mAmplitudeRatio / DEFAULT_AMPLITUDE_RATIO, 0, mDefaultWaterLevel);
// Translate shader according to waveShiftRatio and waterLevelRatio.
// This decides the start position(waveShiftRatio for x, waterLevelRatio for y) of waves.
mShaderMatrix.postTranslate(mWaveShiftRatio * getWidth(), (DEFAULT_WATER_LEVEL_RATIO - mWaterLevelRatio) * getHeight());
// Assign matrix to invalidate the shader.
mWaveShader.setLocalMatrix(mShaderMatrix);
// Get borderWidth.
float borderWidth = mBorderPaint.getStrokeWidth();
// The default type is triangle.
switch(mShapeType) {
// Draw triangle
case 0:
// Currently does not support the border settings
Point start = new Point(0, getHeight());
Path triangle = getEquilateralTriangle(start, getWidth(), getHeight(), mTriangleDirection);
canvas.drawPath(triangle, mWaveBgPaint);
canvas.drawPath(triangle, mWavePaint);
break;
// Draw circle
case 1:
if (borderWidth > 0) {
canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, (getWidth() - borderWidth) / 2f - 1f, mBorderPaint);
}
float radius = getWidth() / 2f - borderWidth;
// Draw background
canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, radius, mWaveBgPaint);
canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, radius, mWavePaint);
break;
// Draw square
case 2:
if (borderWidth > 0) {
canvas.drawRect(borderWidth / 2f, borderWidth / 2f, getWidth() - borderWidth / 2f - 0.5f, getHeight() - borderWidth / 2f - 0.5f, mBorderPaint);
}
canvas.drawRect(borderWidth, borderWidth, getWidth() - borderWidth, getHeight() - borderWidth, mWaveBgPaint);
canvas.drawRect(borderWidth, borderWidth, getWidth() - borderWidth, getHeight() - borderWidth, mWavePaint);
break;
// Draw rectangle
case 3:
if (mIsRoundRectangle) {
if (borderWidth > 0) {
RectF rect = new RectF(borderWidth / 2f, borderWidth / 2f, getWidth() - borderWidth / 2f - 0.5f, getHeight() - borderWidth / 2f - 0.5f);
canvas.drawRoundRect(rect, mRoundRectangleXY, mRoundRectangleXY, mWaveBgPaint);
canvas.drawRoundRect(rect, mRoundRectangleXY, mRoundRectangleXY, mWavePaint);
} else {
RectF rect = new RectF(0, 0, getWidth(), getHeight());
canvas.drawRoundRect(rect, mRoundRectangleXY, mRoundRectangleXY, mWaveBgPaint);
canvas.drawRoundRect(rect, mRoundRectangleXY, mRoundRectangleXY, mWavePaint);
}
} else {
if (borderWidth > 0) {
canvas.drawRect(borderWidth / 2f, borderWidth / 2f, getWidth() - borderWidth / 2f - 0.5f, getHeight() - borderWidth / 2f - 0.5f, mWaveBgPaint);
canvas.drawRect(borderWidth / 2f, borderWidth / 2f, getWidth() - borderWidth / 2f - 0.5f, getHeight() - borderWidth / 2f - 0.5f, mWavePaint);
} else {
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mWaveBgPaint);
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mWavePaint);
}
}
break;
default:
break;
}
// I know, the code written here is very shit.
if (!TextUtils.isEmpty(mTopTitle)) {
float top = mTopTitlePaint.measureText(mTopTitle);
// Draw the stroke of top text
canvas.drawText(mTopTitle, (getWidth() - top) / 2, getHeight() * 2 / 10.0f, mTopTitleStrokePaint);
// Draw the top text
canvas.drawText(mTopTitle, (getWidth() - top) / 2, getHeight() * 2 / 10.0f, mTopTitlePaint);
}
if (!TextUtils.isEmpty(mCenterTitle)) {
float middle = mCenterTitlePaint.measureText(mCenterTitle);
// Draw the stroke of centered text
canvas.drawText(mCenterTitle, (getWidth() - middle) / 2, getHeight() / 2 - ((mCenterTitleStrokePaint.descent() + mCenterTitleStrokePaint.ascent()) / 2), mCenterTitleStrokePaint);
// Draw the centered text
canvas.drawText(mCenterTitle, (getWidth() - middle) / 2, getHeight() / 2 - ((mCenterTitlePaint.descent() + mCenterTitlePaint.ascent()) / 2), mCenterTitlePaint);
}
if (!TextUtils.isEmpty(mBottomTitle)) {
float bottom = mBottomTitlePaint.measureText(mBottomTitle);
// Draw the stroke of bottom text
canvas.drawText(mBottomTitle, (getWidth() - bottom) / 2, getHeight() * 8 / 10.0f - ((mBottomTitleStrokePaint.descent() + mBottomTitleStrokePaint.ascent()) / 2), mBottomTitleStrokePaint);
// Draw the bottom text
canvas.drawText(mBottomTitle, (getWidth() - bottom) / 2, getHeight() * 8 / 10.0f - ((mBottomTitlePaint.descent() + mBottomTitlePaint.ascent()) / 2), mBottomTitlePaint);
}
} else {
mWavePaint.setShader(null);
}
}
use of android.graphics.RectF in project CalendarListview by traex.
the class SimpleMonthView method drawMonthNums.
protected void drawMonthNums(Canvas canvas) {
int y = (mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2 - DAY_SEPARATOR_WIDTH + MONTH_HEADER_SIZE;
int paddingDay = (mWidth - 2 * mPadding) / (2 * mNumDays);
int dayOffset = findDayOffset();
int day = 1;
while (day <= mNumCells) {
int x = paddingDay * (1 + dayOffset * 2) + mPadding;
if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) {
if (mDrawRect) {
RectF rectF = new RectF(x - DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) - DAY_SELECTED_CIRCLE_SIZE, x + DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) + DAY_SELECTED_CIRCLE_SIZE);
canvas.drawRoundRect(rectF, 10.0f, 10.0f, mSelectedCirclePaint);
} else
canvas.drawCircle(x, y - MINI_DAY_NUMBER_TEXT_SIZE / 3, DAY_SELECTED_CIRCLE_SIZE, mSelectedCirclePaint);
}
if (mHasToday && (mToday == day)) {
mMonthNumPaint.setColor(mCurrentDayTextColor);
mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
} else {
mMonthNumPaint.setColor(mDayNumColor);
mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
}
if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear))
mMonthNumPaint.setColor(mMonthTitleBGColor);
if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mSelectedBeginMonth == mSelectedLastMonth && mSelectedBeginDay == mSelectedLastDay && day == mSelectedBeginDay && mMonth == mSelectedBeginMonth && mYear == mSelectedBeginYear))
mMonthNumPaint.setColor(mSelectedDaysColor);
if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mSelectedBeginYear == mYear) && (((mMonth == mSelectedBeginMonth && mSelectedLastMonth == mSelectedBeginMonth) && ((mSelectedBeginDay < mSelectedLastDay && day > mSelectedBeginDay && day < mSelectedLastDay) || (mSelectedBeginDay > mSelectedLastDay && day < mSelectedBeginDay && day > mSelectedLastDay))) || ((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay)) || ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)))) {
mMonthNumPaint.setColor(mSelectedDaysColor);
}
if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear && ((mSelectedBeginYear == mYear && mMonth == mSelectedBeginMonth) || (mSelectedLastYear == mYear && mMonth == mSelectedLastMonth)) && (((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)) || ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay))))) {
mMonthNumPaint.setColor(mSelectedDaysColor);
}
if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mYear == mSelectedBeginYear) && ((mMonth > mSelectedBeginMonth && mMonth < mSelectedLastMonth && mSelectedBeginMonth < mSelectedLastMonth) || (mMonth < mSelectedBeginMonth && mMonth > mSelectedLastMonth && mSelectedBeginMonth > mSelectedLastMonth))) {
mMonthNumPaint.setColor(mSelectedDaysColor);
}
if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear) && ((mSelectedBeginYear < mSelectedLastYear && ((mMonth > mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth < mSelectedLastMonth && mYear == mSelectedLastYear))) || (mSelectedBeginYear > mSelectedLastYear && ((mMonth < mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth > mSelectedLastMonth && mYear == mSelectedLastYear))))) {
mMonthNumPaint.setColor(mSelectedDaysColor);
}
if (!isPrevDayEnabled && prevDay(day, today) && today.month == mMonth && today.year == mYear) {
mMonthNumPaint.setColor(mPreviousDayColor);
mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));
}
canvas.drawText(String.format("%d", day), x, y, mMonthNumPaint);
dayOffset++;
if (dayOffset == mNumDays) {
dayOffset = 0;
y += mRowHeight;
}
day++;
}
}
use of android.graphics.RectF in project glitch-hq-android by tinyspeck.
the class BitmapUtil method CreateOvalImage.
public static Bitmap CreateOvalImage(Bitmap orgBmp) {
int nW = 60;
int nH = 60;
int nW0 = orgBmp.getWidth();
int nH0 = orgBmp.getHeight();
// Rect r = new Rect();
// r.left = (int) ( nW0 * 0.18 );
// r.top = nH0 / 11;
// r.right = (int) ( nW0 * 0.94 );
// r.bottom = (int) ( nH0 * 0.63 );
Rect r = new Rect();
r.left = 18;
r.top = 16;
r.right = nW0;
r.bottom = 95;
Bitmap bmNew = Bitmap.createBitmap(nW, nH, Bitmap.Config.ARGB_8888);
Canvas cvs = new Canvas(bmNew);
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
paint.setAlpha(78);
paint.setColor(0xffc0c0c0);
RectF rDest = new RectF();
rDest.left = 1;
rDest.right = nW;
rDest.top = 1;
rDest.bottom = nH;
Path clip = new Path();
clip.addCircle(nW / 2, nH / 2, (float) (nW / 2 + 0.5), Path.Direction.CW);
cvs.clipPath(clip);
cvs.drawARGB(78, 233, 240, 240);
cvs.drawBitmap(orgBmp, r, rDest, paint);
cvs.drawCircle(nW / 2, nH / 2, nW / 2, paint);
return bmNew;
}
use of android.graphics.RectF in project BGAQRCode-Android by bingoogolapple.
the class ScanBoxView method drawTipText.
/**
* 画提示文本
*
* @param canvas
*/
private void drawTipText(Canvas canvas) {
if (TextUtils.isEmpty(mTipText) || mTipTextSl == null) {
return;
}
if (mIsTipTextBelowRect) {
if (mIsShowTipBackground) {
mPaint.setColor(mTipBackgroundColor);
mPaint.setStyle(Paint.Style.FILL);
if (mIsShowTipTextAsSingleLine) {
Rect tipRect = new Rect();
mTipPaint.getTextBounds(mTipText, 0, mTipText.length(), tipRect);
float left = (canvas.getWidth() - tipRect.width()) / 2 - mTipBackgroundRadius;
canvas.drawRoundRect(new RectF(left, mFramingRect.bottom + mTipTextMargin - mTipBackgroundRadius, left + tipRect.width() + 2 * mTipBackgroundRadius, mFramingRect.bottom + mTipTextMargin + mTipTextSl.getHeight() + mTipBackgroundRadius), mTipBackgroundRadius, mTipBackgroundRadius, mPaint);
} else {
canvas.drawRoundRect(new RectF(mFramingRect.left, mFramingRect.bottom + mTipTextMargin - mTipBackgroundRadius, mFramingRect.right, mFramingRect.bottom + mTipTextMargin + mTipTextSl.getHeight() + mTipBackgroundRadius), mTipBackgroundRadius, mTipBackgroundRadius, mPaint);
}
}
canvas.save();
if (mIsShowTipTextAsSingleLine) {
canvas.translate(0, mFramingRect.bottom + mTipTextMargin);
} else {
canvas.translate(mFramingRect.left + mTipBackgroundRadius, mFramingRect.bottom + mTipTextMargin);
}
mTipTextSl.draw(canvas);
canvas.restore();
} else {
if (mIsShowTipBackground) {
mPaint.setColor(mTipBackgroundColor);
mPaint.setStyle(Paint.Style.FILL);
if (mIsShowTipTextAsSingleLine) {
Rect tipRect = new Rect();
mTipPaint.getTextBounds(mTipText, 0, mTipText.length(), tipRect);
float left = (canvas.getWidth() - tipRect.width()) / 2 - mTipBackgroundRadius;
canvas.drawRoundRect(new RectF(left, mFramingRect.top - mTipTextMargin - mTipTextSl.getHeight() - mTipBackgroundRadius, left + tipRect.width() + 2 * mTipBackgroundRadius, mFramingRect.top - mTipTextMargin + mTipBackgroundRadius), mTipBackgroundRadius, mTipBackgroundRadius, mPaint);
} else {
canvas.drawRoundRect(new RectF(mFramingRect.left, mFramingRect.top - mTipTextMargin - mTipTextSl.getHeight() - mTipBackgroundRadius, mFramingRect.right, mFramingRect.top - mTipTextMargin + mTipBackgroundRadius), mTipBackgroundRadius, mTipBackgroundRadius, mPaint);
}
}
canvas.save();
if (mIsShowTipTextAsSingleLine) {
canvas.translate(0, mFramingRect.top - mTipTextMargin - mTipTextSl.getHeight());
} else {
canvas.translate(mFramingRect.left + mTipBackgroundRadius, mFramingRect.top - mTipTextMargin - mTipTextSl.getHeight());
}
mTipTextSl.draw(canvas);
canvas.restore();
}
}
use of android.graphics.RectF in project GraphView by appsthatmatter.
the class CursorMode method drawLegend.
protected void drawLegend(Canvas canvas) {
mTextPaint.setTextSize(mStyles.textSize);
mTextPaint.setColor(mStyles.textColor);
int shapeSize = (int) (mStyles.textSize * 0.8d);
// width
int legendWidth = mStyles.width;
if (legendWidth == 0) {
// auto
legendWidth = cachedLegendWidth;
if (legendWidth == 0) {
Rect textBounds = new Rect();
for (Map.Entry<BaseSeries, DataPointInterface> entry : mCurrentSelection.entrySet()) {
String txt = getTextForSeries(entry.getKey(), entry.getValue());
mTextPaint.getTextBounds(txt, 0, txt.length(), textBounds);
legendWidth = Math.max(legendWidth, textBounds.width());
}
if (legendWidth == 0)
legendWidth = 1;
// add shape size
legendWidth += shapeSize + mStyles.padding * 2 + mStyles.spacing;
cachedLegendWidth = legendWidth;
}
}
float legendPosX = mPosX - mStyles.margin - legendWidth;
if (legendPosX < 0) {
legendPosX = 0;
}
// rect
float legendHeight = (mStyles.textSize + mStyles.spacing) * (mCurrentSelection.size() + 1) - mStyles.spacing;
float legendPosY = mPosY - legendHeight - 4.5f * mStyles.textSize;
if (legendPosY < 0) {
legendPosY = 0;
}
float lLeft;
float lTop;
lLeft = legendPosX;
lTop = legendPosY;
float lRight = lLeft + legendWidth;
float lBottom = lTop + legendHeight + 2 * mStyles.padding;
mRectPaint.setColor(mStyles.backgroundColor);
canvas.drawRoundRect(new RectF(lLeft, lTop, lRight, lBottom), 8, 8, mRectPaint);
mTextPaint.setFakeBoldText(true);
canvas.drawText(mGraphView.getGridLabelRenderer().getLabelFormatter().formatLabel(mCurrentSelectionX, true), lLeft + mStyles.padding, lTop + mStyles.padding / 2 + mStyles.textSize, mTextPaint);
mTextPaint.setFakeBoldText(false);
int i = 1;
for (Map.Entry<BaseSeries, DataPointInterface> entry : mCurrentSelection.entrySet()) {
mRectPaint.setColor(entry.getKey().getColor());
canvas.drawRect(new RectF(lLeft + mStyles.padding, lTop + mStyles.padding + (i * (mStyles.textSize + mStyles.spacing)), lLeft + mStyles.padding + shapeSize, lTop + mStyles.padding + (i * (mStyles.textSize + mStyles.spacing)) + shapeSize), mRectPaint);
canvas.drawText(getTextForSeries(entry.getKey(), entry.getValue()), lLeft + mStyles.padding + shapeSize + mStyles.spacing, lTop + mStyles.padding / 2 + mStyles.textSize + (i * (mStyles.textSize + mStyles.spacing)), mTextPaint);
i++;
}
}
Aggregations