mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Use lambdas where possible
PiperOrigin-RevId: 320960833
This commit is contained in:
parent
29b12e2f8d
commit
f205539616
@ -1146,17 +1146,16 @@ public class SessionPlayerConnectorTest {
|
||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||
InstrumentationRegistry.getInstrumentation()
|
||||
.runOnMainSync(
|
||||
() -> {
|
||||
simpleExoPlayer.addListener(
|
||||
new Player.EventListener() {
|
||||
@Override
|
||||
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
|
||||
if (playWhenReady) {
|
||||
simpleExoPlayer.setPlayWhenReady(false);
|
||||
() ->
|
||||
simpleExoPlayer.addListener(
|
||||
new Player.EventListener() {
|
||||
@Override
|
||||
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
|
||||
if (playWhenReady) {
|
||||
simpleExoPlayer.setPlayWhenReady(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
assertPlayerResultSuccess(sessionPlayerConnector.play());
|
||||
assertThat(
|
||||
|
@ -149,19 +149,19 @@ public final class SessionPlayerConnector extends SessionPlayer {
|
||||
@Override
|
||||
public ListenableFuture<PlayerResult> play() {
|
||||
return playerCommandQueue.addCommand(
|
||||
PlayerCommandQueue.COMMAND_CODE_PLAYER_PLAY, /* command= */ () -> player.play());
|
||||
PlayerCommandQueue.COMMAND_CODE_PLAYER_PLAY, /* command= */ player::play);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<PlayerResult> pause() {
|
||||
return playerCommandQueue.addCommand(
|
||||
PlayerCommandQueue.COMMAND_CODE_PLAYER_PAUSE, /* command= */ () -> player.pause());
|
||||
PlayerCommandQueue.COMMAND_CODE_PLAYER_PAUSE, /* command= */ player::pause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<PlayerResult> prepare() {
|
||||
return playerCommandQueue.addCommand(
|
||||
PlayerCommandQueue.COMMAND_CODE_PLAYER_PREPARE, /* command= */ () -> player.prepare());
|
||||
PlayerCommandQueue.COMMAND_CODE_PLAYER_PREPARE, /* command= */ player::prepare);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -771,9 +771,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
||||
keepaliveSessions.add(session);
|
||||
Assertions.checkNotNull(sessionReleasingHandler)
|
||||
.postAtTime(
|
||||
() -> {
|
||||
session.release(/* eventDispatcher= */ null);
|
||||
},
|
||||
() -> session.release(/* eventDispatcher= */ null),
|
||||
session,
|
||||
/* uptimeMillis= */ SystemClock.uptimeMillis() + sessionKeepaliveMs);
|
||||
} else if (newReferenceCount == 0) {
|
||||
|
@ -156,9 +156,8 @@ public final class FrameworkMediaDrm implements ExoMediaDrm {
|
||||
mediaDrm.setOnExpirationUpdateListener(
|
||||
listener == null
|
||||
? null
|
||||
: (mediaDrm, sessionId, expirationTimeMs) -> {
|
||||
listener.onExpirationUpdate(FrameworkMediaDrm.this, sessionId, expirationTimeMs);
|
||||
},
|
||||
: (mediaDrm, sessionId, expirationTimeMs) ->
|
||||
listener.onExpirationUpdate(FrameworkMediaDrm.this, sessionId, expirationTimeMs),
|
||||
/* handler= */ null);
|
||||
}
|
||||
|
||||
|
@ -1913,9 +1913,7 @@ public final class ExoPlayerTest {
|
||||
.waitForTimelineChanged()
|
||||
.pause()
|
||||
.sendMessage(
|
||||
(messageType, payload) -> {
|
||||
counter.getAndIncrement();
|
||||
},
|
||||
(messageType, payload) -> counter.getAndIncrement(),
|
||||
/* windowIndex= */ 0,
|
||||
/* positionMs= */ 2000,
|
||||
/* deleteAfterDelivery= */ false)
|
||||
|
@ -40,7 +40,6 @@ import com.google.android.exoplayer2.testutil.FakeSampleStream;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@ -78,11 +77,8 @@ public class MediaCodecAudioRendererTest {
|
||||
when(audioSink.handleBuffer(any(), anyLong(), anyInt())).thenReturn(true);
|
||||
|
||||
mediaCodecSelector =
|
||||
new MediaCodecSelector() {
|
||||
@Override
|
||||
public List<MediaCodecInfo> getDecoderInfos(
|
||||
String mimeType, boolean requiresSecureDecoder, boolean requiresTunnelingDecoder) {
|
||||
return Collections.singletonList(
|
||||
(mimeType, requiresSecureDecoder, requiresTunnelingDecoder) ->
|
||||
Collections.singletonList(
|
||||
MediaCodecInfo.newInstance(
|
||||
/* name= */ "name",
|
||||
/* mimeType= */ mimeType,
|
||||
@ -93,8 +89,6 @@ public class MediaCodecAudioRendererTest {
|
||||
/* vendor= */ false,
|
||||
/* forceDisableAdaptive= */ false,
|
||||
/* forceSecure= */ false));
|
||||
}
|
||||
};
|
||||
|
||||
mediaCodecAudioRenderer =
|
||||
new MediaCodecAudioRenderer(
|
||||
|
@ -711,19 +711,13 @@ public class DownloadManagerTest {
|
||||
|
||||
private List<Download> postGetCurrentDownloads() {
|
||||
AtomicReference<List<Download>> currentDownloadsReference = new AtomicReference<>();
|
||||
runOnMainThread(
|
||||
() -> {
|
||||
currentDownloadsReference.set(downloadManager.getCurrentDownloads());
|
||||
});
|
||||
runOnMainThread(() -> currentDownloadsReference.set(downloadManager.getCurrentDownloads()));
|
||||
return currentDownloadsReference.get();
|
||||
}
|
||||
|
||||
private DownloadIndex postGetDownloadIndex() {
|
||||
AtomicReference<DownloadIndex> downloadIndexReference = new AtomicReference<>();
|
||||
runOnMainThread(
|
||||
() -> {
|
||||
downloadIndexReference.set(downloadManager.getDownloadIndex());
|
||||
});
|
||||
runOnMainThread(() -> downloadIndexReference.set(downloadManager.getDownloadIndex()));
|
||||
return downloadIndexReference.get();
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,6 @@ import com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamI
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@ -82,11 +81,8 @@ public class MediaCodecVideoRendererTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MediaCodecSelector mediaCodecSelector =
|
||||
new MediaCodecSelector() {
|
||||
@Override
|
||||
public List<MediaCodecInfo> getDecoderInfos(
|
||||
String mimeType, boolean requiresSecureDecoder, boolean requiresTunnelingDecoder) {
|
||||
return Collections.singletonList(
|
||||
(mimeType, requiresSecureDecoder, requiresTunnelingDecoder) ->
|
||||
Collections.singletonList(
|
||||
MediaCodecInfo.newInstance(
|
||||
/* name= */ "name",
|
||||
/* mimeType= */ mimeType,
|
||||
@ -97,8 +93,6 @@ public class MediaCodecVideoRendererTest {
|
||||
/* vendor= */ false,
|
||||
/* forceDisableAdaptive= */ false,
|
||||
/* forceSecure= */ false));
|
||||
}
|
||||
};
|
||||
|
||||
mediaCodecVideoRenderer =
|
||||
new MediaCodecVideoRenderer(
|
||||
|
@ -558,7 +558,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||
}
|
||||
fullScreenButton = findViewById(R.id.exo_fullscreen);
|
||||
if (fullScreenButton != null) {
|
||||
fullScreenButton.setOnClickListener(fullScreenModeChangedListener);
|
||||
fullScreenButton.setOnClickListener(this::onFullScreenButtonClicked);
|
||||
}
|
||||
settingsButton = findViewById(R.id.exo_settings);
|
||||
if (settingsButton != null) {
|
||||
@ -648,7 +648,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||
String normalSpeed = resources.getString(R.string.exo_controls_playback_speed_normal);
|
||||
selectedPlaybackSpeedIndex = playbackSpeedTextList.indexOf(normalSpeed);
|
||||
|
||||
playbackSpeedMultBy100List = new ArrayList<Integer>();
|
||||
playbackSpeedMultBy100List = new ArrayList<>();
|
||||
int[] speeds = resources.getIntArray(R.array.exo_speed_multiplied_by_100);
|
||||
for (int speed : speeds) {
|
||||
playbackSpeedMultBy100List.add(speed);
|
||||
@ -699,34 +699,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||
shuffleOffContentDescription =
|
||||
resources.getString(R.string.exo_controls_shuffle_off_description);
|
||||
|
||||
addOnLayoutChangeListener(
|
||||
new OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(
|
||||
View v,
|
||||
int left,
|
||||
int top,
|
||||
int right,
|
||||
int bottom,
|
||||
int oldLeft,
|
||||
int oldTop,
|
||||
int oldRight,
|
||||
int oldBottom) {
|
||||
int width = right - left;
|
||||
int height = bottom - top;
|
||||
int oldWidth = oldRight - oldLeft;
|
||||
int oldHeight = oldBottom - oldTop;
|
||||
|
||||
if ((width != oldWidth || height != oldHeight) && settingsWindow.isShowing()) {
|
||||
updateSettingsWindowSize();
|
||||
|
||||
int xoff = getWidth() - settingsWindow.getWidth() - settingsWindowMargin;
|
||||
int yoff = -settingsWindow.getHeight() - settingsWindowMargin;
|
||||
|
||||
settingsWindow.update(v, xoff, yoff, -1, -1);
|
||||
}
|
||||
}
|
||||
});
|
||||
addOnLayoutChangeListener(this::onLayoutChange);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResourceType")
|
||||
@ -1545,29 +1518,47 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||
return controlDispatcher.dispatchSeekTo(player, windowIndex, positionMs);
|
||||
}
|
||||
|
||||
private final OnClickListener fullScreenModeChangedListener =
|
||||
new OnClickListener() {
|
||||
private void onFullScreenButtonClicked(View v) {
|
||||
if (onFullScreenModeChangedListener == null || fullScreenButton == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onFullScreenModeChangedListener == null || fullScreenButton == null) {
|
||||
return;
|
||||
}
|
||||
isFullScreen = !isFullScreen;
|
||||
if (isFullScreen) {
|
||||
fullScreenButton.setImageDrawable(fullScreenExitDrawable);
|
||||
fullScreenButton.setContentDescription(fullScreenExitContentDescription);
|
||||
} else {
|
||||
fullScreenButton.setImageDrawable(fullScreenEnterDrawable);
|
||||
fullScreenButton.setContentDescription(fullScreenEnterContentDescription);
|
||||
}
|
||||
|
||||
isFullScreen = !isFullScreen;
|
||||
if (isFullScreen) {
|
||||
fullScreenButton.setImageDrawable(fullScreenExitDrawable);
|
||||
fullScreenButton.setContentDescription(fullScreenExitContentDescription);
|
||||
} else {
|
||||
fullScreenButton.setImageDrawable(fullScreenEnterDrawable);
|
||||
fullScreenButton.setContentDescription(fullScreenEnterContentDescription);
|
||||
}
|
||||
if (onFullScreenModeChangedListener != null) {
|
||||
onFullScreenModeChangedListener.onFullScreenModeChanged(isFullScreen);
|
||||
}
|
||||
}
|
||||
|
||||
if (onFullScreenModeChangedListener != null) {
|
||||
onFullScreenModeChangedListener.onFullScreenModeChanged(isFullScreen);
|
||||
}
|
||||
}
|
||||
};
|
||||
private void onLayoutChange(
|
||||
View v,
|
||||
int left,
|
||||
int top,
|
||||
int right,
|
||||
int bottom,
|
||||
int oldLeft,
|
||||
int oldTop,
|
||||
int oldRight,
|
||||
int oldBottom) {
|
||||
int width = right - left;
|
||||
int height = bottom - top;
|
||||
int oldWidth = oldRight - oldLeft;
|
||||
int oldHeight = oldBottom - oldTop;
|
||||
|
||||
if ((width != oldWidth || height != oldHeight) && settingsWindow.isShowing()) {
|
||||
updateSettingsWindowSize();
|
||||
int xOffset = getWidth() - settingsWindow.getWidth() - settingsWindowMargin;
|
||||
int yOffset = -settingsWindow.getHeight() - settingsWindowMargin;
|
||||
settingsWindow.update(v, xOffset, yOffset, -1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
@ -1868,25 +1859,22 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||
iconView = itemView.findViewById(R.id.exo_icon);
|
||||
|
||||
itemView.setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = SettingsViewHolder.this.getAdapterPosition();
|
||||
if (position == RecyclerView.NO_POSITION) {
|
||||
return;
|
||||
}
|
||||
v -> {
|
||||
int position = SettingsViewHolder.this.getAdapterPosition();
|
||||
if (position == RecyclerView.NO_POSITION) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (position == SETTINGS_PLAYBACK_SPEED_POSITION) {
|
||||
subSettingsAdapter.setTexts(playbackSpeedTextList);
|
||||
subSettingsAdapter.setCheckPosition(selectedPlaybackSpeedIndex);
|
||||
selectedMainSettingsPosition = SETTINGS_PLAYBACK_SPEED_POSITION;
|
||||
displaySettingsWindow(subSettingsAdapter);
|
||||
} else if (position == SETTINGS_AUDIO_TRACK_SELECTION_POSITION) {
|
||||
selectedMainSettingsPosition = SETTINGS_AUDIO_TRACK_SELECTION_POSITION;
|
||||
displaySettingsWindow(audioTrackSelectionAdapter);
|
||||
} else {
|
||||
settingsWindow.dismiss();
|
||||
}
|
||||
if (position == SETTINGS_PLAYBACK_SPEED_POSITION) {
|
||||
subSettingsAdapter.setTexts(playbackSpeedTextList);
|
||||
subSettingsAdapter.setCheckPosition(selectedPlaybackSpeedIndex);
|
||||
selectedMainSettingsPosition = SETTINGS_PLAYBACK_SPEED_POSITION;
|
||||
displaySettingsWindow(subSettingsAdapter);
|
||||
} else if (position == SETTINGS_AUDIO_TRACK_SELECTION_POSITION) {
|
||||
selectedMainSettingsPosition = SETTINGS_AUDIO_TRACK_SELECTION_POSITION;
|
||||
displaySettingsWindow(audioTrackSelectionAdapter);
|
||||
} else {
|
||||
settingsWindow.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1938,22 +1926,19 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||
checkView = itemView.findViewById(R.id.exo_check);
|
||||
|
||||
itemView.setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = SubSettingsViewHolder.this.getAdapterPosition();
|
||||
if (position == RecyclerView.NO_POSITION) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedMainSettingsPosition == SETTINGS_PLAYBACK_SPEED_POSITION) {
|
||||
if (position != selectedPlaybackSpeedIndex) {
|
||||
float speed = playbackSpeedMultBy100List.get(position) / 100.0f;
|
||||
setPlaybackSpeed(speed);
|
||||
}
|
||||
}
|
||||
settingsWindow.dismiss();
|
||||
v -> {
|
||||
int position = SubSettingsViewHolder.this.getAdapterPosition();
|
||||
if (position == RecyclerView.NO_POSITION) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedMainSettingsPosition == SETTINGS_PLAYBACK_SPEED_POSITION) {
|
||||
if (position != selectedPlaybackSpeedIndex) {
|
||||
float speed = playbackSpeedMultBy100List.get(position) / 100.0f;
|
||||
setPlaybackSpeed(speed);
|
||||
}
|
||||
}
|
||||
settingsWindow.dismiss();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -2012,21 +1997,18 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||
}
|
||||
holder.checkView.setVisibility(isTrackSelectionOff ? VISIBLE : INVISIBLE);
|
||||
holder.itemView.setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (trackSelector != null) {
|
||||
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
||||
for (int i = 0; i < rendererIndices.size(); i++) {
|
||||
int rendererIndex = rendererIndices.get(i);
|
||||
parametersBuilder =
|
||||
parametersBuilder
|
||||
.clearSelectionOverrides(rendererIndex)
|
||||
.setRendererDisabled(rendererIndex, true);
|
||||
}
|
||||
checkNotNull(trackSelector).setParameters(parametersBuilder);
|
||||
settingsWindow.dismiss();
|
||||
v -> {
|
||||
if (trackSelector != null) {
|
||||
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
||||
for (int i = 0; i < rendererIndices.size(); i++) {
|
||||
int rendererIndex = rendererIndices.get(i);
|
||||
parametersBuilder =
|
||||
parametersBuilder
|
||||
.clearSelectionOverrides(rendererIndex)
|
||||
.setRendererDisabled(rendererIndex, true);
|
||||
}
|
||||
checkNotNull(trackSelector).setParameters(parametersBuilder);
|
||||
settingsWindow.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -2065,22 +2047,19 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||
}
|
||||
holder.checkView.setVisibility(hasSelectionOverride ? INVISIBLE : VISIBLE);
|
||||
holder.itemView.setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (trackSelector != null) {
|
||||
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
||||
for (int i = 0; i < rendererIndices.size(); i++) {
|
||||
int rendererIndex = rendererIndices.get(i);
|
||||
parametersBuilder = parametersBuilder.clearSelectionOverrides(rendererIndex);
|
||||
}
|
||||
checkNotNull(trackSelector).setParameters(parametersBuilder);
|
||||
v -> {
|
||||
if (trackSelector != null) {
|
||||
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
||||
for (int i = 0; i < rendererIndices.size(); i++) {
|
||||
int rendererIndex = rendererIndices.get(i);
|
||||
parametersBuilder = parametersBuilder.clearSelectionOverrides(rendererIndex);
|
||||
}
|
||||
settingsAdapter.updateSubTexts(
|
||||
SETTINGS_AUDIO_TRACK_SELECTION_POSITION,
|
||||
getResources().getString(R.string.exo_track_selection_auto));
|
||||
settingsWindow.dismiss();
|
||||
checkNotNull(trackSelector).setParameters(parametersBuilder);
|
||||
}
|
||||
settingsAdapter.updateSubTexts(
|
||||
SETTINGS_AUDIO_TRACK_SELECTION_POSITION,
|
||||
getResources().getString(R.string.exo_track_selection_auto));
|
||||
settingsWindow.dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
@ -2176,32 +2155,29 @@ public class StyledPlayerControlView extends FrameLayout {
|
||||
holder.textView.setText(track.trackName);
|
||||
holder.checkView.setVisibility(explicitlySelected ? VISIBLE : INVISIBLE);
|
||||
holder.itemView.setOnClickListener(
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mappedTrackInfo != null && trackSelector != null) {
|
||||
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
||||
for (int i = 0; i < rendererIndices.size(); i++) {
|
||||
int rendererIndex = rendererIndices.get(i);
|
||||
if (rendererIndex == track.rendererIndex) {
|
||||
parametersBuilder =
|
||||
parametersBuilder
|
||||
.setSelectionOverride(
|
||||
rendererIndex,
|
||||
checkNotNull(mappedTrackInfo).getTrackGroups(rendererIndex),
|
||||
new SelectionOverride(track.groupIndex, track.trackIndex))
|
||||
.setRendererDisabled(rendererIndex, false);
|
||||
} else {
|
||||
parametersBuilder =
|
||||
parametersBuilder
|
||||
.clearSelectionOverrides(rendererIndex)
|
||||
.setRendererDisabled(rendererIndex, true);
|
||||
}
|
||||
v -> {
|
||||
if (mappedTrackInfo != null && trackSelector != null) {
|
||||
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
||||
for (int i = 0; i < rendererIndices.size(); i++) {
|
||||
int rendererIndex = rendererIndices.get(i);
|
||||
if (rendererIndex == track.rendererIndex) {
|
||||
parametersBuilder =
|
||||
parametersBuilder
|
||||
.setSelectionOverride(
|
||||
rendererIndex,
|
||||
checkNotNull(mappedTrackInfo).getTrackGroups(rendererIndex),
|
||||
new SelectionOverride(track.groupIndex, track.trackIndex))
|
||||
.setRendererDisabled(rendererIndex, false);
|
||||
} else {
|
||||
parametersBuilder =
|
||||
parametersBuilder
|
||||
.clearSelectionOverrides(rendererIndex)
|
||||
.setRendererDisabled(rendererIndex, true);
|
||||
}
|
||||
checkNotNull(trackSelector).setParameters(parametersBuilder);
|
||||
onTrackSelection(track.trackName);
|
||||
settingsWindow.dismiss();
|
||||
}
|
||||
checkNotNull(trackSelector).setParameters(parametersBuilder);
|
||||
onTrackSelection(track.trackName);
|
||||
settingsWindow.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -22,15 +22,14 @@ import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnLayoutChangeListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.MarginLayoutParams;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import androidx.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/* package */ final class StyledPlayerControlViewLayoutManager
|
||||
implements View.OnLayoutChangeListener {
|
||||
/* package */ final class StyledPlayerControlViewLayoutManager {
|
||||
private static final long ANIMATION_INTERVAL_MS = 2_000;
|
||||
private static final long DURATION_FOR_HIDING_ANIMATION_MS = 250;
|
||||
private static final long DURATION_FOR_SHOWING_ANIMATION_MS = 250;
|
||||
@ -47,6 +46,13 @@ import java.util.ArrayList;
|
||||
// Int for defining the UX state where the views are being animated to be shown.
|
||||
private static final int UX_STATE_ANIMATING_SHOW = 4;
|
||||
|
||||
private final Runnable showAllBarsRunnable;
|
||||
private final Runnable hideAllBarsRunnable;
|
||||
private final Runnable hideProgressBarRunnable;
|
||||
private final Runnable hideMainBarsRunnable;
|
||||
private final Runnable hideControllerRunnable;
|
||||
private final OnLayoutChangeListener onLayoutChangeListener;
|
||||
|
||||
private int uxState = UX_STATE_ALL_VISIBLE;
|
||||
private boolean isMinimalMode;
|
||||
private boolean needToShowBars;
|
||||
@ -73,7 +79,16 @@ import java.util.ArrayList;
|
||||
@Nullable private ValueAnimator overflowShowAnimator;
|
||||
@Nullable private ValueAnimator overflowHideAnimator;
|
||||
|
||||
void show() {
|
||||
public StyledPlayerControlViewLayoutManager() {
|
||||
showAllBarsRunnable = this::showAllBars;
|
||||
hideAllBarsRunnable = this::hideAllBars;
|
||||
hideProgressBarRunnable = this::hideProgressBar;
|
||||
hideMainBarsRunnable = this::hideMainBars;
|
||||
hideControllerRunnable = this::hideController;
|
||||
onLayoutChangeListener = this::onLayoutChange;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (this.styledPlayerControlView == null) {
|
||||
return;
|
||||
}
|
||||
@ -83,10 +98,10 @@ import java.util.ArrayList;
|
||||
styledPlayerControlView.updateAll();
|
||||
styledPlayerControlView.requestPlayPauseFocus();
|
||||
}
|
||||
styledPlayerControlView.post(showAllBars);
|
||||
styledPlayerControlView.post(showAllBarsRunnable);
|
||||
}
|
||||
|
||||
void hide() {
|
||||
public void hide() {
|
||||
if (styledPlayerControlView == null
|
||||
|| uxState == UX_STATE_ANIMATING_HIDE
|
||||
|| uxState == UX_STATE_NONE_VISIBLE) {
|
||||
@ -94,23 +109,23 @@ import java.util.ArrayList;
|
||||
}
|
||||
removeHideCallbacks();
|
||||
if (!animationEnabled) {
|
||||
postDelayedRunnable(hideController, 0);
|
||||
postDelayedRunnable(hideControllerRunnable, 0);
|
||||
} else if (uxState == UX_STATE_ONLY_PROGRESS_VISIBLE) {
|
||||
postDelayedRunnable(hideProgressBar, 0);
|
||||
postDelayedRunnable(hideProgressBarRunnable, 0);
|
||||
} else {
|
||||
postDelayedRunnable(hideAllBars, 0);
|
||||
postDelayedRunnable(hideAllBarsRunnable, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void setAnimationEnabled(boolean animationEnabled) {
|
||||
public void setAnimationEnabled(boolean animationEnabled) {
|
||||
this.animationEnabled = animationEnabled;
|
||||
}
|
||||
|
||||
boolean isAnimationEnabled() {
|
||||
public boolean isAnimationEnabled() {
|
||||
return animationEnabled;
|
||||
}
|
||||
|
||||
void resetHideCallbacks() {
|
||||
public void resetHideCallbacks() {
|
||||
if (uxState == UX_STATE_ANIMATING_HIDE) {
|
||||
return;
|
||||
}
|
||||
@ -119,29 +134,29 @@ import java.util.ArrayList;
|
||||
styledPlayerControlView != null ? styledPlayerControlView.getShowTimeoutMs() : 0;
|
||||
if (showTimeoutMs > 0) {
|
||||
if (!animationEnabled) {
|
||||
postDelayedRunnable(hideController, showTimeoutMs);
|
||||
postDelayedRunnable(hideControllerRunnable, showTimeoutMs);
|
||||
} else if (uxState == UX_STATE_ONLY_PROGRESS_VISIBLE) {
|
||||
postDelayedRunnable(hideProgressBar, ANIMATION_INTERVAL_MS);
|
||||
postDelayedRunnable(hideProgressBarRunnable, ANIMATION_INTERVAL_MS);
|
||||
} else {
|
||||
postDelayedRunnable(hideMainBars, showTimeoutMs);
|
||||
postDelayedRunnable(hideMainBarsRunnable, showTimeoutMs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeHideCallbacks() {
|
||||
public void removeHideCallbacks() {
|
||||
if (styledPlayerControlView == null) {
|
||||
return;
|
||||
}
|
||||
styledPlayerControlView.removeCallbacks(hideController);
|
||||
styledPlayerControlView.removeCallbacks(hideAllBars);
|
||||
styledPlayerControlView.removeCallbacks(hideMainBars);
|
||||
styledPlayerControlView.removeCallbacks(hideProgressBar);
|
||||
styledPlayerControlView.removeCallbacks(hideControllerRunnable);
|
||||
styledPlayerControlView.removeCallbacks(hideAllBarsRunnable);
|
||||
styledPlayerControlView.removeCallbacks(hideMainBarsRunnable);
|
||||
styledPlayerControlView.removeCallbacks(hideProgressBarRunnable);
|
||||
}
|
||||
|
||||
void onViewAttached(StyledPlayerControlView v) {
|
||||
public void onViewAttached(StyledPlayerControlView v) {
|
||||
styledPlayerControlView = v;
|
||||
|
||||
v.addOnLayoutChangeListener(this);
|
||||
v.addOnLayoutChangeListener(onLayoutChangeListener);
|
||||
|
||||
// Relating to Title Bar View
|
||||
ViewGroup titleBar = v.findViewById(R.id.exo_title_bar);
|
||||
@ -167,8 +182,8 @@ import java.util.ArrayList;
|
||||
overflowShowButton = v.findViewById(R.id.exo_overflow_show);
|
||||
View overflowHideButton = v.findViewById(R.id.exo_overflow_hide);
|
||||
if (overflowShowButton != null && overflowHideButton != null) {
|
||||
overflowShowButton.setOnClickListener(overflowListener);
|
||||
overflowHideButton.setOnClickListener(overflowListener);
|
||||
overflowShowButton.setOnClickListener(this::onOverflowButtonClick);
|
||||
overflowHideButton.setOnClickListener(this::onOverflowButtonClick);
|
||||
}
|
||||
|
||||
this.titleBar = titleBar;
|
||||
@ -256,7 +271,7 @@ import java.util.ArrayList;
|
||||
setUxState(UX_STATE_ONLY_PROGRESS_VISIBLE);
|
||||
if (needToShowBars) {
|
||||
if (styledPlayerControlView != null) {
|
||||
styledPlayerControlView.post(showAllBars);
|
||||
styledPlayerControlView.post(showAllBarsRunnable);
|
||||
}
|
||||
needToShowBars = false;
|
||||
}
|
||||
@ -282,7 +297,7 @@ import java.util.ArrayList;
|
||||
setUxState(UX_STATE_NONE_VISIBLE);
|
||||
if (needToShowBars) {
|
||||
if (styledPlayerControlView != null) {
|
||||
styledPlayerControlView.post(showAllBars);
|
||||
styledPlayerControlView.post(showAllBarsRunnable);
|
||||
}
|
||||
needToShowBars = false;
|
||||
}
|
||||
@ -306,7 +321,7 @@ import java.util.ArrayList;
|
||||
setUxState(UX_STATE_NONE_VISIBLE);
|
||||
if (needToShowBars) {
|
||||
if (styledPlayerControlView != null) {
|
||||
styledPlayerControlView.post(showAllBars);
|
||||
styledPlayerControlView.post(showAllBarsRunnable);
|
||||
}
|
||||
needToShowBars = false;
|
||||
}
|
||||
@ -403,11 +418,11 @@ import java.util.ArrayList;
|
||||
});
|
||||
}
|
||||
|
||||
void onViewDetached(StyledPlayerControlView v) {
|
||||
v.removeOnLayoutChangeListener(this);
|
||||
public void onViewDetached(StyledPlayerControlView v) {
|
||||
v.removeOnLayoutChangeListener(onLayoutChangeListener);
|
||||
}
|
||||
|
||||
boolean isFullyVisible() {
|
||||
public boolean isFullyVisible() {
|
||||
if (styledPlayerControlView == null) {
|
||||
return false;
|
||||
}
|
||||
@ -432,80 +447,91 @@ import java.util.ArrayList;
|
||||
}
|
||||
}
|
||||
|
||||
private final Runnable showAllBars =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!animationEnabled) {
|
||||
setUxState(UX_STATE_ALL_VISIBLE);
|
||||
resetHideCallbacks();
|
||||
return;
|
||||
}
|
||||
private void onLayoutChange(
|
||||
View v,
|
||||
int left,
|
||||
int top,
|
||||
int right,
|
||||
int bottom,
|
||||
int oldLeft,
|
||||
int oldTop,
|
||||
int oldRight,
|
||||
int oldBottom) {
|
||||
|
||||
switch (uxState) {
|
||||
case UX_STATE_NONE_VISIBLE:
|
||||
if (showAllBarsAnimator != null) {
|
||||
showAllBarsAnimator.start();
|
||||
}
|
||||
break;
|
||||
case UX_STATE_ONLY_PROGRESS_VISIBLE:
|
||||
if (showMainBarsAnimator != null) {
|
||||
showMainBarsAnimator.start();
|
||||
}
|
||||
break;
|
||||
case UX_STATE_ANIMATING_HIDE:
|
||||
needToShowBars = true;
|
||||
break;
|
||||
case UX_STATE_ANIMATING_SHOW:
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
resetHideCallbacks();
|
||||
}
|
||||
};
|
||||
boolean shouldBeMinimalMode = shouldBeMinimalMode();
|
||||
if (isMinimalMode != shouldBeMinimalMode) {
|
||||
isMinimalMode = shouldBeMinimalMode;
|
||||
v.post(this::updateLayoutForSizeChange);
|
||||
}
|
||||
boolean widthChanged = (right - left) != (oldRight - oldLeft);
|
||||
if (!isMinimalMode && widthChanged) {
|
||||
v.post(this::onLayoutWidthChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private final Runnable hideAllBars =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (hideAllBarsAnimator == null) {
|
||||
return;
|
||||
}
|
||||
hideAllBarsAnimator.start();
|
||||
}
|
||||
};
|
||||
private void onOverflowButtonClick(View v) {
|
||||
resetHideCallbacks();
|
||||
if (v.getId() == R.id.exo_overflow_show && overflowShowAnimator != null) {
|
||||
overflowShowAnimator.start();
|
||||
} else if (v.getId() == R.id.exo_overflow_hide && overflowHideAnimator != null) {
|
||||
overflowHideAnimator.start();
|
||||
}
|
||||
}
|
||||
|
||||
private final Runnable hideMainBars =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (hideMainBarsAnimator == null) {
|
||||
return;
|
||||
}
|
||||
hideMainBarsAnimator.start();
|
||||
postDelayedRunnable(hideProgressBar, ANIMATION_INTERVAL_MS);
|
||||
}
|
||||
};
|
||||
private void showAllBars() {
|
||||
if (!animationEnabled) {
|
||||
setUxState(UX_STATE_ALL_VISIBLE);
|
||||
resetHideCallbacks();
|
||||
return;
|
||||
}
|
||||
|
||||
private final Runnable hideProgressBar =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (hideProgressBarAnimator == null) {
|
||||
return;
|
||||
}
|
||||
hideProgressBarAnimator.start();
|
||||
switch (uxState) {
|
||||
case UX_STATE_NONE_VISIBLE:
|
||||
if (showAllBarsAnimator != null) {
|
||||
showAllBarsAnimator.start();
|
||||
}
|
||||
};
|
||||
break;
|
||||
case UX_STATE_ONLY_PROGRESS_VISIBLE:
|
||||
if (showMainBarsAnimator != null) {
|
||||
showMainBarsAnimator.start();
|
||||
}
|
||||
break;
|
||||
case UX_STATE_ANIMATING_HIDE:
|
||||
needToShowBars = true;
|
||||
break;
|
||||
case UX_STATE_ANIMATING_SHOW:
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
resetHideCallbacks();
|
||||
}
|
||||
|
||||
private final Runnable hideController =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setUxState(UX_STATE_NONE_VISIBLE);
|
||||
}
|
||||
};
|
||||
private void hideAllBars() {
|
||||
if (hideAllBarsAnimator == null) {
|
||||
return;
|
||||
}
|
||||
hideAllBarsAnimator.start();
|
||||
}
|
||||
|
||||
private void hideProgressBar() {
|
||||
if (hideProgressBarAnimator == null) {
|
||||
return;
|
||||
}
|
||||
hideProgressBarAnimator.start();
|
||||
}
|
||||
|
||||
private void hideMainBars() {
|
||||
if (hideMainBarsAnimator == null) {
|
||||
return;
|
||||
}
|
||||
hideMainBarsAnimator.start();
|
||||
postDelayedRunnable(hideProgressBarRunnable, ANIMATION_INTERVAL_MS);
|
||||
}
|
||||
|
||||
private void hideController() {
|
||||
setUxState(UX_STATE_NONE_VISIBLE);
|
||||
}
|
||||
|
||||
private static ObjectAnimator ofTranslationY(float startValue, float endValue, View target) {
|
||||
return ObjectAnimator.ofFloat(target, "translationY", startValue, endValue);
|
||||
@ -532,50 +558,6 @@ import java.util.ArrayList;
|
||||
}
|
||||
}
|
||||
|
||||
private final OnClickListener overflowListener =
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
resetHideCallbacks();
|
||||
if (v.getId() == R.id.exo_overflow_show && overflowShowAnimator != null) {
|
||||
overflowShowAnimator.start();
|
||||
} else if (v.getId() == R.id.exo_overflow_hide && overflowHideAnimator != null) {
|
||||
overflowHideAnimator.start();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onLayoutChange(
|
||||
View v,
|
||||
int left,
|
||||
int top,
|
||||
int right,
|
||||
int bottom,
|
||||
int oldLeft,
|
||||
int oldTop,
|
||||
int oldRight,
|
||||
int oldBottom) {
|
||||
|
||||
boolean shouldBeMinimalMode = shouldBeMinimalMode();
|
||||
if (isMinimalMode != shouldBeMinimalMode) {
|
||||
isMinimalMode = shouldBeMinimalMode;
|
||||
v.post(() -> updateLayoutForSizeChange());
|
||||
}
|
||||
boolean widthChanged = (right - left) != (oldRight - oldLeft);
|
||||
if (!isMinimalMode && widthChanged) {
|
||||
v.post(() -> onLayoutWidthChanged());
|
||||
}
|
||||
}
|
||||
|
||||
private static int getWidth(@Nullable View v) {
|
||||
return (v != null ? v.getWidth() : 0);
|
||||
}
|
||||
|
||||
private static int getHeight(@Nullable View v) {
|
||||
return (v != null ? v.getHeight() : 0);
|
||||
}
|
||||
|
||||
private boolean shouldBeMinimalMode() {
|
||||
if (this.styledPlayerControlView == null) {
|
||||
return isMinimalMode;
|
||||
@ -733,4 +715,12 @@ import java.util.ArrayList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int getWidth(@Nullable View v) {
|
||||
return (v != null ? v.getWidth() : 0);
|
||||
}
|
||||
|
||||
private static int getHeight(@Nullable View v) {
|
||||
return (v != null ? v.getHeight() : 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user