Search in sources :

Example 1 with ResourceRepository

use of com.android.ide.common.resources.ResourceRepository in project android_frameworks_base by DirtyUnicorns.

the class Main method setUp.

/**
     * Initialize the bridge and the resource maps.
     */
@BeforeClass
public static void setUp() {
    File data_dir = new File(PLATFORM_DIR, "data");
    File res = new File(data_dir, "res");
    sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
    sFrameworkRepo.loadResources();
    sFrameworkRepo.loadPublicResources(getLogger());
    sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {

        @NonNull
        @Override
        protected ResourceItem createResourceItem(@NonNull String name) {
            return new ResourceItem(name);
        }
    };
    sProjectResources.loadResources();
    File fontLocation = new File(data_dir, "fonts");
    File buildProp = new File(PLATFORM_DIR, "build.prop");
    File attrs = new File(res, "values" + File.separator + "attrs.xml");
    sBridge = new Bridge();
    sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) NonNull(android.annotation.NonNull) FolderWrapper(com.android.io.FolderWrapper) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) File(java.io.File) Bridge(com.android.layoutlib.bridge.Bridge) BeforeClass(org.junit.BeforeClass)

Example 2 with ResourceRepository

use of com.android.ide.common.resources.ResourceRepository in project android_frameworks_base by AOSPA.

the class Main method setUp.

/**
     * Initialize the bridge and the resource maps.
     */
@BeforeClass
public static void setUp() {
    File data_dir = new File(PLATFORM_DIR, "data");
    File res = new File(data_dir, "res");
    sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
    sFrameworkRepo.loadResources();
    sFrameworkRepo.loadPublicResources(getLogger());
    sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {

        @NonNull
        @Override
        protected ResourceItem createResourceItem(@NonNull String name) {
            return new ResourceItem(name);
        }
    };
    sProjectResources.loadResources();
    File fontLocation = new File(data_dir, "fonts");
    File buildProp = new File(PLATFORM_DIR, "build.prop");
    File attrs = new File(res, "values" + File.separator + "attrs.xml");
    sBridge = new Bridge();
    sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) NonNull(android.annotation.NonNull) FolderWrapper(com.android.io.FolderWrapper) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) File(java.io.File) Bridge(com.android.layoutlib.bridge.Bridge) BeforeClass(org.junit.BeforeClass)

Example 3 with ResourceRepository

use of com.android.ide.common.resources.ResourceRepository in project android_frameworks_base by ResurrectionRemix.

the class Main method setUp.

/**
     * Initialize the bridge and the resource maps.
     */
@BeforeClass
public static void setUp() {
    File data_dir = new File(PLATFORM_DIR, "data");
    File res = new File(data_dir, "res");
    sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
    sFrameworkRepo.loadResources();
    sFrameworkRepo.loadPublicResources(getLogger());
    sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {

        @NonNull
        @Override
        protected ResourceItem createResourceItem(@NonNull String name) {
            return new ResourceItem(name);
        }
    };
    sProjectResources.loadResources();
    File fontLocation = new File(data_dir, "fonts");
    File buildProp = new File(PLATFORM_DIR, "build.prop");
    File attrs = new File(res, "values" + File.separator + "attrs.xml");
    sBridge = new Bridge();
    sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) NonNull(android.annotation.NonNull) FolderWrapper(com.android.io.FolderWrapper) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) File(java.io.File) Bridge(com.android.layoutlib.bridge.Bridge) BeforeClass(org.junit.BeforeClass)

Example 4 with ResourceRepository

use of com.android.ide.common.resources.ResourceRepository in project android by JetBrains.

the class ResolutionUtils method getFolderConfiguration.

/**
   * Gets the {@link FolderConfiguration} of a ResourceValue
   * e.g. if we resolve a drawable using a mdpi configuration, yet that drawable only exists inside xhdpi, this method will return xhdpi
   * @param configuration the FolderConfiguration that was used for resolving the ResourceValue
   * @return the FolderConfiguration of the ResourceValue
   */
@NotNull
public static FolderConfiguration getFolderConfiguration(@NotNull AndroidFacet facet, @NotNull ResourceValue resolvedValue, @NotNull FolderConfiguration configuration) {
    List<? extends Configurable> configurables;
    if (resolvedValue.isFramework()) {
        ConfigurationManager configurationManager = facet.getConfigurationManager();
        // same as getHighestApiTarget();
        IAndroidTarget target = configurationManager.getDefaultTarget();
        assert target != null;
        ResourceRepository resourceRepository = configurationManager.getResolverCache().getFrameworkResources(configuration, target);
        assert resourceRepository != null;
        ResourceItem resourceItem = resourceRepository.getResourceItem(resolvedValue.getResourceType(), resolvedValue.getName());
        configurables = resourceItem.getSourceFileList();
    } else {
        AppResourceRepository appResourceRepository = facet.getAppResources(true);
        configurables = appResourceRepository.getResourceItem(resolvedValue.getResourceType(), resolvedValue.getName());
    }
    Configurable configurable = configuration.findMatchingConfigurable(configurables);
    assert configurable != null;
    return configurable.getConfiguration();
}
Also used : AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) IAndroidTarget(com.android.sdklib.IAndroidTarget) Configurable(com.android.ide.common.resources.configuration.Configurable) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ResourceRepository

use of com.android.ide.common.resources.ResourceRepository in project android_frameworks_base by crdroidandroid.

the class Main method setUp.

/**
     * Initialize the bridge and the resource maps.
     */
@BeforeClass
public static void setUp() {
    File data_dir = new File(PLATFORM_DIR, "data");
    File res = new File(data_dir, "res");
    sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
    sFrameworkRepo.loadResources();
    sFrameworkRepo.loadPublicResources(getLogger());
    sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {

        @NonNull
        @Override
        protected ResourceItem createResourceItem(@NonNull String name) {
            return new ResourceItem(name);
        }
    };
    sProjectResources.loadResources();
    File fontLocation = new File(data_dir, "fonts");
    File buildProp = new File(PLATFORM_DIR, "build.prop");
    File attrs = new File(res, "values" + File.separator + "attrs.xml");
    sBridge = new Bridge();
    sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) NonNull(android.annotation.NonNull) FolderWrapper(com.android.io.FolderWrapper) ResourceRepository(com.android.ide.common.resources.ResourceRepository) ResourceItem(com.android.ide.common.resources.ResourceItem) File(java.io.File) Bridge(com.android.layoutlib.bridge.Bridge) BeforeClass(org.junit.BeforeClass)

Aggregations

ResourceRepository (com.android.ide.common.resources.ResourceRepository)11 ResourceItem (com.android.ide.common.resources.ResourceItem)7 NonNull (android.annotation.NonNull)5 FrameworkResources (com.android.ide.common.resources.FrameworkResources)5 FolderWrapper (com.android.io.FolderWrapper)5 Bridge (com.android.layoutlib.bridge.Bridge)5 File (java.io.File)5 BeforeClass (org.junit.BeforeClass)5 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)4 IAndroidTarget (com.android.sdklib.IAndroidTarget)3 LocalResourceRepository (com.android.tools.idea.res.LocalResourceRepository)3 ResourceResolver (com.android.ide.common.resources.ResourceResolver)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 ResourceItemResolver (com.android.ide.common.resources.ResourceItemResolver)1 ResourceValueMap (com.android.ide.common.resources.ResourceValueMap)1 Configurable (com.android.ide.common.resources.configuration.Configurable)1 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 ResourceType (com.android.resources.ResourceType)1