forked from organicmaps/organicmaps
[android] Separated textcolor and bg color for Rating view, opt UI
This commit is contained in:
parent
783081698d
commit
b0a20daa2b
7 changed files with 41 additions and 22 deletions
|
@ -56,6 +56,7 @@
|
|||
android:layout_marginStart="@dimen/margin_quarter"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:textSize="@dimen/text_size_body_4"
|
||||
android:alpha="@integer/opaque"
|
||||
tools:text="-20%"
|
||||
app:drawSmile="false"
|
||||
app:rating="discount"/>
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
<declare-styleable name="RatingView">
|
||||
<attr name="android:textSize"/>
|
||||
<attr name="android:text"/>
|
||||
<attr name="android:alpha"/>
|
||||
<attr name="rating" format="enum">
|
||||
<enum name="none" value="0" />
|
||||
<enum name="horrible" value="1"/>
|
||||
|
|
|
@ -8,4 +8,5 @@
|
|||
|
||||
<integer name="search_fade_in_anim_time">200</integer>
|
||||
<integer name="search_fade_out_anim_time">150</integer>
|
||||
<integer name="opaque">255</integer>
|
||||
</resources>
|
||||
|
|
|
@ -15,23 +15,31 @@ public enum Impress
|
|||
EXCELLENT(R.drawable.ic_24px_rating_excellent, R.color.rating_excellent),
|
||||
COMING_SOON(R.drawable.ic_24px_rating_coming_soon, R.color.rating_coming_soon),
|
||||
POPULAR(R.drawable.ic_thumb_up, R.color.rating_coming_soon),
|
||||
DISCOUNT(R.drawable.ic_thumb_up, R.color.rating_coming_soon);
|
||||
DISCOUNT(R.drawable.ic_thumb_up, android.R.color.white, R.color.rating_coming_soon);
|
||||
|
||||
@DrawableRes
|
||||
private final int mDrawableId;
|
||||
@ColorRes
|
||||
private final int mColorId;
|
||||
private final int mTextColor;
|
||||
@ColorRes
|
||||
private final int mBgColor;
|
||||
|
||||
Impress(@DrawableRes int smile, @ColorRes int color)
|
||||
{
|
||||
this(smile, color, color);
|
||||
}
|
||||
|
||||
Impress(@DrawableRes int smile, @ColorRes int color, @ColorRes int bgColor)
|
||||
{
|
||||
mDrawableId = smile;
|
||||
mColorId = color;
|
||||
mTextColor = color;
|
||||
mBgColor = bgColor;
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
public int getColorId()
|
||||
public int getTextColor()
|
||||
{
|
||||
return mColorId;
|
||||
return mTextColor;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
|
@ -39,4 +47,10 @@ public enum Impress
|
|||
{
|
||||
return mDrawableId;
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
public int getBgColor()
|
||||
{
|
||||
return mBgColor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.mapswithme.maps.ugc.Impress;
|
|||
|
||||
public class RatingView extends View
|
||||
{
|
||||
private static final int DEF_ALPHA = 31/* 12% */;
|
||||
@Nullable
|
||||
private Drawable mDrawable;
|
||||
@NonNull
|
||||
|
@ -38,12 +39,15 @@ public class RatingView extends View
|
|||
@Nullable
|
||||
private String mRating;
|
||||
@ColorInt
|
||||
private int mRatingColor;
|
||||
private int mTextColor;
|
||||
private boolean mDrawSmile;
|
||||
private int mBackgroundCornerRadius;
|
||||
private boolean mForceDrawBg;
|
||||
private int mAlpha;
|
||||
@NonNull
|
||||
private TextUtils.TruncateAt mTruncate = TextUtils.TruncateAt.END;
|
||||
@ColorInt
|
||||
private int mBgColor;
|
||||
|
||||
public RatingView(Context context, @Nullable AttributeSet attrs)
|
||||
{
|
||||
|
@ -69,7 +73,7 @@ public class RatingView extends View
|
|||
mRating = a.getString(R.styleable.RatingView_android_text);
|
||||
mDrawSmile = a.getBoolean(R.styleable.RatingView_drawSmile, true);
|
||||
mForceDrawBg = a.getBoolean(R.styleable.RatingView_forceDrawBg, true);
|
||||
|
||||
mAlpha = a.getInteger(R.styleable.RatingView_android_alpha, DEF_ALPHA);
|
||||
int rating = a.getInteger(R.styleable.RatingView_rating, 0);
|
||||
int index = a.getInteger(R.styleable.RatingView_android_ellipsize,
|
||||
TextUtils.TruncateAt.END.ordinal());
|
||||
|
@ -84,12 +88,14 @@ public class RatingView extends View
|
|||
{
|
||||
mRating = rating;
|
||||
Resources res = getContext().getResources();
|
||||
mRatingColor = res.getColor(impress.getColorId());
|
||||
mBackgroundPaint.setColor(mRatingColor);
|
||||
mBackgroundPaint.setAlpha(31 /* 12% */);
|
||||
mTextColor = res.getColor(impress.getTextColor());
|
||||
mBgColor = res.getColor(impress.getBgColor());
|
||||
|
||||
mBackgroundPaint.setColor(mBgColor);
|
||||
mBackgroundPaint.setAlpha(mAlpha);
|
||||
if (mDrawSmile)
|
||||
mDrawable = DrawableCompat.wrap(res.getDrawable(impress.getDrawableId()));
|
||||
mTextPaint.setColor(mRatingColor);
|
||||
mTextPaint.setColor(mTextColor);
|
||||
invalidate();
|
||||
requestLayout();
|
||||
}
|
||||
|
@ -148,7 +154,7 @@ public class RatingView extends View
|
|||
if (mDrawable != null)
|
||||
{
|
||||
mDrawable.mutate();
|
||||
DrawableCompat.setTint(mDrawable, mRatingColor);
|
||||
DrawableCompat.setTint(mDrawable, mTextColor);
|
||||
mDrawable.setBounds(mDrawableBounds);
|
||||
mDrawable.draw(canvas);
|
||||
}
|
||||
|
|
|
@ -11,16 +11,16 @@ public class HotelPriceInfo
|
|||
@NonNull
|
||||
private final String mCurrency;
|
||||
private final int mDiscount;
|
||||
private final boolean mHasSmartDeal;
|
||||
private final boolean mSmartDeal;
|
||||
|
||||
public HotelPriceInfo(@NonNull String id, @NonNull String price, @NonNull String currency,
|
||||
int discount, boolean hasSmartDeal)
|
||||
int discount, boolean smartDeal)
|
||||
{
|
||||
mId = id;
|
||||
mPrice = price;
|
||||
mCurrency = currency;
|
||||
mDiscount = discount;
|
||||
mHasSmartDeal = hasSmartDeal;
|
||||
mSmartDeal = smartDeal;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -48,7 +48,7 @@ public class HotelPriceInfo
|
|||
|
||||
public boolean hasSmartDeal()
|
||||
{
|
||||
return mHasSmartDeal;
|
||||
return mSmartDeal;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,7 +59,7 @@ public class HotelPriceInfo
|
|||
sb.append(", mPrice='").append(mPrice).append('\'');
|
||||
sb.append(", mCurrency='").append(mCurrency).append('\'');
|
||||
sb.append(", mDiscount=").append(mDiscount);
|
||||
sb.append(", mHasSmartDeal=").append(mHasSmartDeal);
|
||||
sb.append(", mSmartDeal=").append(mSmartDeal);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
@ -1464,8 +1464,6 @@ public class PlacePageView extends RelativeLayout
|
|||
boolean isBookingInfoExist = (!isRatingEmpty || !isPriceEmpty) &&
|
||||
mSponsored.getType() == Sponsored.TYPE_BOOKING;
|
||||
UiUtils.showIf(isBookingInfoExist, mPreviewRatingInfo);
|
||||
UiUtils.showIf(true, mHotelDiscount);
|
||||
|
||||
String discount = getHotelDiscount();
|
||||
UiUtils.hideIf(TextUtils.isEmpty(discount), mHotelDiscount);
|
||||
mHotelDiscount.setRating(Impress.DISCOUNT, discount);
|
||||
|
@ -1476,9 +1474,7 @@ public class PlacePageView extends RelativeLayout
|
|||
{
|
||||
boolean hasPercentsDiscount = mPriceInfo != null && mPriceInfo.getDiscount() > 0;
|
||||
if (hasPercentsDiscount)
|
||||
return new StringBuilder().append(DISCOUNT_PREFIX)
|
||||
.append(mPriceInfo.getDiscount())
|
||||
.append(DISCOUNT_SUFFIX).toString();
|
||||
return DISCOUNT_PREFIX + mPriceInfo.getDiscount() + DISCOUNT_SUFFIX;
|
||||
|
||||
return mPriceInfo != null && mPriceInfo.hasSmartDeal() ? DISCOUNT_SUFFIX : null;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue