Add show/hideScrubber to DefaultTimeBar

PiperOrigin-RevId: 300249371
This commit is contained in:
olly 2020-03-11 05:01:42 +00:00 committed by Andrew Lewis
parent 2640538228
commit d162c07ecf
2 changed files with 52 additions and 14 deletions

View File

@ -32,6 +32,7 @@
* UI:
* Fix `DefaultTimeBar` to respect touch transformations
([#7303](https://github.com/google/ExoPlayer/issues/7303)).
* Add `showScrubber` and `hideScrubber` methods to `DefaultTimeBar`.
* Update `TrackSelectionDialogBuilder` to use AndroidX Compat Dialog
([#7357](https://github.com/google/ExoPlayer/issues/7357)).
* Text: Use anti-aliasing and bitmap filtering when displaying bitmap

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.ui;
import android.annotation.TargetApi;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@ -166,6 +167,9 @@ public class DefaultTimeBar extends View implements TimeBar {
private static final int DEFAULT_INCREMENT_COUNT = 20;
private static final float SHOWN_SCRUBBER_SCALE = 1.0f;
private static final float HIDDEN_SCRUBBER_SCALE = 0.0f;
/**
* The name of the Android SDK view that most closely resembles this custom view. Used as the
* class name for accessibility.
@ -203,6 +207,7 @@ public class DefaultTimeBar extends View implements TimeBar {
private int lastCoarseScrubXPosition;
@MonotonicNonNull private Rect lastExclusionRectangle;
private ValueAnimator scrubberScalingAnimator;
private float scrubberScale;
private boolean scrubbing;
private long scrubPosition;
@ -331,6 +336,12 @@ public class DefaultTimeBar extends View implements TimeBar {
/ 2;
}
scrubberScale = 1.0f;
scrubberScalingAnimator = new ValueAnimator();
scrubberScalingAnimator.addUpdateListener(
animation -> {
scrubberScale = (float) animation.getAnimatedValue();
invalidate(seekBounds);
});
duration = C.TIME_UNSET;
keyTimeIncrement = C.TIME_UNSET;
keyCountIncrement = DEFAULT_INCREMENT_COUNT;
@ -340,6 +351,44 @@ public class DefaultTimeBar extends View implements TimeBar {
}
}
/** Shows the scrubber handle. */
public void showScrubber() {
showScrubber(/* showAnimationDurationMs= */ 0);
}
/**
* Shows the scrubber handle with animation.
*
* @param showAnimationDurationMs The duration for scrubber showing animation.
*/
public void showScrubber(long showAnimationDurationMs) {
if (scrubberScalingAnimator.isStarted()) {
scrubberScalingAnimator.cancel();
}
scrubberScalingAnimator.setFloatValues(scrubberScale, SHOWN_SCRUBBER_SCALE);
scrubberScalingAnimator.setDuration(showAnimationDurationMs);
scrubberScalingAnimator.start();
}
/** Hides the scrubber handle. */
public void hideScrubber() {
hideScrubber(/* hideAnimationDurationMs= */ 0);
}
/**
* Hides the scrubber handle with animation.
*
* @param hideAnimationDurationMs The duration for scrubber hiding animation.
*/
public void hideScrubber(long hideAnimationDurationMs) {
if (scrubberScalingAnimator.isStarted()) {
scrubberScalingAnimator.cancel();
}
scrubberScalingAnimator.setFloatValues(scrubberScale, HIDDEN_SCRUBBER_SCALE);
scrubberScalingAnimator.setDuration(hideAnimationDurationMs);
scrubberScalingAnimator.start();
}
/**
* Sets the color for the portion of the time bar representing media before the playback position.
*
@ -361,18 +410,6 @@ public class DefaultTimeBar extends View implements TimeBar {
invalidate(seekBounds);
}
/**
* Sets the scale factor for the scrubber handle. Scrubber enabled size, scrubber disabled size,
* scrubber dragged size are scaled by the scale factor. If scrubber drawable is set, the scale
* factor isn't applied.
*
* @param scrubberScale The scale factor for the scrubber handle.
*/
public void setScrubberScale(float scrubberScale) {
this.scrubberScale = scrubberScale;
invalidate(seekBounds);
}
/**
* Sets the color for the portion of the time bar after the current played position up to the
* current buffered position.
@ -832,8 +869,8 @@ public class DefaultTimeBar extends View implements TimeBar {
int playheadRadius = (int) ((scrubberSize * scrubberScale) / 2);
canvas.drawCircle(playheadX, playheadY, playheadRadius, scrubberPaint);
} else {
int scrubberDrawableWidth = scrubberDrawable.getIntrinsicWidth();
int scrubberDrawableHeight = scrubberDrawable.getIntrinsicHeight();
int scrubberDrawableWidth = (int) (scrubberDrawable.getIntrinsicWidth() * scrubberScale);
int scrubberDrawableHeight = (int) (scrubberDrawable.getIntrinsicHeight() * scrubberScale);
scrubberDrawable.setBounds(
playheadX - scrubberDrawableWidth / 2,
playheadY - scrubberDrawableHeight / 2,