Commit 6c31e345 by olly Committed by kim-vde

Use onEvents in PlayerControlView/StyledPlayerControlView

#exofixit

PiperOrigin-RevId: 343821736
parent e5e903eb
...@@ -757,6 +757,18 @@ public interface Player { ...@@ -757,6 +757,18 @@ public interface Player {
} }
/** /**
* Returns whether any of the given events occurred.
*
* @param events The {@link EventFlags events}.
* @return Whether any of the events occurred.
*/
@Override
public boolean containsAny(@EventFlags int... events) {
// Overridden to add IntDef compiler enforcement and new JavaDoc.
return super.containsAny(events);
}
/**
* Returns the {@link EventFlags event} at the given index. * Returns the {@link EventFlags event} at the given index.
* *
* <p>Although index-based access is possible, it doesn't imply a particular order of these * <p>Although index-based access is possible, it doesn't imply a particular order of these
......
...@@ -111,6 +111,18 @@ public interface AnalyticsListener { ...@@ -111,6 +111,18 @@ public interface AnalyticsListener {
} }
/** /**
* Returns whether any of the given events occurred.
*
* @param events The {@link EventFlags events}.
* @return Whether any of the events occurred.
*/
@Override
public boolean containsAny(@EventFlags int... events) {
// Overridden to add IntDef compiler enforcement and new JavaDoc.
return super.containsAny(events);
}
/**
* Returns the {@link EventFlags event} at the given index. * Returns the {@link EventFlags event} at the given index.
* *
* <p>Although index-based access is possible, it doesn't imply a particular order of these * <p>Although index-based access is possible, it doesn't imply a particular order of these
......
...@@ -57,6 +57,21 @@ public class MutableFlags { ...@@ -57,6 +57,21 @@ public class MutableFlags {
return flags.get(flag); return flags.get(flag);
} }
/**
* Returns whether the set contains at least one of the given flags.
*
* @param flags The flags.
* @return Whether the set contains at least one of the flags.
*/
public boolean containsAny(int... flags) {
for (int flag : flags) {
if (contains(flag)) {
return true;
}
}
return false;
}
/** Returns the number of flags in this set. */ /** Returns the number of flags in this set. */
public int size() { public int size() {
return flags.size(); return flags.size();
......
...@@ -15,6 +15,14 @@ ...@@ -15,6 +15,14 @@
*/ */
package com.google.android.exoplayer2.ui; package com.google.android.exoplayer2.ui;
import static com.google.android.exoplayer2.Player.EVENT_IS_PLAYING_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_PLAYBACK_STATE_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_PLAY_WHEN_READY_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_POSITION_DISCONTINUITY;
import static com.google.android.exoplayer2.Player.EVENT_REPEAT_MODE_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_SHUFFLE_MODE_ENABLED_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_TIMELINE_CHANGED;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
...@@ -38,6 +46,7 @@ import com.google.android.exoplayer2.DefaultControlDispatcher; ...@@ -38,6 +46,7 @@ import com.google.android.exoplayer2.DefaultControlDispatcher;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo; import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.PlaybackPreparer; import com.google.android.exoplayer2.PlaybackPreparer;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Player.Events;
import com.google.android.exoplayer2.Player.State; import com.google.android.exoplayer2.Player.State;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
...@@ -1336,46 +1345,31 @@ public class PlayerControlView extends FrameLayout { ...@@ -1336,46 +1345,31 @@ public class PlayerControlView extends FrameLayout {
} }
@Override @Override
public void onPlaybackStateChanged(@Player.State int playbackState) { public void onEvents(Player player, Events events) {
if (events.containsAny(EVENT_PLAYBACK_STATE_CHANGED, EVENT_PLAY_WHEN_READY_CHANGED)) {
updatePlayPauseButton(); updatePlayPauseButton();
updateProgress();
} }
if (events.containsAny(
@Override EVENT_PLAYBACK_STATE_CHANGED, EVENT_PLAY_WHEN_READY_CHANGED, EVENT_IS_PLAYING_CHANGED)) {
public void onPlayWhenReadyChanged(
boolean playWhenReady, @Player.PlayWhenReadyChangeReason int reason) {
updatePlayPauseButton();
updateProgress(); updateProgress();
} }
if (events.contains(EVENT_REPEAT_MODE_CHANGED)) {
@Override
public void onIsPlayingChanged(boolean isPlaying) {
updateProgress();
}
@Override
public void onRepeatModeChanged(int repeatMode) {
updateRepeatModeButton(); updateRepeatModeButton();
updateNavigation();
} }
if (events.contains(EVENT_SHUFFLE_MODE_ENABLED_CHANGED)) {
@Override
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
updateShuffleButton(); updateShuffleButton();
updateNavigation();
} }
if (events.containsAny(
@Override EVENT_REPEAT_MODE_CHANGED,
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) { EVENT_SHUFFLE_MODE_ENABLED_CHANGED,
EVENT_POSITION_DISCONTINUITY,
EVENT_TIMELINE_CHANGED)) {
updateNavigation(); updateNavigation();
updateTimeline();
} }
if (events.containsAny(EVENT_POSITION_DISCONTINUITY, EVENT_TIMELINE_CHANGED)) {
@Override
public void onTimelineChanged(Timeline timeline, @Player.TimelineChangeReason int reason) {
updateNavigation();
updateTimeline(); updateTimeline();
} }
}
@Override @Override
public void onClick(View view) { public void onClick(View view) {
......
...@@ -15,6 +15,15 @@ ...@@ -15,6 +15,15 @@
*/ */
package com.google.android.exoplayer2.ui; package com.google.android.exoplayer2.ui;
import static com.google.android.exoplayer2.Player.EVENT_IS_PLAYING_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_PLAYBACK_PARAMETERS_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_PLAYBACK_STATE_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_PLAY_WHEN_READY_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_POSITION_DISCONTINUITY;
import static com.google.android.exoplayer2.Player.EVENT_REPEAT_MODE_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_SHUFFLE_MODE_ENABLED_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_TIMELINE_CHANGED;
import static com.google.android.exoplayer2.Player.EVENT_TRACKS_CHANGED;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
...@@ -45,6 +54,7 @@ import com.google.android.exoplayer2.Format; ...@@ -45,6 +54,7 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.PlaybackPreparer; import com.google.android.exoplayer2.PlaybackPreparer;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Player.Events;
import com.google.android.exoplayer2.Player.State; import com.google.android.exoplayer2.Player.State;
import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.Timeline;
...@@ -1767,55 +1777,36 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1767,55 +1777,36 @@ public class StyledPlayerControlView extends FrameLayout {
} }
@Override @Override
public void onPlaybackStateChanged(@Player.State int playbackState) { public void onEvents(Player player, Events events) {
if (events.containsAny(EVENT_PLAYBACK_STATE_CHANGED, EVENT_PLAY_WHEN_READY_CHANGED)) {
updatePlayPauseButton(); updatePlayPauseButton();
updateProgress();
} }
if (events.containsAny(
@Override EVENT_PLAYBACK_STATE_CHANGED, EVENT_PLAY_WHEN_READY_CHANGED, EVENT_IS_PLAYING_CHANGED)) {
public void onPlayWhenReadyChanged(
boolean playWhenReady, @Player.PlayWhenReadyChangeReason int state) {
updatePlayPauseButton();
updateProgress(); updateProgress();
} }
if (events.contains(EVENT_REPEAT_MODE_CHANGED)) {
@Override
public void onIsPlayingChanged(boolean isPlaying) {
updateProgress();
}
@Override
public void onRepeatModeChanged(int repeatMode) {
updateRepeatModeButton(); updateRepeatModeButton();
updateNavigation();
} }
if (events.contains(EVENT_SHUFFLE_MODE_ENABLED_CHANGED)) {
@Override
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
updateShuffleButton(); updateShuffleButton();
updateNavigation();
} }
if (events.containsAny(
@Override EVENT_REPEAT_MODE_CHANGED,
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) { EVENT_SHUFFLE_MODE_ENABLED_CHANGED,
EVENT_POSITION_DISCONTINUITY,
EVENT_TIMELINE_CHANGED)) {
updateNavigation(); updateNavigation();
}
if (events.containsAny(EVENT_POSITION_DISCONTINUITY, EVENT_TIMELINE_CHANGED)) {
updateTimeline(); updateTimeline();
} }
if (events.contains(EVENT_PLAYBACK_PARAMETERS_CHANGED)) {
@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
updateSettingsPlaybackSpeedLists(); updateSettingsPlaybackSpeedLists();
} }
if (events.contains(EVENT_TRACKS_CHANGED)) {
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
updateTrackLists(); updateTrackLists();
} }
@Override
public void onTimelineChanged(Timeline timeline, @Player.TimelineChangeReason int reason) {
updateNavigation();
updateTimeline();
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment