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
33f8f406
authored
Dec 15, 2022
by
bachinger
Committed by
Tianyi Feng
Dec 21, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use theme when loading drawables on API 21+
Issue: androidx/media#220 PiperOrigin-RevId: 495642588
parent
8dea624c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
38 deletions
library/common/src/main/java/com/google/android/exoplayer2/util/Util.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java
library/common/src/main/java/com/google/android/exoplayer2/util/Util.java
View file @
33f8f406
...
...
@@ -48,6 +48,7 @@ import android.content.res.Resources;
import
android.database.DatabaseUtils
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.graphics.Point
;
import
android.graphics.drawable.Drawable
;
import
android.hardware.display.DisplayManager
;
import
android.media.AudioFormat
;
import
android.media.AudioManager
;
...
...
@@ -68,6 +69,8 @@ import android.util.SparseLongArray;
import
android.view.Display
;
import
android.view.SurfaceView
;
import
android.view.WindowManager
;
import
androidx.annotation.DoNotInline
;
import
androidx.annotation.DrawableRes
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
com.google.android.exoplayer2.C
;
...
...
@@ -2786,6 +2789,22 @@ public final class Util {
return
sum
;
}
/**
* Returns a {@link Drawable} for the given resource or throws a {@link
* Resources.NotFoundException} if not found.
*
* @param context The context to get the theme from starting with API 21.
* @param resources The resources to load the drawable from.
* @param drawableRes The drawable resource int.
* @return The loaded {@link Drawable}.
*/
public
static
Drawable
getDrawable
(
Context
context
,
Resources
resources
,
@DrawableRes
int
drawableRes
)
{
return
SDK_INT
>=
21
?
Api21
.
getDrawable
(
context
,
resources
,
drawableRes
)
:
resources
.
getDrawable
(
drawableRes
);
}
@Nullable
private
static
String
getSystemProperty
(
String
name
)
{
try
{
...
...
@@ -3022,4 +3041,12 @@ public final class Util {
0xDE
,
0xD9
,
0xD0
,
0xD7
,
0xC2
,
0xC5
,
0xCC
,
0xCB
,
0xE6
,
0xE1
,
0xE8
,
0xEF
,
0xFA
,
0xFD
,
0xF4
,
0xF3
};
@RequiresApi
(
21
)
private
static
final
class
Api21
{
@DoNotInline
public
static
Drawable
getDrawable
(
Context
context
,
Resources
resources
,
@DrawableRes
int
res
)
{
return
resources
.
getDrawable
(
res
,
context
.
getTheme
());
}
}
}
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java
View file @
33f8f406
...
...
@@ -28,6 +28,7 @@ import static com.google.android.exoplayer2.Player.EVENT_POSITION_DISCONTINUITY;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_REPEAT_MODE_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_SHUFFLE_MODE_ENABLED_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_TIMELINE_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
getDrawable
;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
...
...
@@ -488,11 +489,11 @@ public class PlayerControlView extends FrameLayout {
buttonAlphaDisabled
=
(
float
)
resources
.
getInteger
(
R
.
integer
.
exo_media_button_opacity_percentage_disabled
)
/
100
;
repeatOffButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_controls_repeat_off
);
repeatOneButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_controls_repeat_one
);
repeatAllButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_controls_repeat_all
);
shuffleOnButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_controls_shuffle_on
);
shuffleOffButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_controls_shuffle_off
);
repeatOffButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_controls_repeat_off
);
repeatOneButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_controls_repeat_one
);
repeatAllButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_controls_repeat_all
);
shuffleOnButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_controls_shuffle_on
);
shuffleOffButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_controls_shuffle_off
);
repeatOffButtonContentDescription
=
resources
.
getString
(
R
.
string
.
exo_controls_repeat_off_description
);
repeatOneButtonContentDescription
=
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java
View file @
33f8f406
...
...
@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.ui;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_GET_TEXT
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SET_VIDEO_SURFACE
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
getDrawable
;
import
static
java
.
lang
.
annotation
.
ElementType
.
TYPE_USE
;
import
android.annotation.SuppressLint
;
...
...
@@ -342,9 +343,9 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
overlayFrameLayout
=
null
;
ImageView
logo
=
new
ImageView
(
context
);
if
(
Util
.
SDK_INT
>=
23
)
{
configureEditModeLogoV23
(
getResources
(),
logo
);
configureEditModeLogoV23
(
context
,
getResources
(),
logo
);
}
else
{
configureEditModeLogo
(
getResources
(),
logo
);
configureEditModeLogo
(
context
,
getResources
(),
logo
);
}
addView
(
logo
);
return
;
...
...
@@ -1388,13 +1389,14 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
}
@RequiresApi
(
23
)
private
static
void
configureEditModeLogoV23
(
Resources
resources
,
ImageView
logo
)
{
logo
.
setImageDrawable
(
resources
.
getDrawable
(
R
.
drawable
.
exo_edit_mode_logo
,
null
));
private
static
void
configureEditModeLogoV23
(
Context
context
,
Resources
resources
,
ImageView
logo
)
{
logo
.
setImageDrawable
(
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_edit_mode_logo
));
logo
.
setBackgroundColor
(
resources
.
getColor
(
R
.
color
.
exo_edit_mode_background_color
,
null
));
}
private
static
void
configureEditModeLogo
(
Resources
resources
,
ImageView
logo
)
{
logo
.
setImageDrawable
(
resources
.
getDrawable
(
R
.
drawable
.
exo_edit_mode_logo
));
private
static
void
configureEditModeLogo
(
Context
context
,
Resources
resources
,
ImageView
logo
)
{
logo
.
setImageDrawable
(
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_edit_mode_logo
));
logo
.
setBackgroundColor
(
resources
.
getColor
(
R
.
color
.
exo_edit_mode_background_color
));
}
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java
View file @
33f8f406
...
...
@@ -34,6 +34,7 @@ import static com.google.android.exoplayer2.Player.EVENT_TIMELINE_CHANGED;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_TRACKS_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
castNonNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
getDrawable
;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
...
...
@@ -53,7 +54,9 @@ import android.widget.FrameLayout;
import
android.widget.ImageView
;
import
android.widget.PopupWindow
;
import
android.widget.TextView
;
import
androidx.annotation.DrawableRes
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.StringRes
;
import
androidx.core.content.res.ResourcesCompat
;
import
androidx.recyclerview.widget.LinearLayoutManager
;
import
androidx.recyclerview.widget.RecyclerView
;
...
...
@@ -535,11 +538,11 @@ public class StyledPlayerControlView extends FrameLayout {
settingTexts
[
SETTINGS_PLAYBACK_SPEED_POSITION
]
=
resources
.
getString
(
R
.
string
.
exo_controls_playback_speed
);
settingIcons
[
SETTINGS_PLAYBACK_SPEED_POSITION
]
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_speed
);
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_speed
);
settingTexts
[
SETTINGS_AUDIO_TRACK_SELECTION_POSITION
]
=
resources
.
getString
(
R
.
string
.
exo_track_selection_title_audio
);
settingIcons
[
SETTINGS_AUDIO_TRACK_SELECTION_POSITION
]
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_audiotrack
);
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_audiotrack
);
settingsAdapter
=
new
SettingsAdapter
(
settingTexts
,
settingIcons
);
settingsWindowMargin
=
resources
.
getDimensionPixelSize
(
R
.
dimen
.
exo_settings_offset
);
settingsView
=
...
...
@@ -559,8 +562,10 @@ public class StyledPlayerControlView extends FrameLayout {
needToHideBars
=
true
;
trackNameProvider
=
new
DefaultTrackNameProvider
(
getResources
());
subtitleOnButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_subtitle_on
);
subtitleOffButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_subtitle_off
);
subtitleOnButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_subtitle_on
);
subtitleOffButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_subtitle_off
);
subtitleOnContentDescription
=
resources
.
getString
(
R
.
string
.
exo_controls_cc_enabled_description
);
subtitleOffContentDescription
=
...
...
@@ -571,14 +576,20 @@ public class StyledPlayerControlView extends FrameLayout {
new
PlaybackSpeedAdapter
(
resources
.
getStringArray
(
R
.
array
.
exo_controls_playback_speeds
),
PLAYBACK_SPEEDS
);
fullScreenExitDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_fullscreen_exit
);
fullScreenExitDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_fullscreen_exit
);
fullScreenEnterDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_fullscreen_enter
);
repeatOffButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_repeat_off
);
repeatOneButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_repeat_one
);
repeatAllButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_repeat_all
);
shuffleOnButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_shuffle_on
);
shuffleOffButtonDrawable
=
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_shuffle_off
);
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_fullscreen_enter
);
repeatOffButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_repeat_off
);
repeatOneButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_repeat_one
);
repeatAllButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_repeat_all
);
shuffleOnButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_shuffle_on
);
shuffleOffButtonDrawable
=
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_styled_controls_shuffle_off
);
fullScreenExitContentDescription
=
resources
.
getString
(
R
.
string
.
exo_controls_fullscreen_exit_description
);
fullScreenEnterContentDescription
=
...
...
@@ -961,17 +972,20 @@ public class StyledPlayerControlView extends FrameLayout {
return
;
}
if
(
playPauseButton
!=
null
)
{
if
(
shouldShowPauseButton
())
{
boolean
shouldShowPauseButton
=
shouldShowPauseButton
();
@DrawableRes
int
drawableRes
=
shouldShowPauseButton
?
R
.
drawable
.
exo_styled_controls_pause
:
R
.
drawable
.
exo_styled_controls_play
;
@StringRes
int
stringRes
=
shouldShowPauseButton
?
R
.
string
.
exo_controls_pause_description
:
R
.
string
.
exo_controls_play_description
;
((
ImageView
)
playPauseButton
)
.
setImageDrawable
(
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_pause
));
playPauseButton
.
setContentDescription
(
resources
.
getString
(
R
.
string
.
exo_controls_pause_description
));
}
else
{
((
ImageView
)
playPauseButton
)
.
setImageDrawable
(
resources
.
getDrawable
(
R
.
drawable
.
exo_styled_controls_play
));
playPauseButton
.
setContentDescription
(
resources
.
getString
(
R
.
string
.
exo_controls_play_description
));
}
.
setImageDrawable
(
getDrawable
(
getContext
(),
resources
,
drawableRes
));
playPauseButton
.
setContentDescription
(
resources
.
getString
(
stringRes
));
}
}
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java
View file @
33f8f406
...
...
@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.ui;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_GET_TEXT
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SET_VIDEO_SURFACE
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
getDrawable
;
import
static
java
.
lang
.
annotation
.
ElementType
.
TYPE_USE
;
import
android.annotation.SuppressLint
;
...
...
@@ -287,9 +288,9 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
overlayFrameLayout
=
null
;
ImageView
logo
=
new
ImageView
(
context
);
if
(
Util
.
SDK_INT
>=
23
)
{
configureEditModeLogoV23
(
getResources
(),
logo
);
configureEditModeLogoV23
(
context
,
getResources
(),
logo
);
}
else
{
configureEditModeLogo
(
getResources
(),
logo
);
configureEditModeLogo
(
context
,
getResources
(),
logo
);
}
addView
(
logo
);
return
;
...
...
@@ -1415,13 +1416,14 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
}
@RequiresApi
(
23
)
private
static
void
configureEditModeLogoV23
(
Resources
resources
,
ImageView
logo
)
{
logo
.
setImageDrawable
(
resources
.
getDrawable
(
R
.
drawable
.
exo_edit_mode_logo
,
null
));
private
static
void
configureEditModeLogoV23
(
Context
context
,
Resources
resources
,
ImageView
logo
)
{
logo
.
setImageDrawable
(
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_edit_mode_logo
));
logo
.
setBackgroundColor
(
resources
.
getColor
(
R
.
color
.
exo_edit_mode_background_color
,
null
));
}
private
static
void
configureEditModeLogo
(
Resources
resources
,
ImageView
logo
)
{
logo
.
setImageDrawable
(
resources
.
getDrawable
(
R
.
drawable
.
exo_edit_mode_logo
));
private
static
void
configureEditModeLogo
(
Context
context
,
Resources
resources
,
ImageView
logo
)
{
logo
.
setImageDrawable
(
getDrawable
(
context
,
resources
,
R
.
drawable
.
exo_edit_mode_logo
));
logo
.
setBackgroundColor
(
resources
.
getColor
(
R
.
color
.
exo_edit_mode_background_color
));
}
...
...
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