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
fa0178d0
authored
May 01, 2020
by
ibaker
Committed by
Oliver Woodman
May 01, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add TypefaceSpan support to SpannedToHtmlConverter
PiperOrigin-RevId: 309390050
parent
10db7a9c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 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 @
fa0178d0
...
...
@@ -22,6 +22,7 @@ import android.text.Spanned;
import
android.text.style.BackgroundColorSpan
;
import
android.text.style.ForegroundColorSpan
;
import
android.text.style.StyleSpan
;
import
android.text.style.TypefaceSpan
;
import
android.text.style.UnderlineSpan
;
import
android.util.SparseArray
;
import
androidx.annotation.Nullable
;
...
...
@@ -131,6 +132,11 @@ import java.util.regex.Pattern;
HtmlUtils
.
toCssRgba
(
colorSpan
.
getBackgroundColor
()));
}
else
if
(
span
instanceof
HorizontalTextInVerticalContextSpan
)
{
return
"<span style='text-combine-upright:all;'>"
;
}
else
if
(
span
instanceof
TypefaceSpan
)
{
@Nullable
String
fontFamily
=
((
TypefaceSpan
)
span
).
getFamily
();
return
fontFamily
!=
null
?
Util
.
formatInvariant
(
"<span style='font-family:\"%s\";'>"
,
fontFamily
)
:
null
;
}
else
if
(
span
instanceof
StyleSpan
)
{
switch
(((
StyleSpan
)
span
).
getStyle
())
{
case
Typeface
.
BOLD
:
...
...
@@ -167,6 +173,9 @@ import java.util.regex.Pattern;
||
span
instanceof
BackgroundColorSpan
||
span
instanceof
HorizontalTextInVerticalContextSpan
)
{
return
"</span>"
;
}
else
if
(
span
instanceof
TypefaceSpan
)
{
@Nullable
String
fontFamily
=
((
TypefaceSpan
)
span
).
getFamily
();
return
fontFamily
!=
null
?
"</span>"
:
null
;
}
else
if
(
span
instanceof
StyleSpan
)
{
switch
(((
StyleSpan
)
span
).
getStyle
())
{
case
Typeface
.
BOLD
:
...
...
library/ui/src/test/java/com/google/android/exoplayer2/ui/SpannedToHtmlConverterTest.java
View file @
fa0178d0
...
...
@@ -25,6 +25,7 @@ import android.text.Spanned;
import
android.text.style.BackgroundColorSpan
;
import
android.text.style.ForegroundColorSpan
;
import
android.text.style.StyleSpan
;
import
android.text.style.TypefaceSpan
;
import
android.text.style.UnderlineSpan
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan
;
...
...
@@ -86,6 +87,37 @@ public class SpannedToHtmlConverterTest {
}
@Test
public
void
convert_supportsTypefaceSpan
()
{
SpannableString
spanned
=
new
SpannableString
(
"String with Times New Roman section"
);
spanned
.
setSpan
(
new
TypefaceSpan
(
/* family= */
"Times New Roman"
),
"String with "
.
length
(),
"String with Times New Roman"
.
length
(),
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
String
html
=
SpannedToHtmlConverter
.
convert
(
spanned
);
assertThat
(
html
)
.
isEqualTo
(
"String with <span style='font-family:\"Times New Roman\";'>Times New Roman</span>"
+
" section"
);
}
@Test
public
void
convert_supportsTypefaceSpan_nullFamily
()
{
SpannableString
spanned
=
new
SpannableString
(
"String with unstyled section"
);
spanned
.
setSpan
(
new
TypefaceSpan
(
/* family= */
(
String
)
null
),
"String with "
.
length
(),
"String with unstyled"
.
length
(),
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
String
html
=
SpannedToHtmlConverter
.
convert
(
spanned
);
assertThat
(
html
).
isEqualTo
(
"String with unstyled section"
);
}
@Test
public
void
convert_supportsStyleSpan
()
{
SpannableString
spanned
=
new
SpannableString
(
"String with bold, italic and bold-italic sections."
);
...
...
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