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

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

Introduction

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

Prototype

int RATING_HEART

To view the source code for android.support.v4.media RatingCompat RATING_HEART.

Click Source Link

Document

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

Usage

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 w  ww.ja  va2 s.c  o  m*/
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;
    }
}

From source file:org.runbuddy.tomahawk.services.PlaybackService.java

private void initMediaSession() {
    ComponentName componentName = new ComponentName(this, MediaButtonReceiver.class);
    mMediaSession = new MediaSessionCompat(getApplicationContext(), "Tomahawk", componentName, null);
    mMediaSession.setFlags(//from  w  ww.ja  v  a  2 s.co  m
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    Intent intent = new Intent(PlaybackService.this, TomahawkMainActivity.class);
    intent.setAction(TomahawkMainActivity.SHOW_PLAYBACKFRAGMENT_ON_STARTUP);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(PlaybackService.this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mMediaSession.setSessionActivity(pendingIntent);
    HandlerThread thread = new HandlerThread("playbackservice_callback");
    thread.start();
    mCallbackHandler = new Handler(thread.getLooper());
    mMediaSession.setCallback(mMediaSessionCallback, mCallbackHandler);
    mMediaSession.setRatingType(RatingCompat.RATING_HEART);
    Bundle extras = new Bundle();
    extras.putString(EXTRAS_KEY_PLAYBACKMANAGER, mPlaybackManager.getId());
    mMediaSession.setExtras(extras);
    updateMediaPlayState();
    setSessionToken(mMediaSession.getSessionToken());
}