mirror of
https://github.com/androidx/media.git
synced 2025-05-09 16:40:55 +08:00
Rollback of ff6e641fbb
*** Original commit ***
Rollback of 20282151b5
*** Original commit ***
Fix PlayerView touch handling
Overriding onTouchEvent was causing multiple issues, and
appears to be unnecessary. Removing the override fixes:
1. StyledPlayerView accessibility issue where "hide player
controls" actually toggled play/pause.
2. Delivery of events to a registered OnClick...
***
PiperOrigin-RevId: 434502423
This commit is contained in:
parent
dadfea0211
commit
dacf8f847c
@ -514,11 +514,14 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
||||
this.controllerAutoShow = controllerAutoShow;
|
||||
this.controllerHideDuringAds = controllerHideDuringAds;
|
||||
this.useController = useController && controller != null;
|
||||
hideController();
|
||||
updateContentDescription();
|
||||
if (controller != null) {
|
||||
controller.hide();
|
||||
controller.addVisibilityListener(/* listener= */ componentListener);
|
||||
}
|
||||
if (useController) {
|
||||
setClickable(true);
|
||||
}
|
||||
updateContentDescription();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -682,10 +685,14 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
||||
* Sets whether the playback controls can be shown. If set to {@code false} the playback controls
|
||||
* are never visible and are disconnected from the player.
|
||||
*
|
||||
* <p>This call will update whether the view is clickable. After the call, the view will be
|
||||
* clickable if playback controls can be shown or if the view has a registered click listener.
|
||||
*
|
||||
* @param useController Whether the playback controls can be shown.
|
||||
*/
|
||||
public void setUseController(boolean useController) {
|
||||
Assertions.checkState(!useController || controller != null);
|
||||
setClickable(useController || hasOnClickListeners());
|
||||
if (this.useController == useController) {
|
||||
return;
|
||||
}
|
||||
@ -1072,31 +1079,10 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
||||
return subtitleView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (!useController() || player == null) {
|
||||
return false;
|
||||
}
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
isTouching = true;
|
||||
return true;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (isTouching) {
|
||||
isTouching = false;
|
||||
performClick();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performClick() {
|
||||
super.performClick();
|
||||
return toggleControllerVisibility();
|
||||
toggleControllerVisibility();
|
||||
return super.performClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1192,16 +1178,15 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean toggleControllerVisibility() {
|
||||
private void toggleControllerVisibility() {
|
||||
if (!useController() || player == null) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (!controller.isVisible()) {
|
||||
maybeShowController(true);
|
||||
} else if (controllerHideOnTouch) {
|
||||
controller.hide();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Shows the playback controls, but only if forced or shown indefinitely. */
|
||||
|
@ -432,6 +432,9 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
|
||||
controller.hideImmediately();
|
||||
controller.addVisibilityListener(/* listener= */ componentListener);
|
||||
}
|
||||
if (useController) {
|
||||
setClickable(true);
|
||||
}
|
||||
updateContentDescription();
|
||||
}
|
||||
|
||||
@ -596,10 +599,14 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
|
||||
* Sets whether the playback controls can be shown. If set to {@code false} the playback controls
|
||||
* are never visible and are disconnected from the player.
|
||||
*
|
||||
* <p>This call will update whether the view is clickable. After the call, the view will be
|
||||
* clickable if playback controls can be shown or if the view has a registered click listener.
|
||||
*
|
||||
* @param useController Whether the playback controls can be shown.
|
||||
*/
|
||||
public void setUseController(boolean useController) {
|
||||
Assertions.checkState(!useController || controller != null);
|
||||
setClickable(useController || hasOnClickListeners());
|
||||
if (this.useController == useController) {
|
||||
return;
|
||||
}
|
||||
@ -1018,30 +1025,10 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
|
||||
return subtitleView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (!useController() || player == null) {
|
||||
return false;
|
||||
}
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
isTouching = true;
|
||||
return true;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (isTouching) {
|
||||
isTouching = false;
|
||||
return performClick();
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performClick() {
|
||||
super.performClick();
|
||||
return toggleControllerVisibility();
|
||||
toggleControllerVisibility();
|
||||
return super.performClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1137,18 +1124,15 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean toggleControllerVisibility() {
|
||||
private void toggleControllerVisibility() {
|
||||
if (!useController() || player == null) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (!controller.isFullyVisible()) {
|
||||
maybeShowController(true);
|
||||
return true;
|
||||
} else if (controllerHideOnTouch) {
|
||||
controller.hide();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Shows the playback controls, but only if forced or shown indefinitely. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user