Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
416bd435
authored
May 03, 2021
by
gyumin
Committed by
bachinger
May 04, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Revise javadoc for Rating classes
PiperOrigin-RevId: 371625281
parent
f7a8c6e4
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
107 additions
and
117 deletions
library/common/src/main/java/com/google/android/exoplayer2/HeartRating.java
library/common/src/main/java/com/google/android/exoplayer2/PercentageRating.java
library/common/src/main/java/com/google/android/exoplayer2/Rating.java
library/common/src/main/java/com/google/android/exoplayer2/StarRating.java
library/common/src/main/java/com/google/android/exoplayer2/ThumbRating.java
library/common/src/test/java/com/google/android/exoplayer2/RatingTest.java
library/common/src/main/java/com/google/android/exoplayer2/HeartRating.java
View file @
416bd435
...
@@ -26,42 +26,40 @@ import java.lang.annotation.Retention;
...
@@ -26,42 +26,40 @@ import java.lang.annotation.Retention;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.RetentionPolicy
;
/**
/**
* A
class for rating with a single degree of rating, "heart" vs "no heart". This can be used to
* A
rating expressed as "heart" or "no heart". It can be used to indicate whether the content is a
*
indicate the content referred to is a favorite (or not)
.
*
favorite
.
*/
*/
public
final
class
HeartRating
extends
Rating
{
public
final
class
HeartRating
extends
Rating
{
@RatingType
private
static
final
int
TYPE
=
RATING_TYPE_HEART
;
private
final
boolean
rated
;
private
final
boolean
isRated
;
/** Whether the rating
has a heart rating or not
. */
/** Whether the rating
is "heart"
. */
public
final
boolean
ha
sHeart
;
public
final
boolean
i
sHeart
;
/** Creates a unrated
HeartRating
instance. */
/** Creates a unrated instance. */
public
HeartRating
()
{
public
HeartRating
()
{
isR
ated
=
false
;
r
ated
=
false
;
ha
sHeart
=
false
;
i
sHeart
=
false
;
}
}
/**
/**
* Creates a
HeartRating
instance.
* Creates a
rated
instance.
*
*
* @param
hasHeart true for a "heart selected" rating, false for "heart unselected
".
* @param
isHeart {@code true} for "heart", {@code false} for "no heart
".
*/
*/
public
HeartRating
(
boolean
ha
sHeart
)
{
public
HeartRating
(
boolean
i
sHeart
)
{
isR
ated
=
true
;
r
ated
=
true
;
this
.
hasHeart
=
ha
sHeart
;
this
.
isHeart
=
i
sHeart
;
}
}
@Override
@Override
public
boolean
isRated
()
{
public
boolean
isRated
()
{
return
isR
ated
;
return
r
ated
;
}
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hashCode
(
isRated
,
ha
sHeart
);
return
Objects
.
hashCode
(
rated
,
i
sHeart
);
}
}
@Override
@Override
...
@@ -70,42 +68,40 @@ public final class HeartRating extends Rating {
...
@@ -70,42 +68,40 @@ public final class HeartRating extends Rating {
return
false
;
return
false
;
}
}
HeartRating
other
=
(
HeartRating
)
obj
;
HeartRating
other
=
(
HeartRating
)
obj
;
return
hasHeart
==
other
.
hasHeart
&&
isRated
==
other
.
isRated
;
return
isHeart
==
other
.
isHeart
&&
rated
==
other
.
rated
;
}
@Override
public
String
toString
()
{
return
"HeartRating: "
+
(
isRated
?
"hasHeart="
+
hasHeart
:
"unrated"
);
}
}
// Bundleable implementation.
// Bundleable implementation.
@RatingType
private
static
final
int
TYPE
=
RATING_TYPE_HEART
;
@Documented
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@Retention
(
RetentionPolicy
.
SOURCE
)
@IntDef
({
FIELD_RATING_TYPE
,
FIELD_
IS_RATED
,
FIELD_HA
S_HEART
})
@IntDef
({
FIELD_RATING_TYPE
,
FIELD_
RATED
,
FIELD_I
S_HEART
})
private
@interface
FieldNumber
{}
private
@interface
FieldNumber
{}
private
static
final
int
FIELD_
IS_
RATED
=
1
;
private
static
final
int
FIELD_RATED
=
1
;
private
static
final
int
FIELD_
HA
S_HEART
=
2
;
private
static
final
int
FIELD_
I
S_HEART
=
2
;
@Override
@Override
public
Bundle
toBundle
()
{
public
Bundle
toBundle
()
{
Bundle
bundle
=
new
Bundle
();
Bundle
bundle
=
new
Bundle
();
bundle
.
putInt
(
keyForField
(
FIELD_RATING_TYPE
),
TYPE
);
bundle
.
putInt
(
keyForField
(
FIELD_RATING_TYPE
),
TYPE
);
bundle
.
putBoolean
(
keyForField
(
FIELD_
IS_RATED
),
isR
ated
);
bundle
.
putBoolean
(
keyForField
(
FIELD_
RATED
),
r
ated
);
bundle
.
putBoolean
(
keyForField
(
FIELD_
HAS_HEART
),
ha
sHeart
);
bundle
.
putBoolean
(
keyForField
(
FIELD_
IS_HEART
),
i
sHeart
);
return
bundle
;
return
bundle
;
}
}
/** Object that can restore a {@link HeartRating} from a {@link Bundle}. */
public
static
final
Creator
<
HeartRating
>
CREATOR
=
HeartRating:
:
fromBundle
;
public
static
final
Creator
<
HeartRating
>
CREATOR
=
HeartRating:
:
fromBundle
;
private
static
HeartRating
fromBundle
(
Bundle
bundle
)
{
private
static
HeartRating
fromBundle
(
Bundle
bundle
)
{
checkArgument
(
checkArgument
(
bundle
.
getInt
(
keyForField
(
FIELD_RATING_TYPE
),
/* defaultValue= */
RATING_TYPE_DEFAULT
)
bundle
.
getInt
(
keyForField
(
FIELD_RATING_TYPE
),
/* defaultValue= */
RATING_TYPE_DEFAULT
)
==
TYPE
);
==
TYPE
);
boolean
isRated
=
bundle
.
getBoolean
(
keyForField
(
FIELD_
IS_
RATED
),
/* defaultValue= */
false
);
boolean
isRated
=
bundle
.
getBoolean
(
keyForField
(
FIELD_RATED
),
/* defaultValue= */
false
);
return
isRated
return
isRated
?
new
HeartRating
(
?
new
HeartRating
(
bundle
.
getBoolean
(
keyForField
(
FIELD_IS_HEART
),
/* defaultValue= */
false
))
bundle
.
getBoolean
(
keyForField
(
FIELD_HAS_HEART
),
/* defaultValue= */
false
))
:
new
HeartRating
();
:
new
HeartRating
();
}
}
...
...
library/common/src/main/java/com/google/android/exoplayer2/PercentageRating.java
View file @
416bd435
...
@@ -26,30 +26,27 @@ import java.lang.annotation.Documented;
...
@@ -26,30 +26,27 @@ import java.lang.annotation.Documented;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.RetentionPolicy
;
/** A
class for
rating expressed as a percentage. */
/** A rating expressed as a percentage. */
public
final
class
PercentageRating
extends
Rating
{
public
final
class
PercentageRating
extends
Rating
{
@RatingType
private
static
final
int
TYPE
=
RATING_TYPE_PERCENTAGE
;
/**
/**
* The percent value of this rating. Will be
greater or equal to 0.0f, or {@link #RATING_UNSET} if
* The percent value of this rating. Will be
within the range {@code [0f, 100f]}, or {@link
*
it is
unrated.
*
#RATING_UNSET} if
unrated.
*/
*/
public
final
float
percent
;
public
final
float
percent
;
/** Creates a unrated
PercentageRating
instance. */
/** Creates a unrated instance. */
public
PercentageRating
()
{
public
PercentageRating
()
{
percent
=
RATING_UNSET
;
percent
=
RATING_UNSET
;
}
}
/**
/**
* Creates a PercentageRating instance with the given percentage. If {@code percent} is less than
* Creates a rated instance with the given percentage.
* 0f or greater than 100f, it will throw IllegalArgumentException.
*
*
* @param percent
the value of the rating
* @param percent
The percentage value of the rating.
*/
*/
public
PercentageRating
(
@FloatRange
(
from
=
0
,
to
=
100
)
float
percent
)
{
public
PercentageRating
(
@FloatRange
(
from
=
0
,
to
=
100
)
float
percent
)
{
checkArgument
(
percent
>=
0.0f
&&
percent
<=
100.0f
,
"percent must be in the rage of [0, 100]"
);
checkArgument
(
percent
>=
0.0f
&&
percent
<=
100.0f
,
"percent must be in the ra
n
ge of [0, 100]"
);
this
.
percent
=
percent
;
this
.
percent
=
percent
;
}
}
...
@@ -71,12 +68,10 @@ public final class PercentageRating extends Rating {
...
@@ -71,12 +68,10 @@ public final class PercentageRating extends Rating {
return
percent
==
((
PercentageRating
)
obj
).
percent
;
return
percent
==
((
PercentageRating
)
obj
).
percent
;
}
}
@Override
public
String
toString
()
{
return
"PercentageRating: "
+
(
isRated
()
?
"percentage="
+
percent
:
"unrated"
);
}
// Bundleable implementation.
// Bundleable implementation.
@RatingType
private
static
final
int
TYPE
=
RATING_TYPE_PERCENTAGE
;
@Documented
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@Retention
(
RetentionPolicy
.
SOURCE
)
@IntDef
({
FIELD_RATING_TYPE
,
FIELD_PERCENT
})
@IntDef
({
FIELD_RATING_TYPE
,
FIELD_PERCENT
})
...
@@ -92,6 +87,7 @@ public final class PercentageRating extends Rating {
...
@@ -92,6 +87,7 @@ public final class PercentageRating extends Rating {
return
bundle
;
return
bundle
;
}
}
/** Object that can restore a {@link PercentageRating} from a {@link Bundle}. */
public
static
final
Creator
<
PercentageRating
>
CREATOR
=
PercentageRating:
:
fromBundle
;
public
static
final
Creator
<
PercentageRating
>
CREATOR
=
PercentageRating:
:
fromBundle
;
private
static
PercentageRating
fromBundle
(
Bundle
bundle
)
{
private
static
PercentageRating
fromBundle
(
Bundle
bundle
)
{
...
...
library/common/src/main/java/com/google/android/exoplayer2/Rating.java
View file @
416bd435
...
@@ -21,11 +21,23 @@ import java.lang.annotation.Documented;
...
@@ -21,11 +21,23 @@ import java.lang.annotation.Documented;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.RetentionPolicy
;
/** An abstract class to encapsulate rating information used as content metadata. */
/**
* A rating for media content. The style of a rating can be one of {@link HeartRating}, {@link
* PercentageRating}, {@link StarRating}, or {@link ThumbRating}.
*/
public
abstract
class
Rating
implements
Bundleable
{
public
abstract
class
Rating
implements
Bundleable
{
/** A float value that denotes the rating is unset. */
public
static
final
float
RATING_UNSET
=
-
1.0f
;
public
static
final
float
RATING_UNSET
=
-
1.0f
;
// Default package-private constructor to prevent extending Rating class outside this package.
/* package */
Rating
()
{}
/** Whether the rating exists or not. */
public
abstract
boolean
isRated
();
// Bundleable implementation.
@Documented
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@Retention
(
RetentionPolicy
.
SOURCE
)
@IntDef
({
@IntDef
({
...
@@ -35,28 +47,22 @@ public abstract class Rating implements Bundleable {
...
@@ -35,28 +47,22 @@ public abstract class Rating implements Bundleable {
RATING_TYPE_STAR
,
RATING_TYPE_STAR
,
RATING_TYPE_THUMB
RATING_TYPE_THUMB
})
})
protected
@interface
RatingType
{}
/* package */
@interface
RatingType
{}
protected
static
final
int
RATING_TYPE_DEFAULT
=
-
1
;
protected
static
final
int
RATING_TYPE_HEART
=
0
;
protected
static
final
int
RATING_TYPE_PERCENTAGE
=
1
;
protected
static
final
int
RATING_TYPE_STAR
=
2
;
protected
static
final
int
RATING_TYPE_THUMB
=
3
;
// Default package-private constructor to prevent extending Rating class outside this package.
/* package */
static
final
int
RATING_TYPE_DEFAULT
=
-
1
;
/* package */
Rating
()
{}
/* package */
static
final
int
RATING_TYPE_HEART
=
0
;
/* package */
static
final
int
RATING_TYPE_PERCENTAGE
=
1
;
/* package */
static
final
int
RATING_TYPE_STAR
=
2
;
/* package */
static
final
int
RATING_TYPE_THUMB
=
3
;
/** Whether rating exists or not. */
public
abstract
boolean
isRated
();
// Bundleable implementation.
@Documented
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@Retention
(
RetentionPolicy
.
SOURCE
)
@IntDef
({
FIELD_RATING_TYPE
})
@IntDef
({
FIELD_RATING_TYPE
})
private
@interface
FieldNumber
{}
private
@interface
FieldNumber
{}
protected
static
final
int
FIELD_RATING_TYPE
=
0
;
/* package */
static
final
int
FIELD_RATING_TYPE
=
0
;
/** Object that can restore a {@link Rating} from a {@link Bundle}. */
public
static
final
Creator
<
Rating
>
CREATOR
=
Rating:
:
fromBundle
;
public
static
final
Creator
<
Rating
>
CREATOR
=
Rating:
:
fromBundle
;
private
static
Rating
fromBundle
(
Bundle
bundle
)
{
private
static
Rating
fromBundle
(
Bundle
bundle
)
{
...
...
library/common/src/main/java/com/google/android/exoplayer2/StarRating.java
View file @
416bd435
...
@@ -27,28 +27,24 @@ import java.lang.annotation.Documented;
...
@@ -27,28 +27,24 @@ import java.lang.annotation.Documented;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.RetentionPolicy
;
/** A
class for rating expressed as the
number of stars. */
/** A
rating expressed as a fractional
number of stars. */
public
final
class
StarRating
extends
Rating
{
public
final
class
StarRating
extends
Rating
{
@RatingType
private
static
final
int
TYPE
=
RATING_TYPE_STAR
;
/** The maximum number of stars. Must be a positive number. */
private
static
final
int
MAX_STARS_DEFAULT
=
5
;
/** The maximum number of stars for this rating. Must be a positive number. */
@IntRange
(
from
=
1
)
@IntRange
(
from
=
1
)
public
final
int
maxStars
;
public
final
int
maxStars
;
/**
/**
* The
value of stars for this rating. Will range from 0.0f to {@link #maxStars}, or {@link
* The
fractional number of stars of this rating. Will range from {@code 0f} to {@link #maxStars},
*
#RATING_UNSET} if it is
unrated.
*
or {@link #RATING_UNSET} if
unrated.
*/
*/
public
final
float
starRating
;
public
final
float
starRating
;
/**
/**
* Creates a unrated
StarRating instance with {@code maxStars}. If {@code maxStars} is not a
* Creates a unrated
instance with {@code maxStars}. If {@code maxStars} is not a positive
*
positive integer, it will throw IllegalArgumentException
.
*
integer, it will throw an {@link IllegalArgumentException}
.
*
*
* @param maxStars
a range of this star rating from 0.0f to {@code maxStars}
* @param maxStars
The maximum number of stars this rating can have.
*/
*/
public
StarRating
(
@IntRange
(
from
=
1
)
int
maxStars
)
{
public
StarRating
(
@IntRange
(
from
=
1
)
int
maxStars
)
{
checkArgument
(
maxStars
>
0
,
"maxStars must be a positive integer"
);
checkArgument
(
maxStars
>
0
,
"maxStars must be a positive integer"
);
...
@@ -57,13 +53,14 @@ public final class StarRating extends Rating {
...
@@ -57,13 +53,14 @@ public final class StarRating extends Rating {
}
}
/**
/**
* Creates a
StarRating instance with {@code maxStars} and the given integer or fractional number
* Creates a
rated instance with {@code maxStars} and the given fractional number of stars.
*
of stars. Non-integer values can for instance be used to represent an average rating value,
*
Non-integer values may be used to represent an average rating value. If {@code maxStars} is not
*
which might not be an integer number of stars. If {@code maxStars} is not a positive integer or
*
a positive integer or {@code starRating} is out of range, it will throw an {@link
*
{@code starRating} has invalid value, it will throw IllegalArgumentException
.
*
IllegalArgumentException}
.
*
*
* @param maxStars the maximum number of stars which this rating can have.
* @param maxStars The maximum number of stars this rating can have.
* @param starRating a number ranging from 0.0f to {@code maxStars}
* @param starRating A fractional number of stars of this rating from {@code 0f} to {@code
* maxStars}.
*/
*/
public
StarRating
(
@IntRange
(
from
=
1
)
int
maxStars
,
@FloatRange
(
from
=
0.0
)
float
starRating
)
{
public
StarRating
(
@IntRange
(
from
=
1
)
int
maxStars
,
@FloatRange
(
from
=
0.0
)
float
starRating
)
{
checkArgument
(
maxStars
>
0
,
"maxStars must be a positive integer"
);
checkArgument
(
maxStars
>
0
,
"maxStars must be a positive integer"
);
...
@@ -92,14 +89,11 @@ public final class StarRating extends Rating {
...
@@ -92,14 +89,11 @@ public final class StarRating extends Rating {
return
maxStars
==
other
.
maxStars
&&
starRating
==
other
.
starRating
;
return
maxStars
==
other
.
maxStars
&&
starRating
==
other
.
starRating
;
}
}
@Override
public
String
toString
()
{
return
"StarRating: maxStars="
+
maxStars
+
(
isRated
()
?
", starRating="
+
starRating
:
", unrated"
);
}
// Bundleable implementation.
// Bundleable implementation.
@RatingType
private
static
final
int
TYPE
=
RATING_TYPE_STAR
;
private
static
final
int
MAX_STARS_DEFAULT
=
5
;
@Documented
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@Retention
(
RetentionPolicy
.
SOURCE
)
@IntDef
({
FIELD_RATING_TYPE
,
FIELD_MAX_STARS
,
FIELD_STAR_RATING
})
@IntDef
({
FIELD_RATING_TYPE
,
FIELD_MAX_STARS
,
FIELD_STAR_RATING
})
...
@@ -117,6 +111,7 @@ public final class StarRating extends Rating {
...
@@ -117,6 +111,7 @@ public final class StarRating extends Rating {
return
bundle
;
return
bundle
;
}
}
/** Object that can restore a {@link StarRating} from a {@link Bundle}. */
public
static
final
Creator
<
StarRating
>
CREATOR
=
StarRating:
:
fromBundle
;
public
static
final
Creator
<
StarRating
>
CREATOR
=
StarRating:
:
fromBundle
;
private
static
StarRating
fromBundle
(
Bundle
bundle
)
{
private
static
StarRating
fromBundle
(
Bundle
bundle
)
{
...
...
library/common/src/main/java/com/google/android/exoplayer2/ThumbRating.java
View file @
416bd435
...
@@ -25,40 +25,38 @@ import java.lang.annotation.Documented;
...
@@ -25,40 +25,38 @@ import java.lang.annotation.Documented;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.RetentionPolicy
;
/** A
class for rating with a single degree of rating, "thumb up" vs "thumb
down". */
/** A
rating expressed as "thumbs up" or "thumbs
down". */
public
final
class
ThumbRating
extends
Rating
{
public
final
class
ThumbRating
extends
Rating
{
@RatingType
private
static
final
int
TYPE
=
RATING_TYPE_THUMB
;
private
final
boolean
rated
;
private
final
boolean
isRated
;
/** Whether the rating
has a thumb up or thumb down rating
. */
/** Whether the rating
is "thumbs up"
. */
public
final
boolean
thumb
Up
;
public
final
boolean
isThumbs
Up
;
/** Creates a unrated
ThumbRating
instance. */
/** Creates a unrated instance. */
public
ThumbRating
()
{
public
ThumbRating
()
{
isR
ated
=
false
;
r
ated
=
false
;
thumb
Up
=
false
;
isThumbs
Up
=
false
;
}
}
/**
/**
* Creates a
ThumbRating
instance.
* Creates a
rated
instance.
*
*
* @param
thumbIsUp true for a "thumb up" rating, false for "thumb
down".
* @param
isThumbsUp {@code true} for "thumbs up", {@code false} for "thumbs
down".
*/
*/
public
ThumbRating
(
boolean
thumbI
sUp
)
{
public
ThumbRating
(
boolean
isThumb
sUp
)
{
isR
ated
=
true
;
r
ated
=
true
;
th
umbUp
=
thumbI
sUp
;
th
is
.
isThumbsUp
=
isThumb
sUp
;
}
}
@Override
@Override
public
boolean
isRated
()
{
public
boolean
isRated
()
{
return
isR
ated
;
return
r
ated
;
}
}
@Override
@Override
public
int
hashCode
()
{
public
int
hashCode
()
{
return
Objects
.
hashCode
(
isRated
,
thumb
Up
);
return
Objects
.
hashCode
(
rated
,
isThumbs
Up
);
}
}
@Override
@Override
...
@@ -67,42 +65,41 @@ public final class ThumbRating extends Rating {
...
@@ -67,42 +65,41 @@ public final class ThumbRating extends Rating {
return
false
;
return
false
;
}
}
ThumbRating
other
=
(
ThumbRating
)
obj
;
ThumbRating
other
=
(
ThumbRating
)
obj
;
return
thumbUp
==
other
.
thumbUp
&&
isRated
==
other
.
isRated
;
return
isThumbsUp
==
other
.
isThumbsUp
&&
rated
==
other
.
rated
;
}
@Override
public
String
toString
()
{
return
"ThumbRating: "
+
(
isRated
?
"isThumbUp="
+
thumbUp
:
"unrated"
);
}
}
// Bundleable implementation.
// Bundleable implementation.
@RatingType
private
static
final
int
TYPE
=
RATING_TYPE_THUMB
;
@Documented
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@Retention
(
RetentionPolicy
.
SOURCE
)
@IntDef
({
FIELD_RATING_TYPE
,
FIELD_
IS_RATED
,
FIELD_IS_THUMB
_UP
})
@IntDef
({
FIELD_RATING_TYPE
,
FIELD_
RATED
,
FIELD_IS_THUMBS
_UP
})
private
@interface
FieldNumber
{}
private
@interface
FieldNumber
{}
private
static
final
int
FIELD_
IS_
RATED
=
1
;
private
static
final
int
FIELD_RATED
=
1
;
private
static
final
int
FIELD_IS_THUMB_UP
=
2
;
private
static
final
int
FIELD_IS_THUMB
S
_UP
=
2
;
@Override
@Override
public
Bundle
toBundle
()
{
public
Bundle
toBundle
()
{
Bundle
bundle
=
new
Bundle
();
Bundle
bundle
=
new
Bundle
();
bundle
.
putInt
(
keyForField
(
FIELD_RATING_TYPE
),
TYPE
);
bundle
.
putInt
(
keyForField
(
FIELD_RATING_TYPE
),
TYPE
);
bundle
.
putBoolean
(
keyForField
(
FIELD_
IS_RATED
),
isR
ated
);
bundle
.
putBoolean
(
keyForField
(
FIELD_
RATED
),
r
ated
);
bundle
.
putBoolean
(
keyForField
(
FIELD_IS_THUMB
_UP
),
thumb
Up
);
bundle
.
putBoolean
(
keyForField
(
FIELD_IS_THUMB
S_UP
),
isThumbs
Up
);
return
bundle
;
return
bundle
;
}
}
/** Object that can restore a {@link ThumbRating} from a {@link Bundle}. */
public
static
final
Creator
<
ThumbRating
>
CREATOR
=
ThumbRating:
:
fromBundle
;
public
static
final
Creator
<
ThumbRating
>
CREATOR
=
ThumbRating:
:
fromBundle
;
private
static
ThumbRating
fromBundle
(
Bundle
bundle
)
{
private
static
ThumbRating
fromBundle
(
Bundle
bundle
)
{
checkArgument
(
checkArgument
(
bundle
.
getInt
(
keyForField
(
FIELD_RATING_TYPE
),
/* defaultValue= */
RATING_TYPE_DEFAULT
)
bundle
.
getInt
(
keyForField
(
FIELD_RATING_TYPE
),
/* defaultValue= */
RATING_TYPE_DEFAULT
)
==
TYPE
);
==
TYPE
);
boolean
isRated
=
bundle
.
getBoolean
(
keyForField
(
FIELD_IS
_RATED
),
/* defaultValue= */
false
);
boolean
rated
=
bundle
.
getBoolean
(
keyForField
(
FIELD
_RATED
),
/* defaultValue= */
false
);
return
isR
ated
return
r
ated
?
new
ThumbRating
(
?
new
ThumbRating
(
bundle
.
getBoolean
(
keyForField
(
FIELD_IS_THUMB_UP
),
/* defaultValue= */
false
))
bundle
.
getBoolean
(
keyForField
(
FIELD_IS_THUMB
S
_UP
),
/* defaultValue= */
false
))
:
new
ThumbRating
();
:
new
ThumbRating
();
}
}
...
...
library/common/src/test/java/com/google/android/exoplayer2/RatingTest.java
View file @
416bd435
...
@@ -39,7 +39,7 @@ public class RatingTest {
...
@@ -39,7 +39,7 @@ public class RatingTest {
boolean
hasHeart
=
true
;
boolean
hasHeart
=
true
;
HeartRating
rating
=
new
HeartRating
(
hasHeart
);
HeartRating
rating
=
new
HeartRating
(
hasHeart
);
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
ha
sHeart
).
isEqualTo
(
hasHeart
);
assertThat
(
rating
.
i
sHeart
).
isEqualTo
(
hasHeart
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
}
}
...
@@ -71,7 +71,7 @@ public class RatingTest {
...
@@ -71,7 +71,7 @@ public class RatingTest {
boolean
isThumbUp
=
true
;
boolean
isThumbUp
=
true
;
ThumbRating
rating
=
new
ThumbRating
(
isThumbUp
);
ThumbRating
rating
=
new
ThumbRating
(
isThumbUp
);
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
isRated
()).
isTrue
();
assertThat
(
rating
.
thumb
Up
).
isEqualTo
(
isThumbUp
);
assertThat
(
rating
.
isThumbs
Up
).
isEqualTo
(
isThumbUp
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
assertThat
(
roundTripViaBundle
(
rating
)).
isEqualTo
(
rating
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment