From cb5ed33145dfd6b595a6e26d063e5a33af7ea643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=97=D0=B0=D1=86=D0=B5=D0=BF=D0=B8=D0=BD?= Date: Thu, 14 Sep 2017 15:57:52 +0300 Subject: [PATCH] [android] Added custom background support for RatingView [android] Added more flexible drawing the drawable and text, if someone is absent it will not stop drawing rest one --- .../mapswithme/maps/widget/RatingView.java | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/android/src/com/mapswithme/maps/widget/RatingView.java b/android/src/com/mapswithme/maps/widget/RatingView.java index b593f8f457..a4d7e95b5e 100644 --- a/android/src/com/mapswithme/maps/widget/RatingView.java +++ b/android/src/com/mapswithme/maps/widget/RatingView.java @@ -102,19 +102,24 @@ public class RatingView extends View @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - if (TextUtils.isEmpty(mRatingValue)) + final int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec); + int width = getPaddingLeft(); + if (mDrawable != null) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - return; + final int drawableWidth = height - getPaddingTop() - getPaddingBottom(); + mDrawableBounds.set(getPaddingLeft(), getPaddingTop(), drawableWidth + getPaddingLeft(), + drawableWidth + getPaddingTop()); + width += drawableWidth; } - final int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec); - final int drawableWidth = height - getPaddingTop() - getPaddingBottom(); - mDrawableBounds.set(getPaddingLeft(), getPaddingTop(), drawableWidth + getPaddingLeft(), - drawableWidth + getPaddingTop()); - mTextPaint.getTextBounds(mRatingValue, 0, mRatingValue.length(), mTextBounds); - int width = getPaddingLeft() + drawableWidth + getPaddingLeft() - + mTextBounds.width() + getPaddingRight(); + if (mRatingValue != null) + { + mTextPaint.getTextBounds(mRatingValue, 0, mRatingValue.length(), mTextBounds); + width += getPaddingLeft() + mTextBounds.width(); + } + + width += getPaddingRight(); + mBackgroundBounds.set(0, 0, width, height); setMeasuredDimension(width, height); } @@ -122,20 +127,22 @@ public class RatingView extends View @Override protected void onDraw(Canvas canvas) { - super.onDraw(canvas); + if (getBackground() == null) + canvas.drawRoundRect(mBackgroundBounds, CORNER_RADIUS_PX, CORNER_RADIUS_PX, mBackgroundPaint); - if (mDrawable == null || TextUtils.isEmpty(mRatingValue)) - return; + if (mDrawable != null) + { + mDrawable.mutate(); + DrawableCompat.setTint(mDrawable, mRatingColor); + mDrawable.setBounds(mDrawableBounds); + mDrawable.draw(canvas); + } - canvas.drawRoundRect(mBackgroundBounds, CORNER_RADIUS_PX, CORNER_RADIUS_PX, mBackgroundPaint); - - mDrawable.mutate(); - DrawableCompat.setTint(mDrawable, mRatingColor); - mDrawable.setBounds(mDrawableBounds); - mDrawable.draw(canvas); - - float yPos = getHeight() / 2; - yPos += (Math.abs(mTextBounds.height())) / 2; - canvas.drawText(mRatingValue, mDrawable.getBounds().right + getPaddingLeft(), yPos, mTextPaint); + if (mRatingValue != null) + { + float yPos = getHeight() / 2; + yPos += (Math.abs(mTextBounds.height())) / 2; + canvas.drawText(mRatingValue, mDrawable.getBounds().right + getPaddingLeft(), yPos, mTextPaint); + } } }