StyledPlayerView: Fix progressBar to noBar transformation

Also make some related naming improvements.

PiperOrigin-RevId: 347653802
This commit is contained in:
olly 2020-12-15 19:20:38 +00:00 committed by Christos Tsilopoulos
parent 70ba62a281
commit 7c28df62fd

View File

@ -60,10 +60,10 @@ import java.util.List;
@Nullable private final View timeBar; @Nullable private final View timeBar;
@Nullable private final View overflowShowButton; @Nullable private final View overflowShowButton;
private final AnimatorSet hideMainBarsAnimator; private final AnimatorSet hideMainBarAnimator;
private final AnimatorSet hideProgressBarAnimator; private final AnimatorSet hideProgressBarAnimator;
private final AnimatorSet hideAllBarsAnimator; private final AnimatorSet hideAllBarsAnimator;
private final AnimatorSet showMainBarsAnimator; private final AnimatorSet showMainBarAnimator;
private final AnimatorSet showAllBarsAnimator; private final AnimatorSet showAllBarsAnimator;
private final ValueAnimator overflowShowAnimator; private final ValueAnimator overflowShowAnimator;
private final ValueAnimator overflowHideAnimator; private final ValueAnimator overflowHideAnimator;
@ -71,7 +71,7 @@ import java.util.List;
private final Runnable showAllBarsRunnable; private final Runnable showAllBarsRunnable;
private final Runnable hideAllBarsRunnable; private final Runnable hideAllBarsRunnable;
private final Runnable hideProgressBarRunnable; private final Runnable hideProgressBarRunnable;
private final Runnable hideMainBarsRunnable; private final Runnable hideMainBarRunnable;
private final Runnable hideControllerRunnable; private final Runnable hideControllerRunnable;
private final OnLayoutChangeListener onLayoutChangeListener; private final OnLayoutChangeListener onLayoutChangeListener;
@ -91,7 +91,7 @@ import java.util.List;
showAllBarsRunnable = this::showAllBars; showAllBarsRunnable = this::showAllBars;
hideAllBarsRunnable = this::hideAllBars; hideAllBarsRunnable = this::hideAllBars;
hideProgressBarRunnable = this::hideProgressBar; hideProgressBarRunnable = this::hideProgressBar;
hideMainBarsRunnable = this::hideMainBars; hideMainBarRunnable = this::hideMainBar;
hideControllerRunnable = this::hideController; hideControllerRunnable = this::hideController;
onLayoutChangeListener = this::onLayoutChange; onLayoutChangeListener = this::onLayoutChange;
animationEnabled = true; animationEnabled = true;
@ -124,15 +124,6 @@ import java.util.List;
overflowHideButton.setOnClickListener(this::onOverflowButtonClick); overflowHideButton.setOnClickListener(this::onOverflowButtonClick);
} }
Resources resources = styledPlayerControlView.getResources();
float bottomBarHeight =
resources.getDimension(R.dimen.exo_styled_bottom_bar_height)
- resources.getDimension(R.dimen.exo_styled_progress_bar_height);
float progressBarHeight =
resources.getDimension(R.dimen.exo_styled_progress_margin_bottom)
+ resources.getDimension(R.dimen.exo_styled_progress_layout_height)
- bottomBarHeight;
ValueAnimator fadeOutAnimator = ValueAnimator.ofFloat(1.0f, 0.0f); ValueAnimator fadeOutAnimator = ValueAnimator.ofFloat(1.0f, 0.0f);
fadeOutAnimator.setInterpolator(new LinearInterpolator()); fadeOutAnimator.setInterpolator(new LinearInterpolator());
fadeOutAnimator.addUpdateListener( fadeOutAnimator.addUpdateListener(
@ -205,9 +196,15 @@ import java.util.List;
} }
}); });
hideMainBarsAnimator = new AnimatorSet(); Resources resources = styledPlayerControlView.getResources();
hideMainBarsAnimator.setDuration(DURATION_FOR_HIDING_ANIMATION_MS); float translationYForProgressBar =
hideMainBarsAnimator.addListener( resources.getDimension(R.dimen.exo_styled_bottom_bar_height)
- resources.getDimension(R.dimen.exo_styled_progress_bar_height);
float translationYForNoBars = resources.getDimension(R.dimen.exo_styled_bottom_bar_height);
hideMainBarAnimator = new AnimatorSet();
hideMainBarAnimator.setDuration(DURATION_FOR_HIDING_ANIMATION_MS);
hideMainBarAnimator.addListener(
new AnimatorListenerAdapter() { new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationStart(Animator animation) { public void onAnimationStart(Animator animation) {
@ -223,10 +220,10 @@ import java.util.List;
} }
} }
}); });
hideMainBarsAnimator hideMainBarAnimator
.play(fadeOutAnimator) .play(fadeOutAnimator)
.with(ofTranslationY(0, bottomBarHeight, timeBar)) .with(ofTranslationY(0, translationYForProgressBar, timeBar))
.with(ofTranslationY(0, bottomBarHeight, bottomBar)); .with(ofTranslationY(0, translationYForProgressBar, bottomBar));
hideProgressBarAnimator = new AnimatorSet(); hideProgressBarAnimator = new AnimatorSet();
hideProgressBarAnimator.setDuration(DURATION_FOR_HIDING_ANIMATION_MS); hideProgressBarAnimator.setDuration(DURATION_FOR_HIDING_ANIMATION_MS);
@ -247,8 +244,8 @@ import java.util.List;
} }
}); });
hideProgressBarAnimator hideProgressBarAnimator
.play(ofTranslationY(bottomBarHeight, bottomBarHeight + progressBarHeight, timeBar)) .play(ofTranslationY(translationYForProgressBar, translationYForNoBars, timeBar))
.with(ofTranslationY(bottomBarHeight, bottomBarHeight + progressBarHeight, bottomBar)); .with(ofTranslationY(translationYForProgressBar, translationYForNoBars, bottomBar));
hideAllBarsAnimator = new AnimatorSet(); hideAllBarsAnimator = new AnimatorSet();
hideAllBarsAnimator.setDuration(DURATION_FOR_HIDING_ANIMATION_MS); hideAllBarsAnimator.setDuration(DURATION_FOR_HIDING_ANIMATION_MS);
@ -270,12 +267,12 @@ import java.util.List;
}); });
hideAllBarsAnimator hideAllBarsAnimator
.play(fadeOutAnimator) .play(fadeOutAnimator)
.with(ofTranslationY(0, bottomBarHeight + progressBarHeight, timeBar)) .with(ofTranslationY(0, translationYForNoBars, timeBar))
.with(ofTranslationY(0, bottomBarHeight + progressBarHeight, bottomBar)); .with(ofTranslationY(0, translationYForNoBars, bottomBar));
showMainBarsAnimator = new AnimatorSet(); showMainBarAnimator = new AnimatorSet();
showMainBarsAnimator.setDuration(DURATION_FOR_SHOWING_ANIMATION_MS); showMainBarAnimator.setDuration(DURATION_FOR_SHOWING_ANIMATION_MS);
showMainBarsAnimator.addListener( showMainBarAnimator.addListener(
new AnimatorListenerAdapter() { new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationStart(Animator animation) { public void onAnimationStart(Animator animation) {
@ -287,10 +284,10 @@ import java.util.List;
setUxState(UX_STATE_ALL_VISIBLE); setUxState(UX_STATE_ALL_VISIBLE);
} }
}); });
showMainBarsAnimator showMainBarAnimator
.play(fadeInAnimator) .play(fadeInAnimator)
.with(ofTranslationY(bottomBarHeight, 0, timeBar)) .with(ofTranslationY(translationYForProgressBar, 0, timeBar))
.with(ofTranslationY(bottomBarHeight, 0, bottomBar)); .with(ofTranslationY(translationYForProgressBar, 0, bottomBar));
showAllBarsAnimator = new AnimatorSet(); showAllBarsAnimator = new AnimatorSet();
showAllBarsAnimator.setDuration(DURATION_FOR_SHOWING_ANIMATION_MS); showAllBarsAnimator.setDuration(DURATION_FOR_SHOWING_ANIMATION_MS);
@ -308,8 +305,8 @@ import java.util.List;
}); });
showAllBarsAnimator showAllBarsAnimator
.play(fadeInAnimator) .play(fadeInAnimator)
.with(ofTranslationY(bottomBarHeight + progressBarHeight, 0, timeBar)) .with(ofTranslationY(translationYForNoBars, 0, timeBar))
.with(ofTranslationY(bottomBarHeight + progressBarHeight, 0, bottomBar)); .with(ofTranslationY(translationYForNoBars, 0, bottomBar));
overflowShowAnimator = ValueAnimator.ofFloat(0.0f, 1.0f); overflowShowAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
overflowShowAnimator.setDuration(DURATION_FOR_SHOWING_ANIMATION_MS); overflowShowAnimator.setDuration(DURATION_FOR_SHOWING_ANIMATION_MS);
@ -407,7 +404,7 @@ import java.util.List;
} else if (uxState == UX_STATE_ONLY_PROGRESS_VISIBLE) { } else if (uxState == UX_STATE_ONLY_PROGRESS_VISIBLE) {
postDelayedRunnable(hideProgressBarRunnable, ANIMATION_INTERVAL_MS); postDelayedRunnable(hideProgressBarRunnable, ANIMATION_INTERVAL_MS);
} else { } else {
postDelayedRunnable(hideMainBarsRunnable, showTimeoutMs); postDelayedRunnable(hideMainBarRunnable, showTimeoutMs);
} }
} }
} }
@ -415,7 +412,7 @@ import java.util.List;
public void removeHideCallbacks() { public void removeHideCallbacks() {
styledPlayerControlView.removeCallbacks(hideControllerRunnable); styledPlayerControlView.removeCallbacks(hideControllerRunnable);
styledPlayerControlView.removeCallbacks(hideAllBarsRunnable); styledPlayerControlView.removeCallbacks(hideAllBarsRunnable);
styledPlayerControlView.removeCallbacks(hideMainBarsRunnable); styledPlayerControlView.removeCallbacks(hideMainBarRunnable);
styledPlayerControlView.removeCallbacks(hideProgressBarRunnable); styledPlayerControlView.removeCallbacks(hideProgressBarRunnable);
} }
@ -510,7 +507,7 @@ import java.util.List;
showAllBarsAnimator.start(); showAllBarsAnimator.start();
break; break;
case UX_STATE_ONLY_PROGRESS_VISIBLE: case UX_STATE_ONLY_PROGRESS_VISIBLE:
showMainBarsAnimator.start(); showMainBarAnimator.start();
break; break;
case UX_STATE_ANIMATING_HIDE: case UX_STATE_ANIMATING_HIDE:
needToShowBars = true; needToShowBars = true;
@ -531,8 +528,8 @@ import java.util.List;
hideProgressBarAnimator.start(); hideProgressBarAnimator.start();
} }
private void hideMainBars() { private void hideMainBar() {
hideMainBarsAnimator.start(); hideMainBarAnimator.start();
postDelayedRunnable(hideProgressBarRunnable, ANIMATION_INTERVAL_MS); postDelayedRunnable(hideProgressBarRunnable, ANIMATION_INTERVAL_MS);
} }