Fix DefaultTimeBar accessibility class name

See https://support.google.com/accessibility/android/answer/7661305.

Also fix/suppress nullability warnings.

Issue: #4611

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=207245115
This commit is contained in:
andrewlewis 2018-08-03 03:25:03 -07:00 committed by Oliver Woodman
parent 4c7fbd67ea
commit b3b8356766
2 changed files with 27 additions and 21 deletions

View File

@ -82,6 +82,8 @@
([#273](https://github.com/google/ExoPlayer/issues/273)). ([#273](https://github.com/google/ExoPlayer/issues/273)).
* Fix where transitions to clipped media sources happened too early * Fix where transitions to clipped media sources happened too early
([#4583](https://github.com/google/ExoPlayer/issues/4583)). ([#4583](https://github.com/google/ExoPlayer/issues/4583)).
* Fix accessibility class name for `DefaultTimeBar`
([#4611](https://github.com/google/ExoPlayer/issues/4611)).
### 2.8.3 ### ### 2.8.3 ###

View File

@ -174,6 +174,12 @@ public class DefaultTimeBar extends View implements TimeBar {
private static final long STOP_SCRUBBING_TIMEOUT_MS = 1000; private static final long STOP_SCRUBBING_TIMEOUT_MS = 1000;
private static final int DEFAULT_INCREMENT_COUNT = 20; private static final int DEFAULT_INCREMENT_COUNT = 20;
/**
* The name of the Android SDK view that most closely resembles this custom view. Used as the
* class name for accessibility.
*/
private static final String ACCESSIBILITY_CLASS_NAME = "android.widget.SeekBar";
private final Rect seekBounds; private final Rect seekBounds;
private final Rect progressBar; private final Rect progressBar;
private final Rect bufferedBar; private final Rect bufferedBar;
@ -184,7 +190,7 @@ public class DefaultTimeBar extends View implements TimeBar {
private final Paint adMarkerPaint; private final Paint adMarkerPaint;
private final Paint playedAdMarkerPaint; private final Paint playedAdMarkerPaint;
private final Paint scrubberPaint; private final Paint scrubberPaint;
private final Drawable scrubberDrawable; private final @Nullable Drawable scrubberDrawable;
private final int barHeight; private final int barHeight;
private final int touchTargetHeight; private final int touchTargetHeight;
private final int adMarkerWidth; private final int adMarkerWidth;
@ -197,12 +203,12 @@ public class DefaultTimeBar extends View implements TimeBar {
private final Formatter formatter; private final Formatter formatter;
private final Runnable stopScrubbingRunnable; private final Runnable stopScrubbingRunnable;
private final CopyOnWriteArraySet<OnScrubListener> listeners; private final CopyOnWriteArraySet<OnScrubListener> listeners;
private final int[] locationOnScreen;
private final Point touchPosition;
private int keyCountIncrement; private int keyCountIncrement;
private long keyTimeIncrement; private long keyTimeIncrement;
private int lastCoarseScrubXPosition; private int lastCoarseScrubXPosition;
private int[] locationOnScreen;
private Point touchPosition;
private boolean scrubbing; private boolean scrubbing;
private long scrubPosition; private long scrubPosition;
@ -210,12 +216,12 @@ public class DefaultTimeBar extends View implements TimeBar {
private long position; private long position;
private long bufferedPosition; private long bufferedPosition;
private int adGroupCount; private int adGroupCount;
private long[] adGroupTimesMs; private @Nullable long[] adGroupTimesMs;
private boolean[] playedAdGroups; private @Nullable boolean[] playedAdGroups;
/** /** Creates a new time bar. */
* Creates a new time bar. // Suppress warnings due to usage of View methods in the constructor.
*/ @SuppressWarnings("nullness:method.invocation.invalid")
public DefaultTimeBar(Context context, AttributeSet attrs) { public DefaultTimeBar(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
seekBounds = new Rect(); seekBounds = new Rect();
@ -230,6 +236,8 @@ public class DefaultTimeBar extends View implements TimeBar {
scrubberPaint = new Paint(); scrubberPaint = new Paint();
scrubberPaint.setAntiAlias(true); scrubberPaint.setAntiAlias(true);
listeners = new CopyOnWriteArraySet<>(); listeners = new CopyOnWriteArraySet<>();
locationOnScreen = new int[2];
touchPosition = new Point();
// Calculate the dimensions and paints for drawn elements. // Calculate the dimensions and paints for drawn elements.
Resources res = context.getResources(); Resources res = context.getResources();
@ -299,12 +307,7 @@ public class DefaultTimeBar extends View implements TimeBar {
} }
formatBuilder = new StringBuilder(); formatBuilder = new StringBuilder();
formatter = new Formatter(formatBuilder, Locale.getDefault()); formatter = new Formatter(formatBuilder, Locale.getDefault());
stopScrubbingRunnable = new Runnable() { stopScrubbingRunnable = () -> stopScrubbing(/* canceled= */ false);
@Override
public void run() {
stopScrubbing(false);
}
};
if (scrubberDrawable != null) { if (scrubberDrawable != null) {
scrubberPadding = (scrubberDrawable.getMinimumWidth() + 1) / 2; scrubberPadding = (scrubberDrawable.getMinimumWidth() + 1) / 2;
} else { } else {
@ -593,14 +596,14 @@ public class DefaultTimeBar extends View implements TimeBar {
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) { if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
event.getText().add(getProgressText()); event.getText().add(getProgressText());
} }
event.setClassName(DefaultTimeBar.class.getName()); event.setClassName(ACCESSIBILITY_CLASS_NAME);
} }
@TargetApi(21) @TargetApi(21)
@Override @Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info); super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(DefaultTimeBar.class.getCanonicalName()); info.setClassName(ACCESSIBILITY_CLASS_NAME);
info.setContentDescription(getProgressText()); info.setContentDescription(getProgressText());
if (duration <= 0) { if (duration <= 0) {
return; return;
@ -616,7 +619,7 @@ public class DefaultTimeBar extends View implements TimeBar {
@TargetApi(16) @TargetApi(16)
@Override @Override
public boolean performAccessibilityAction(int action, Bundle args) { public boolean performAccessibilityAction(int action, @Nullable Bundle args) {
if (super.performAccessibilityAction(action, args)) { if (super.performAccessibilityAction(action, args)) {
return true; return true;
} }
@ -693,10 +696,6 @@ public class DefaultTimeBar extends View implements TimeBar {
} }
private Point resolveRelativeTouchPosition(MotionEvent motionEvent) { private Point resolveRelativeTouchPosition(MotionEvent motionEvent) {
if (locationOnScreen == null) {
locationOnScreen = new int[2];
touchPosition = new Point();
}
getLocationOnScreen(locationOnScreen); getLocationOnScreen(locationOnScreen);
touchPosition.set( touchPosition.set(
((int) motionEvent.getRawX()) - locationOnScreen[0], ((int) motionEvent.getRawX()) - locationOnScreen[0],
@ -736,6 +735,11 @@ public class DefaultTimeBar extends View implements TimeBar {
if (scrubberBar.width() > 0) { if (scrubberBar.width() > 0) {
canvas.drawRect(scrubberBar.left, barTop, scrubberBar.right, barBottom, playedPaint); canvas.drawRect(scrubberBar.left, barTop, scrubberBar.right, barBottom, playedPaint);
} }
if (adGroupCount == 0) {
return;
}
long[] adGroupTimesMs = Assertions.checkNotNull(this.adGroupTimesMs);
boolean[] playedAdGroups = Assertions.checkNotNull(this.playedAdGroups);
int adMarkerOffset = adMarkerWidth / 2; int adMarkerOffset = adMarkerWidth / 2;
for (int i = 0; i < adGroupCount; i++) { for (int i = 0; i < adGroupCount; i++) {
long adGroupTimeMs = Util.constrainValue(adGroupTimesMs[i], 0, duration); long adGroupTimeMs = Util.constrainValue(adGroupTimesMs[i], 0, duration);