Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb302ccd authored by Adam Lesinski's avatar Adam Lesinski
Browse files

Move the guts of Resources to ResourcesImpl

In order to satisfy the requirement that clients can
cache a Resources object when a configuration change happens,
we move the caches and all other method bodies to ResourcesImpl.
These can then be swapped out for the correct version when needed,
while allowing clients to keep holding the existing Resources references.

This is part 1 of 2 CLs. The next one will do the actual switching of implementations
based on configuration changes for multiwindow.

Bug:26854894
Change-Id: I41156194a3541e59053b4048c3a15981c7d8a506
parent d25d2f53
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;
        }
+3 −1
Original line number Diff line number Diff line
@@ -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);

+3 −13
Original line number Diff line number Diff line
@@ -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;
+3 −13
Original line number Diff line number Diff line
@@ -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;
+221 −1063

File changed.

Preview size limit exceeded, changes collapsed.

Loading