From 26bbee5b4024e61c904e8adb98bcf41db125879a 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 --- .../google/android/exoplayer2/ui/PlaybackControlView.java | 8 ++++++-- .../google/android/exoplayer2/ui/SimpleExoPlayerView.java | 8 ++++---- 2 files changed, 10 insertions(+), 6 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 017a200005c..e9da88cb2f1 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 @@ -339,15 +339,19 @@ public PlaybackControlView(Context context, AttributeSet attrs) { } 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; if (attrs != null) { - TypedArray a = context.getTheme().obtainStyledAttributes(attrs, + 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 0d10e0fcf90..d51fa87ed76 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 @@ -239,7 +239,7 @@ public SimpleExoPlayerView(Context context, AttributeSet attrs, int defStyleAttr 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 { @@ -329,9 +329,9 @@ public SimpleExoPlayerView(Context context, AttributeSet attrs, int defStyleAttr 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);