Fields Summary |
---|
private static final String | TAG |
public static final int | RATING_NONEIndicates 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. |
public static final int | RATING_HEARTA 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). |
public static final int | RATING_THUMB_UP_DOWNA rating style for "thumb up" vs "thumb down". |
public static final int | RATING_3_STARSA rating style with 0 to 3 stars. |
public static final int | RATING_4_STARSA rating style with 0 to 4 stars. |
public static final int | RATING_5_STARSA rating style with 0 to 5 stars. |
public static final int | RATING_PERCENTAGEA rating style expressed as a percentage. |
private static final float | RATING_NOT_RATED |
private final int | mRatingStyle |
private final float | mRatingValue |
private Object | mRatingObj |
public static final Parcelable.Creator | CREATOR |
Methods Summary |
---|
public int | describeContents()
return mRatingStyle;
|
public static android.support.v4.media.RatingCompat | fromRating(java.lang.Object ratingObj)Creates an instance from a framework {@link android.media.Rating} object.
This method is only supported on API 21+.
if (ratingObj == null || Build.VERSION.SDK_INT < 21) {
return null;
}
final int ratingStyle = RatingCompatApi21.getRatingStyle(ratingObj);
final RatingCompat rating;
if (RatingCompatApi21.isRated(ratingObj)) {
switch (ratingStyle) {
case RATING_HEART:
rating = newHeartRating(RatingCompatApi21.hasHeart(ratingObj));
break;
case RATING_THUMB_UP_DOWN:
rating = newThumbRating(RatingCompatApi21.isThumbUp(ratingObj));
break;
case RATING_3_STARS:
case RATING_4_STARS:
case RATING_5_STARS:
rating = newStarRating(ratingStyle,
RatingCompatApi21.getStarRating(ratingObj));
break;
case RATING_PERCENTAGE:
rating = newPercentageRating(RatingCompatApi21.getPercentRating(ratingObj));
break;
default:
return null;
}
} else {
rating = newUnratedRating(ratingStyle);
}
rating.mRatingObj = ratingObj;
return rating;
|
public float | getPercentRating()Return the percentage-based rating value.
if ((mRatingStyle != RATING_PERCENTAGE) || !isRated()) {
return -1.0f;
} else {
return mRatingValue;
}
|
public java.lang.Object | getRating()Gets the underlying framework {@link android.media.Rating} object.
This method is only supported on API 21+.
if (mRatingObj != null || Build.VERSION.SDK_INT < 21) {
return mRatingObj;
}
if (isRated()) {
switch (mRatingStyle) {
case RATING_HEART:
mRatingObj = RatingCompatApi21.newHeartRating(hasHeart());
break;
case RATING_THUMB_UP_DOWN:
mRatingObj = RatingCompatApi21.newThumbRating(isThumbUp());
break;
case RATING_3_STARS:
case RATING_4_STARS:
case RATING_5_STARS:
mRatingObj = RatingCompatApi21.newStarRating(mRatingStyle, getStarRating());
break;
case RATING_PERCENTAGE:
mRatingObj = RatingCompatApi21.newPercentageRating(getPercentRating());
default:
return null;
}
} else {
mRatingObj = RatingCompatApi21.newUnratedRating(mRatingStyle);
}
return mRatingObj;
|
public int | getRatingStyle()Return the rating style.
return mRatingStyle;
|
public float | getStarRating()Return the star-based rating value.
switch (mRatingStyle) {
case RATING_3_STARS:
case RATING_4_STARS:
case RATING_5_STARS:
if (isRated()) {
return mRatingValue;
}
default:
return -1.0f;
}
|
public boolean | hasHeart()Return whether the rating is "heart selected".
if (mRatingStyle != RATING_HEART) {
return false;
} else {
return (mRatingValue == 1.0f);
}
|
public boolean | isRated()Return whether there is a rating value available.
return mRatingValue >= 0.0f;
|
public boolean | isThumbUp()Return whether the rating is "thumb up".
if (mRatingStyle != RATING_THUMB_UP_DOWN) {
return false;
} else {
return (mRatingValue == 1.0f);
}
|
public static android.support.v4.media.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 {@link #RATING_HEART},
and a heart-based rating.
return new RatingCompat(RATING_HEART, hasHeart ? 1.0f : 0.0f);
|
public static android.support.v4.media.RatingCompat | newPercentageRating(float percent)Return a Rating instance with a percentage-based rating.
Create and return a new Rating instance with a {@link #RATING_PERCENTAGE}
rating style, and a rating of the given percentage.
if ((percent < 0.0f) || (percent > 100.0f)) {
Log.e(TAG, "Invalid percentage-based rating value");
return null;
} else {
return new RatingCompat(RATING_PERCENTAGE, percent);
}
|
public static android.support.v4.media.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.
float maxRating = -1.0f;
switch(starRatingStyle) {
case RATING_3_STARS:
maxRating = 3.0f;
break;
case RATING_4_STARS:
maxRating = 4.0f;
break;
case RATING_5_STARS:
maxRating = 5.0f;
break;
default:
Log.e(TAG, "Invalid rating style (" + starRatingStyle + ") for a star rating");
return null;
}
if ((starRating < 0.0f) || (starRating > maxRating)) {
Log.e(TAG, "Trying to set out of range star-based rating");
return null;
}
return new RatingCompat(starRatingStyle, starRating);
|
public static android.support.v4.media.RatingCompat | newThumbRating(boolean thumbIsUp)Return a Rating instance with a thumb-based rating.
Create and return a new Rating instance with a {@link #RATING_THUMB_UP_DOWN}
rating style, and a "thumb up" or "thumb down" rating.
return new RatingCompat(RATING_THUMB_UP_DOWN, thumbIsUp ? 1.0f : 0.0f);
|
public static android.support.v4.media.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.
switch(ratingStyle) {
case RATING_HEART:
case RATING_THUMB_UP_DOWN:
case RATING_3_STARS:
case RATING_4_STARS:
case RATING_5_STARS:
case RATING_PERCENTAGE:
return new RatingCompat(ratingStyle, RATING_NOT_RATED);
default:
return null;
}
|
public java.lang.String | toString()
return "Rating:style=" + mRatingStyle + " rating="
+ (mRatingValue < 0.0f ? "unrated" : String.valueOf(mRatingValue));
|
public void | writeToParcel(android.os.Parcel dest, int flags)
dest.writeInt(mRatingStyle);
dest.writeFloat(mRatingValue);
|