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
129efa2e
authored
Nov 01, 2019
by
ibaker
Committed by
Oliver Woodman
Nov 05, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Remove WebvttCssStyle from null-checking blacklist
PiperOrigin-RevId: 277916508
parent
2139973e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
14 deletions
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCssStyle.java
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCssStyle.java
View file @
129efa2e
...
...
@@ -17,7 +17,9 @@ package com.google.android.exoplayer2.text.webvtt;
import
android.graphics.Typeface
;
import
android.text.Layout
;
import
android.text.TextUtils
;
import
androidx.annotation.IntDef
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.util.Util
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Retention
;
...
...
@@ -25,6 +27,7 @@ import java.lang.annotation.RetentionPolicy;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
org.checkerframework.checker.nullness.qual.EnsuresNonNull
;
/**
* Style object of a Css style block in a Webvtt file.
...
...
@@ -80,7 +83,7 @@ public final class WebvttCssStyle {
private
String
targetVoice
;
// Style properties.
private
String
fontFamily
;
@Nullable
private
String
fontFamily
;
private
int
fontColor
;
private
boolean
hasFontColor
;
private
int
backgroundColor
;
...
...
@@ -91,12 +94,16 @@ public final class WebvttCssStyle {
@OptionalBoolean
private
int
italic
;
@FontSizeUnit
private
int
fontSizeUnit
;
private
float
fontSize
;
private
Layout
.
Alignment
textAlign
;
@Nullable
private
Layout
.
Alignment
textAlign
;
// Calling reset() is forbidden because `this` isn't initialized. This can be safely suppressed
// because reset() only assigns fields, it doesn't read any.
@SuppressWarnings
(
"nullness:method.invocation.invalid"
)
public
WebvttCssStyle
()
{
reset
();
}
@EnsuresNonNull
({
"targetId"
,
"targetTag"
,
"targetClasses"
,
"targetVoice"
})
public
void
reset
()
{
targetId
=
""
;
targetTag
=
""
;
...
...
@@ -133,14 +140,13 @@ public final class WebvttCssStyle {
* Returns a value in a score system compliant with the CSS Specificity rules.
*
* @see <a href="https://www.w3.org/TR/CSS2/cascade.html">CSS Cascading</a>
*
* The score works as follows:
* <ul>
* <li> Id match adds 0x40000000 to the score.
* <li> Each class and voice match adds 4 to the score.
* <li> Tag matching adds 2 to the score.
* <li> Universal selector matching scores 1.
* </ul>
* <p>The score works as follows:
* <ul>
* <li>Id match adds 0x40000000 to the score.
* <li>Each class and voice match adds 4 to the score.
* <li>Tag matching adds 2 to the score.
* <li>Universal selector matching scores 1.
* </ul>
*
* @param id The id of the cue if present, {@code null} otherwise.
* @param tag Name of the tag, {@code null} if it refers to the entire cue.
...
...
@@ -148,12 +154,13 @@ public final class WebvttCssStyle {
* @param voice Annotated voice if present, {@code null} otherwise.
* @return The score of the match, zero if there is no match.
*/
public
int
getSpecificityScore
(
String
id
,
String
tag
,
String
[]
classes
,
String
voice
)
{
public
int
getSpecificityScore
(
@Nullable
String
id
,
@Nullable
String
tag
,
String
[]
classes
,
@Nullable
String
voice
)
{
if
(
targetId
.
isEmpty
()
&&
targetTag
.
isEmpty
()
&&
targetClasses
.
isEmpty
()
&&
targetVoice
.
isEmpty
())
{
// The selector is universal. It matches with the minimum score if and only if the given
// element is a whole cue.
return
tag
.
isEmpty
(
)
?
1
:
0
;
return
TextUtils
.
isEmpty
(
tag
)
?
1
:
0
;
}
int
score
=
0
;
score
=
updateScoreForMatch
(
score
,
targetId
,
id
,
0x40000000
);
...
...
@@ -208,6 +215,7 @@ public final class WebvttCssStyle {
return
this
;
}
@Nullable
public
String
getFontFamily
()
{
return
fontFamily
;
}
...
...
@@ -251,6 +259,7 @@ public final class WebvttCssStyle {
return
hasBackgroundColor
;
}
@Nullable
public
Layout
.
Alignment
getTextAlign
()
{
return
textAlign
;
}
...
...
@@ -309,8 +318,8 @@ public final class WebvttCssStyle {
}
}
private
static
int
updateScoreForMatch
(
int
currentScore
,
String
target
,
String
actual
,
int
score
)
{
private
static
int
updateScoreForMatch
(
int
currentScore
,
String
target
,
@Nullable
String
actual
,
int
score
)
{
if
(
target
.
isEmpty
()
||
currentScore
==
-
1
)
{
return
currentScore
;
}
...
...
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