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

Commit 35ea7cd4 authored by Xavier Ducrohet's avatar Xavier Ducrohet
Browse files

LayoutLib: Update with the new resource map APIs.

Change-Id: I30d83c2bb4569513f4f5e22670cffe938706f105
parent 270cbcc1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public abstract class Gradient_Delegate extends Shader_Delegate {
         * Pre-computes the colors for the gradient. This must be called once before any call
         * to {@link #getGradientColor(float)}
         */
        protected synchronized void precomputeGradientColors() {
        protected void precomputeGradientColors() {
            if (mGradient == null) {
                // actually create an array with an extra size, so that we can really go
                // from 0 to SIZE (100%), or currentPos in the loop below will never equal 1.0
+4 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.layoutlib.bridge.android.BridgeAssetManager;
import com.android.layoutlib.bridge.impl.FontLoader;
import com.android.layoutlib.bridge.impl.RenderSessionImpl;
import com.android.ninepatch.NinePatchChunk;
import com.android.resources.ResourceType;
import com.android.tools.layoutlib.create.MethodAdapter;
import com.android.tools.layoutlib.create.OverrideMethod;

@@ -410,8 +411,9 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
     * @param name the name of the resource.
     * @return an {@link Integer} containing the resource id, or null if no resource were found.
     */
    public static Integer getResourceValue(String type, String name) {
        Map<String, Integer> map = sRFullMap.get(type);
    public static Integer getResourceValue(ResourceType type, String name) {
        String typeString = type.getName();
        Map<String, Integer> map = sRFullMap.get(typeString);
        if (map != null) {
            return map.get(name);
        }
+3 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.ide.common.rendering.api.StyleResourceValue;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.Stack;
import com.android.resources.ResourceType;

import android.app.Activity;
import android.app.Fragment;
@@ -614,7 +615,7 @@ public final class BridgeContext extends Activity {
        return null;
    }

    int getFrameworkResourceValue(String resType, String resName, int defValue) {
    int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) {
        Integer value = Bridge.getResourceValue(resType, resName);
        if (value != null) {
            return value.intValue();
@@ -623,7 +624,7 @@ public final class BridgeContext extends Activity {
        return defValue;
    }

    int getProjectResourceValue(String resType, String resName, int defValue) {
    int getProjectResourceValue(ResourceType resType, String resName, int defValue) {
        if (mProjectCallback != null) {
            Integer value = mProjectCallback.getResourceValue(resType, resName);
            if (value != null) {
+3 −3
Original line number Diff line number Diff line
@@ -19,9 +19,9 @@ package com.android.layoutlib.bridge.android;
import com.android.ide.common.rendering.api.IProjectCallback;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.ide.common.rendering.api.MergeCookie;
import com.android.ide.common.rendering.api.RenderResources;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.layoutlib.bridge.Bridge;
import com.android.resources.ResourceType;

import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
@@ -158,13 +158,13 @@ public final class BridgeInflater extends LayoutInflater {
            String[] layoutInfo = Bridge.resolveResourceValue(resource);
            if (layoutInfo != null) {
                value = bridgeContext.getRenderResources().getFrameworkResource(
                        RenderResources.RES_LAYOUT, layoutInfo[0]);
                        ResourceType.LAYOUT, layoutInfo[0]);
            } else {
                layoutInfo = mProjectCallback.resolveResourceValue(resource);

                if (layoutInfo != null) {
                    value = bridgeContext.getRenderResources().getProjectResource(
                            RenderResources.RES_LAYOUT, layoutInfo[0]);
                            ResourceType.LAYOUT, layoutInfo[0]);
                }
            }

+13 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.ide.common.rendering.api.ResourceValue;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.ResourceHelper;
import com.android.resources.ResourceType;

import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
@@ -103,9 +104,14 @@ public final class BridgeResources extends Resources {
        String[] resourceInfo = Bridge.resolveResourceValue(id);

        if (resourceInfo != null) {
            ResourceType resType = ResourceType.getEnum(resourceInfo[1]);
            if (resType == null) {
                return null;
            }

            platformResFlag_out[0] = true;
            return mContext.getRenderResources().getFrameworkResource(
                    resourceInfo[1], resourceInfo[0]);
                    resType, resourceInfo[0]);
        }

        // didn't find a match in the framework? look in the project.
@@ -113,9 +119,14 @@ public final class BridgeResources extends Resources {
            resourceInfo = mProjectCallback.resolveResourceValue(id);

            if (resourceInfo != null) {
                ResourceType resType = ResourceType.getEnum(resourceInfo[1]);
                if (resType == null) {
                    return null;
                }

                platformResFlag_out[0] = false;
                return mContext.getRenderResources().getProjectResource(
                        resourceInfo[1], resourceInfo[0]);
                        resType, resourceInfo[0]);
            }
        }

Loading