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
7bf1d891
authored
Sep 01, 2015
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Fixed overlapping captions.
parent
9231520e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
11 deletions
library/src/main/java/com/google/android/exoplayer/text/CuePainter.java
library/src/main/java/com/google/android/exoplayer/text/SubtitleLayout.java
library/src/main/java/com/google/android/exoplayer/text/CuePainter.java
View file @
7bf1d891
...
...
@@ -52,12 +52,6 @@ import android.util.Log;
private
static
final
float
LINE_HEIGHT_FRACTION
=
0.0533f
;
/**
* The default bottom padding to apply when {@link Cue#line} is {@link Cue#UNSET_VALUE}, as a
* fraction of the viewport height.
*/
private
static
final
float
DEFAULT_BOTTOM_PADDING_FRACTION
=
0.08f
;
/**
* Temporary rectangle used for computing line bounds.
*/
private
final
RectF
lineBounds
=
new
RectF
();
...
...
@@ -82,6 +76,8 @@ import android.util.Log;
private
int
windowColor
;
private
int
edgeColor
;
private
int
edgeType
;
private
float
fontScale
;
private
float
bottomPaddingFraction
;
private
int
parentLeft
;
private
int
parentTop
;
private
int
parentRight
;
...
...
@@ -127,14 +123,16 @@ import android.util.Log;
* @param cue The cue to draw.
* @param style The style to use when drawing the cue text.
* @param fontScale The font scale.
* @param bottomPaddingFraction The bottom padding fraction to apply when {@link Cue#line} is
* {@link Cue#UNSET_VALUE}, as a fraction of the viewport height
* @param canvas The canvas into which to draw.
* @param cueBoxLeft The left position of the enclosing cue box.
* @param cueBoxTop The top position of the enclosing cue box.
* @param cueBoxRight The right position of the enclosing cue box.
* @param cueBoxBottom The bottom position of the enclosing cue box.
*/
public
void
draw
(
Cue
cue
,
CaptionStyleCompat
style
,
float
fontScale
,
Canvas
canvas
,
int
cueBoxLeft
,
int
cueBoxTop
,
int
cueBoxRight
,
int
cueBoxBottom
)
{
public
void
draw
(
Cue
cue
,
CaptionStyleCompat
style
,
float
fontScale
,
float
bottomPaddingFraction
,
Canvas
canvas
,
int
cueBoxLeft
,
int
cueBoxTop
,
int
cueBoxRight
,
int
cueBoxBottom
)
{
if
(
TextUtils
.
isEmpty
(
cue
.
text
))
{
// Nothing to draw.
return
;
...
...
@@ -149,6 +147,8 @@ import android.util.Log;
&&
edgeType
==
style
.
edgeType
&&
edgeColor
==
style
.
edgeColor
&&
Util
.
areEqual
(
textPaint
.
getTypeface
(),
style
.
typeface
)
&&
this
.
fontScale
==
fontScale
&&
this
.
bottomPaddingFraction
==
bottomPaddingFraction
&&
parentLeft
==
cueBoxLeft
&&
parentTop
==
cueBoxTop
&&
parentRight
==
cueBoxRight
...
...
@@ -167,6 +167,8 @@ import android.util.Log;
edgeType
=
style
.
edgeType
;
edgeColor
=
style
.
edgeColor
;
textPaint
.
setTypeface
(
style
.
typeface
);
this
.
fontScale
=
fontScale
;
this
.
bottomPaddingFraction
=
bottomPaddingFraction
;
parentLeft
=
cueBoxLeft
;
parentTop
=
cueBoxTop
;
parentRight
=
cueBoxRight
;
...
...
@@ -199,7 +201,7 @@ import android.util.Log;
int
textLeft
=
(
parentWidth
-
textWidth
)
/
2
;
int
textRight
=
textLeft
+
textWidth
;
int
textTop
=
parentBottom
-
textHeight
-
(
int
)
(
parentHeight
*
DEFAULT_BOTTOM_PADDING_FRACTION
);
-
(
int
)
(
parentHeight
*
bottomPaddingFraction
);
int
textBottom
=
textTop
+
textHeight
;
if
(
cue
.
position
!=
Cue
.
UNSET_VALUE
)
{
...
...
library/src/main/java/com/google/android/exoplayer/text/SubtitleLayout.java
View file @
7bf1d891
...
...
@@ -28,11 +28,18 @@ import java.util.List;
*/
public
final
class
SubtitleLayout
extends
View
{
/**
* The default bottom padding to apply when {@link Cue#line} is {@link Cue#UNSET_VALUE}, as a
* fraction of the viewport height.
*/
public
static
final
float
DEFAULT_BOTTOM_PADDING_FRACTION
=
0.08f
;
private
final
List
<
CuePainter
>
painters
;
private
List
<
Cue
>
cues
;
private
float
fontScale
;
private
CaptionStyleCompat
style
;
private
float
bottomPaddingFraction
;
public
SubtitleLayout
(
Context
context
)
{
this
(
context
,
null
);
...
...
@@ -43,6 +50,7 @@ public final class SubtitleLayout extends View {
painters
=
new
ArrayList
<>();
fontScale
=
1
;
style
=
CaptionStyleCompat
.
DEFAULT
;
bottomPaddingFraction
=
DEFAULT_BOTTOM_PADDING_FRACTION
;
}
/**
...
...
@@ -92,12 +100,27 @@ public final class SubtitleLayout extends View {
invalidate
();
}
/**
* Sets the bottom padding fraction to apply when {@link Cue#line} is {@link Cue#UNSET_VALUE},
* as a fraction of the viewport height.
*
* @param bottomPaddingFraction The bottom padding fraction.
*/
public
void
setBottomPaddingFraction
(
float
bottomPaddingFraction
)
{
if
(
this
.
bottomPaddingFraction
==
bottomPaddingFraction
)
{
return
;
}
this
.
bottomPaddingFraction
=
bottomPaddingFraction
;
// Invalidate to trigger drawing.
invalidate
();
}
@Override
public
void
dispatchDraw
(
Canvas
canvas
)
{
int
cueCount
=
(
cues
==
null
)
?
0
:
cues
.
size
();
for
(
int
i
=
0
;
i
<
cueCount
;
i
++)
{
painters
.
get
(
i
).
draw
(
cues
.
get
(
i
),
style
,
fontScale
,
canvas
,
getLeft
(),
getTop
(),
getRigh
t
(),
getBottom
());
painters
.
get
(
i
).
draw
(
cues
.
get
(
i
),
style
,
fontScale
,
bottomPaddingFraction
,
canvas
,
getLef
t
(),
get
Top
(),
getRight
(),
get
Bottom
());
}
}
...
...
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