From fb023da529d9d86ec2f7c921dae7ba084fa50e5c Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 5 Sep 2017 13:06:02 -0700 Subject: [PATCH] Fix attr inheritance in SimpleExoPlayerView When creating PlaybackControlView inside SimpleExoPlayerView, we want certain attributes to be passed through. This lets you set control attributes on the SimpleExoPlayerView directly. We don't want all attributes to be propagated though; only our own custom ones. Not sure if there's a cleaner way to do this. Pragmatically this solution seems ... ok :)? ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=167619801 --- .../android/exoplayer2/ui/PlaybackControlView.java | 10 +++++++--- .../android/exoplayer2/ui/SimpleExoPlayerView.java | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlaybackControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlaybackControlView.java index c89feaebf5..9bbb2fa27b 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlaybackControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlaybackControlView.java @@ -298,16 +298,20 @@ public class PlaybackControlView extends FrameLayout { } public PlaybackControlView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); + this(context, attrs, defStyleAttr, attrs); + } + public PlaybackControlView(Context context, AttributeSet attrs, int defStyleAttr, + AttributeSet playbackAttrs) { + super(context, attrs, defStyleAttr); int controllerLayoutId = R.layout.exo_playback_control_view; rewindMs = DEFAULT_REWIND_MS; fastForwardMs = DEFAULT_FAST_FORWARD_MS; showTimeoutMs = DEFAULT_SHOW_TIMEOUT_MS; repeatToggleModes = DEFAULT_REPEAT_TOGGLE_MODES; showShuffleButton = false; - if (attrs != null) { - TypedArray a = context.getTheme().obtainStyledAttributes(attrs, + if (playbackAttrs != null) { + TypedArray a = context.getTheme().obtainStyledAttributes(playbackAttrs, R.styleable.PlaybackControlView, 0, 0); try { rewindMs = a.getInt(R.styleable.PlaybackControlView_rewind_increment, rewindMs); diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/SimpleExoPlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/SimpleExoPlayerView.java index 5b6e11c5e4..488411550c 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/SimpleExoPlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/SimpleExoPlayerView.java @@ -240,7 +240,7 @@ public final class SimpleExoPlayerView extends FrameLayout { controller = null; componentListener = null; overlayFrameLayout = null; - ImageView logo = new ImageView(context, attrs); + ImageView logo = new ImageView(context); if (Util.SDK_INT >= 23) { configureEditModeLogoV23(getResources(), logo); } else { @@ -330,9 +330,9 @@ public final class SimpleExoPlayerView extends FrameLayout { if (customController != null) { this.controller = customController; } else if (controllerPlaceholder != null) { - // Note: rewindMs and fastForwardMs are passed via attrs, so we don't need to make explicit - // calls to set them. - this.controller = new PlaybackControlView(context, attrs); + // Propagate attrs as playbackAttrs so that PlaybackControlView's custom attributes are + // transferred, but standard FrameLayout attributes (e.g. background) are not. + this.controller = new PlaybackControlView(context, null, 0, attrs); controller.setLayoutParams(controllerPlaceholder.getLayoutParams()); ViewGroup parent = ((ViewGroup) controllerPlaceholder.getParent()); int controllerIndex = parent.indexOfChild(controllerPlaceholder);