added in version 22.1.0
belongs to Maven artifact com.android.support:support-media-compat:28.0.0-alpha1

RatingCompat

public final class RatingCompat
extends Object implements Parcelable

java.lang.Object
   ↳ android.support.v4.media.RatingCompat


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".

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<RatingCompat> CREATOR

Public methods

int describeContents()
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()
void writeToParcel(Parcel dest, int flags)

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

Constants

RATING_3_STARS

added in version 22.1.0
int RATING_3_STARS

A rating style with 0 to 3 stars.

Constant Value: 3 (0x00000003)

RATING_4_STARS

added in version 22.1.0
int RATING_4_STARS

A rating style with 0 to 4 stars.

Constant Value: 4 (0x00000004)

RATING_5_STARS

added in version 22.1.0
int RATING_5_STARS

A rating style with 0 to 5 stars.

Constant Value: 5 (0x00000005)

RATING_HEART

added in version 22.1.0
int RATING_HEART

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)

RATING_NONE

added in version 22.1.0
int RATING_NONE

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)

RATING_PERCENTAGE

added in version 22.1.0
int RATING_PERCENTAGE

A rating style expressed as a percentage.

Constant Value: 6 (0x00000006)

RATING_THUMB_UP_DOWN

added in version 22.1.0
int RATING_THUMB_UP_DOWN

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

Constant Value: 2 (0x00000002)

Fields

CREATOR

added in version 22.1.0
Creator<RatingCompat> CREATOR

Public methods

describeContents

added in version 22.1.0
int describeContents ()

Returns
int

fromRating

added in version 22.1.0
RatingCompat fromRating (Object ratingObj)

Creates an instance from a framework Rating object.

This method is only supported on API 19+.

Parameters
ratingObj Object: A Rating object, or null if none.

Returns
RatingCompat An equivalent RatingCompat object, or null if none.

getPercentRating

added in version 22.1.0
float getPercentRating ()

Return the percentage-based rating value.

Returns
float 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.

getRating

added in version 22.1.0
Object getRating ()

Gets the underlying framework Rating object.

This method is only supported on API 19+.

Returns
Object An equivalent Rating object, or null if none.

getRatingStyle

added in version 22.1.0
int getRatingStyle ()

Return the rating style.

Returns
int one of RATING_HEART, RATING_THUMB_UP_DOWN, RATING_3_STARS, RATING_4_STARS, RATING_5_STARS, or RATING_PERCENTAGE.

getStarRating

added in version 22.1.0
float getStarRating ()

Return the star-based rating value.

Returns
float 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.

hasHeart

added in version 22.1.0
boolean hasHeart ()

Return whether the rating is "heart selected".

Returns
boolean 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.

isRated

added in version 22.1.0
boolean isRated ()

Return whether there is a rating value available.

Returns
boolean true if the instance was not created with newUnratedRating(int).

isThumbUp

added in version 22.1.0
boolean isThumbUp ()

Return whether the rating is "thumb up".

Returns
boolean 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.

newHeartRating

added in version 22.1.0
RatingCompat newHeartRating (boolean hasHeart)

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 boolean: true for a "heart selected" rating, false for "heart unselected".

Returns
RatingCompat a new Rating instance.

newPercentageRating

added in version 22.1.0
RatingCompat newPercentageRating (float percent)

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 float: the value of the rating

Returns
RatingCompat null if the rating is out of range, a new Rating instance otherwise.

newStarRating

added in version 22.1.0
RatingCompat newStarRating (int starRatingStyle,
                float starRating)

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 int: one of RATING_3_STARS, RATING_4_STARS, RATING_5_STARS.

starRating float: a number ranging from 0.0f to 3.0f, 4.0f or 5.0f according to the rating style.

Returns
RatingCompat null if the rating style is invalid, or the rating is out of range, a new Rating instance otherwise.

newThumbRating

added in version 22.1.0
RatingCompat newThumbRating (boolean thumbIsUp)

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 boolean: true for a "thumb up" rating, false for "thumb down".

Returns
RatingCompat a new Rating instance.

newUnratedRating

added in version 22.1.0
RatingCompat newUnratedRating (int ratingStyle)

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

Parameters
ratingStyle int: one of RATING_HEART, RATING_THUMB_UP_DOWN, RATING_3_STARS, RATING_4_STARS, RATING_5_STARS, or RATING_PERCENTAGE.

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

toString

String toString ()

Returns
String

writeToParcel

added in version 22.1.0
void writeToParcel (Parcel dest,
                int flags)

Parameters
dest Parcel

flags int