Search in sources :

Example 6 with AndroidTargetData

use of org.jetbrains.android.sdk.AndroidTargetData in project android by JetBrains.

the class RefreshRenderAction method clearCache.

public static void clearCache(EditorDesignSurface surface) {
    ModuleClassLoader.clearCache();
    Configuration configuration = surface.getConfiguration();
    if (configuration != null) {
        // Clear layoutlib bitmap cache (in case files have been modified externally)
        IAndroidTarget target = configuration.getTarget();
        Module module = configuration.getModule();
        if (module != null) {
            ResourceClassRegistry.get(module.getProject()).clearCache();
            if (target != null) {
                AndroidTargetData targetData = AndroidTargetData.getTargetData(target, module);
                if (targetData != null) {
                    targetData.clearLayoutBitmapCache(module);
                }
            }
        }
        AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
        if (facet != null) {
            facet.refreshResources();
        }
        configuration.updated(ConfigurationListener.MASK_RENDERING);
    }
    surface.requestRender();
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData)

Example 7 with AndroidTargetData

use of org.jetbrains.android.sdk.AndroidTargetData in project android by JetBrains.

the class ModuleClassLoader method create.

@Nullable
public static ClassLoader create(IAndroidTarget target, Module module) throws Exception {
    AndroidPlatform androidPlatform = AndroidPlatform.getInstance(module);
    if (androidPlatform == null) {
        return null;
    }
    AndroidTargetData targetData = androidPlatform.getSdkData().getTargetData(target);
    LayoutLibrary library = targetData.getLayoutLibrary(module.getProject());
    if (library == null) {
        return null;
    }
    return get(library, module);
}
Also used : LayoutLibrary(com.android.ide.common.rendering.LayoutLibrary) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with AndroidTargetData

use of org.jetbrains.android.sdk.AndroidTargetData in project android by JetBrains.

the class ResolutionUtils method getAttributeDefinition.

@Nullable
public static AttributeDefinition getAttributeDefinition(@NotNull Module module, @Nullable Configuration configuration, @NotNull String name) {
    AttributeDefinitions definitions;
    if (name.startsWith(ANDROID_NS_NAME_PREFIX)) {
        IAndroidTarget target;
        if (configuration == null) {
            AndroidFacet facet = AndroidFacet.getInstance(module);
            assert facet != null;
            // same as getHighestApiTarget();
            target = facet.getConfigurationManager().getDefaultTarget();
        } else {
            target = configuration.getRealTarget();
        }
        assert target != null;
        AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, module);
        assert androidTargetData != null;
        definitions = androidTargetData.getAllAttrDefs(module.getProject());
    } else {
        AndroidFacet facet = AndroidFacet.getInstance(module);
        assert facet != null : String.format("Module %s is not an Android module", module.getName());
        definitions = facet.getLocalResourceManager().getAttributeDefinitions();
    }
    if (definitions == null) {
        return null;
    }
    return definitions.getAttrDefByName(getNameFromQualifiedName(name));
}
Also used : AttributeDefinitions(org.jetbrains.android.dom.attrs.AttributeDefinitions) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with AndroidTargetData

use of org.jetbrains.android.sdk.AndroidTargetData in project android by JetBrains.

the class ResourceFolderRepository method bitmapUpdated.

/**
   * Called when a bitmap has been changed/deleted. In that case we need to clear out any caches for that
   * image held by layout lib.
   */
private void bitmapUpdated() {
    ConfigurationManager configurationManager = myFacet.getConfigurationManager(false);
    if (configurationManager != null) {
        IAndroidTarget target = configurationManager.getTarget();
        if (target != null) {
            Module module = myFacet.getModule();
            AndroidTargetData targetData = AndroidTargetData.getTargetData(target, module);
            if (targetData != null) {
                targetData.clearLayoutBitmapCache(module);
            }
        }
    }
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData)

Example 10 with AndroidTargetData

use of org.jetbrains.android.sdk.AndroidTargetData 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

AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)11 IAndroidTarget (com.android.sdklib.IAndroidTarget)8 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)5 Nullable (org.jetbrains.annotations.Nullable)5 Module (com.intellij.openapi.module.Module)3 Configuration (com.android.tools.idea.configurations.Configuration)2 IOException (java.io.IOException)2 AttributeDefinitions (org.jetbrains.android.dom.attrs.AttributeDefinitions)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 LayoutLibrary (com.android.ide.common.rendering.LayoutLibrary)1 ResourceVisibilityLookup (com.android.ide.common.repository.ResourceVisibilityLookup)1 FrameworkResources (com.android.ide.common.resources.FrameworkResources)1 ResourceRepository (com.android.ide.common.resources.ResourceRepository)1 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)1 ResourceType (com.android.resources.ResourceType)1 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)1 HtmlBuilder (com.android.utils.HtmlBuilder)1 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)1