Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b743ad9f
authored
Apr 11, 2023
by
Googler
Committed by
Rohit Singh
Apr 12, 2023
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Make PlayerView fold aware
PiperOrigin-RevId: 523413988
parent
0a9134ff
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
0 deletions
constants.gradle
library/ui/build.gradle
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java
constants.gradle
View file @
b743ad9f
...
@@ -54,6 +54,7 @@ project.ext {
...
@@ -54,6 +54,7 @@ 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
=
':'
...
...
library/ui/build.gradle
View file @
b743ad9f
...
@@ -25,7 +25,10 @@ dependencies {
...
@@ -25,7 +25,10 @@ dependencies {
implementation
project
(
modulePrefix
+
'library-common'
)
implementation
project
(
modulePrefix
+
'library-common'
)
api
'androidx.media:media:'
+
androidxMediaVersion
api
'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
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
testImplementation
project
(
modulePrefix
+
'testutils'
)
testImplementation
project
(
modulePrefix
+
'testutils'
)
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java
View file @
b743ad9f
...
@@ -26,7 +26,10 @@ import static com.google.android.exoplayer2.util.Util.getDrawable;
...
@@ -26,7 +26,10 @@ import static com.google.android.exoplayer2.util.Util.getDrawable;
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
;
...
@@ -53,6 +56,14 @@ import androidx.annotation.IntDef;
...
@@ -53,6 +56,14 @@ 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.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.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.MediaMetadata
;
import
com.google.android.exoplayer2.MediaMetadata
;
import
com.google.android.exoplayer2.PlaybackException
;
import
com.google.android.exoplayer2.PlaybackException
;
...
@@ -76,6 +87,7 @@ import java.lang.annotation.Target;
...
@@ -76,6 +87,7 @@ 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
;
/**
/**
...
@@ -263,6 +275,9 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
...
@@ -263,6 +275,9 @@ public class StyledPlayerView 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
StyledPlayerView
(
Context
context
)
{
public
StyledPlayerView
(
Context
context
)
{
this
(
context
,
/* attrs= */
null
);
this
(
context
,
/* attrs= */
null
);
...
@@ -276,6 +291,9 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
...
@@ -276,6 +291,9 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
public
StyledPlayerView
(
Context
context
,
@Nullable
AttributeSet
attrs
,
int
defStyleAttr
)
{
public
StyledPlayerView
(
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
())
{
...
@@ -579,6 +597,25 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
...
@@ -579,6 +597,25 @@ public class StyledPlayerView 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}.
*
*
...
@@ -1488,6 +1525,53 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
...
@@ -1488,6 +1525,53 @@ public class StyledPlayerView 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 StyledPlayerControlView.VisibilityListener and
// Implementing the deprecated StyledPlayerControlView.VisibilityListener and
// StyledPlayerControlView.OnFullScreenModeChangedListener for now.
// StyledPlayerControlView.OnFullScreenModeChangedListener for now.
@SuppressWarnings
(
"deprecation"
)
@SuppressWarnings
(
"deprecation"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment