public final class

ThumbRating

extends java.lang.Object

implements Rating

 java.lang.Object

↳androidx.media2.session.ThumbRating

Gradle dependencies

compile group: 'androidx.media2', name: 'media2-session', version: '1.2.1'

  • groupId: androidx.media2
  • artifactId: media2-session
  • version: 1.2.1

Artifact androidx.media2:media2-session:1.2.1 it located at Google repository (https://maven.google.com/)

Overview

A class for rating with a single degree of rating, "thumb up" vs "thumb down".

Summary

Constructors
publicThumbRating()

Creates a unrated ThumbRating instance.

publicThumbRating(boolean thumbIsUp)

Creates a ThumbRating instance.

Methods
public booleanequals(java.lang.Object obj)

public inthashCode()

public booleanisRated()

public booleanisThumbUp()

Returns whether the rating is "thumb up".

public java.lang.StringtoString()

from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Constructors

public ThumbRating()

Creates a unrated ThumbRating instance.

public ThumbRating(boolean thumbIsUp)

Creates a ThumbRating instance.

Parameters:

thumbIsUp: true for a "thumb up" rating, false for "thumb down".

Methods

public boolean isRated()

public int hashCode()

public boolean equals(java.lang.Object obj)

public java.lang.String toString()

public boolean isThumbUp()

Returns whether the rating is "thumb up".

Returns:

true if the rating is "thumb up", false if the rating is "thumb down", or if it is unrated.

Source

/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.media2.session;

import androidx.core.util.ObjectsCompat;
import androidx.media2.common.Rating;
import androidx.versionedparcelable.ParcelField;
import androidx.versionedparcelable.VersionedParcelize;

/**
 * A class for rating with a single degree of rating, "thumb up" vs "thumb down".
 */
@VersionedParcelize
public final class ThumbRating implements Rating {
    @ParcelField(1)
    boolean mIsRated;

    @ParcelField(2)
    boolean mThumbUp;

    // WARNING: Adding a new ParcelField may break old library users (b/152830728)

    /**
     * Creates a unrated ThumbRating instance.
     */
    public ThumbRating() {
        mIsRated = false;
    }

    /**
     * Creates a ThumbRating instance.
     *
     * @param thumbIsUp true for a "thumb up" rating, false for "thumb down".
     */
    public ThumbRating(boolean thumbIsUp) {
        mThumbUp = thumbIsUp;
        mIsRated = true;
    }

    @Override
    public boolean isRated() {
        return mIsRated;
    }

    @Override
    public int hashCode() {
        return ObjectsCompat.hash(mIsRated, mThumbUp);
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ThumbRating)) {
            return false;
        }
        ThumbRating other = (ThumbRating) obj;
        return mThumbUp == other.mThumbUp && mIsRated == other.mIsRated;
    }

    @Override
    public String toString() {
        return "ThumbRating: " + (mIsRated ? "isThumbUp=" + mThumbUp : "unrated");
    }

    /**
     * Returns whether the rating is "thumb up".
     *
     * @return true if the rating is "thumb up", false if the rating is "thumb down",
     *         or if it is unrated.
     */
    public boolean isThumbUp() {
        return mThumbUp;
    }
}