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
fc5dbfeb
authored
Feb 13, 2020
by
Daniele Bonaldo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add default colors list in WebvttCueParser for text foreground class matching with tests
TIL: papayawhip is a color
parent
e99a7f6c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
8 deletions
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParser.java
library/core/src/main/java/com/google/android/exoplayer2/util/ColorParser.java
library/core/src/test/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParserTest.java
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParser.java
View file @
fc5dbfeb
...
...
@@ -40,7 +40,6 @@ import com.google.android.exoplayer2.text.Cue;
import
com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan
;
import
com.google.android.exoplayer2.text.span.RubySpan
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.ColorParser
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.ParsableByteArray
;
import
com.google.android.exoplayer2.util.Util
;
...
...
@@ -49,7 +48,9 @@ import java.lang.annotation.Retention;
import
java.util.ArrayDeque
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
...
...
@@ -138,6 +139,20 @@ public final class WebvttCueParser {
private
static
final
String
TAG
=
"WebvttCueParser"
;
private
static
final
Map
<
String
,
Integer
>
DEFAULT_COLORS
;
static
{
DEFAULT_COLORS
=
new
HashMap
<>();
DEFAULT_COLORS
.
put
(
"black"
,
0xFF000000
);
DEFAULT_COLORS
.
put
(
"blue"
,
0xFF0000FF
);
DEFAULT_COLORS
.
put
(
"cyan"
,
0xFF00FFFF
);
DEFAULT_COLORS
.
put
(
"lime"
,
0xFF00FF00
);
DEFAULT_COLORS
.
put
(
"magenta"
,
0xFFFF00FF
);
DEFAULT_COLORS
.
put
(
"red"
,
0xFFFF0000
);
DEFAULT_COLORS
.
put
(
"white"
,
0xFFFFFFFF
);
DEFAULT_COLORS
.
put
(
"yellow"
,
0xFFFFFF00
);
}
/**
* Parses the next valid WebVTT cue in a parsable array, including timestamps, settings and text.
*
...
...
@@ -535,9 +550,9 @@ public final class WebvttCueParser {
private
static
void
applySupportedClasses
(
SpannableStringBuilder
text
,
String
[]
classes
,
int
start
,
int
end
)
{
for
(
String
className
:
classes
)
{
if
(
ColorParser
.
isNamedColor
(
className
))
{
int
color
=
ColorParser
.
parseCssColor
(
className
);
text
.
setSpan
(
new
ForegroundColorSpan
(
color
),
start
,
end
,
Spann
able
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
if
(
DEFAULT_COLORS
.
containsKey
(
className
))
{
int
color
=
DEFAULT_COLORS
.
get
(
Util
.
toLowerInvariant
(
className
)
);
text
.
setSpan
(
new
ForegroundColorSpan
(
color
),
start
,
end
,
Spann
ed
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
}
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/util/ColorParser.java
View file @
fc5dbfeb
...
...
@@ -43,10 +43,6 @@ public final class ColorParser {
private
static
final
Map
<
String
,
Integer
>
COLOR_MAP
;
public
static
boolean
isNamedColor
(
String
expression
)
{
return
COLOR_MAP
.
containsKey
(
expression
);
}
/**
* Parses a TTML color expression.
*
...
...
library/core/src/test/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParserTest.java
View file @
fc5dbfeb
...
...
@@ -80,6 +80,22 @@ public final class WebvttCueParserTest {
}
@Test
public
void
testForegroundTextColorClass
()
throws
Exception
{
Spanned
text
=
parseCueText
(
"In this sentence <c.red>this text</c> is red"
);
assertThat
(
text
.
toString
()).
isEqualTo
(
"In this sentence this text is red"
);
assertThat
(
text
).
hasForegroundColorSpanBetween
(
"In this sentence "
.
length
(),
"In this sentence this text"
.
length
());
}
@Test
public
void
testUnsupportedColorForForegroundTextColorClass
()
throws
Exception
{
Spanned
text
=
parseCueText
(
"In this sentence <c.papayawhip>this text</c> is not papaya"
);
assertThat
(
text
.
toString
()).
isEqualTo
(
"In this sentence this text is not papaya"
);
assertThat
(
text
).
hasNoSpans
();
}
@Test
public
void
testParseWellFormedUnclosedEndAtCueEnd
()
throws
Exception
{
Spanned
text
=
parseCueText
(
"An <u some trailing stuff>unclosed u tag with "
+
"<i>italic</i> inside"
);
...
...
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