Android APIs
public final class

Rating

extends Object
implements Parcelable
java.lang.Object
   ↳ android.media.Rating

Class Overview

A class to encapsulate rating information used as content metadata. A rating is defined by its rating style (see 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.

Summary

Constants
int RATING_3_STARS A rating style with 0 to 3 stars.
int RATING_4_STARS A rating style with 0 to 4 stars.
int RATING_5_STARS A rating style with 0 to 5 stars.
int RATING_HEART A rating style with a single degree of rating, "heart" vs "no heart".
int RATING_NONE Indicates a rating style is not supported.
int RATING_PERCENTAGE A rating style expressed as a percentage.
int RATING_THUMB_UP_DOWN A rating style for "thumb up" vs "thumb down".
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<Rating> CREATOR
Public Methods
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
float getPercentRating()
Return the percentage-based rating value.
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 Rating newHeartRating(boolean hasHeart)
Return a Rating instance with a heart-based rating.
static Rating newPercentageRating(float percent)
Return a Rating instance with a percentage-based rating.
static Rating newStarRating(int starRatingStyle, float starRating)
Return a Rating instance with a star-based rating.
static Rating newThumbRating(boolean thumbIsUp)
Return a Rating instance with a thumb-based rating.
static Rating newUnratedRating(int ratingStyle)
Return a Rating instance with no rating.
String toString()
Returns a string containing a concise, human-readable description of this object.
void writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final int RATING_3_STARS

Added in API level 19

A rating style with 0 to 3 stars.

Constant Value: 3 (0x00000003)

public static final int RATING_4_STARS

Added in API level 19

A rating style with 0 to 4 stars.

Constant Value: 4 (0x00000004)

public static final int RATING_5_STARS

Added in API level 19

A rating style with 0 to 5 stars.

Constant Value: 5 (0x00000005)

public static final int RATING_HEART

Added in API level 19

A rating style with a single degree of rating, "heart" vs "no heart". Can be used to indicate the content referred to is a favorite (or not).

Constant Value: 1 (0x00000001)

public static final int RATING_NONE

Added in API level 21

Indicates a rating style is not supported. A Rating will never have this type, but can be used by other classes to indicate they do not support Rating.

Constant Value: 0 (0x00000000)

public static final int RATING_PERCENTAGE

Added in API level 19

A rating style expressed as a percentage.

Constant Value: 6 (0x00000006)

public static final int RATING_THUMB_UP_DOWN

Added in API level 19

A rating style for "thumb up" vs "thumb down".

Constant Value: 2 (0x00000002)

Fields

public static final Creator<Rating> CREATOR

Added in API level 19

Public Methods

public int describeContents ()

Added in API level 19

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public float getPercentRating ()

Added in API level 19

Return the percentage-based rating value.

Returns
  • a rating value greater or equal to 0.0f, or a negative value if the rating style is not percentage-based, or if it is unrated.

public int getRatingStyle ()

Added in API level 19

public float getStarRating ()

Added in API level 19

Return the star-based rating value.

Returns
  • a rating value greater or equal to 0.0f, or a negative value if the rating style is not star-based, or if it is unrated.

public boolean hasHeart ()

Added in API level 19

Return whether the rating is "heart selected".

Returns
  • true if the rating is "heart selected", false if the rating is "heart unselected", if the rating style is not RATING_HEART or if it is unrated.

public boolean isRated ()

Added in API level 19

Return whether there is a rating value available.

Returns

public boolean isThumbUp ()

Added in API level 19

Return whether the rating is "thumb up".

Returns
  • true if the rating is "thumb up", false if the rating is "thumb down", if the rating style is not RATING_THUMB_UP_DOWN or if it is unrated.

public static Rating newHeartRating (boolean hasHeart)

Added in API level 19

Return a Rating instance with a heart-based rating. Create and return a new Rating instance with a rating style of RATING_HEART, and a heart-based rating.

Parameters
hasHeart true for a "heart selected" rating, false for "heart unselected".
Returns
  • a new Rating instance.

public static Rating newPercentageRating (float percent)

Added in API level 19

Return a Rating instance with a percentage-based rating. Create and return a new Rating instance with a RATING_PERCENTAGE rating style, and a rating of the given percentage.

Parameters
percent the value of the rating
Returns
  • null if the rating is out of range, a new Rating instance otherwise.

public static Rating newStarRating (int starRatingStyle, float starRating)

Added in API level 19

Return a Rating instance with a star-based rating. Create and return a new Rating instance with one of the star-base rating styles and the given integer or fractional number of stars. Non integer values can for instance be used to represent an average rating value, which might not be an integer number of stars.

Parameters
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.
Returns
  • null if the rating style is invalid, or the rating is out of range, a new Rating instance otherwise.

public static Rating newThumbRating (boolean thumbIsUp)

Added in API level 19

Return a Rating instance with a thumb-based rating. Create and return a new Rating instance with a RATING_THUMB_UP_DOWN rating style, and a "thumb up" or "thumb down" rating.

Parameters
thumbIsUp true for a "thumb up" rating, false for "thumb down".
Returns
  • a new Rating instance.

public static Rating newUnratedRating (int ratingStyle)

Added in API level 19

Return a Rating instance with no rating. Create and return a new Rating instance with no rating known for the given rating style.

Returns
  • null if an invalid rating style is passed, a new Rating instance otherwise.

public String toString ()

Added in API level 19

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public void writeToParcel (Parcel dest, int flags)

Added in API level 19

Flatten this object in to a Parcel.

Parameters
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_WRITE_RETURN_VALUE.