Skip to content

Commit

Permalink
Make DefaultTimeBar exclude itself for gestures
Browse files Browse the repository at this point in the history
Issue: #6685
PiperOrigin-RevId: 284736041
  • Loading branch information
ojw28 committed Dec 10, 2019
1 parent c027b4e commit 90329a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Upgrade Truth dependency from 0.44 to 1.0.
* Upgrade to JUnit 4.13-rc-2.
* Add support for attaching DRM sessions to clear content in the demo app.
* UI: Exclude `DefaultTimeBar` region from system gesture detection
([#6685](https://github.com/google/ExoPlayer/issues/6685)).

### 2.11.0 (2019-12-11) ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.util.Collections;
import java.util.Formatter;
import java.util.Locale;
import java.util.concurrent.CopyOnWriteArraySet;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;

/**
* A time bar that shows a current position, buffered position, duration and ad markers.
Expand Down Expand Up @@ -199,6 +202,7 @@ public class DefaultTimeBar extends View implements TimeBar {
private int keyCountIncrement;
private long keyTimeIncrement;
private int lastCoarseScrubXPosition;
@MonotonicNonNull private Rect lastExclusionRectangle;

private boolean scrubbing;
private long scrubPosition;
Expand Down Expand Up @@ -604,6 +608,9 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
seekBounds.set(seekLeft, barY, seekRight, barY + touchTargetHeight);
progressBar.set(seekBounds.left + scrubberPadding, progressY,
seekBounds.right - scrubberPadding, progressY + barHeight);
if (Util.SDK_INT >= 29) {
setSystemGestureExclusionRectsV29(width, height);
}
update();
}

Expand Down Expand Up @@ -834,6 +841,18 @@ private void updateDrawableState() {
}
}

@RequiresApi(29)
private void setSystemGestureExclusionRectsV29(int width, int height) {
if (lastExclusionRectangle != null
&& lastExclusionRectangle.width() == width
&& lastExclusionRectangle.height() == height) {
// Allocating inside onLayout is considered a DrawAllocation lint error, so avoid if possible.
return;
}
lastExclusionRectangle = new Rect(/* left= */ 0, /* top= */ 0, width, height);
setSystemGestureExclusionRects(Collections.singletonList(lastExclusionRectangle));
}

private String getProgressText() {
return Util.getStringForTime(formatBuilder, formatter, position);
}
Expand Down

0 comments on commit 90329a1

Please sign in to comment.