Example usage for android.support.v4.media RatingCompat hasHeart

List of usage examples for android.support.v4.media RatingCompat hasHeart

Introduction

In this page you can find the example usage for android.support.v4.media RatingCompat hasHeart.

Prototype

public boolean hasHeart() 

Source Link

Document

Return whether the rating is "heart selected".

Usage

From source file:org.runbuddy.tomahawk.utils.MediaNotification.java

private void updateFavoriteAction() {
    Log.d(TAG, "updateFavoriteAction");
    String favoriteLabel;/* w  w  w  .j  av a 2s  .  c  o m*/
    int favoriteIcon;
    RatingCompat rating = mMetadata.getRating(MediaMetadataCompat.METADATA_KEY_USER_RATING);
    if (rating != null && rating.hasHeart()) {
        favoriteLabel = mService.getString(R.string.playback_unfavorite);
        favoriteIcon = R.drawable.ic_action_favorites_small_underlined;
    } else {
        favoriteLabel = mService.getString(R.string.playback_favorite);
        favoriteIcon = R.drawable.ic_action_favorites_small;
    }
    if (mFavoriteAction == null) {
        mFavoriteAction = new NotificationCompat.Action.Builder(favoriteIcon, favoriteLabel,
                mIntents.get(favoriteIcon)).build();
    } else {
        mFavoriteAction.icon = favoriteIcon;
        mFavoriteAction.title = favoriteLabel;
        mFavoriteAction.actionIntent = mIntents.get(favoriteIcon);
    }
}

From source file:androidx.media.MediaUtils2.java

/**
 * Creates a {@link Rating2} from the {@link RatingCompat}.
 *
 * @param ratingCompat A {@link RatingCompat} object.
 * @return The newly created {@link Rating2} object.
 *///from  ww w  .j  a va2s.c om
Rating2 createRating2(RatingCompat ratingCompat) {
    if (ratingCompat == null) {
        return null;
    }
    if (!ratingCompat.isRated()) {
        return Rating2.newUnratedRating(ratingCompat.getRatingStyle());
    }

    switch (ratingCompat.getRatingStyle()) {
    case RatingCompat.RATING_3_STARS:
    case RatingCompat.RATING_4_STARS:
    case RatingCompat.RATING_5_STARS:
        return Rating2.newStarRating(ratingCompat.getRatingStyle(), ratingCompat.getStarRating());
    case RatingCompat.RATING_HEART:
        return Rating2.newHeartRating(ratingCompat.hasHeart());
    case RatingCompat.RATING_THUMB_UP_DOWN:
        return Rating2.newThumbRating(ratingCompat.isThumbUp());
    case RatingCompat.RATING_PERCENTAGE:
        return Rating2.newPercentageRating(ratingCompat.getPercentRating());
    default:
        return null;
    }
}