public final class StarRating extends Rating


A rating expressed as a fractional number of stars.

Summary

Public fields

final @IntRange(from = 1) int
final float

Public constructors

StarRating(@IntRange(from = 1) int maxStars)

Creates a unrated instance with maxStars.

StarRating(
    @IntRange(from = 1) int maxStars,
    @FloatRange(from = 0.0) float starRating
)

Creates a rated instance with maxStars and the given fractional number of stars.

Public methods

boolean
static StarRating

Restores a StarRating from a Bundle.

@IntRange(from = 1) int

Returns the maximum number of stars.

float

Returns the fractional number of stars of this rating.

int
boolean

Whether the rating exists or not.

Bundle

Returns a Bundle representing the information stored in this rating.

Inherited methods

From androidx.media3.common.Rating
static Rating

Restores a Rating from a Bundle.

Public fields

maxStars

public final @IntRange(from = 1) int maxStars

starRating

public final float starRating

Public constructors

StarRating

public StarRating(@IntRange(from = 1) int maxStars)

Creates a unrated instance with maxStars. If maxStars is not a positive integer, it will throw an IllegalArgumentException.

Parameters
@IntRange(from = 1) int maxStars

The maximum number of stars this rating can have.

StarRating

public StarRating(
    @IntRange(from = 1) int maxStars,
    @FloatRange(from = 0.0) float starRating
)

Creates a rated instance with maxStars and the given fractional number of stars. Non-integer values may be used to represent an average rating value. If maxStars is not a positive integer or starRating is out of range, it will throw an .

Parameters
@IntRange(from = 1) int maxStars

The maximum number of stars this rating can have.

@FloatRange(from = 0.0) float starRating

A fractional number of stars of this rating from 0f to maxStars.

Public methods

equals

public boolean equals(@Nullable Object obj)

fromBundle

@UnstableApi
public static StarRating fromBundle(Bundle bundle)

Restores a StarRating from a Bundle.

getMaxStars

public @IntRange(from = 1) int getMaxStars()

Returns the maximum number of stars. Must be a positive number.

getStarRating

public float getStarRating()

Returns the fractional number of stars of this rating. Will range from 0f to maxStars, or RATING_UNSET if unrated.

hashCode

public int hashCode()

isRated

public boolean isRated()

Whether the rating exists or not.

toBundle

@UnstableApi
public Bundle toBundle()

Returns a Bundle representing the information stored in this rating.