mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Rollback of 46b4ebc7b6
*** Original commit *** Make PlayerView fold aware *** PiperOrigin-RevId: 493846471
This commit is contained in:
parent
927b2d6a43
commit
481f3fa7c7
@ -54,7 +54,6 @@ project.ext {
|
|||||||
androidxTestRulesVersion = '1.4.0'
|
androidxTestRulesVersion = '1.4.0'
|
||||||
androidxTestServicesStorageVersion = '1.4.0'
|
androidxTestServicesStorageVersion = '1.4.0'
|
||||||
androidxTestTruthVersion = '1.4.0'
|
androidxTestTruthVersion = '1.4.0'
|
||||||
androidxWindowVersion = '1.0.0'
|
|
||||||
truthVersion = '1.1.3'
|
truthVersion = '1.1.3'
|
||||||
okhttpVersion = '4.9.2'
|
okhttpVersion = '4.9.2'
|
||||||
modulePrefix = ':'
|
modulePrefix = ':'
|
||||||
|
@ -25,9 +25,7 @@ dependencies {
|
|||||||
implementation project(modulePrefix + 'lib-common')
|
implementation project(modulePrefix + 'lib-common')
|
||||||
implementation 'androidx.media:media:' + androidxMediaVersion
|
implementation 'androidx.media:media:' + androidxMediaVersion
|
||||||
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
|
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
|
||||||
implementation 'androidx.core:core:' + androidxCoreVersion
|
|
||||||
implementation 'androidx.recyclerview:recyclerview:' + androidxRecyclerViewVersion
|
implementation 'androidx.recyclerview:recyclerview:' + androidxRecyclerViewVersion
|
||||||
implementation 'androidx.window:window:' + androidxWindowVersion
|
|
||||||
implementation 'androidx.window:window-java:' + androidxWindowVersion
|
implementation 'androidx.window:window-java:' + androidxWindowVersion
|
||||||
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||||
compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
|
compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
|
||||||
|
@ -21,10 +21,7 @@ import static androidx.media3.common.util.Assertions.checkNotNull;
|
|||||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
@ -51,7 +48,6 @@ import androidx.annotation.IntDef;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.util.Consumer;
|
|
||||||
import androidx.media3.common.AdOverlayInfo;
|
import androidx.media3.common.AdOverlayInfo;
|
||||||
import androidx.media3.common.AdViewProvider;
|
import androidx.media3.common.AdViewProvider;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
@ -70,13 +66,6 @@ import androidx.media3.common.util.RepeatModeUtil;
|
|||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.ui.AspectRatioFrameLayout.ResizeMode;
|
import androidx.media3.ui.AspectRatioFrameLayout.ResizeMode;
|
||||||
import androidx.window.java.layout.WindowInfoTrackerCallbackAdapter;
|
|
||||||
import androidx.window.layout.DisplayFeature;
|
|
||||||
import androidx.window.layout.FoldingFeature;
|
|
||||||
import androidx.window.layout.FoldingFeature.Orientation;
|
|
||||||
import androidx.window.layout.FoldingFeature.State;
|
|
||||||
import androidx.window.layout.WindowInfoTracker;
|
|
||||||
import androidx.window.layout.WindowLayoutInfo;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -85,7 +74,6 @@ import java.lang.annotation.Target;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
|
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|
||||||
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -274,9 +262,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
private boolean controllerHideOnTouch;
|
private boolean controllerHideOnTouch;
|
||||||
private int textureViewRotation;
|
private int textureViewRotation;
|
||||||
private boolean isTouching;
|
private boolean isTouching;
|
||||||
private boolean isTabletop;
|
|
||||||
private final WindowInfoTrackerCallbackAdapter windowInfoTracker;
|
|
||||||
@MonotonicNonNull private Consumer<WindowLayoutInfo> layoutStateChangeCallback;
|
|
||||||
|
|
||||||
public PlayerView(Context context) {
|
public PlayerView(Context context) {
|
||||||
this(context, /* attrs= */ null);
|
this(context, /* attrs= */ null);
|
||||||
@ -290,9 +275,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
public PlayerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
public PlayerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
|
|
||||||
isTabletop = false;
|
|
||||||
windowInfoTracker =
|
|
||||||
new WindowInfoTrackerCallbackAdapter(WindowInfoTracker.getOrCreate(context));
|
|
||||||
componentListener = new ComponentListener();
|
componentListener = new ComponentListener();
|
||||||
|
|
||||||
if (isInEditMode()) {
|
if (isInEditMode()) {
|
||||||
@ -588,25 +570,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onAttachedToWindow() {
|
|
||||||
super.onAttachedToWindow();
|
|
||||||
layoutStateChangeCallback = this::consumeWindowLayoutInfo;
|
|
||||||
@Nullable Activity activity = getActivity();
|
|
||||||
if (activity != null) {
|
|
||||||
windowInfoTracker.addWindowLayoutInfoListener(
|
|
||||||
activity, ContextCompat.getMainExecutor(getContext()), layoutStateChangeCallback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDetachedFromWindow() {
|
|
||||||
super.onDetachedFromWindow();
|
|
||||||
if (layoutStateChangeCallback != null) {
|
|
||||||
windowInfoTracker.removeWindowLayoutInfoListener(layoutStateChangeCallback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link ResizeMode}.
|
* Sets the {@link ResizeMode}.
|
||||||
*
|
*
|
||||||
@ -1538,53 +1501,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
|| keyCode == KeyEvent.KEYCODE_DPAD_CENTER;
|
|| keyCode == KeyEvent.KEYCODE_DPAD_CENTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private Activity getActivity() {
|
|
||||||
Context context = getContext();
|
|
||||||
while (context instanceof ContextWrapper) {
|
|
||||||
if (context instanceof Activity) {
|
|
||||||
return (Activity) context;
|
|
||||||
}
|
|
||||||
context = ((ContextWrapper) context).getBaseContext();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onConfigurationChanged(Configuration newConfig) {
|
|
||||||
super.onConfigurationChanged(newConfig);
|
|
||||||
isTabletop = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void consumeWindowLayoutInfo(WindowLayoutInfo windowLayoutInfo) {
|
|
||||||
List<DisplayFeature> features = windowLayoutInfo.getDisplayFeatures();
|
|
||||||
int foldingFeatureIndex = C.INDEX_UNSET;
|
|
||||||
|
|
||||||
for (int i = 0; i < features.size(); i++) {
|
|
||||||
DisplayFeature feature = features.get(i);
|
|
||||||
if (feature instanceof FoldingFeature) {
|
|
||||||
if (foldingFeatureIndex != C.INDEX_UNSET) {
|
|
||||||
// For now, we are only handling single folding features like tabletop and book fold.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
foldingFeatureIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (foldingFeatureIndex != C.INDEX_UNSET) {
|
|
||||||
handleFoldingFeature((FoldingFeature) features.get(foldingFeatureIndex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleFoldingFeature(FoldingFeature feature) {
|
|
||||||
boolean isTabletopFeature =
|
|
||||||
feature.getOrientation() == Orientation.HORIZONTAL
|
|
||||||
&& feature.getState() == State.HALF_OPENED;
|
|
||||||
// Only enter or exit tabletop if different than current orientation and state
|
|
||||||
if (isTabletopFeature != isTabletop) {
|
|
||||||
isTabletop = isTabletopFeature;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implementing the deprecated PlayerControlView.VisibilityListener and
|
// Implementing the deprecated PlayerControlView.VisibilityListener and
|
||||||
// PlayerControlView.OnFullScreenModeChangedListener for now.
|
// PlayerControlView.OnFullScreenModeChangedListener for now.
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user