Add show/hideScrubber to DefaultTimeBar
PiperOrigin-RevId: 300249371
This commit is contained in:
parent
c6e8e24ada
commit
f82bc244ea
@ -87,6 +87,7 @@
|
|||||||
* Upgrade Truth dependency from 0.44 to 1.0.
|
* Upgrade Truth dependency from 0.44 to 1.0.
|
||||||
* Upgrade to JUnit 4.13-rc-2.
|
* Upgrade to JUnit 4.13-rc-2.
|
||||||
* UI
|
* UI
|
||||||
|
* Add `showScrubber` and `hideScrubber` methods to DefaultTimeBar.
|
||||||
* Move logic of prev, next, fast forward and rewind to ControlDispatcher
|
* Move logic of prev, next, fast forward and rewind to ControlDispatcher
|
||||||
([#6926](https://github.com/google/ExoPlayer/issues/6926)).
|
([#6926](https://github.com/google/ExoPlayer/issues/6926)).
|
||||||
* Demo apps: Add
|
* Demo apps: Add
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.ui;
|
package com.google.android.exoplayer2.ui;
|
||||||
|
|
||||||
|
import android.animation.ValueAnimator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
@ -163,6 +164,9 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
|
|
||||||
private static final int DEFAULT_INCREMENT_COUNT = 20;
|
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
|
* The name of the Android SDK view that most closely resembles this custom view. Used as the
|
||||||
* class name for accessibility.
|
* class name for accessibility.
|
||||||
@ -201,6 +205,7 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
private int lastCoarseScrubXPosition;
|
private int lastCoarseScrubXPosition;
|
||||||
private @MonotonicNonNull Rect lastExclusionRectangle;
|
private @MonotonicNonNull Rect lastExclusionRectangle;
|
||||||
|
|
||||||
|
private ValueAnimator scrubberScalingAnimator;
|
||||||
private float scrubberScale;
|
private float scrubberScale;
|
||||||
private boolean scrubbing;
|
private boolean scrubbing;
|
||||||
private long scrubPosition;
|
private long scrubPosition;
|
||||||
@ -326,6 +331,12 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
/ 2;
|
/ 2;
|
||||||
}
|
}
|
||||||
scrubberScale = 1.0f;
|
scrubberScale = 1.0f;
|
||||||
|
scrubberScalingAnimator = new ValueAnimator();
|
||||||
|
scrubberScalingAnimator.addUpdateListener(
|
||||||
|
animation -> {
|
||||||
|
scrubberScale = (float) animation.getAnimatedValue();
|
||||||
|
invalidate(seekBounds);
|
||||||
|
});
|
||||||
duration = C.TIME_UNSET;
|
duration = C.TIME_UNSET;
|
||||||
keyTimeIncrement = C.TIME_UNSET;
|
keyTimeIncrement = C.TIME_UNSET;
|
||||||
keyCountIncrement = DEFAULT_INCREMENT_COUNT;
|
keyCountIncrement = DEFAULT_INCREMENT_COUNT;
|
||||||
@ -335,6 +346,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.
|
* Sets the color for the portion of the time bar representing media before the playback position.
|
||||||
*
|
*
|
||||||
@ -356,18 +405,6 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
invalidate(seekBounds);
|
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
|
* Sets the color for the portion of the time bar after the current played position up to the
|
||||||
* current buffered position.
|
* current buffered position.
|
||||||
@ -829,8 +866,8 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
int playheadRadius = (int) ((scrubberSize * scrubberScale) / 2);
|
int playheadRadius = (int) ((scrubberSize * scrubberScale) / 2);
|
||||||
canvas.drawCircle(playheadX, playheadY, playheadRadius, scrubberPaint);
|
canvas.drawCircle(playheadX, playheadY, playheadRadius, scrubberPaint);
|
||||||
} else {
|
} else {
|
||||||
int scrubberDrawableWidth = scrubberDrawable.getIntrinsicWidth();
|
int scrubberDrawableWidth = (int) (scrubberDrawable.getIntrinsicWidth() * scrubberScale);
|
||||||
int scrubberDrawableHeight = scrubberDrawable.getIntrinsicHeight();
|
int scrubberDrawableHeight = (int) (scrubberDrawable.getIntrinsicHeight() * scrubberScale);
|
||||||
scrubberDrawable.setBounds(
|
scrubberDrawable.setBounds(
|
||||||
playheadX - scrubberDrawableWidth / 2,
|
playheadX - scrubberDrawableWidth / 2,
|
||||||
playheadY - scrubberDrawableHeight / 2,
|
playheadY - scrubberDrawableHeight / 2,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user