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
5a7dbae1
authored
Apr 07, 2020
by
ibaker
Committed by
Oliver Woodman
Apr 07, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use Android's Color.argb() and Color.rgb() methods in ColorParser
PiperOrigin-RevId: 305216138
parent
8df6a4b3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
10 deletions
library/core/src/main/java/com/google/android/exoplayer2/util/ColorParser.java
library/core/src/main/java/com/google/android/exoplayer2/util/ColorParser.java
View file @
5a7dbae1
...
@@ -15,7 +15,9 @@
...
@@ -15,7 +15,9 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
util
;
package
com
.
google
.
android
.
exoplayer2
.
util
;
import
android.graphics.Color
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
androidx.annotation.ColorInt
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
...
@@ -49,6 +51,7 @@ public final class ColorParser {
...
@@ -49,6 +51,7 @@ public final class ColorParser {
* @param colorExpression The color expression.
* @param colorExpression The color expression.
* @return The parsed ARGB color.
* @return The parsed ARGB color.
*/
*/
@ColorInt
public
static
int
parseTtmlColor
(
String
colorExpression
)
{
public
static
int
parseTtmlColor
(
String
colorExpression
)
{
return
parseColorInternal
(
colorExpression
,
false
);
return
parseColorInternal
(
colorExpression
,
false
);
}
}
...
@@ -59,10 +62,12 @@ public final class ColorParser {
...
@@ -59,10 +62,12 @@ public final class ColorParser {
* @param colorExpression The color expression.
* @param colorExpression The color expression.
* @return The parsed ARGB color.
* @return The parsed ARGB color.
*/
*/
@ColorInt
public
static
int
parseCssColor
(
String
colorExpression
)
{
public
static
int
parseCssColor
(
String
colorExpression
)
{
return
parseColorInternal
(
colorExpression
,
true
);
return
parseColorInternal
(
colorExpression
,
true
);
}
}
@ColorInt
private
static
int
parseColorInternal
(
String
colorExpression
,
boolean
alphaHasFloatFormat
)
{
private
static
int
parseColorInternal
(
String
colorExpression
,
boolean
alphaHasFloatFormat
)
{
Assertions
.
checkArgument
(!
TextUtils
.
isEmpty
(
colorExpression
));
Assertions
.
checkArgument
(!
TextUtils
.
isEmpty
(
colorExpression
));
colorExpression
=
colorExpression
.
replace
(
" "
,
""
);
colorExpression
=
colorExpression
.
replace
(
" "
,
""
);
...
@@ -83,7 +88,7 @@ public final class ColorParser {
...
@@ -83,7 +88,7 @@ public final class ColorParser {
Matcher
matcher
=
(
alphaHasFloatFormat
?
RGBA_PATTERN_FLOAT_ALPHA
:
RGBA_PATTERN_INT_ALPHA
)
Matcher
matcher
=
(
alphaHasFloatFormat
?
RGBA_PATTERN_FLOAT_ALPHA
:
RGBA_PATTERN_INT_ALPHA
)
.
matcher
(
colorExpression
);
.
matcher
(
colorExpression
);
if
(
matcher
.
matches
())
{
if
(
matcher
.
matches
())
{
return
argb
(
return
Color
.
argb
(
alphaHasFloatFormat
alphaHasFloatFormat
?
(
int
)
(
255
*
Float
.
parseFloat
(
Assertions
.
checkNotNull
(
matcher
.
group
(
4
))))
?
(
int
)
(
255
*
Float
.
parseFloat
(
Assertions
.
checkNotNull
(
matcher
.
group
(
4
))))
:
Integer
.
parseInt
(
Assertions
.
checkNotNull
(
matcher
.
group
(
4
)),
10
),
:
Integer
.
parseInt
(
Assertions
.
checkNotNull
(
matcher
.
group
(
4
)),
10
),
...
@@ -94,7 +99,7 @@ public final class ColorParser {
...
@@ -94,7 +99,7 @@ public final class ColorParser {
}
else
if
(
colorExpression
.
startsWith
(
RGB
))
{
}
else
if
(
colorExpression
.
startsWith
(
RGB
))
{
Matcher
matcher
=
RGB_PATTERN
.
matcher
(
colorExpression
);
Matcher
matcher
=
RGB_PATTERN
.
matcher
(
colorExpression
);
if
(
matcher
.
matches
())
{
if
(
matcher
.
matches
())
{
return
rgb
(
return
Color
.
rgb
(
Integer
.
parseInt
(
Assertions
.
checkNotNull
(
matcher
.
group
(
1
)),
10
),
Integer
.
parseInt
(
Assertions
.
checkNotNull
(
matcher
.
group
(
1
)),
10
),
Integer
.
parseInt
(
Assertions
.
checkNotNull
(
matcher
.
group
(
2
)),
10
),
Integer
.
parseInt
(
Assertions
.
checkNotNull
(
matcher
.
group
(
2
)),
10
),
Integer
.
parseInt
(
Assertions
.
checkNotNull
(
matcher
.
group
(
3
)),
10
));
Integer
.
parseInt
(
Assertions
.
checkNotNull
(
matcher
.
group
(
3
)),
10
));
...
@@ -109,14 +114,6 @@ public final class ColorParser {
...
@@ -109,14 +114,6 @@ public final class ColorParser {
throw
new
IllegalArgumentException
();
throw
new
IllegalArgumentException
();
}
}
private
static
int
argb
(
int
alpha
,
int
red
,
int
green
,
int
blue
)
{
return
(
alpha
<<
24
)
|
(
red
<<
16
)
|
(
green
<<
8
)
|
blue
;
}
private
static
int
rgb
(
int
red
,
int
green
,
int
blue
)
{
return
argb
(
0xFF
,
red
,
green
,
blue
);
}
static
{
static
{
COLOR_MAP
=
new
HashMap
<>();
COLOR_MAP
=
new
HashMap
<>();
COLOR_MAP
.
put
(
"aliceblue"
,
0xFFF0F8FF
);
COLOR_MAP
.
put
(
"aliceblue"
,
0xFFF0F8FF
);
...
...
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