Added in API level 19

Rating


class Rating : Parcelable
kotlin.Any
   ↳ android.media.Rating

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
static Int

A rating style with 0 to 3 stars.

static Int

A rating style with 0 to 4 stars.

static Int

A rating style with 0 to 5 stars.

static Int

A rating style with a single degree of rating, "heart" vs "no heart".

static Int

Indicates a rating style is not supported.

static Int

A rating style expressed as a percentage.

static Int

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

Inherited constants
Public methods
Int

Float

Return the percentage-based rating value.

Int

Return the rating style.

Float

Return the star-based rating value.

Boolean

Return whether the rating is "heart selected".

Boolean

Return whether there is a rating value available.

Boolean

Return whether the rating is "thumb up".

static Rating!

Return a Rating instance with a heart-based rating.

static Rating!

Return a Rating instance with a percentage-based rating.

static Rating!
newStarRating(starRatingStyle: Int, starRating: Float)

Return a Rating instance with a star-based rating.

static Rating!
newThumbRating(thumbIsUp: Boolean)

Return a Rating instance with a thumb-based rating.

static Rating!
newUnratedRating(ratingStyle: Int)

Return a Rating instance with no rating.

String

Unit
writeToParcel(dest: Parcel, flags: Int)

Properties
static Parcelable.Creator<Rating!>

Constants

RATING_3_STARS

Added in API level 19
static val RATING_3_STARS: Int

A rating style with 0 to 3 stars.

Value: 3

RATING_4_STARS

Added in API level 19
static val RATING_4_STARS: Int

A rating style with 0 to 4 stars.

Value: 4

RATING_5_STARS

Added in API level 19
static val RATING_5_STARS: Int

A rating style with 0 to 5 stars.

Value: 5

RATING_HEART

Added in API level 19
static val RATING_HEART: Int

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

Value: 1

RATING_NONE

Added in API level 21
static val RATING_NONE: Int

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.

Value: 0

RATING_PERCENTAGE

Added in API level 19
static val RATING_PERCENTAGE: Int

A rating style expressed as a percentage.

Value: 6

RATING_THUMB_UP_DOWN

Added in API level 19
static val RATING_THUMB_UP_DOWN: Int

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

Value: 2

Public methods

describeContents

Added in API level 19
fun describeContents(): Int
Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

getPercentRating

Added in API level 19
fun getPercentRating(): Float

Return the percentage-based rating value.

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

getStarRating

Added in API level 19
fun getStarRating(): Float

Return the star-based rating value.

Return
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 API level 19
fun hasHeart(): Boolean

Return whether the rating is "heart selected".

Return
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 API level 19
fun isRated(): Boolean

Return whether there is a rating value available.

Return
Boolean true if the instance was not created with newUnratedRating(int).

isThumbUp

Added in API level 19
fun isThumbUp(): Boolean

Return whether the rating is "thumb up".

Return
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 API level 19
static fun newHeartRating(hasHeart: Boolean): Rating!

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".
Return
Rating! a new Rating instance.

newPercentageRating

Added in API level 19
static fun newPercentageRating(percent: Float): Rating!

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
Return
Rating! null if the rating is out of range, a new Rating instance otherwise.

newStarRating

Added in API level 19
static fun newStarRating(
    starRatingStyle: Int,
    starRating: Float
): Rating!

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. Value is android.media.Rating#RATING_3_STARS, android.media.Rating#RATING_4_STARS, or android.media.Rating#RATING_5_STARS
starRating Float: a number ranging from 0.0f to 3.0f, 4.0f or 5.0f according to the rating style.
Return
Rating! null if the rating style is invalid, or the rating is out of range, a new Rating instance otherwise.

newThumbRating

Added in API level 19
static fun newThumbRating(thumbIsUp: Boolean): Rating!

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".
Return
Rating! a new Rating instance.

newUnratedRating

Added in API level 19
static fun newUnratedRating(ratingStyle: Int): Rating!

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. Value is android.media.Rating#RATING_NONE, android.media.Rating#RATING_HEART, android.media.Rating#RATING_THUMB_UP_DOWN, android.media.Rating#RATING_3_STARS, android.media.Rating#RATING_4_STARS, android.media.Rating#RATING_5_STARS, or android.media.Rating#RATING_PERCENTAGE
Return
Rating! null if an invalid rating style is passed, a new Rating instance otherwise.

toString

Added in API level 19
fun toString(): String
Return
String a string representation of the object.

writeToParcel

Added in API level 19
fun writeToParcel(
    dest: Parcel,
    flags: Int
): Unit
Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Properties

CREATOR

Added in API level 19
static val CREATOR: Parcelable.Creator<Rating!>