RatingCompat

class RatingCompat : Parcelable


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

const Parcelable.Creator<RatingCompat!>!
const Int

A rating style with 0 to 3 stars.

const Int

A rating style with 0 to 4 stars.

const Int

A rating style with 0 to 5 stars.

const Int

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

const Int

Indicates a rating style is not supported.

const Int

A rating style expressed as a percentage.

const Int

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

Public functions

Int
java-static RatingCompat!
fromRating(ratingObj: Any!)

Creates an instance from a framework android.media.Rating object.

Float

Return the percentage-based rating value.

Any!

Gets the underlying framework android.media.Rating object.

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

java-static RatingCompat!

Return a Rating instance with a heart-based rating.

java-static RatingCompat!

Return a Rating instance with a percentage-based rating.

java-static RatingCompat!
newStarRating(starRatingStyle: Int, starRating: Float)

Return a Rating instance with a star-based rating.

java-static RatingCompat!
newThumbRating(thumbIsUp: Boolean)

Return a Rating instance with a thumb-based rating.

java-static RatingCompat!
newUnratedRating(ratingStyle: Int)

Return a Rating instance with no rating.

String!
Unit
writeToParcel(dest: Parcel!, flags: Int)

Constants

CREATOR

Added in 1.1.0
const val CREATORParcelable.Creator<RatingCompat!>!

RATING_3_STARS

Added in 1.1.0
const val RATING_3_STARS = 3: Int

A rating style with 0 to 3 stars.

RATING_4_STARS

Added in 1.1.0
const val RATING_4_STARS = 4: Int

A rating style with 0 to 4 stars.

RATING_5_STARS

Added in 1.1.0
const val RATING_5_STARS = 5: Int

A rating style with 0 to 5 stars.

RATING_HEART

Added in 1.1.0
const val RATING_HEART = 1: 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).

RATING_NONE

Added in 1.1.0
const val RATING_NONE = 0: 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.

RATING_PERCENTAGE

Added in 1.1.0
const val RATING_PERCENTAGE = 6: Int

A rating style expressed as a percentage.

RATING_THUMB_UP_DOWN

Added in 1.1.0
const val RATING_THUMB_UP_DOWN = 2: Int

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

Public functions

describeContents

Added in 1.1.0
fun describeContents(): Int

fromRating

Added in 1.1.0
java-static fun fromRating(ratingObj: Any!): RatingCompat!

Creates an instance from a framework android.media.Rating object.

This method is only supported on API 19+.

Parameters
ratingObj: Any!

A android.media.Rating object, or null if none.

Returns
RatingCompat!

An equivalent RatingCompat object, or null if none.

getPercentRating

Added in 1.1.0
fun getPercentRating(): Float

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 1.1.0
fun getRating(): Any!

Gets the underlying framework android.media.Rating object.

This method is only supported on API 19+.

Returns
Any!

An equivalent android.media.Rating object, or null if none.

getRatingStyle

Added in 1.1.0
fun getRatingStyle(): Int

Return the rating style.

getStarRating

Added in 1.1.0
fun getStarRating(): Float

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 1.1.0
fun hasHeart(): Boolean

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 1.1.0
fun isRated(): Boolean

Return whether there is a rating value available.

Returns
Boolean

true if the instance was not created with newUnratedRating.

isThumbUp

Added in 1.1.0
fun isThumbUp(): Boolean

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 1.1.0
java-static fun newHeartRating(hasHeart: Boolean): RatingCompat!

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 1.1.0
java-static fun newPercentageRating(percent: Float): RatingCompat!

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 1.1.0
java-static fun newStarRating(starRatingStyle: Int, starRating: Float): RatingCompat!

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 1.1.0
java-static fun newThumbRating(thumbIsUp: Boolean): RatingCompat!

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 1.1.0
java-static fun newUnratedRating(ratingStyle: Int): RatingCompat!

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

Returns
RatingCompat!

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

toString

fun toString(): String!

writeToParcel

Added in 1.1.0
fun writeToParcel(dest: Parcel!, flags: Int): Unit