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
4371617e
authored
Apr 30, 2020
by
ibaker
Committed by
Oliver Woodman
May 01, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add HTML support for BackgroundColorSpan
PiperOrigin-RevId: 309244135
parent
8c64d188
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
5 deletions
library/ui/src/main/java/com/google/android/exoplayer2/ui/SpannedToHtmlConverter.java
library/ui/src/test/java/com/google/android/exoplayer2/ui/SpannedToHtmlConverterTest.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/SpannedToHtmlConverter.java
View file @
4371617e
...
@@ -20,6 +20,7 @@ import android.graphics.Color;
...
@@ -20,6 +20,7 @@ import android.graphics.Color;
import
android.graphics.Typeface
;
import
android.graphics.Typeface
;
import
android.text.Html
;
import
android.text.Html
;
import
android.text.Spanned
;
import
android.text.Spanned
;
import
android.text.style.BackgroundColorSpan
;
import
android.text.style.ForegroundColorSpan
;
import
android.text.style.ForegroundColorSpan
;
import
android.text.style.StyleSpan
;
import
android.text.style.StyleSpan
;
import
android.text.style.UnderlineSpan
;
import
android.text.style.UnderlineSpan
;
...
@@ -125,6 +126,10 @@ import java.util.regex.Pattern;
...
@@ -125,6 +126,10 @@ import java.util.regex.Pattern;
ForegroundColorSpan
colorSpan
=
(
ForegroundColorSpan
)
span
;
ForegroundColorSpan
colorSpan
=
(
ForegroundColorSpan
)
span
;
return
Util
.
formatInvariant
(
return
Util
.
formatInvariant
(
"<span style='color:%s;'>"
,
toCssColor
(
colorSpan
.
getForegroundColor
()));
"<span style='color:%s;'>"
,
toCssColor
(
colorSpan
.
getForegroundColor
()));
}
else
if
(
span
instanceof
BackgroundColorSpan
)
{
BackgroundColorSpan
colorSpan
=
(
BackgroundColorSpan
)
span
;
return
Util
.
formatInvariant
(
"<span style='background-color:%s;'>"
,
toCssColor
(
colorSpan
.
getBackgroundColor
()));
}
else
if
(
span
instanceof
HorizontalTextInVerticalContextSpan
)
{
}
else
if
(
span
instanceof
HorizontalTextInVerticalContextSpan
)
{
return
"<span style='text-combine-upright:all;'>"
;
return
"<span style='text-combine-upright:all;'>"
;
}
else
if
(
span
instanceof
StyleSpan
)
{
}
else
if
(
span
instanceof
StyleSpan
)
{
...
@@ -159,9 +164,9 @@ import java.util.regex.Pattern;
...
@@ -159,9 +164,9 @@ import java.util.regex.Pattern;
@Nullable
@Nullable
private
static
String
getClosingTag
(
Object
span
)
{
private
static
String
getClosingTag
(
Object
span
)
{
if
(
span
instanceof
ForegroundColorSpan
)
{
if
(
span
instanceof
ForegroundColorSpan
return
"</span>"
;
||
span
instanceof
BackgroundColorSpan
}
else
if
(
span
instanceof
HorizontalTextInVerticalContextSpan
)
{
||
span
instanceof
HorizontalTextInVerticalContextSpan
)
{
return
"</span>"
;
return
"</span>"
;
}
else
if
(
span
instanceof
StyleSpan
)
{
}
else
if
(
span
instanceof
StyleSpan
)
{
switch
(((
StyleSpan
)
span
).
getStyle
())
{
switch
(((
StyleSpan
)
span
).
getStyle
())
{
...
...
library/ui/src/test/java/com/google/android/exoplayer2/ui/SpannedToHtmlConverterTest.java
View file @
4371617e
...
@@ -22,6 +22,7 @@ import android.graphics.Color;
...
@@ -22,6 +22,7 @@ import android.graphics.Color;
import
android.graphics.Typeface
;
import
android.graphics.Typeface
;
import
android.text.SpannableString
;
import
android.text.SpannableString
;
import
android.text.Spanned
;
import
android.text.Spanned
;
import
android.text.style.BackgroundColorSpan
;
import
android.text.style.ForegroundColorSpan
;
import
android.text.style.ForegroundColorSpan
;
import
android.text.style.StyleSpan
;
import
android.text.style.StyleSpan
;
import
android.text.style.UnderlineSpan
;
import
android.text.style.UnderlineSpan
;
...
@@ -39,7 +40,7 @@ public class SpannedToHtmlConverterTest {
...
@@ -39,7 +40,7 @@ public class SpannedToHtmlConverterTest {
public
void
convert_supportsForegroundColorSpan
()
{
public
void
convert_supportsForegroundColorSpan
()
{
SpannableString
spanned
=
new
SpannableString
(
"String with colored section"
);
SpannableString
spanned
=
new
SpannableString
(
"String with colored section"
);
spanned
.
setSpan
(
spanned
.
setSpan
(
new
ForegroundColorSpan
(
Color
.
argb
(
128
,
64
,
32
,
16
)),
new
ForegroundColorSpan
(
Color
.
argb
(
51
,
64
,
32
,
16
)),
"String with "
.
length
(),
"String with "
.
length
(),
"String with colored"
.
length
(),
"String with colored"
.
length
(),
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
...
@@ -47,7 +48,24 @@ public class SpannedToHtmlConverterTest {
...
@@ -47,7 +48,24 @@ public class SpannedToHtmlConverterTest {
String
html
=
SpannedToHtmlConverter
.
convert
(
spanned
);
String
html
=
SpannedToHtmlConverter
.
convert
(
spanned
);
assertThat
(
html
)
assertThat
(
html
)
.
isEqualTo
(
"String with <span style='color:rgba(64,32,16,0.502);'>colored</span> section"
);
.
isEqualTo
(
"String with <span style='color:rgba(64,32,16,0.200);'>colored</span> section"
);
}
@Test
public
void
convert_supportsBackgroundColorSpan
()
{
SpannableString
spanned
=
new
SpannableString
(
"String with highlighted section"
);
spanned
.
setSpan
(
new
BackgroundColorSpan
(
Color
.
argb
(
51
,
64
,
32
,
16
)),
"String with "
.
length
(),
"String with highlighted"
.
length
(),
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
String
html
=
SpannedToHtmlConverter
.
convert
(
spanned
);
assertThat
(
html
)
.
isEqualTo
(
"String with <span style='background-color:rgba(64,32,16,0.200);'>highlighted</span>"
+
" section"
);
}
}
@Test
@Test
...
...
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