Use lambdas where possible
PiperOrigin-RevId: 320960833
This commit is contained in:
parent
29b12e2f8d
commit
f205539616
@ -1146,7 +1146,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
assertPlayerResultSuccess(sessionPlayerConnector.prepare());
|
||||||
InstrumentationRegistry.getInstrumentation()
|
InstrumentationRegistry.getInstrumentation()
|
||||||
.runOnMainSync(
|
.runOnMainSync(
|
||||||
() -> {
|
() ->
|
||||||
simpleExoPlayer.addListener(
|
simpleExoPlayer.addListener(
|
||||||
new Player.EventListener() {
|
new Player.EventListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -1155,8 +1155,7 @@ public class SessionPlayerConnectorTest {
|
|||||||
simpleExoPlayer.setPlayWhenReady(false);
|
simpleExoPlayer.setPlayWhenReady(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
assertPlayerResultSuccess(sessionPlayerConnector.play());
|
assertPlayerResultSuccess(sessionPlayerConnector.play());
|
||||||
assertThat(
|
assertThat(
|
||||||
|
@ -149,19 +149,19 @@ public final class SessionPlayerConnector extends SessionPlayer {
|
|||||||
@Override
|
@Override
|
||||||
public ListenableFuture<PlayerResult> play() {
|
public ListenableFuture<PlayerResult> play() {
|
||||||
return playerCommandQueue.addCommand(
|
return playerCommandQueue.addCommand(
|
||||||
PlayerCommandQueue.COMMAND_CODE_PLAYER_PLAY, /* command= */ () -> player.play());
|
PlayerCommandQueue.COMMAND_CODE_PLAYER_PLAY, /* command= */ player::play);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<PlayerResult> pause() {
|
public ListenableFuture<PlayerResult> pause() {
|
||||||
return playerCommandQueue.addCommand(
|
return playerCommandQueue.addCommand(
|
||||||
PlayerCommandQueue.COMMAND_CODE_PLAYER_PAUSE, /* command= */ () -> player.pause());
|
PlayerCommandQueue.COMMAND_CODE_PLAYER_PAUSE, /* command= */ player::pause);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<PlayerResult> prepare() {
|
public ListenableFuture<PlayerResult> prepare() {
|
||||||
return playerCommandQueue.addCommand(
|
return playerCommandQueue.addCommand(
|
||||||
PlayerCommandQueue.COMMAND_CODE_PLAYER_PREPARE, /* command= */ () -> player.prepare());
|
PlayerCommandQueue.COMMAND_CODE_PLAYER_PREPARE, /* command= */ player::prepare);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -771,9 +771,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
keepaliveSessions.add(session);
|
keepaliveSessions.add(session);
|
||||||
Assertions.checkNotNull(sessionReleasingHandler)
|
Assertions.checkNotNull(sessionReleasingHandler)
|
||||||
.postAtTime(
|
.postAtTime(
|
||||||
() -> {
|
() -> session.release(/* eventDispatcher= */ null),
|
||||||
session.release(/* eventDispatcher= */ null);
|
|
||||||
},
|
|
||||||
session,
|
session,
|
||||||
/* uptimeMillis= */ SystemClock.uptimeMillis() + sessionKeepaliveMs);
|
/* uptimeMillis= */ SystemClock.uptimeMillis() + sessionKeepaliveMs);
|
||||||
} else if (newReferenceCount == 0) {
|
} else if (newReferenceCount == 0) {
|
||||||
|
@ -156,9 +156,8 @@ public final class FrameworkMediaDrm implements ExoMediaDrm {
|
|||||||
mediaDrm.setOnExpirationUpdateListener(
|
mediaDrm.setOnExpirationUpdateListener(
|
||||||
listener == null
|
listener == null
|
||||||
? null
|
? null
|
||||||
: (mediaDrm, sessionId, expirationTimeMs) -> {
|
: (mediaDrm, sessionId, expirationTimeMs) ->
|
||||||
listener.onExpirationUpdate(FrameworkMediaDrm.this, sessionId, expirationTimeMs);
|
listener.onExpirationUpdate(FrameworkMediaDrm.this, sessionId, expirationTimeMs),
|
||||||
},
|
|
||||||
/* handler= */ null);
|
/* handler= */ null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1913,9 +1913,7 @@ public final class ExoPlayerTest {
|
|||||||
.waitForTimelineChanged()
|
.waitForTimelineChanged()
|
||||||
.pause()
|
.pause()
|
||||||
.sendMessage(
|
.sendMessage(
|
||||||
(messageType, payload) -> {
|
(messageType, payload) -> counter.getAndIncrement(),
|
||||||
counter.getAndIncrement();
|
|
||||||
},
|
|
||||||
/* windowIndex= */ 0,
|
/* windowIndex= */ 0,
|
||||||
/* positionMs= */ 2000,
|
/* positionMs= */ 2000,
|
||||||
/* deleteAfterDelivery= */ false)
|
/* deleteAfterDelivery= */ false)
|
||||||
|
@ -40,7 +40,6 @@ import com.google.android.exoplayer2.testutil.FakeSampleStream;
|
|||||||
import com.google.android.exoplayer2.util.MimeTypes;
|
import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -78,11 +77,8 @@ public class MediaCodecAudioRendererTest {
|
|||||||
when(audioSink.handleBuffer(any(), anyLong(), anyInt())).thenReturn(true);
|
when(audioSink.handleBuffer(any(), anyLong(), anyInt())).thenReturn(true);
|
||||||
|
|
||||||
mediaCodecSelector =
|
mediaCodecSelector =
|
||||||
new MediaCodecSelector() {
|
(mimeType, requiresSecureDecoder, requiresTunnelingDecoder) ->
|
||||||
@Override
|
Collections.singletonList(
|
||||||
public List<MediaCodecInfo> getDecoderInfos(
|
|
||||||
String mimeType, boolean requiresSecureDecoder, boolean requiresTunnelingDecoder) {
|
|
||||||
return Collections.singletonList(
|
|
||||||
MediaCodecInfo.newInstance(
|
MediaCodecInfo.newInstance(
|
||||||
/* name= */ "name",
|
/* name= */ "name",
|
||||||
/* mimeType= */ mimeType,
|
/* mimeType= */ mimeType,
|
||||||
@ -93,8 +89,6 @@ public class MediaCodecAudioRendererTest {
|
|||||||
/* vendor= */ false,
|
/* vendor= */ false,
|
||||||
/* forceDisableAdaptive= */ false,
|
/* forceDisableAdaptive= */ false,
|
||||||
/* forceSecure= */ false));
|
/* forceSecure= */ false));
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
mediaCodecAudioRenderer =
|
mediaCodecAudioRenderer =
|
||||||
new MediaCodecAudioRenderer(
|
new MediaCodecAudioRenderer(
|
||||||
|
@ -711,19 +711,13 @@ public class DownloadManagerTest {
|
|||||||
|
|
||||||
private List<Download> postGetCurrentDownloads() {
|
private List<Download> postGetCurrentDownloads() {
|
||||||
AtomicReference<List<Download>> currentDownloadsReference = new AtomicReference<>();
|
AtomicReference<List<Download>> currentDownloadsReference = new AtomicReference<>();
|
||||||
runOnMainThread(
|
runOnMainThread(() -> currentDownloadsReference.set(downloadManager.getCurrentDownloads()));
|
||||||
() -> {
|
|
||||||
currentDownloadsReference.set(downloadManager.getCurrentDownloads());
|
|
||||||
});
|
|
||||||
return currentDownloadsReference.get();
|
return currentDownloadsReference.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private DownloadIndex postGetDownloadIndex() {
|
private DownloadIndex postGetDownloadIndex() {
|
||||||
AtomicReference<DownloadIndex> downloadIndexReference = new AtomicReference<>();
|
AtomicReference<DownloadIndex> downloadIndexReference = new AtomicReference<>();
|
||||||
runOnMainThread(
|
runOnMainThread(() -> downloadIndexReference.set(downloadManager.getDownloadIndex()));
|
||||||
() -> {
|
|
||||||
downloadIndexReference.set(downloadManager.getDownloadIndex());
|
|
||||||
});
|
|
||||||
return downloadIndexReference.get();
|
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.android.exoplayer2.util.MimeTypes;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -82,11 +81,8 @@ public class MediaCodecVideoRendererTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
MediaCodecSelector mediaCodecSelector =
|
MediaCodecSelector mediaCodecSelector =
|
||||||
new MediaCodecSelector() {
|
(mimeType, requiresSecureDecoder, requiresTunnelingDecoder) ->
|
||||||
@Override
|
Collections.singletonList(
|
||||||
public List<MediaCodecInfo> getDecoderInfos(
|
|
||||||
String mimeType, boolean requiresSecureDecoder, boolean requiresTunnelingDecoder) {
|
|
||||||
return Collections.singletonList(
|
|
||||||
MediaCodecInfo.newInstance(
|
MediaCodecInfo.newInstance(
|
||||||
/* name= */ "name",
|
/* name= */ "name",
|
||||||
/* mimeType= */ mimeType,
|
/* mimeType= */ mimeType,
|
||||||
@ -97,8 +93,6 @@ public class MediaCodecVideoRendererTest {
|
|||||||
/* vendor= */ false,
|
/* vendor= */ false,
|
||||||
/* forceDisableAdaptive= */ false,
|
/* forceDisableAdaptive= */ false,
|
||||||
/* forceSecure= */ false));
|
/* forceSecure= */ false));
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
mediaCodecVideoRenderer =
|
mediaCodecVideoRenderer =
|
||||||
new MediaCodecVideoRenderer(
|
new MediaCodecVideoRenderer(
|
||||||
|
@ -558,7 +558,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
fullScreenButton = findViewById(R.id.exo_fullscreen);
|
fullScreenButton = findViewById(R.id.exo_fullscreen);
|
||||||
if (fullScreenButton != null) {
|
if (fullScreenButton != null) {
|
||||||
fullScreenButton.setOnClickListener(fullScreenModeChangedListener);
|
fullScreenButton.setOnClickListener(this::onFullScreenButtonClicked);
|
||||||
}
|
}
|
||||||
settingsButton = findViewById(R.id.exo_settings);
|
settingsButton = findViewById(R.id.exo_settings);
|
||||||
if (settingsButton != null) {
|
if (settingsButton != null) {
|
||||||
@ -648,7 +648,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
String normalSpeed = resources.getString(R.string.exo_controls_playback_speed_normal);
|
String normalSpeed = resources.getString(R.string.exo_controls_playback_speed_normal);
|
||||||
selectedPlaybackSpeedIndex = playbackSpeedTextList.indexOf(normalSpeed);
|
selectedPlaybackSpeedIndex = playbackSpeedTextList.indexOf(normalSpeed);
|
||||||
|
|
||||||
playbackSpeedMultBy100List = new ArrayList<Integer>();
|
playbackSpeedMultBy100List = new ArrayList<>();
|
||||||
int[] speeds = resources.getIntArray(R.array.exo_speed_multiplied_by_100);
|
int[] speeds = resources.getIntArray(R.array.exo_speed_multiplied_by_100);
|
||||||
for (int speed : speeds) {
|
for (int speed : speeds) {
|
||||||
playbackSpeedMultBy100List.add(speed);
|
playbackSpeedMultBy100List.add(speed);
|
||||||
@ -699,34 +699,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
shuffleOffContentDescription =
|
shuffleOffContentDescription =
|
||||||
resources.getString(R.string.exo_controls_shuffle_off_description);
|
resources.getString(R.string.exo_controls_shuffle_off_description);
|
||||||
|
|
||||||
addOnLayoutChangeListener(
|
addOnLayoutChangeListener(this::onLayoutChange);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ResourceType")
|
@SuppressWarnings("ResourceType")
|
||||||
@ -1545,11 +1518,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
return controlDispatcher.dispatchSeekTo(player, windowIndex, positionMs);
|
return controlDispatcher.dispatchSeekTo(player, windowIndex, positionMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final OnClickListener fullScreenModeChangedListener =
|
private void onFullScreenButtonClicked(View v) {
|
||||||
new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (onFullScreenModeChangedListener == null || fullScreenButton == null) {
|
if (onFullScreenModeChangedListener == null || fullScreenButton == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1567,7 +1536,29 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
onFullScreenModeChangedListener.onFullScreenModeChanged(isFullScreen);
|
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
|
@Override
|
||||||
public void onAttachedToWindow() {
|
public void onAttachedToWindow() {
|
||||||
@ -1868,9 +1859,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
iconView = itemView.findViewById(R.id.exo_icon);
|
iconView = itemView.findViewById(R.id.exo_icon);
|
||||||
|
|
||||||
itemView.setOnClickListener(
|
itemView.setOnClickListener(
|
||||||
new OnClickListener() {
|
v -> {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
int position = SettingsViewHolder.this.getAdapterPosition();
|
int position = SettingsViewHolder.this.getAdapterPosition();
|
||||||
if (position == RecyclerView.NO_POSITION) {
|
if (position == RecyclerView.NO_POSITION) {
|
||||||
return;
|
return;
|
||||||
@ -1887,7 +1876,6 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
} else {
|
} else {
|
||||||
settingsWindow.dismiss();
|
settingsWindow.dismiss();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1938,9 +1926,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
checkView = itemView.findViewById(R.id.exo_check);
|
checkView = itemView.findViewById(R.id.exo_check);
|
||||||
|
|
||||||
itemView.setOnClickListener(
|
itemView.setOnClickListener(
|
||||||
new OnClickListener() {
|
v -> {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
int position = SubSettingsViewHolder.this.getAdapterPosition();
|
int position = SubSettingsViewHolder.this.getAdapterPosition();
|
||||||
if (position == RecyclerView.NO_POSITION) {
|
if (position == RecyclerView.NO_POSITION) {
|
||||||
return;
|
return;
|
||||||
@ -1953,7 +1939,6 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
settingsWindow.dismiss();
|
settingsWindow.dismiss();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2012,9 +1997,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
holder.checkView.setVisibility(isTrackSelectionOff ? VISIBLE : INVISIBLE);
|
holder.checkView.setVisibility(isTrackSelectionOff ? VISIBLE : INVISIBLE);
|
||||||
holder.itemView.setOnClickListener(
|
holder.itemView.setOnClickListener(
|
||||||
new OnClickListener() {
|
v -> {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (trackSelector != null) {
|
if (trackSelector != null) {
|
||||||
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
||||||
for (int i = 0; i < rendererIndices.size(); i++) {
|
for (int i = 0; i < rendererIndices.size(); i++) {
|
||||||
@ -2027,7 +2010,6 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
checkNotNull(trackSelector).setParameters(parametersBuilder);
|
checkNotNull(trackSelector).setParameters(parametersBuilder);
|
||||||
settingsWindow.dismiss();
|
settingsWindow.dismiss();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2065,9 +2047,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
holder.checkView.setVisibility(hasSelectionOverride ? INVISIBLE : VISIBLE);
|
holder.checkView.setVisibility(hasSelectionOverride ? INVISIBLE : VISIBLE);
|
||||||
holder.itemView.setOnClickListener(
|
holder.itemView.setOnClickListener(
|
||||||
new OnClickListener() {
|
v -> {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (trackSelector != null) {
|
if (trackSelector != null) {
|
||||||
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
||||||
for (int i = 0; i < rendererIndices.size(); i++) {
|
for (int i = 0; i < rendererIndices.size(); i++) {
|
||||||
@ -2080,7 +2060,6 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
SETTINGS_AUDIO_TRACK_SELECTION_POSITION,
|
SETTINGS_AUDIO_TRACK_SELECTION_POSITION,
|
||||||
getResources().getString(R.string.exo_track_selection_auto));
|
getResources().getString(R.string.exo_track_selection_auto));
|
||||||
settingsWindow.dismiss();
|
settingsWindow.dismiss();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2176,9 +2155,7 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
holder.textView.setText(track.trackName);
|
holder.textView.setText(track.trackName);
|
||||||
holder.checkView.setVisibility(explicitlySelected ? VISIBLE : INVISIBLE);
|
holder.checkView.setVisibility(explicitlySelected ? VISIBLE : INVISIBLE);
|
||||||
holder.itemView.setOnClickListener(
|
holder.itemView.setOnClickListener(
|
||||||
new OnClickListener() {
|
v -> {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (mappedTrackInfo != null && trackSelector != null) {
|
if (mappedTrackInfo != null && trackSelector != null) {
|
||||||
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
ParametersBuilder parametersBuilder = trackSelector.getParameters().buildUpon();
|
||||||
for (int i = 0; i < rendererIndices.size(); i++) {
|
for (int i = 0; i < rendererIndices.size(); i++) {
|
||||||
@ -2202,7 +2179,6 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
onTrackSelection(track.trackName);
|
onTrackSelection(track.trackName);
|
||||||
settingsWindow.dismiss();
|
settingsWindow.dismiss();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,15 +22,14 @@ import android.animation.ObjectAnimator;
|
|||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnLayoutChangeListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewGroup.MarginLayoutParams;
|
import android.view.ViewGroup.MarginLayoutParams;
|
||||||
import android.view.animation.LinearInterpolator;
|
import android.view.animation.LinearInterpolator;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/* package */ final class StyledPlayerControlViewLayoutManager
|
/* package */ final class StyledPlayerControlViewLayoutManager {
|
||||||
implements View.OnLayoutChangeListener {
|
|
||||||
private static final long ANIMATION_INTERVAL_MS = 2_000;
|
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_HIDING_ANIMATION_MS = 250;
|
||||||
private static final long DURATION_FOR_SHOWING_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.
|
// 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 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 int uxState = UX_STATE_ALL_VISIBLE;
|
||||||
private boolean isMinimalMode;
|
private boolean isMinimalMode;
|
||||||
private boolean needToShowBars;
|
private boolean needToShowBars;
|
||||||
@ -73,7 +79,16 @@ import java.util.ArrayList;
|
|||||||
@Nullable private ValueAnimator overflowShowAnimator;
|
@Nullable private ValueAnimator overflowShowAnimator;
|
||||||
@Nullable private ValueAnimator overflowHideAnimator;
|
@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) {
|
if (this.styledPlayerControlView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -83,10 +98,10 @@ import java.util.ArrayList;
|
|||||||
styledPlayerControlView.updateAll();
|
styledPlayerControlView.updateAll();
|
||||||
styledPlayerControlView.requestPlayPauseFocus();
|
styledPlayerControlView.requestPlayPauseFocus();
|
||||||
}
|
}
|
||||||
styledPlayerControlView.post(showAllBars);
|
styledPlayerControlView.post(showAllBarsRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hide() {
|
public void hide() {
|
||||||
if (styledPlayerControlView == null
|
if (styledPlayerControlView == null
|
||||||
|| uxState == UX_STATE_ANIMATING_HIDE
|
|| uxState == UX_STATE_ANIMATING_HIDE
|
||||||
|| uxState == UX_STATE_NONE_VISIBLE) {
|
|| uxState == UX_STATE_NONE_VISIBLE) {
|
||||||
@ -94,23 +109,23 @@ import java.util.ArrayList;
|
|||||||
}
|
}
|
||||||
removeHideCallbacks();
|
removeHideCallbacks();
|
||||||
if (!animationEnabled) {
|
if (!animationEnabled) {
|
||||||
postDelayedRunnable(hideController, 0);
|
postDelayedRunnable(hideControllerRunnable, 0);
|
||||||
} else if (uxState == UX_STATE_ONLY_PROGRESS_VISIBLE) {
|
} else if (uxState == UX_STATE_ONLY_PROGRESS_VISIBLE) {
|
||||||
postDelayedRunnable(hideProgressBar, 0);
|
postDelayedRunnable(hideProgressBarRunnable, 0);
|
||||||
} else {
|
} else {
|
||||||
postDelayedRunnable(hideAllBars, 0);
|
postDelayedRunnable(hideAllBarsRunnable, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAnimationEnabled(boolean animationEnabled) {
|
public void setAnimationEnabled(boolean animationEnabled) {
|
||||||
this.animationEnabled = animationEnabled;
|
this.animationEnabled = animationEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAnimationEnabled() {
|
public boolean isAnimationEnabled() {
|
||||||
return animationEnabled;
|
return animationEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetHideCallbacks() {
|
public void resetHideCallbacks() {
|
||||||
if (uxState == UX_STATE_ANIMATING_HIDE) {
|
if (uxState == UX_STATE_ANIMATING_HIDE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -119,29 +134,29 @@ import java.util.ArrayList;
|
|||||||
styledPlayerControlView != null ? styledPlayerControlView.getShowTimeoutMs() : 0;
|
styledPlayerControlView != null ? styledPlayerControlView.getShowTimeoutMs() : 0;
|
||||||
if (showTimeoutMs > 0) {
|
if (showTimeoutMs > 0) {
|
||||||
if (!animationEnabled) {
|
if (!animationEnabled) {
|
||||||
postDelayedRunnable(hideController, showTimeoutMs);
|
postDelayedRunnable(hideControllerRunnable, showTimeoutMs);
|
||||||
} else if (uxState == UX_STATE_ONLY_PROGRESS_VISIBLE) {
|
} else if (uxState == UX_STATE_ONLY_PROGRESS_VISIBLE) {
|
||||||
postDelayedRunnable(hideProgressBar, ANIMATION_INTERVAL_MS);
|
postDelayedRunnable(hideProgressBarRunnable, ANIMATION_INTERVAL_MS);
|
||||||
} else {
|
} else {
|
||||||
postDelayedRunnable(hideMainBars, showTimeoutMs);
|
postDelayedRunnable(hideMainBarsRunnable, showTimeoutMs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeHideCallbacks() {
|
public void removeHideCallbacks() {
|
||||||
if (styledPlayerControlView == null) {
|
if (styledPlayerControlView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
styledPlayerControlView.removeCallbacks(hideController);
|
styledPlayerControlView.removeCallbacks(hideControllerRunnable);
|
||||||
styledPlayerControlView.removeCallbacks(hideAllBars);
|
styledPlayerControlView.removeCallbacks(hideAllBarsRunnable);
|
||||||
styledPlayerControlView.removeCallbacks(hideMainBars);
|
styledPlayerControlView.removeCallbacks(hideMainBarsRunnable);
|
||||||
styledPlayerControlView.removeCallbacks(hideProgressBar);
|
styledPlayerControlView.removeCallbacks(hideProgressBarRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onViewAttached(StyledPlayerControlView v) {
|
public void onViewAttached(StyledPlayerControlView v) {
|
||||||
styledPlayerControlView = v;
|
styledPlayerControlView = v;
|
||||||
|
|
||||||
v.addOnLayoutChangeListener(this);
|
v.addOnLayoutChangeListener(onLayoutChangeListener);
|
||||||
|
|
||||||
// Relating to Title Bar View
|
// Relating to Title Bar View
|
||||||
ViewGroup titleBar = v.findViewById(R.id.exo_title_bar);
|
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);
|
overflowShowButton = v.findViewById(R.id.exo_overflow_show);
|
||||||
View overflowHideButton = v.findViewById(R.id.exo_overflow_hide);
|
View overflowHideButton = v.findViewById(R.id.exo_overflow_hide);
|
||||||
if (overflowShowButton != null && overflowHideButton != null) {
|
if (overflowShowButton != null && overflowHideButton != null) {
|
||||||
overflowShowButton.setOnClickListener(overflowListener);
|
overflowShowButton.setOnClickListener(this::onOverflowButtonClick);
|
||||||
overflowHideButton.setOnClickListener(overflowListener);
|
overflowHideButton.setOnClickListener(this::onOverflowButtonClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.titleBar = titleBar;
|
this.titleBar = titleBar;
|
||||||
@ -256,7 +271,7 @@ import java.util.ArrayList;
|
|||||||
setUxState(UX_STATE_ONLY_PROGRESS_VISIBLE);
|
setUxState(UX_STATE_ONLY_PROGRESS_VISIBLE);
|
||||||
if (needToShowBars) {
|
if (needToShowBars) {
|
||||||
if (styledPlayerControlView != null) {
|
if (styledPlayerControlView != null) {
|
||||||
styledPlayerControlView.post(showAllBars);
|
styledPlayerControlView.post(showAllBarsRunnable);
|
||||||
}
|
}
|
||||||
needToShowBars = false;
|
needToShowBars = false;
|
||||||
}
|
}
|
||||||
@ -282,7 +297,7 @@ import java.util.ArrayList;
|
|||||||
setUxState(UX_STATE_NONE_VISIBLE);
|
setUxState(UX_STATE_NONE_VISIBLE);
|
||||||
if (needToShowBars) {
|
if (needToShowBars) {
|
||||||
if (styledPlayerControlView != null) {
|
if (styledPlayerControlView != null) {
|
||||||
styledPlayerControlView.post(showAllBars);
|
styledPlayerControlView.post(showAllBarsRunnable);
|
||||||
}
|
}
|
||||||
needToShowBars = false;
|
needToShowBars = false;
|
||||||
}
|
}
|
||||||
@ -306,7 +321,7 @@ import java.util.ArrayList;
|
|||||||
setUxState(UX_STATE_NONE_VISIBLE);
|
setUxState(UX_STATE_NONE_VISIBLE);
|
||||||
if (needToShowBars) {
|
if (needToShowBars) {
|
||||||
if (styledPlayerControlView != null) {
|
if (styledPlayerControlView != null) {
|
||||||
styledPlayerControlView.post(showAllBars);
|
styledPlayerControlView.post(showAllBarsRunnable);
|
||||||
}
|
}
|
||||||
needToShowBars = false;
|
needToShowBars = false;
|
||||||
}
|
}
|
||||||
@ -403,11 +418,11 @@ import java.util.ArrayList;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void onViewDetached(StyledPlayerControlView v) {
|
public void onViewDetached(StyledPlayerControlView v) {
|
||||||
v.removeOnLayoutChangeListener(this);
|
v.removeOnLayoutChangeListener(onLayoutChangeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isFullyVisible() {
|
public boolean isFullyVisible() {
|
||||||
if (styledPlayerControlView == null) {
|
if (styledPlayerControlView == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -432,10 +447,38 @@ import java.util.ArrayList;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Runnable showAllBars =
|
private void onLayoutChange(
|
||||||
new Runnable() {
|
View v,
|
||||||
@Override
|
int left,
|
||||||
public void run() {
|
int top,
|
||||||
|
int right,
|
||||||
|
int bottom,
|
||||||
|
int oldLeft,
|
||||||
|
int oldTop,
|
||||||
|
int oldRight,
|
||||||
|
int oldBottom) {
|
||||||
|
|
||||||
|
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 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 void showAllBars() {
|
||||||
if (!animationEnabled) {
|
if (!animationEnabled) {
|
||||||
setUxState(UX_STATE_ALL_VISIBLE);
|
setUxState(UX_STATE_ALL_VISIBLE);
|
||||||
resetHideCallbacks();
|
resetHideCallbacks();
|
||||||
@ -463,49 +506,32 @@ import java.util.ArrayList;
|
|||||||
}
|
}
|
||||||
resetHideCallbacks();
|
resetHideCallbacks();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private final Runnable hideAllBars =
|
private void hideAllBars() {
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (hideAllBarsAnimator == null) {
|
if (hideAllBarsAnimator == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hideAllBarsAnimator.start();
|
hideAllBarsAnimator.start();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private final Runnable hideMainBars =
|
private void hideProgressBar() {
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (hideMainBarsAnimator == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
hideMainBarsAnimator.start();
|
|
||||||
postDelayedRunnable(hideProgressBar, ANIMATION_INTERVAL_MS);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final Runnable hideProgressBar =
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (hideProgressBarAnimator == null) {
|
if (hideProgressBarAnimator == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hideProgressBarAnimator.start();
|
hideProgressBarAnimator.start();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private final Runnable hideController =
|
private void hideMainBars() {
|
||||||
new Runnable() {
|
if (hideMainBarsAnimator == null) {
|
||||||
@Override
|
return;
|
||||||
public void run() {
|
}
|
||||||
|
hideMainBarsAnimator.start();
|
||||||
|
postDelayedRunnable(hideProgressBarRunnable, ANIMATION_INTERVAL_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideController() {
|
||||||
setUxState(UX_STATE_NONE_VISIBLE);
|
setUxState(UX_STATE_NONE_VISIBLE);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private static ObjectAnimator ofTranslationY(float startValue, float endValue, View target) {
|
private static ObjectAnimator ofTranslationY(float startValue, float endValue, View target) {
|
||||||
return ObjectAnimator.ofFloat(target, "translationY", startValue, endValue);
|
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() {
|
private boolean shouldBeMinimalMode() {
|
||||||
if (this.styledPlayerControlView == null) {
|
if (this.styledPlayerControlView == null) {
|
||||||
return isMinimalMode;
|
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