From ee3eba07acca1cadd99a6a70ce78fe2de1f4e576 Mon Sep 17 00:00:00 2001 From: insun Date: Mon, 16 Nov 2020 07:11:23 +0000 Subject: [PATCH] Increase touch target height of timebar in StyledPlayerControlView This change also introduces gravity attribute to DefaultTimeBar. PiperOrigin-RevId: 342573167 --- RELEASENOTES.md | 4 +++- .../android/exoplayer2/ui/DefaultTimeBar.java | 21 ++++++++++++++++++- library/ui/src/main/res/values/attrs.xml | 9 ++++++++ library/ui/src/main/res/values/dimens.xml | 4 ++-- library/ui/src/main/res/values/styles.xml | 1 + 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index c00a49e7c8..bea3db01ce 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -36,7 +36,9 @@ `LeanbackPlayerAdapter` and use `ControlDispatcher` for dispatching prepare instead ([#7882](https://github.com/google/ExoPlayer/issues/7882)). - * Switch StyledPlayerView button controls to borderless ripples. + * Switch `StyledPlayerControlView` button controls to borderless ripples. + * Add `bar_gravity` attribute into `DefaultTimeBar`. + * Increase seekbar's touch target height in `StyledPlayerControlView`. * Audio: * Retry playback after some types of `AudioTrack` error. * Work around `AudioManager` crashes when calling `getStreamVolume` diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/DefaultTimeBar.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/DefaultTimeBar.java index f7a99a50dc..4e96d39e7c 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/DefaultTimeBar.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/DefaultTimeBar.java @@ -152,6 +152,15 @@ public class DefaultTimeBar extends View implements TimeBar { /** Default color for played ad markers. */ public static final int DEFAULT_PLAYED_AD_MARKER_COLOR = 0x33FFFF00; + // LINT.IfChange + /** Vertical gravity for progress bar to be located at the center in the view. */ + public static final int BAR_GRAVITY_CENTER = 0; + /** Vertical gravity for progress bar to be located at the bottom in the view. */ + public static final int BAR_GRAVITY_BOTTOM = 1; + /** Vertical gravity for progress bar to be located at the top in the view. */ + public static final int BAR_GRAVITY_TOP = 2; + // LINT.ThenChange(../../../../../../../../../ui/src/main/res/values/attrs.xml) + /** The threshold in dps above the bar at which touch events trigger fine scrub mode. */ private static final int FINE_SCRUB_Y_THRESHOLD_DP = -50; /** The ratio by which times are reduced in fine scrub mode. */ @@ -186,6 +195,7 @@ public class DefaultTimeBar extends View implements TimeBar { @Nullable private final Drawable scrubberDrawable; private final int barHeight; private final int touchTargetHeight; + private final int barGravity; private final int adMarkerWidth; private final int scrubberEnabledSize; private final int scrubberDisabledSize; @@ -286,6 +296,7 @@ public class DefaultTimeBar extends View implements TimeBar { defaultBarHeight); touchTargetHeight = a.getDimensionPixelSize(R.styleable.DefaultTimeBar_touch_target_height, defaultTouchTargetHeight); + barGravity = a.getInt(R.styleable.DefaultTimeBar_bar_gravity, BAR_GRAVITY_CENTER); adMarkerWidth = a.getDimensionPixelSize(R.styleable.DefaultTimeBar_ad_marker_width, defaultAdMarkerWidth); scrubberEnabledSize = a.getDimensionPixelSize( @@ -318,6 +329,7 @@ public class DefaultTimeBar extends View implements TimeBar { } else { barHeight = defaultBarHeight; touchTargetHeight = defaultTouchTargetHeight; + barGravity = BAR_GRAVITY_CENTER; adMarkerWidth = defaultAdMarkerWidth; scrubberEnabledSize = defaultScrubberEnabledSize; scrubberDisabledSize = defaultScrubberDisabledSize; @@ -659,7 +671,14 @@ public class DefaultTimeBar extends View implements TimeBar { int barY = (height - touchTargetHeight) / 2; int seekLeft = getPaddingLeft(); int seekRight = width - getPaddingRight(); - int progressY = barY + (touchTargetHeight - barHeight) / 2; + int progressY; + if (barGravity == BAR_GRAVITY_BOTTOM) { + progressY = barY + touchTargetHeight - (getPaddingBottom() + scrubberPadding + barHeight / 2); + } else if (barGravity == BAR_GRAVITY_TOP) { + progressY = barY + getPaddingTop() + scrubberPadding - barHeight / 2; + } else { + progressY = barY + (touchTargetHeight - barHeight) / 2; + } seekBounds.set(seekLeft, barY, seekRight, barY + touchTargetHeight); progressBar.set(seekBounds.left + scrubberPadding, progressY, seekBounds.right - scrubberPadding, progressY + barHeight); diff --git a/library/ui/src/main/res/values/attrs.xml b/library/ui/src/main/res/values/attrs.xml index 439afb19c2..00456222c4 100644 --- a/library/ui/src/main/res/values/attrs.xml +++ b/library/ui/src/main/res/values/attrs.xml @@ -74,6 +74,11 @@ + + + + + @@ -154,6 +159,7 @@ + @@ -186,6 +192,7 @@ + @@ -217,6 +224,7 @@ + @@ -233,6 +241,7 @@ + diff --git a/library/ui/src/main/res/values/dimens.xml b/library/ui/src/main/res/values/dimens.xml index 93bfd8828d..3c4e998852 100644 --- a/library/ui/src/main/res/values/dimens.xml +++ b/library/ui/src/main/res/values/dimens.xml @@ -38,8 +38,8 @@ 2dp 10dp 14dp - 14dp - 14dp + 48dp + 48dp 52dp 60dp diff --git a/library/ui/src/main/res/values/styles.xml b/library/ui/src/main/res/values/styles.xml index 8b48f2fcb5..4e3491b97a 100644 --- a/library/ui/src/main/res/values/styles.xml +++ b/library/ui/src/main/res/values/styles.xml @@ -188,6 +188,7 @@