Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_frameworks_base-old
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Farzin Kazemzadeh
platform_frameworks_base-old
Commits
0b723fdb
Commit
0b723fdb
authored
10 years ago
by
Alan Viverette
Committed by
Android (Google) Code Review
10 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Handle hybrid themes correctly in Drawable cache" into lmp-preview-dev
parents
7a57c01a
75257cef
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/java/android/content/res/Resources.java
+33
-35
33 additions, 35 deletions
core/java/android/content/res/Resources.java
with
33 additions
and
35 deletions
core/java/android/content/res/Resources.java
+
33
−
35
View file @
0b723fdb
...
...
@@ -31,11 +31,11 @@ import android.os.Build;
import
android.os.Bundle
;
import
android.os.IBinder
;
import
android.os.Trace
;
import
android.util.ArrayMap
;
import
android.util.AttributeSet
;
import
android.util.DisplayMetrics
;
import
android.util.Log
;
import
android.util.Slog
;
import
android.util.SparseArray
;
import
android.util.TypedValue
;
import
android.util.LongSparseArray
;
...
...
@@ -104,10 +104,10 @@ public class Resources {
// These are protected by mAccessLock.
private
final
Object
mAccessLock
=
new
Object
();
private
final
Configuration
mTmpConfig
=
new
Configuration
();
private
final
ThemedCaches
<
ConstantState
>
mDrawableCache
=
new
ThemedCaches
<
ConstantState
>();
private
final
ThemedCaches
<
ConstantState
>
mColorDrawableCache
=
new
ThemedCaches
<
ConstantState
>();
private
final
ArrayMap
<
String
,
LongSparseArray
<
WeakReference
<
ConstantState
>
>>
mDrawableCache
=
new
ArrayMap
<
String
,
LongSparseArray
<
WeakReference
<
ConstantState
>
>>
();
private
final
ArrayMap
<
String
,
LongSparseArray
<
WeakReference
<
ConstantState
>
>>
mColorDrawableCache
=
new
ArrayMap
<
String
,
LongSparseArray
<
WeakReference
<
ConstantState
>
>>
();
private
final
LongSparseArray
<
WeakReference
<
ColorStateList
>>
mColorStateListCache
=
new
LongSparseArray
<
WeakReference
<
ColorStateList
>>();
...
...
@@ -1261,18 +1261,17 @@ public class Resources {
* any of the style's attributes are already defined in the theme, the
* current values in the theme will be overwritten.
*
* @param res
i
d The resource ID of a style resource from which to
* @param res
I
d The resource ID of a style resource from which to
* obtain attribute values.
* @param force If true, values in the style resource will always be
* used in the theme; otherwise, they will only be used
* if not already defined in the theme.
*/
public
void
applyStyle
(
int
res
i
d
,
boolean
force
)
{
AssetManager
.
applyThemeStyle
(
mTheme
,
res
i
d
,
force
);
public
void
applyStyle
(
int
res
I
d
,
boolean
force
)
{
AssetManager
.
applyThemeStyle
(
mTheme
,
res
I
d
,
force
);
// TODO: In very rare cases, we may end up with a hybrid theme
// that can't map to a single theme ID.
mThemeResId
=
resid
;
mThemeResId
=
resId
;
mKey
+=
Integer
.
toHexString
(
resId
)
+
(
force
?
"! "
:
" "
);
}
/**
...
...
@@ -1288,6 +1287,7 @@ public class Resources {
AssetManager
.
copyTheme
(
mTheme
,
other
.
mTheme
);
mThemeResId
=
other
.
mThemeResId
;
mKey
=
other
.
mKey
;
}
/**
...
...
@@ -1577,6 +1577,9 @@ public class Resources {
/** Resource identifier for the theme. */
private
int
mThemeResId
=
0
;
/** Unique key for the series of styles applied to this theme. */
private
String
mKey
=
""
;
// Needed by layoutlib.
/*package*/
long
getNativeTheme
()
{
return
mTheme
;
...
...
@@ -1585,6 +1588,10 @@ public class Resources {
/*package*/
int
getAppliedStyleResId
()
{
return
mThemeResId
;
}
/*package*/
String
getKey
()
{
return
mKey
;
}
}
/**
...
...
@@ -1740,7 +1747,8 @@ public class Resources {
}
private
void
clearDrawableCachesLocked
(
ThemedCaches
<
ConstantState
>
caches
,
int
configChanges
)
{
ArrayMap
<
String
,
LongSparseArray
<
WeakReference
<
ConstantState
>>>
caches
,
int
configChanges
)
{
final
int
N
=
caches
.
size
();
for
(
int
i
=
0
;
i
<
N
;
i
++)
{
clearDrawableCacheLocked
(
caches
.
valueAt
(
i
),
configChanges
);
...
...
@@ -1763,7 +1771,7 @@ public class Resources {
configChanges
,
cs
.
getChangingConfigurations
()))
{
if
(
DEBUG_CONFIG
)
{
Log
.
d
(
TAG
,
"FLUSHING #0x"
+
Long
.
toHexString
(
mDrawableC
ache
.
keyAt
(
i
))
+
Long
.
toHexString
(
c
ache
.
keyAt
(
i
))
+
" / "
+
cs
+
" with changes: 0x"
+
Integer
.
toHexString
(
cs
.
getChangingConfigurations
()));
}
...
...
@@ -2205,7 +2213,7 @@ public class Resources {
}
final
boolean
isColorDrawable
;
final
ThemedCaches
<
ConstantState
>
caches
;
final
ArrayMap
<
String
,
LongSparseArray
<
WeakReference
<
ConstantState
>
>>
caches
;
final
long
key
;
if
(
value
.
type
>=
TypedValue
.
TYPE_FIRST_COLOR_INT
&&
value
.
type
<=
TypedValue
.
TYPE_LAST_COLOR_INT
)
{
...
...
@@ -2258,7 +2266,8 @@ public class Resources {
}
private
void
cacheDrawable
(
TypedValue
value
,
Theme
theme
,
boolean
isColorDrawable
,
ThemedCaches
<
ConstantState
>
caches
,
long
key
,
Drawable
dr
)
{
ArrayMap
<
String
,
LongSparseArray
<
WeakReference
<
ConstantState
>>>
caches
,
long
key
,
Drawable
dr
)
{
final
ConstantState
cs
=
dr
.
getConstantState
();
if
(
cs
==
null
)
{
return
;
...
...
@@ -2287,8 +2296,12 @@ public class Resources {
}
}
else
{
synchronized
(
mAccessLock
)
{
final
LongSparseArray
<
WeakReference
<
ConstantState
>>
themedCache
;
themedCache
=
caches
.
getOrCreate
(
theme
==
null
?
0
:
theme
.
mThemeResId
);
final
String
themeKey
=
theme
==
null
?
""
:
theme
.
mKey
;
LongSparseArray
<
WeakReference
<
ConstantState
>>
themedCache
=
caches
.
get
(
themeKey
);
if
(
themedCache
==
null
)
{
themedCache
=
new
LongSparseArray
<
WeakReference
<
ConstantState
>>(
1
);
caches
.
put
(
themeKey
,
themedCache
);
}
themedCache
.
put
(
key
,
new
WeakReference
<
ConstantState
>(
cs
));
}
}
...
...
@@ -2347,7 +2360,9 @@ public class Resources {
return
dr
;
}
private
Drawable
getCachedDrawable
(
ThemedCaches
<
ConstantState
>
caches
,
long
key
,
Theme
theme
)
{
private
Drawable
getCachedDrawable
(
ArrayMap
<
String
,
LongSparseArray
<
WeakReference
<
ConstantState
>>>
caches
,
long
key
,
Theme
theme
)
{
synchronized
(
mAccessLock
)
{
final
int
themeKey
=
theme
!=
null
?
theme
.
mThemeResId
:
0
;
final
LongSparseArray
<
WeakReference
<
ConstantState
>>
themedCache
=
caches
.
get
(
themeKey
);
...
...
@@ -2584,21 +2599,4 @@ public class Resources {
updateConfiguration
(
null
,
null
);
mAssets
.
ensureStringBlocks
();
}
static
class
ThemedCaches
<
T
>
extends
SparseArray
<
LongSparseArray
<
WeakReference
<
T
>>>
{
/**
* Returns the cache of drawables styled for the specified theme.
* <p>
* Drawables that have themeable attributes but were loaded without
* specifying a theme are cached at themeResId = 0.
*/
public
LongSparseArray
<
WeakReference
<
T
>>
getOrCreate
(
int
themeResId
)
{
LongSparseArray
<
WeakReference
<
T
>>
result
=
get
(
themeResId
);
if
(
result
==
null
)
{
result
=
new
LongSparseArray
<
WeakReference
<
T
>>(
1
);
put
(
themeResId
,
result
);
}
return
result
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment