Use defStyleAttr when obtaining styled attributes in player views

#minor-release
#exofixit
Issue #9024

PiperOrigin-RevId: 395224661
This commit is contained in:
olly 2021-09-07 13:14:54 +01:00 committed by Ian Baker
parent 97b717b8dc
commit 730cdbb9e6
5 changed files with 23 additions and 8 deletions

View File

@ -31,6 +31,9 @@
* `SubtitleView` no longer implements `TextOutput`. `SubtitleView` * `SubtitleView` no longer implements `TextOutput`. `SubtitleView`
implements `Player.Listener`, so can be registered to a player with implements `Player.Listener`, so can be registered to a player with
`Player.addListener`. `Player.addListener`.
* Use `defStyleAttr` when obtaining styled attributes in
`StyledPlayerView`, `PlayerView` and `PlayerControlView`
([#9024](https://github.com/google/ExoPlayer/issues/9024)).
* Remove deprecated symbols: * Remove deprecated symbols:
* Remove `Renderer.VIDEO_SCALING_MODE_*` constants. Use identically named * Remove `Renderer.VIDEO_SCALING_MODE_*` constants. Use identically named
constants in `C` instead. constants in `C` instead.

View File

@ -377,7 +377,8 @@ public class PlayerControlView extends FrameLayout {
TypedArray a = TypedArray a =
context context
.getTheme() .getTheme()
.obtainStyledAttributes(playbackAttrs, R.styleable.PlayerControlView, 0, 0); .obtainStyledAttributes(
playbackAttrs, R.styleable.PlayerControlView, defStyleAttr, /* defStyleRes= */ 0);
try { try {
showTimeoutMs = a.getInt(R.styleable.PlayerControlView_show_timeout, showTimeoutMs); showTimeoutMs = a.getInt(R.styleable.PlayerControlView_show_timeout, showTimeoutMs);
controllerLayoutId = controllerLayoutId =
@ -424,8 +425,8 @@ public class PlayerControlView extends FrameLayout {
if (customTimeBar != null) { if (customTimeBar != null) {
timeBar = customTimeBar; timeBar = customTimeBar;
} else if (timeBarPlaceholder != null) { } else if (timeBarPlaceholder != null) {
// Propagate attrs as timebarAttrs so that DefaultTimeBar's custom attributes are transferred, // Propagate playbackAttrs as timebarAttrs so that DefaultTimeBar's custom attributes are
// but standard attributes (e.g. background) are not. // transferred, but standard attributes (e.g. background) are not.
DefaultTimeBar defaultTimeBar = new DefaultTimeBar(context, null, 0, playbackAttrs); DefaultTimeBar defaultTimeBar = new DefaultTimeBar(context, null, 0, playbackAttrs);
defaultTimeBar.setId(R.id.exo_progress); defaultTimeBar.setId(R.id.exo_progress);
defaultTimeBar.setLayoutParams(timeBarPlaceholder.getLayoutParams()); defaultTimeBar.setLayoutParams(timeBarPlaceholder.getLayoutParams());

View File

@ -367,7 +367,11 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
boolean controllerHideDuringAds = true; boolean controllerHideDuringAds = true;
int showBuffering = SHOW_BUFFERING_NEVER; int showBuffering = SHOW_BUFFERING_NEVER;
if (attrs != null) { if (attrs != null) {
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PlayerView, 0, 0); TypedArray a =
context
.getTheme()
.obtainStyledAttributes(
attrs, R.styleable.PlayerView, defStyleAttr, /* defStyleRes= */ 0);
try { try {
shutterColorSet = a.hasValue(R.styleable.PlayerView_shutter_background_color); shutterColorSet = a.hasValue(R.styleable.PlayerView_shutter_background_color);
shutterColor = a.getColor(R.styleable.PlayerView_shutter_background_color, shutterColor); shutterColor = a.getColor(R.styleable.PlayerView_shutter_background_color, shutterColor);

View File

@ -490,7 +490,11 @@ public class StyledPlayerControlView extends FrameLayout {
TypedArray a = TypedArray a =
context context
.getTheme() .getTheme()
.obtainStyledAttributes(playbackAttrs, R.styleable.StyledPlayerControlView, 0, 0); .obtainStyledAttributes(
playbackAttrs,
R.styleable.StyledPlayerControlView,
defStyleAttr,
/* defStyleRes= */ 0);
try { try {
controllerLayoutId = controllerLayoutId =
a.getResourceId( a.getResourceId(
@ -575,8 +579,8 @@ public class StyledPlayerControlView extends FrameLayout {
if (customTimeBar != null) { if (customTimeBar != null) {
timeBar = customTimeBar; timeBar = customTimeBar;
} else if (timeBarPlaceholder != null) { } else if (timeBarPlaceholder != null) {
// Propagate attrs as timebarAttrs so that DefaultTimeBar's custom attributes are transferred, // Propagate playbackAttrs as timebarAttrs so that DefaultTimeBar's custom attributes are
// but standard attributes (e.g. background) are not. // transferred, but standard attributes (e.g. background) are not.
DefaultTimeBar defaultTimeBar = DefaultTimeBar defaultTimeBar =
new DefaultTimeBar(context, null, 0, playbackAttrs, R.style.ExoStyledControls_TimeBar); new DefaultTimeBar(context, null, 0, playbackAttrs, R.style.ExoStyledControls_TimeBar);
defaultTimeBar.setId(R.id.exo_progress); defaultTimeBar.setId(R.id.exo_progress);

View File

@ -369,7 +369,10 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
int showBuffering = SHOW_BUFFERING_NEVER; int showBuffering = SHOW_BUFFERING_NEVER;
if (attrs != null) { if (attrs != null) {
TypedArray a = TypedArray a =
context.getTheme().obtainStyledAttributes(attrs, R.styleable.StyledPlayerView, 0, 0); context
.getTheme()
.obtainStyledAttributes(
attrs, R.styleable.StyledPlayerView, defStyleAttr, /* defStyleRes= */ 0);
try { try {
shutterColorSet = a.hasValue(R.styleable.StyledPlayerView_shutter_background_color); shutterColorSet = a.hasValue(R.styleable.StyledPlayerView_shutter_background_color);
shutterColor = shutterColor =