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
987939d3
authored
Feb 13, 2020
by
Daniele Bonaldo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add suport for text background color classes
parent
fc5dbfeb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletions
library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParser.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 @
987939d3
...
...
@@ -140,6 +140,7 @@ public final class WebvttCueParser {
private
static
final
String
TAG
=
"WebvttCueParser"
;
private
static
final
Map
<
String
,
Integer
>
DEFAULT_COLORS
;
private
static
final
Map
<
String
,
Integer
>
DEFAULT_BACKGROUND_COLORS
;
static
{
DEFAULT_COLORS
=
new
HashMap
<>();
...
...
@@ -151,6 +152,16 @@ public final class WebvttCueParser {
DEFAULT_COLORS
.
put
(
"red"
,
0xFFFF0000
);
DEFAULT_COLORS
.
put
(
"white"
,
0xFFFFFFFF
);
DEFAULT_COLORS
.
put
(
"yellow"
,
0xFFFFFF00
);
DEFAULT_BACKGROUND_COLORS
=
new
HashMap
<>();
DEFAULT_BACKGROUND_COLORS
.
put
(
"bg_black"
,
0xFF000000
);
DEFAULT_BACKGROUND_COLORS
.
put
(
"bg_blue"
,
0xFF0000FF
);
DEFAULT_BACKGROUND_COLORS
.
put
(
"bg_cyan"
,
0xFF00FFFF
);
DEFAULT_BACKGROUND_COLORS
.
put
(
"bg_lime"
,
0xFF00FF00
);
DEFAULT_BACKGROUND_COLORS
.
put
(
"bg_magenta"
,
0xFFFF00FF
);
DEFAULT_BACKGROUND_COLORS
.
put
(
"bg_red"
,
0xFFFF0000
);
DEFAULT_BACKGROUND_COLORS
.
put
(
"bg_white"
,
0xFFFFFFFF
);
DEFAULT_BACKGROUND_COLORS
.
put
(
"bg_yellow"
,
0xFFFFFF00
);
}
/**
...
...
@@ -551,9 +562,13 @@ public final class WebvttCueParser {
int
start
,
int
end
)
{
for
(
String
className
:
classes
)
{
if
(
DEFAULT_COLORS
.
containsKey
(
className
))
{
int
color
=
DEFAULT_COLORS
.
get
(
Util
.
toLowerInvariant
(
className
)
);
int
color
=
DEFAULT_COLORS
.
get
(
className
);
text
.
setSpan
(
new
ForegroundColorSpan
(
color
),
start
,
end
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
if
(
DEFAULT_BACKGROUND_COLORS
.
containsKey
(
className
))
{
int
color
=
DEFAULT_BACKGROUND_COLORS
.
get
(
className
);
text
.
setSpan
(
new
BackgroundColorSpan
(
color
),
start
,
end
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
}
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParserTest.java
View file @
987939d3
...
...
@@ -96,6 +96,22 @@ public final class WebvttCueParserTest {
}
@Test
public
void
testBackgroundTextColorClass
()
throws
Exception
{
Spanned
text
=
parseCueText
(
"In this sentence <c.bg_red>this text</c> has a red background"
);
assertThat
(
text
.
toString
()).
isEqualTo
(
"In this sentence this text has a red background"
);
assertThat
(
text
).
hasBackgroundColorSpanBetween
(
"In this sentence "
.
length
(),
"In this sentence this text"
.
length
());
}
@Test
public
void
testUnsupportedColorForBackgroundTextColorClass
()
throws
Exception
{
Spanned
text
=
parseCueText
(
"In this sentence <c.bg_papayawhip>this text</c> doesn't have a papaya background"
);
assertThat
(
text
.
toString
()).
isEqualTo
(
"In this sentence this text doesn't have a papaya background"
);
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