public final class RatingCompat extends Object implements Parcelable
RATING_HEART
,
RATING_THUMB_UP_DOWN
, RATING_3_STARS
, RATING_4_STARS
,
RATING_5_STARS
or RATING_PERCENTAGE
) and the actual rating value (which may
be defined as "unrated"), both of which are defined when the rating instance is constructed
through one of the factory methods.Modifier and Type | Class and Description |
---|---|
static interface |
RatingCompat.StarStyle |
static interface |
RatingCompat.Style |
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<RatingCompat> |
CREATOR |
static int |
RATING_3_STARS
A rating style with 0 to 3 stars.
|
static int |
RATING_4_STARS
A rating style with 0 to 4 stars.
|
static int |
RATING_5_STARS
A rating style with 0 to 5 stars.
|
static int |
RATING_HEART
A rating style with a single degree of rating, "heart" vs "no heart".
|
static int |
RATING_NONE
Indicates a rating style is not supported.
|
static int |
RATING_PERCENTAGE
A rating style expressed as a percentage.
|
static int |
RATING_THUMB_UP_DOWN
A rating style for "thumb up" vs "thumb down".
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Modifier and Type | Method and Description |
---|---|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
static RatingCompat |
fromRating(Object ratingObj)
Creates an instance from a framework
Rating object. |
float |
getPercentRating()
Return the percentage-based rating value.
|
Object |
getRating()
Gets the underlying framework
Rating object. |
int |
getRatingStyle()
Return the rating style.
|
float |
getStarRating()
Return the star-based rating value.
|
boolean |
hasHeart()
Return whether the rating is "heart selected".
|
boolean |
isRated()
Return whether there is a rating value available.
|
boolean |
isThumbUp()
Return whether the rating is "thumb up".
|
static RatingCompat |
newHeartRating(boolean hasHeart)
Return a Rating instance with a heart-based rating.
|
static RatingCompat |
newPercentageRating(float percent)
Return a Rating instance with a percentage-based rating.
|
static RatingCompat |
newStarRating(int starRatingStyle,
float starRating)
Return a Rating instance with a star-based rating.
|
static RatingCompat |
newThumbRating(boolean thumbIsUp)
Return a Rating instance with a thumb-based rating.
|
static RatingCompat |
newUnratedRating(int ratingStyle)
Return a Rating instance with no rating.
|
String |
toString()
Returns a string representation of the object.
|
void |
writeToParcel(Parcel dest,
int flags)
Flatten this object in to a Parcel.
|
public static final int RATING_NONE
public static final int RATING_HEART
public static final int RATING_THUMB_UP_DOWN
public static final int RATING_3_STARS
public static final int RATING_4_STARS
public static final int RATING_5_STARS
public static final int RATING_PERCENTAGE
public static final Parcelable.Creator<RatingCompat> CREATOR
public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel dest, int flags)
Parcelable
writeToParcel
in interface Parcelable
dest
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.public static RatingCompat newUnratedRating(int ratingStyle)
ratingStyle
- one of RATING_HEART
, RATING_THUMB_UP_DOWN
,
RATING_3_STARS
, RATING_4_STARS
, RATING_5_STARS
,
or RATING_PERCENTAGE
.public static RatingCompat newHeartRating(boolean hasHeart)
RATING_HEART
,
and a heart-based rating.hasHeart
- true for a "heart selected" rating, false for "heart unselected".public static RatingCompat newThumbRating(boolean thumbIsUp)
RATING_THUMB_UP_DOWN
rating style, and a "thumb up" or "thumb down" rating.thumbIsUp
- true for a "thumb up" rating, false for "thumb down".public static RatingCompat newStarRating(int starRatingStyle, float starRating)
starRatingStyle
- one of RATING_3_STARS
, RATING_4_STARS
,
RATING_5_STARS
.starRating
- a number ranging from 0.0f to 3.0f, 4.0f or 5.0f according to
the rating style.public static RatingCompat newPercentageRating(float percent)
RATING_PERCENTAGE
rating style, and a rating of the given percentage.percent
- the value of the ratingpublic boolean isRated()
newUnratedRating(int)
.public int getRatingStyle()
RATING_HEART
, RATING_THUMB_UP_DOWN
,
RATING_3_STARS
, RATING_4_STARS
, RATING_5_STARS
,
or RATING_PERCENTAGE
.public boolean hasHeart()
RATING_HEART
or if it is unrated.public boolean isThumbUp()
RATING_THUMB_UP_DOWN
or if it is unrated.public float getStarRating()
public float getPercentRating()
public static RatingCompat fromRating(Object ratingObj)
Rating
object.
This method is only supported on API 19+.
ratingObj
- A Rating
object, or null if none.RatingCompat
object, or null if none.