Increase touch target height of timebar in StyledPlayerControlView

This change also introduces gravity attribute to DefaultTimeBar.

PiperOrigin-RevId: 342573167
This commit is contained in:
insun 2020-11-16 07:11:23 +00:00 committed by Ian Baker
parent 6b31a3eea5
commit ee3eba07ac
5 changed files with 35 additions and 4 deletions

View File

@ -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`

View File

@ -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);

View File

@ -74,6 +74,11 @@
<!-- DefaultTimeBar attributes -->
<attr name="bar_height" format="dimension"/>
<attr name="bar_gravity" format="enum">
<enum name="center" value="0"/>
<enum name="bottom" value="1"/>
<enum name="top" value="2"/>
</attr>
<attr name="touch_target_height" format="dimension"/>
<attr name="ad_marker_width" format="dimension"/>
<attr name="scrubber_enabled_size" format="dimension"/>
@ -154,6 +159,7 @@
<attr name="animation_enabled"/>
<!-- DefaultTimeBar attributes -->
<attr name="bar_height"/>
<attr name="bar_gravity"/>
<attr name="touch_target_height"/>
<attr name="ad_marker_width"/>
<attr name="scrubber_enabled_size"/>
@ -186,6 +192,7 @@
<attr name="controller_layout_id"/>
<!-- DefaultTimeBar attributes -->
<attr name="bar_height"/>
<attr name="bar_gravity"/>
<attr name="touch_target_height"/>
<attr name="ad_marker_width"/>
<attr name="scrubber_enabled_size"/>
@ -217,6 +224,7 @@
<attr name="animation_enabled"/>
<!-- DefaultTimeBar attributes -->
<attr name="bar_height"/>
<attr name="bar_gravity"/>
<attr name="touch_target_height"/>
<attr name="ad_marker_width"/>
<attr name="scrubber_enabled_size"/>
@ -233,6 +241,7 @@
<declare-styleable name="DefaultTimeBar">
<attr name="bar_height"/>
<attr name="bar_gravity"/>
<attr name="touch_target_height"/>
<attr name="ad_marker_width"/>
<attr name="scrubber_enabled_size"/>

View File

@ -38,8 +38,8 @@
<dimen name="exo_styled_progress_bar_height">2dp</dimen>
<dimen name="exo_styled_progress_enabled_thumb_size">10dp</dimen>
<dimen name="exo_styled_progress_dragged_thumb_size">14dp</dimen>
<dimen name="exo_styled_progress_layout_height">14dp</dimen>
<dimen name="exo_styled_progress_touch_target_height">14dp</dimen>
<dimen name="exo_styled_progress_layout_height">48dp</dimen>
<dimen name="exo_styled_progress_touch_target_height">48dp</dimen>
<dimen name="exo_styled_progress_margin_bottom">52dp</dimen>
<dimen name="exo_bottom_bar_height">60dp</dimen>

View File

@ -188,6 +188,7 @@
<style name="ExoStyledControls.TimeBar">
<item name="bar_height">@dimen/exo_styled_progress_bar_height</item>
<item name="bar_gravity">bottom</item>
<item name="touch_target_height">@dimen/exo_styled_progress_touch_target_height</item>
<item name="scrubber_enabled_size">@dimen/exo_styled_progress_enabled_thumb_size</item>
<item name="scrubber_dragged_size">@dimen/exo_styled_progress_dragged_thumb_size</item>