Commit 602d8808 by insun Committed by kim-vde

Fix StyledControlView's minimal mode bug and setShow{*}Button bug

There were two bugs in StyledPlayerControlView:
- Center icons are shown when toggling control view in minimal mode.
- `StyledControlView#setShow{*}Button` methods and corresponding
  `set_show_*_button` attributes didn't work properly.

This CL fixes bugs by controlling the buttons' visibility in one place,
StyledPlayerControlViewLayoutManager.

PiperOrigin-RevId: 326567213
parent e6bf7bd0
...@@ -408,12 +408,6 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -408,12 +408,6 @@ public class StyledPlayerControlView extends FrameLayout {
private int showTimeoutMs; private int showTimeoutMs;
private int timeBarMinUpdateIntervalMs; private int timeBarMinUpdateIntervalMs;
private @RepeatModeUtil.RepeatToggleModes int repeatToggleModes; private @RepeatModeUtil.RepeatToggleModes int repeatToggleModes;
private boolean showRewindButton;
private boolean showFastForwardButton;
private boolean showPreviousButton;
private boolean showNextButton;
private boolean showShuffleButton;
private boolean showSubtitleButton;
private long[] adGroupTimesMs; private long[] adGroupTimesMs;
private boolean[] playedAdGroups; private boolean[] playedAdGroups;
private long[] extraAdGroupTimesMs; private long[] extraAdGroupTimesMs;
...@@ -478,12 +472,12 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -478,12 +472,12 @@ public class StyledPlayerControlView extends FrameLayout {
showTimeoutMs = DEFAULT_SHOW_TIMEOUT_MS; showTimeoutMs = DEFAULT_SHOW_TIMEOUT_MS;
repeatToggleModes = DEFAULT_REPEAT_TOGGLE_MODES; repeatToggleModes = DEFAULT_REPEAT_TOGGLE_MODES;
timeBarMinUpdateIntervalMs = DEFAULT_TIME_BAR_MIN_UPDATE_INTERVAL_MS; timeBarMinUpdateIntervalMs = DEFAULT_TIME_BAR_MIN_UPDATE_INTERVAL_MS;
showRewindButton = true; boolean showRewindButton = true;
showFastForwardButton = true; boolean showFastForwardButton = true;
showPreviousButton = true; boolean showPreviousButton = true;
showNextButton = true; boolean showNextButton = true;
showShuffleButton = false; boolean showShuffleButton = false;
showSubtitleButton = false; boolean showSubtitleButton = false;
boolean animationEnabled = true; boolean animationEnabled = true;
boolean showVrButton = false; boolean showVrButton = false;
...@@ -530,7 +524,6 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -530,7 +524,6 @@ public class StyledPlayerControlView extends FrameLayout {
a.recycle(); a.recycle();
} }
} }
controlViewLayoutManager = new StyledPlayerControlViewLayoutManager(); controlViewLayoutManager = new StyledPlayerControlViewLayoutManager();
controlViewLayoutManager.setAnimationEnabled(animationEnabled); controlViewLayoutManager.setAnimationEnabled(animationEnabled);
visibilityListeners = new CopyOnWriteArrayList<>(); visibilityListeners = new CopyOnWriteArrayList<>();
...@@ -558,7 +551,6 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -558,7 +551,6 @@ public class StyledPlayerControlView extends FrameLayout {
subtitleButton = findViewById(R.id.exo_subtitle); subtitleButton = findViewById(R.id.exo_subtitle);
if (subtitleButton != null) { if (subtitleButton != null) {
subtitleButton.setOnClickListener(componentListener); subtitleButton.setOnClickListener(componentListener);
subtitleButton.setVisibility(showSubtitleButton ? VISIBLE : GONE);
} }
fullScreenButton = findViewById(R.id.exo_fullscreen); fullScreenButton = findViewById(R.id.exo_fullscreen);
if (fullScreenButton != null) { if (fullScreenButton != null) {
...@@ -712,6 +704,16 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -712,6 +704,16 @@ 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);
// TODO(insun) : Make showing bottomBar configurable. (ex. show_bottom_bar attribute).
ViewGroup bottomBar = findViewById(R.id.exo_bottom_bar);
controlViewLayoutManager.setShowButton(bottomBar, true);
controlViewLayoutManager.setShowButton(fastForwardButton, showFastForwardButton);
controlViewLayoutManager.setShowButton(rewindButton, showRewindButton);
controlViewLayoutManager.setShowButton(previousButton, showPreviousButton);
controlViewLayoutManager.setShowButton(nextButton, showNextButton);
controlViewLayoutManager.setShowButton(shuffleButton, showShuffleButton);
controlViewLayoutManager.setShowButton(subtitleButton, showSubtitleButton);
controlViewLayoutManager.setShowButton(vrButton, showVrButton);
addOnLayoutChangeListener(this::onLayoutChange); addOnLayoutChangeListener(this::onLayoutChange);
} }
...@@ -853,7 +855,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -853,7 +855,7 @@ public class StyledPlayerControlView extends FrameLayout {
* @param showRewindButton Whether the rewind button is shown. * @param showRewindButton Whether the rewind button is shown.
*/ */
public void setShowRewindButton(boolean showRewindButton) { public void setShowRewindButton(boolean showRewindButton) {
this.showRewindButton = showRewindButton; controlViewLayoutManager.setShowButton(rewindButton, showRewindButton);
updateNavigation(); updateNavigation();
} }
...@@ -863,7 +865,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -863,7 +865,7 @@ public class StyledPlayerControlView extends FrameLayout {
* @param showFastForwardButton Whether the fast forward button is shown. * @param showFastForwardButton Whether the fast forward button is shown.
*/ */
public void setShowFastForwardButton(boolean showFastForwardButton) { public void setShowFastForwardButton(boolean showFastForwardButton) {
this.showFastForwardButton = showFastForwardButton; controlViewLayoutManager.setShowButton(fastForwardButton, showFastForwardButton);
updateNavigation(); updateNavigation();
} }
...@@ -873,7 +875,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -873,7 +875,7 @@ public class StyledPlayerControlView extends FrameLayout {
* @param showPreviousButton Whether the previous button is shown. * @param showPreviousButton Whether the previous button is shown.
*/ */
public void setShowPreviousButton(boolean showPreviousButton) { public void setShowPreviousButton(boolean showPreviousButton) {
this.showPreviousButton = showPreviousButton; controlViewLayoutManager.setShowButton(previousButton, showPreviousButton);
updateNavigation(); updateNavigation();
} }
...@@ -883,7 +885,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -883,7 +885,7 @@ public class StyledPlayerControlView extends FrameLayout {
* @param showNextButton Whether the next button is shown. * @param showNextButton Whether the next button is shown.
*/ */
public void setShowNextButton(boolean showNextButton) { public void setShowNextButton(boolean showNextButton) {
this.showNextButton = showNextButton; controlViewLayoutManager.setShowButton(nextButton, showNextButton);
updateNavigation(); updateNavigation();
} }
...@@ -941,12 +943,14 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -941,12 +943,14 @@ public class StyledPlayerControlView extends FrameLayout {
controlDispatcher.dispatchSetRepeatMode(player, Player.REPEAT_MODE_ALL); controlDispatcher.dispatchSetRepeatMode(player, Player.REPEAT_MODE_ALL);
} }
} }
controlViewLayoutManager.setShowButton(
repeatToggleButton, repeatToggleModes != RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE);
updateRepeatModeButton(); updateRepeatModeButton();
} }
/** Returns whether the shuffle button is shown. */ /** Returns whether the shuffle button is shown. */
public boolean getShowShuffleButton() { public boolean getShowShuffleButton() {
return showShuffleButton; return controlViewLayoutManager.getShowButton(shuffleButton);
} }
/** /**
...@@ -955,13 +959,13 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -955,13 +959,13 @@ public class StyledPlayerControlView extends FrameLayout {
* @param showShuffleButton Whether the shuffle button is shown. * @param showShuffleButton Whether the shuffle button is shown.
*/ */
public void setShowShuffleButton(boolean showShuffleButton) { public void setShowShuffleButton(boolean showShuffleButton) {
this.showShuffleButton = showShuffleButton; controlViewLayoutManager.setShowButton(shuffleButton, showShuffleButton);
updateShuffleButton(); updateShuffleButton();
} }
/** Returns whether the subtitle button is shown. */ /** Returns whether the subtitle button is shown. */
public boolean getShowSubtitleButton() { public boolean getShowSubtitleButton() {
return showSubtitleButton; return controlViewLayoutManager.getShowButton(subtitleButton);
} }
/** /**
...@@ -970,15 +974,12 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -970,15 +974,12 @@ public class StyledPlayerControlView extends FrameLayout {
* @param showSubtitleButton Whether the subtitle button is shown. * @param showSubtitleButton Whether the subtitle button is shown.
*/ */
public void setShowSubtitleButton(boolean showSubtitleButton) { public void setShowSubtitleButton(boolean showSubtitleButton) {
this.showSubtitleButton = showSubtitleButton; controlViewLayoutManager.setShowButton(subtitleButton, showSubtitleButton);
if (subtitleButton != null) {
subtitleButton.setVisibility(showSubtitleButton ? VISIBLE : GONE);
}
} }
/** Returns whether the VR button is shown. */ /** Returns whether the VR button is shown. */
public boolean getShowVrButton() { public boolean getShowVrButton() {
return vrButton != null && vrButton.getVisibility() == VISIBLE; return controlViewLayoutManager.getShowButton(vrButton);
} }
/** /**
...@@ -987,9 +988,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -987,9 +988,7 @@ public class StyledPlayerControlView extends FrameLayout {
* @param showVrButton Whether the VR button is shown. * @param showVrButton Whether the VR button is shown.
*/ */
public void setShowVrButton(boolean showVrButton) { public void setShowVrButton(boolean showVrButton) {
if (vrButton != null) { controlViewLayoutManager.setShowButton(vrButton, showVrButton);
updateButton(showVrButton, vrButton.hasOnClickListeners(), vrButton);
}
} }
/** /**
...@@ -1000,7 +999,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1000,7 +999,7 @@ public class StyledPlayerControlView extends FrameLayout {
public void setVrButtonListener(@Nullable OnClickListener onClickListener) { public void setVrButtonListener(@Nullable OnClickListener onClickListener) {
if (vrButton != null) { if (vrButton != null) {
vrButton.setOnClickListener(onClickListener); vrButton.setOnClickListener(onClickListener);
updateButton(getShowVrButton(), onClickListener != null, vrButton); updateButton(onClickListener != null, vrButton);
} }
} }
...@@ -1143,10 +1142,10 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1143,10 +1142,10 @@ public class StyledPlayerControlView extends FrameLayout {
updateFastForwardButton(); updateFastForwardButton();
} }
updateButton(showPreviousButton, enablePrevious, previousButton); updateButton(enablePrevious, previousButton);
updateButton(showRewindButton, enableRewind, rewindButton); updateButton(enableRewind, rewindButton);
updateButton(showFastForwardButton, enableFastForward, fastForwardButton); updateButton(enableFastForward, fastForwardButton);
updateButton(showNextButton, enableNext, nextButton); updateButton(enableNext, nextButton);
if (timeBar != null) { if (timeBar != null) {
timeBar.setEnabled(enableSeeking); timeBar.setEnabled(enableSeeking);
} }
...@@ -1187,19 +1186,19 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1187,19 +1186,19 @@ public class StyledPlayerControlView extends FrameLayout {
} }
if (repeatToggleModes == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE) { if (repeatToggleModes == RepeatModeUtil.REPEAT_TOGGLE_MODE_NONE) {
updateButton(/* visible= */ false, /* enabled= */ false, repeatToggleButton); updateButton(/* enabled= */ false, repeatToggleButton);
return; return;
} }
@Nullable Player player = this.player; @Nullable Player player = this.player;
if (player == null) { if (player == null) {
updateButton(/* visible= */ true, /* enabled= */ false, repeatToggleButton); updateButton(/* enabled= */ false, repeatToggleButton);
repeatToggleButton.setImageDrawable(repeatOffButtonDrawable); repeatToggleButton.setImageDrawable(repeatOffButtonDrawable);
repeatToggleButton.setContentDescription(repeatOffButtonContentDescription); repeatToggleButton.setContentDescription(repeatOffButtonContentDescription);
return; return;
} }
updateButton(/* visible= */ true, /* enabled= */ true, repeatToggleButton); updateButton(/* enabled= */ true, repeatToggleButton);
switch (player.getRepeatMode()) { switch (player.getRepeatMode()) {
case Player.REPEAT_MODE_OFF: case Player.REPEAT_MODE_OFF:
repeatToggleButton.setImageDrawable(repeatOffButtonDrawable); repeatToggleButton.setImageDrawable(repeatOffButtonDrawable);
...@@ -1224,14 +1223,14 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1224,14 +1223,14 @@ public class StyledPlayerControlView extends FrameLayout {
} }
@Nullable Player player = this.player; @Nullable Player player = this.player;
if (!showShuffleButton) { if (!controlViewLayoutManager.getShowButton(shuffleButton)) {
updateButton(/* visible= */ false, /* enabled= */ false, shuffleButton); updateButton(/* enabled= */ false, shuffleButton);
} else if (player == null) { } else if (player == null) {
updateButton(/* visible= */ true, /* enabled= */ false, shuffleButton); updateButton(/* enabled= */ false, shuffleButton);
shuffleButton.setImageDrawable(shuffleOffButtonDrawable); shuffleButton.setImageDrawable(shuffleOffButtonDrawable);
shuffleButton.setContentDescription(shuffleOffContentDescription); shuffleButton.setContentDescription(shuffleOffContentDescription);
} else { } else {
updateButton(/* visible= */ true, /* enabled= */ true, shuffleButton); updateButton(/* enabled= */ true, shuffleButton);
shuffleButton.setImageDrawable( shuffleButton.setImageDrawable(
player.getShuffleModeEnabled() ? shuffleOnButtonDrawable : shuffleOffButtonDrawable); player.getShuffleModeEnabled() ? shuffleOnButtonDrawable : shuffleOffButtonDrawable);
shuffleButton.setContentDescription( shuffleButton.setContentDescription(
...@@ -1243,7 +1242,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1243,7 +1242,7 @@ public class StyledPlayerControlView extends FrameLayout {
private void updateTrackLists() { private void updateTrackLists() {
initTrackSelectionAdapter(); initTrackSelectionAdapter();
updateButton(showSubtitleButton, textTrackSelectionAdapter.getItemCount() > 0, subtitleButton); updateButton(textTrackSelectionAdapter.getItemCount() > 0, subtitleButton);
} }
private void initTrackSelectionAdapter() { private void initTrackSelectionAdapter() {
...@@ -1265,7 +1264,7 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1265,7 +1264,7 @@ public class StyledPlayerControlView extends FrameLayout {
rendererIndex < mappedTrackInfo.getRendererCount(); rendererIndex < mappedTrackInfo.getRendererCount();
rendererIndex++) { rendererIndex++) {
if (mappedTrackInfo.getRendererType(rendererIndex) == C.TRACK_TYPE_TEXT if (mappedTrackInfo.getRendererType(rendererIndex) == C.TRACK_TYPE_TEXT
&& showSubtitleButton) { && controlViewLayoutManager.getShowButton(subtitleButton)) {
// Get TrackSelection at the corresponding renderer index. // Get TrackSelection at the corresponding renderer index.
gatherTrackInfosForAdapter(mappedTrackInfo, rendererIndex, textTracks); gatherTrackInfosForAdapter(mappedTrackInfo, rendererIndex, textTracks);
textRendererIndices.add(rendererIndex); textRendererIndices.add(rendererIndex);
...@@ -1491,13 +1490,12 @@ public class StyledPlayerControlView extends FrameLayout { ...@@ -1491,13 +1490,12 @@ public class StyledPlayerControlView extends FrameLayout {
} }
} }
private void updateButton(boolean visible, boolean enabled, @Nullable View view) { private void updateButton(boolean enabled, @Nullable View view) {
if (view == null) { if (view == null) {
return; return;
} }
view.setEnabled(enabled); view.setEnabled(enabled);
view.setAlpha(enabled ? buttonAlphaEnabled : buttonAlphaDisabled); view.setAlpha(enabled ? buttonAlphaEnabled : buttonAlphaDisabled);
view.setVisibility(visible ? VISIBLE : GONE);
} }
private void seekToTimeBarPosition(Player player, long positionMs) { private void seekToTimeBarPosition(Player player, long positionMs) {
......
...@@ -28,6 +28,7 @@ import android.view.ViewGroup.MarginLayoutParams; ...@@ -28,6 +28,7 @@ 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;
import java.util.List;
/* package */ final class StyledPlayerControlViewLayoutManager { /* package */ final class StyledPlayerControlViewLayoutManager {
private static final long ANIMATION_INTERVAL_MS = 2_000; private static final long ANIMATION_INTERVAL_MS = 2_000;
...@@ -53,6 +54,8 @@ import java.util.ArrayList; ...@@ -53,6 +54,8 @@ import java.util.ArrayList;
private final Runnable hideControllerRunnable; private final Runnable hideControllerRunnable;
private final OnLayoutChangeListener onLayoutChangeListener; private final OnLayoutChangeListener onLayoutChangeListener;
private final List<View> shownButtons;
private int uxState; private int uxState;
private boolean initiallyHidden; private boolean initiallyHidden;
private boolean isMinimalMode; private boolean isMinimalMode;
...@@ -88,6 +91,7 @@ import java.util.ArrayList; ...@@ -88,6 +91,7 @@ import java.util.ArrayList;
onLayoutChangeListener = this::onLayoutChange; onLayoutChangeListener = this::onLayoutChange;
animationEnabled = true; animationEnabled = true;
uxState = UX_STATE_ALL_VISIBLE; uxState = UX_STATE_ALL_VISIBLE;
shownButtons = new ArrayList<>();
} }
public void show() { public void show() {
...@@ -157,6 +161,7 @@ import java.util.ArrayList; ...@@ -157,6 +161,7 @@ import java.util.ArrayList;
styledPlayerControlView.removeCallbacks(hideProgressBarRunnable); styledPlayerControlView.removeCallbacks(hideProgressBarRunnable);
} }
// TODO(insun): Pass StyledPlayerControlView to constructor and reduce multiple nullchecks.
public void onViewAttached(StyledPlayerControlView v) { public void onViewAttached(StyledPlayerControlView v) {
styledPlayerControlView = v; styledPlayerControlView = v;
...@@ -426,6 +431,27 @@ import java.util.ArrayList; ...@@ -426,6 +431,27 @@ import java.util.ArrayList;
return uxState == UX_STATE_ALL_VISIBLE && styledPlayerControlView.isVisible(); return uxState == UX_STATE_ALL_VISIBLE && styledPlayerControlView.isVisible();
} }
public void setShowButton(@Nullable View button, boolean showButton) {
if (button == null) {
return;
}
if (!showButton) {
button.setVisibility(View.GONE);
shownButtons.remove(button);
return;
}
if (isMinimalMode && shouldHideInMinimalMode(button)) {
button.setVisibility(View.INVISIBLE);
} else {
button.setVisibility(View.VISIBLE);
}
shownButtons.add(button);
}
public boolean getShowButton(@Nullable View button) {
return button != null && shownButtons.contains(button);
}
private void setUxState(int uxState) { private void setUxState(int uxState) {
int prevUxState = this.uxState; int prevUxState = this.uxState;
this.uxState = uxState; this.uxState = uxState;
...@@ -573,9 +599,7 @@ import java.util.ArrayList; ...@@ -573,9 +599,7 @@ import java.util.ArrayList;
Math.max( Math.max(
getWidth(embeddedTransportControls), getWidth(timeView) + getWidth(overflowShowButton)); getWidth(embeddedTransportControls), getWidth(timeView) + getWidth(overflowShowButton));
int defaultModeHeight = int defaultModeHeight =
getHeight(embeddedTransportControls) getHeight(embeddedTransportControls) + getHeight(timeBar) + getHeight(bottomBar);
+ getHeight(timeBar)
+ getHeight(bottomBar);
return (width <= defaultModeWidth || height <= defaultModeHeight); return (width <= defaultModeWidth || height <= defaultModeHeight);
} }
...@@ -584,7 +608,7 @@ import java.util.ArrayList; ...@@ -584,7 +608,7 @@ import java.util.ArrayList;
if (this.styledPlayerControlView == null) { if (this.styledPlayerControlView == null) {
return; return;
} }
ViewGroup playerControlView = this.styledPlayerControlView; StyledPlayerControlView playerControlView = this.styledPlayerControlView;
if (minimalControls != null) { if (minimalControls != null) {
minimalControls.setVisibility(isMinimalMode ? View.VISIBLE : View.INVISIBLE); minimalControls.setVisibility(isMinimalMode ? View.VISIBLE : View.INVISIBLE);
...@@ -624,23 +648,22 @@ import java.util.ArrayList; ...@@ -624,23 +648,22 @@ import java.util.ArrayList;
} }
} }
int[] idsToHideInMinimalMode = { for (View v : shownButtons) {
R.id.exo_bottom_bar, v.setVisibility(isMinimalMode && shouldHideInMinimalMode(v) ? View.INVISIBLE : View.VISIBLE);
R.id.exo_prev,
R.id.exo_next,
R.id.exo_rew,
R.id.exo_rew_with_amount,
R.id.exo_ffwd,
R.id.exo_ffwd_with_amount
};
for (int id : idsToHideInMinimalMode) {
View v = playerControlView.findViewById(id);
if (v != null) {
v.setVisibility(isMinimalMode ? View.INVISIBLE : View.VISIBLE);
}
} }
} }
private boolean shouldHideInMinimalMode(View button) {
int id = button.getId();
return (id == R.id.exo_bottom_bar
|| id == R.id.exo_prev
|| id == R.id.exo_next
|| id == R.id.exo_rew
|| id == R.id.exo_rew_with_amount
|| id == R.id.exo_ffwd
|| id == R.id.exo_ffwd_with_amount);
}
private void onLayoutWidthChanged() { private void onLayoutWidthChanged() {
if (basicControls == null || extraControls == null) { if (basicControls == null || extraControls == null) {
return; return;
......
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