Commit d7c71610 by olly Committed by Andrew Lewis

Core/UI decoupling: Replace SingleTapListener with OnClickListener

PiperOrigin-RevId: 368448442
parent 54f3dfb4
......@@ -61,7 +61,6 @@ import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionUtil;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode;
import com.google.android.exoplayer2.ui.spherical.SingleTapListener;
import com.google.android.exoplayer2.ui.spherical.SphericalGLSurfaceView;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ErrorMessageProvider;
......@@ -426,9 +425,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
surfaceView = new TextureView(context);
break;
case SURFACE_TYPE_SPHERICAL_GL_SURFACE_VIEW:
SphericalGLSurfaceView sphericalGLSurfaceView = new SphericalGLSurfaceView(context);
sphericalGLSurfaceView.setSingleTapListener(componentListener);
surfaceView = sphericalGLSurfaceView;
surfaceView = new SphericalGLSurfaceView(context);
surfaceViewIgnoresVideoAspectRatio = true;
break;
case SURFACE_TYPE_VIDEO_DECODER_GL_SURFACE_VIEW:
......@@ -439,6 +436,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
break;
}
surfaceView.setLayoutParams(params);
surfaceView.setOnClickListener(componentListener);
contentFrame.addView(surfaceView, 0);
} else {
surfaceView = null;
......@@ -1486,7 +1484,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
implements Player.Listener,
VideoListener,
OnLayoutChangeListener,
SingleTapListener,
OnClickListener,
PlayerControlView.VisibilityListener {
private final Period period;
......@@ -1613,11 +1611,11 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
applyTextureViewRotation((TextureView) view, textureViewRotation);
}
// SingleTapListener implementation
// OnClickListener implementation
@Override
public boolean onSingleTapUp(MotionEvent e) {
return toggleControllerVisibility();
public void onClick(View view) {
toggleControllerVisibility();
}
// PlayerControlView.VisibilityListener implementation
......
......@@ -63,7 +63,6 @@ import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionUtil;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode;
import com.google.android.exoplayer2.ui.spherical.SingleTapListener;
import com.google.android.exoplayer2.ui.spherical.SphericalGLSurfaceView;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ErrorMessageProvider;
......@@ -433,9 +432,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
surfaceView = new TextureView(context);
break;
case SURFACE_TYPE_SPHERICAL_GL_SURFACE_VIEW:
SphericalGLSurfaceView sphericalGLSurfaceView = new SphericalGLSurfaceView(context);
sphericalGLSurfaceView.setSingleTapListener(componentListener);
surfaceView = sphericalGLSurfaceView;
surfaceView = new SphericalGLSurfaceView(context);
surfaceViewIgnoresVideoAspectRatio = true;
break;
case SURFACE_TYPE_VIDEO_DECODER_GL_SURFACE_VIEW:
......@@ -446,6 +443,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
break;
}
surfaceView.setLayoutParams(params);
surfaceView.setOnClickListener(componentListener);
contentFrame.addView(surfaceView, 0);
} else {
surfaceView = null;
......@@ -1509,7 +1507,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
TextOutput,
VideoListener,
OnLayoutChangeListener,
SingleTapListener,
OnClickListener,
StyledPlayerControlView.VisibilityListener {
private final Period period;
......@@ -1636,11 +1634,11 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
applyTextureViewRotation((TextureView) view, textureViewRotation);
}
// SingleTapListener implementation
// OnClickListener implementation
@Override
public boolean onSingleTapUp(MotionEvent e) {
return toggleControllerVisibility();
public void onClick(View view) {
toggleControllerVisibility();
}
// StyledPlayerControlView.VisibilityListener implementation
......
......@@ -27,6 +27,7 @@ import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.Display;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.WindowManager;
import androidx.annotation.AnyThread;
......@@ -144,11 +145,6 @@ public final class SphericalGLSurfaceView extends GLSurfaceView {
}
}
/** Sets the {@link SingleTapListener} used to listen to single tap events on this view. */
public void setSingleTapListener(@Nullable SingleTapListener listener) {
touchTracker.setSingleTapListener(listener);
}
/** Sets whether to use the orientation sensor for rotation (if available). */
public void setUseSensorRotation(boolean useSensorRotation) {
this.useSensorRotation = useSensorRotation;
......@@ -325,6 +321,12 @@ public final class SphericalGLSurfaceView extends GLSurfaceView {
Matrix.setRotateM(touchYawMatrix, 0, -scrollOffsetDegrees.x, 0, 1, 0);
}
@Override
@UiThread
public boolean onSingleTapUp(MotionEvent event) {
return performClick();
}
private float calculateFieldOfViewInYDirection(float aspect) {
boolean landscapeMode = aspect > 1;
if (landscapeMode) {
......
......@@ -21,7 +21,6 @@ import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.BinderThread;
import androidx.annotation.Nullable;
/**
* Basic touch input system.
......@@ -47,8 +46,12 @@ import androidx.annotation.Nullable;
/* package */ final class TouchTracker extends GestureDetector.SimpleOnGestureListener
implements View.OnTouchListener, OrientationListener.Listener {
/* package */ interface Listener {
public interface Listener {
void onScrollChange(PointF scrollOffsetDegrees);
default boolean onSingleTapUp(MotionEvent event) {
return false;
}
}
// Touch input won't change the pitch beyond +/- 45 degrees. This reduces awkward situations
......@@ -65,7 +68,6 @@ import androidx.annotation.Nullable;
// The conversion from touch to yaw & pitch requires compensating for device roll. This is set
// on the sensor thread and read on the UI thread.
private volatile float roll;
@Nullable private SingleTapListener singleTapListener;
@SuppressWarnings({
"nullness:assignment.type.incompatible",
......@@ -78,10 +80,6 @@ import androidx.annotation.Nullable;
roll = SphericalGLSurfaceView.UPRIGHT_ROLL;
}
public void setSingleTapListener(@Nullable SingleTapListener listener) {
singleTapListener = listener;
}
/**
* Converts ACTION_MOVE events to pitch & yaw events while compensating for device roll.
*
......@@ -125,10 +123,7 @@ import androidx.annotation.Nullable;
@Override
public boolean onSingleTapUp(MotionEvent e) {
if (singleTapListener != null) {
return singleTapListener.onSingleTapUp(e);
}
return false;
return listener.onSingleTapUp(e);
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment