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

Commit 02fc5fef authored by Alan Viverette's avatar Alan Viverette
Browse files

Extract drawable inflation to its own class, inflate from class name

Bug: 22627299
Change-Id: Icd2ac88af4f3102e08e52f6f0f7565839da6437a
parent 306a1d22
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1727,7 +1727,8 @@ public final class ActivityThread {
            String[] libDirs, int displayId, Configuration overrideConfiguration,
            LoadedApk pkgInfo) {
        return mResourcesManager.getTopLevelResources(resDir, splitResDirs, overlayDirs, libDirs,
                displayId, overrideConfiguration, pkgInfo.getCompatibilityInfo());
                displayId, overrideConfiguration, pkgInfo.getCompatibilityInfo(),
                pkgInfo.getClassLoader());
    }

    final Handler getHandler() {
+1 −1
Original line number Diff line number Diff line
@@ -1838,7 +1838,7 @@ class ContextImpl extends Context {
                resources = mResourcesManager.getTopLevelResources(packageInfo.getResDir(),
                        packageInfo.getSplitResDirs(), packageInfo.getOverlayDirs(),
                        packageInfo.getApplicationInfo().sharedLibraryFiles, displayId,
                        overrideConfiguration, compatInfo);
                        overrideConfiguration, compatInfo, packageInfo.getClassLoader());
            }
        }
        mResources = resources;
+3 −2
Original line number Diff line number Diff line
@@ -157,7 +157,8 @@ public class ResourcesManager {
     */
    Resources getTopLevelResources(String resDir, String[] splitResDirs,
            String[] overlayDirs, String[] libDirs, int displayId,
            Configuration overrideConfiguration, CompatibilityInfo compatInfo) {
            Configuration overrideConfiguration, CompatibilityInfo compatInfo,
            ClassLoader classLoader) {
        final float scale = compatInfo.applicationScale;
        Configuration overrideConfigCopy = (overrideConfiguration != null)
                ? new Configuration(overrideConfiguration) : null;
@@ -237,7 +238,7 @@ public class ResourcesManager {
        } else {
            config = getConfiguration();
        }
        r = new Resources(assets, dm, config, compatInfo);
        r = new Resources(assets, dm, config, compatInfo, classLoader);
        if (DEBUG) Slog.i(TAG, "Created app resources " + resDir + " " + r + ": "
                + r.getConfiguration() + " appScale=" + r.getCompatibilityInfo().applicationScale);

+23 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.AttrRes;
import android.annotation.ColorInt;
import android.annotation.StyleRes;
import android.annotation.StyleableRes;
import android.graphics.drawable.DrawableInflater;
import android.icu.text.PluralRules;
import com.android.internal.util.GrowingArrayUtils;
import com.android.internal.util.XmlUtils;
@@ -142,6 +143,9 @@ public class Resources {
    private final ConfigurationBoundResourceCache<StateListAnimator> mStateListAnimatorCache =
            new ConfigurationBoundResourceCache<>(this);

    /** Used to inflate drawable objects from XML. */
    private DrawableInflater mDrawableInflater;

    private TypedValue mTmpValue = new TypedValue();
    private boolean mPreloading;

@@ -150,6 +154,7 @@ public class Resources {
    private final XmlBlock[] mCachedXmlBlocks = new XmlBlock[4];

    final AssetManager mAssets;
    final ClassLoader mClassLoader;
    final DisplayMetrics mMetrics = new DisplayMetrics();

    private final Configuration mConfiguration = new Configuration();
@@ -203,6 +208,17 @@ public class Resources {
        return deviceDefault;
    }

    /**
     * @return the inflater used to create drawable objects
     * @hide Pending API finalization.
     */
    public final DrawableInflater getDrawableInflater() {
        if (mDrawableInflater == null) {
            mDrawableInflater = new DrawableInflater(this, mClassLoader);
        }
        return mDrawableInflater;
    }

    /**
     * Used by AnimatorInflater.
     *
@@ -245,7 +261,7 @@ public class Resources {
     *               selecting/computing resource values (optional).
     */
    public Resources(AssetManager assets, DisplayMetrics metrics, Configuration config) {
        this(assets, metrics, config, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO);
        this(assets, metrics, config, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
    }

    /**
@@ -257,11 +273,15 @@ public class Resources {
     * @param config Desired device configuration to consider when
     *               selecting/computing resource values (optional).
     * @param compatInfo this resource's compatibility info. Must not be null.
     * @param classLoader class loader for the package used to load custom
     *                    resource classes, may be {@code null} to use system
     *                    class loader
     * @hide
     */
    public Resources(AssetManager assets, DisplayMetrics metrics, Configuration config,
            CompatibilityInfo compatInfo) {
            CompatibilityInfo compatInfo, @Nullable ClassLoader classLoader) {
        mAssets = assets;
        mClassLoader = classLoader == null ? ClassLoader.getSystemClassLoader() : classLoader;
        mMetrics.setToDefaults();
        if (compatInfo != null) {
            mCompatibilityInfo = compatInfo;
@@ -2803,6 +2823,7 @@ public class Resources {

    private Resources() {
        mAssets = AssetManager.getSystem();
        mClassLoader = ClassLoader.getSystemClassLoader();
        // NOTE: Intentionally leaving this uninitialized (all values set
        // to zero), so that anyone who tries to do something that requires
        // metrics will get a very wrong value.
+1 −67
Original line number Diff line number Diff line
@@ -1146,77 +1146,11 @@ public abstract class Drawable {
     * document, tries to create a Drawable from that tag. Returns {@code null}
     * if the tag is not a valid drawable.
     */
    @SuppressWarnings("deprecation")
    public static Drawable createFromXmlInner(Resources r, XmlPullParser parser, AttributeSet attrs,
            Theme theme) throws XmlPullParserException, IOException {
        final Drawable drawable;

        final String name = parser.getName();
        switch (name) {
            case "selector":
                drawable = new StateListDrawable();
                break;
            case "animated-selector":
                drawable = new AnimatedStateListDrawable();
                break;
            case "level-list":
                drawable = new LevelListDrawable();
                break;
            case "layer-list":
                drawable = new LayerDrawable();
                break;
            case "transition":
                drawable = new TransitionDrawable();
                break;
            case "ripple":
                drawable = new RippleDrawable();
                break;
            case "color":
                drawable = new ColorDrawable();
                break;
            case "shape":
                drawable = new GradientDrawable();
                break;
            case "vector":
                drawable = new VectorDrawable();
                break;
            case "animated-vector":
                drawable = new AnimatedVectorDrawable();
                break;
            case "scale":
                drawable = new ScaleDrawable();
                break;
            case "clip":
                drawable = new ClipDrawable();
                break;
            case "rotate":
                drawable = new RotateDrawable();
                break;
            case "animated-rotate":
                drawable = new AnimatedRotateDrawable();
                break;
            case "animation-list":
                drawable = new AnimationDrawable();
                break;
            case "inset":
                drawable = new InsetDrawable();
                break;
            case "bitmap":
                drawable = new BitmapDrawable();
                break;
            case "nine-patch":
                drawable = new NinePatchDrawable();
                break;
            default:
                throw new XmlPullParserException(parser.getPositionDescription() +
                        ": invalid drawable tag " + name);

        }
        drawable.inflate(r, parser, attrs, theme);
        return drawable;
        return r.getDrawableInflater().inflateFromXml(parser.getName(), parser, attrs, theme);
    }


    /**
     * Create a drawable from file path name.
     */
Loading