Merge "Move the guts of Resources to ResourcesImpl" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c4dd2e7d52
@@ -108,7 +108,7 @@ public class AnimatorInflater {
|
||||
float pathErrorScale) throws NotFoundException {
|
||||
final ConfigurationBoundResourceCache<Animator> animatorCache = resources
|
||||
.getAnimatorCache();
|
||||
Animator animator = animatorCache.getInstance(id, theme);
|
||||
Animator animator = animatorCache.getInstance(id, resources, theme);
|
||||
if (animator != null) {
|
||||
if (DBG_ANIMATOR_INFLATER) {
|
||||
Log.d(TAG, "loaded animator from cache, " + resources.getResourceName(id));
|
||||
@@ -157,7 +157,7 @@ public class AnimatorInflater {
|
||||
final ConfigurationBoundResourceCache<StateListAnimator> cache = resources
|
||||
.getStateListAnimatorCache();
|
||||
final Theme theme = context.getTheme();
|
||||
StateListAnimator animator = cache.getInstance(id, theme);
|
||||
StateListAnimator animator = cache.getInstance(id, resources, theme);
|
||||
if (animator != null) {
|
||||
return animator;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.content.res.AssetManager;
|
||||
import android.content.res.CompatibilityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.ResourcesImpl;
|
||||
import android.content.res.ResourcesKey;
|
||||
import android.hardware.display.DisplayManagerGlobal;
|
||||
import android.util.ArrayMap;
|
||||
@@ -250,7 +251,8 @@ public class ResourcesManager {
|
||||
} else {
|
||||
config = getConfiguration();
|
||||
}
|
||||
r = new Resources(assets, dm, config, compatInfo, classLoader);
|
||||
r = new Resources(classLoader);
|
||||
r.setImpl(new ResourcesImpl(assets, dm, config, compatInfo));
|
||||
if (DEBUG) Slog.i(TAG, "Created app resources " + resDir + " " + r + ": "
|
||||
+ r.getConfiguration() + " appScale=" + r.getCompatibilityInfo().applicationScale);
|
||||
|
||||
|
||||
@@ -23,29 +23,19 @@ package android.content.res;
|
||||
* @hide For internal use only.
|
||||
*/
|
||||
public class ConfigurationBoundResourceCache<T> extends ThemedResourceCache<ConstantState<T>> {
|
||||
private final Resources mResources;
|
||||
|
||||
/**
|
||||
* Creates a cache for the given Resources instance.
|
||||
*
|
||||
* @param resources the resources to use when creating new instances
|
||||
*/
|
||||
public ConfigurationBoundResourceCache(Resources resources) {
|
||||
mResources = resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the resource is cached, creates and returns a new instance of it.
|
||||
*
|
||||
* @param key a key that uniquely identifies the drawable resource
|
||||
* @param resources a Resources object from which to create new instances.
|
||||
* @param theme the theme where the resource will be used
|
||||
* @return a new instance of the resource, or {@code null} if not in
|
||||
* the cache
|
||||
*/
|
||||
public T getInstance(long key, Resources.Theme theme) {
|
||||
public T getInstance(long key, Resources resources, Resources.Theme theme) {
|
||||
final ConstantState<T> entry = get(key, theme);
|
||||
if (entry != null) {
|
||||
return entry.newInstance(mResources, theme);
|
||||
return entry.newInstance(resources, theme);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -22,29 +22,19 @@ import android.graphics.drawable.Drawable;
|
||||
* Class which can be used to cache Drawable resources against a theme.
|
||||
*/
|
||||
class DrawableCache extends ThemedResourceCache<Drawable.ConstantState> {
|
||||
private final Resources mResources;
|
||||
|
||||
/**
|
||||
* Creates a cache for the given Resources instance.
|
||||
*
|
||||
* @param resources the resources to use when creating new instances
|
||||
*/
|
||||
public DrawableCache(Resources resources) {
|
||||
mResources = resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the resource is cached, creates and returns a new instance of it.
|
||||
*
|
||||
* @param key a key that uniquely identifies the drawable resource
|
||||
* @param resources a Resources object from which to create new instances.
|
||||
* @param theme the theme where the resource will be used
|
||||
* @return a new instance of the resource, or {@code null} if not in
|
||||
* the cache
|
||||
*/
|
||||
public Drawable getInstance(long key, Resources.Theme theme) {
|
||||
public Drawable getInstance(long key, Resources resources, Resources.Theme theme) {
|
||||
final Drawable.ConstantState entry = get(key, theme);
|
||||
if (entry != null) {
|
||||
return entry.newDrawable(mResources, theme);
|
||||
return entry.newDrawable(resources, theme);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
1140
core/java/android/content/res/ResourcesImpl.java
Normal file
1140
core/java/android/content/res/ResourcesImpl.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1206,8 +1206,8 @@ public class TypedArray {
|
||||
|
||||
/*package*/ TypedArray(Resources resources, int[] data, int[] indices, int len) {
|
||||
mResources = resources;
|
||||
mMetrics = mResources.mMetrics;
|
||||
mAssets = mResources.mAssets;
|
||||
mMetrics = mResources.getDisplayMetrics();
|
||||
mAssets = mResources.getAssets();
|
||||
mData = data;
|
||||
mIndices = indices;
|
||||
mLength = len;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ConfigurationBoundResourceCacheTest
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mCache = new ConfigurationBoundResourceCache<Float>(getActivity().getResources());
|
||||
mCache = new ConfigurationBoundResourceCache<>();
|
||||
}
|
||||
|
||||
public void testGetEmpty() {
|
||||
|
||||
Reference in New Issue
Block a user