use of com.android.ide.common.resources.ResourceRepository in project platform_frameworks_base by android.
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());
}
use of com.android.ide.common.resources.ResourceRepository in project android by JetBrains.
the class ResourceResolverCache method getResourceResolver.
@NotNull
public ResourceResolver getResourceResolver(@Nullable IAndroidTarget target, @NotNull String themeStyle, @NotNull final FolderConfiguration fullConfiguration) {
// Are caches up to date?
final LocalResourceRepository resources = AppResourceRepository.getAppResources(myManager.getModule(), true);
assert resources != null;
if (myCachedGeneration != resources.getModificationCount()) {
myResolverMap.clear();
myAppResourceMap.clear();
}
// Store the modification count as soon as possible. This ensures that if there is any modification of resources while the
// resolver is being created, it will be cleared subsequently.
myCachedGeneration = resources.getModificationCount();
// When looking up the configured project and framework resources, the theme doesn't matter, so we look up only
// by the configuration qualifiers; for example, here's a sample key:
// -ldltr-sw384dp-w384dp-h640dp-normal-notlong-port-notnight-xhdpi-finger-keyssoft-nokeys-navhidden-nonav-1280x768-v17
// Note that the target version is already baked in via the -v qualifier.
//
// However, the resource resolver also depends on the theme, so we use a more specific key for the resolver map than
// for the configured resource maps, by prepending the theme name:
// @style/MyTheme-ldltr-sw384dp-w384dp-h640dp-normal-notlong-port-notnight-xhdpi-finger-keyssoft-nokeys-navhidden-nonav-1280x768-v17
String configurationKey = fullConfiguration.getUniqueKey();
String resolverKey = themeStyle + configurationKey;
ResourceResolver resolver = myResolverMap.get(resolverKey);
if (resolver == null) {
Map<ResourceType, ResourceValueMap> configuredAppRes;
Map<ResourceType, ResourceValueMap> frameworkResources;
// Framework resources
if (target == null) {
target = myManager.getTarget();
}
if (target == null) {
frameworkResources = Collections.emptyMap();
} else {
ResourceRepository frameworkRes = getFrameworkResources(fullConfiguration, target);
if (frameworkRes == null) {
frameworkResources = Collections.emptyMap();
} else {
// get the framework resource values based on the current config
frameworkResources = myFrameworkResourceMap.get(configurationKey);
if (frameworkResources == null) {
frameworkResources = frameworkRes.getConfiguredResources(fullConfiguration);
// assets replaced the look for the same theme; that doesn't happen to the same extend for Holo)
if (target instanceof CompatibilityRenderTarget && target.getVersion().getApiLevel() == 8) {
IAndroidTarget realTarget = ((CompatibilityRenderTarget) target).getRealTarget();
if (realTarget != null) {
replaceDrawableBitmaps(frameworkResources, target, realTarget);
}
}
myFrameworkResourceMap.put(configurationKey, frameworkResources);
}
}
}
// App resources
configuredAppRes = myAppResourceMap.get(configurationKey);
if (configuredAppRes == null) {
// get the project resource values based on the current config
Application application = ApplicationManager.getApplication();
configuredAppRes = application.runReadAction(new Computable<Map<ResourceType, ResourceValueMap>>() {
@Override
public Map<ResourceType, ResourceValueMap> compute() {
return resources.getConfiguredResources(fullConfiguration);
}
});
myAppResourceMap.put(configurationKey, configuredAppRes);
}
// Resource Resolver
assert themeStyle.startsWith(PREFIX_RESOURCE_REF) : themeStyle;
boolean isProjectTheme = ResourceHelper.isProjectStyle(themeStyle);
String themeName = ResourceHelper.styleToTheme(themeStyle);
resolver = ResourceResolver.create(configuredAppRes, frameworkResources, themeName, isProjectTheme);
if (target instanceof CompatibilityRenderTarget) {
int apiLevel = target.getVersion().getFeatureLevel();
if (apiLevel >= 21) {
resolver.setDeviceDefaults("Material");
} else if (apiLevel >= 14) {
resolver.setDeviceDefaults("Holo");
} else {
resolver.setDeviceDefaults(ResourceResolver.LEGACY_THEME);
}
}
myResolverMap.put(resolverKey, resolver);
}
return resolver;
}
use of com.android.ide.common.resources.ResourceRepository in project android by JetBrains.
the class AndroidColorAnnotator method findResourceValue.
/** Looks up the resource item of the given type and name for the given configuration, if any */
@Nullable
private static ResourceValue findResourceValue(ResourceType type, String name, boolean isFramework, Module module, Configuration configuration) {
if (isFramework) {
ResourceRepository frameworkResources = configuration.getFrameworkResources();
if (frameworkResources == null) {
return null;
}
if (!frameworkResources.hasResourceItem(type, name)) {
return null;
}
ResourceItem item = frameworkResources.getResourceItem(type, name);
return item.getResourceValue(type, configuration.getFullConfig(), false);
} else {
LocalResourceRepository appResources = AppResourceRepository.getAppResources(module, true);
if (appResources == null) {
return null;
}
if (!appResources.hasResourceItem(type, name)) {
return null;
}
return appResources.getConfiguredValue(type, name, configuration.getFullConfig());
}
}
use of com.android.ide.common.resources.ResourceRepository in project android by JetBrains.
the class ResourceDrawablePanel method updateResolutionChain.
private void updateResolutionChain(@NotNull ResourceChooserItem item) {
// Resource resolver
myResolvedPanel.removeAll();
ResourceValue resourceValue = item.getResourceValue();
Configuration configuration = myDialog.getConfiguration();
ResourceRepository frameworkResources = configuration.getFrameworkResources();
if (frameworkResources != null) {
AppResourceRepository appResources = AppResourceRepository.getAppResources(myDialog.geFacet(), true);
ResourceItemResolver resolver = new ResourceItemResolver(configuration.getFullConfig(), frameworkResources, appResources, null);
List<ResourceValue> lookupChain = Lists.newArrayList();
lookupChain.add(resourceValue);
resolver.setLookupChainList(lookupChain);
resolver.resolveResValue(resourceValue);
String prev = null;
int indent = 0;
if (lookupChain.size() >= 2) {
for (ResourceValue element : lookupChain) {
if (element == null) {
continue;
}
String value = element.getValue();
if (value == null) {
continue;
}
String text = value;
if (text.equals(prev)) {
continue;
}
// Strip paths
if (!(text.startsWith(PREFIX_THEME_REF) || text.startsWith(PREFIX_RESOURCE_REF))) {
if (indent == 0) {
break;
}
int end = Math.max(text.lastIndexOf('/'), text.lastIndexOf('\\'));
if (end != -1) {
text = text.substring(end + 1);
}
}
if (indent > 0) {
// 21D2: Rightwards arrow
text = "⇒ " + text;
}
JBLabel label = new JBLabel(text);
label.setBorder(IdeBorderFactory.createEmptyBorder(0, JBUI.scale(indent * 12), 0, 0));
myResolvedPanel.add(label);
indent++;
prev = value;
}
}
}
}
use of com.android.ide.common.resources.ResourceRepository in project android by JetBrains.
the class StateListPicker method doValidate.
/**
* Returns a {@link ValidationInfo} in the case one of the state list state has a value that does not resolve to a valid resource,
* or a value that is a private framework value. or if one of the state list component requires an API level higher than minApi.
*/
@Nullable
public /*if there is no error*/
ValidationInfo doValidate(int minApi) {
IAndroidTarget target = myConfiguration.getRealTarget();
assert target != null;
final AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, myModule);
assert androidTargetData != null;
ResourceRepository frameworkResources = myConfiguration.getFrameworkResources();
assert frameworkResources != null;
for (StateComponent component : myStateComponents) {
ValidationInfo error = component.doValidate(minApi, androidTargetData);
if (error != null) {
return error;
}
}
return null;
}
Aggregations