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();
}
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);
}
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));
}
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);
}
}
}
}
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;
}
Aggregations