Search in sources :

Example 1 with FrameworkResources

use of com.android.ide.common.resources.FrameworkResources 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 2 with FrameworkResources

use of com.android.ide.common.resources.FrameworkResources 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 3 with FrameworkResources

use of com.android.ide.common.resources.FrameworkResources 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 4 with FrameworkResources

use of com.android.ide.common.resources.FrameworkResources 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)

Example 5 with FrameworkResources

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

the class ResourceHelper method getCompletionFromTypes.

/**
   * Returns the list of all resource names that can be used as a value for one of the {@link ResourceType} in completionTypes,
   * optionally sorting/not sorting the results.
   */
@NotNull
public static List<String> getCompletionFromTypes(@NotNull AndroidFacet facet, @NotNull EnumSet<ResourceType> completionTypes, boolean sort) {
    EnumSet<ResourceType> types = Sets.newEnumSet(completionTypes, ResourceType.class);
    // Use drawables for mipmaps
    if (types.contains(ResourceType.MIPMAP)) {
        types.add(ResourceType.DRAWABLE);
    } else if (types.contains(ResourceType.DRAWABLE)) {
        types.add(ResourceType.MIPMAP);
    }
    boolean completionTypesContainsColor = types.contains(ResourceType.COLOR);
    if (types.contains(ResourceType.DRAWABLE)) {
        // The Drawable type accepts colors as value but not color state lists.
        types.add(ResourceType.COLOR);
    }
    AppResourceRepository repository = AppResourceRepository.getAppResources(facet, true);
    ResourceVisibilityLookup lookup = repository.getResourceVisibility(facet);
    AndroidPlatform androidPlatform = AndroidPlatform.getInstance(facet.getModule());
    FrameworkResources frameworkResources = null;
    if (androidPlatform != null) {
        AndroidTargetData targetData = androidPlatform.getSdkData().getTargetData(androidPlatform.getTarget());
        try {
            frameworkResources = targetData.getFrameworkResources(true);
        } catch (IOException ignore) {
        }
    }
    List<String> resources = Lists.newArrayListWithCapacity(500);
    for (ResourceType type : types) {
        // If type == ResourceType.COLOR, we want to include file resources (i.e. color state lists) only in the case where
        // color was present in completionTypes, and not if we added it because of the presence of ResourceType.DRAWABLES.
        // For any other ResourceType, we always include file resources.
        boolean includeFileResources = (type != ResourceType.COLOR) || completionTypesContainsColor;
        if (frameworkResources != null) {
            addFrameworkItems(resources, type, includeFileResources, frameworkResources);
        }
        addProjectItems(resources, type, includeFileResources, repository, lookup);
    }
    if (sort) {
        Collections.sort(resources, ResourceHelper::compareResourceReferences);
    }
    return resources;
}
Also used : FrameworkResources(com.android.ide.common.resources.FrameworkResources) ResourceType(com.android.resources.ResourceType) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) ResourceVisibilityLookup(com.android.ide.common.repository.ResourceVisibilityLookup) IOException(java.io.IOException) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FrameworkResources (com.android.ide.common.resources.FrameworkResources)6 NonNull (android.annotation.NonNull)5 ResourceItem (com.android.ide.common.resources.ResourceItem)5 ResourceRepository (com.android.ide.common.resources.ResourceRepository)5 FolderWrapper (com.android.io.FolderWrapper)5 Bridge (com.android.layoutlib.bridge.Bridge)5 File (java.io.File)5 BeforeClass (org.junit.BeforeClass)5 ResourceVisibilityLookup (com.android.ide.common.repository.ResourceVisibilityLookup)1 ResourceType (com.android.resources.ResourceType)1 IOException (java.io.IOException)1 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)1 AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)1 NotNull (org.jetbrains.annotations.NotNull)1