use of com.android.ide.common.resources.ResourceResolver in project android by JetBrains.
the class ConstraintUtilities method getDpValue.
/**
* Return a dp value correctly resolved. This is only intended for generic
* dimensions (number + unit). Do not use this if the string can contain
* wrap_content or match_parent. See {@link #getLayoutDimensionDpValue(NlComponent, String)}.
*
* @param component the component we are looking at
* @param value the attribute value we want to parse
* @return the value of the attribute in Dp, or zero if impossible to resolve
*/
public static int getDpValue(@NotNull NlComponent component, String value) {
if (value != null) {
Configuration configuration = component.getModel().getConfiguration();
ResourceResolver resourceResolver = configuration.getResourceResolver();
if (resourceResolver != null) {
Integer px = ViewEditor.resolveDimensionPixelSize(resourceResolver, value, configuration);
return px == null ? 0 : (int) (0.5f + px / (configuration.getDensity().getDpiValue() / 160.0f));
}
}
return 0;
}
use of com.android.ide.common.resources.ResourceResolver in project android by JetBrains.
the class ConstraintUtilities method resolveStringResource.
@NotNull
static String resolveStringResource(@NotNull NlComponent component, @NotNull String text) {
Configuration configuration = component.getModel().getConfiguration();
ResourceResolver resourceResolver = configuration.getResourceResolver();
if (resourceResolver != null) {
return resolveStringValue(resourceResolver, text);
}
return "";
}
use of com.android.ide.common.resources.ResourceResolver in project android by JetBrains.
the class SceneKeepDimensTest method setFakeResource.
private void setFakeResource(String dimension, String value) {
Configuration configuration = Mockito.mock(Configuration.class);
ResourceResolver resolver = Mockito.mock(ResourceResolver.class);
ResourceValue resourceValue = Mockito.mock(ResourceValue.class);
when(configuration.getResourceResolver()).thenReturn(resolver);
when(configuration.getDensity()).thenReturn(Density.MEDIUM);
when(resolver.findResValue(dimension, false)).thenReturn(resourceValue);
when(resolver.resolveResValue(resourceValue)).thenReturn(resourceValue);
when(resourceValue.getValue()).thenReturn(value);
((SyncNlModel) myModel).setConfiguration(configuration);
}
use of com.android.ide.common.resources.ResourceResolver in project android by JetBrains.
the class IncludeReferenceTest method testGetSet.
public void testGetSet() {
VirtualFile included = myFixture.copyFileToProject("designer/included.xml", "res/layout/included.xml");
assertNotNull(included);
VirtualFile includer = myFixture.copyFileToProject("designer/included.xml", "res/layout/includer.xml");
assertNotNull(includer);
XmlFile psiFile = (XmlFile) PsiManager.getInstance(getProject()).findFile(included);
assertNotNull(psiFile);
assertEquals("@layout/includer", IncludeReference.getIncludingLayout(psiFile));
ConfigurationManager manager = myFacet.getConfigurationManager();
Configuration configuration = manager.getConfiguration(included);
ResourceResolver resourceResolver = configuration.getResourceResolver();
assertNotNull(resourceResolver);
IncludeReference reference = IncludeReference.get(myModule, psiFile, resourceResolver);
assertEquals("includer.xml", reference.getFromDisplayName());
assertEquals("includer", reference.getFromResourceName());
assertEquals("@layout/includer", reference.getFromResourceUrl());
assertEquals(reference.getFromFile(), includer);
assertEquals(reference.getToFile(), included);
IncludeReference.setIncludingLayout(getProject(), psiFile, null);
assertEquals(IncludeReference.NONE, IncludeReference.get(myModule, psiFile, resourceResolver));
VirtualFile other = myFixture.copyFileToProject("xmlpull/designtime.xml", "res/layout-land/designtime.xml");
assertNotNull(other);
IncludeReference.setIncludingLayout(getProject(), psiFile, "@layout/designtime");
assertEquals("@layout/designtime", IncludeReference.getIncludingLayout(psiFile));
}
use of com.android.ide.common.resources.ResourceResolver in project android by JetBrains.
the class TextAppearanceEnumSupport method createFromResolvedValue.
@Override
@NotNull
protected ValueWithDisplayString createFromResolvedValue(@NotNull String resolvedValue, @Nullable String value, @Nullable String hint) {
if (value != null && !value.startsWith(STYLE_RESOURCE_PREFIX) && !value.startsWith(ANDROID_STYLE_RESOURCE_PREFIX) && !value.startsWith(ATTR_REF_PREFIX)) {
ResourceResolver resolver = myProperty.getResolver();
ResourceValue resource = resolver.getStyle(value, true);
if (resource == null) {
resource = resolver.getStyle(value, false);
}
if (resource == null && !value.startsWith(TEXT_APPEARANCE)) {
resource = resolver.getStyle(TEXT_APPEARANCE + "." + value, true);
}
if (resource == null && !value.startsWith(TEXT_APPEARANCE)) {
resource = resolver.getStyle(TEXT_APPEARANCE + "." + value, false);
}
if (resource == null) {
value = STYLE_RESOURCE_PREFIX + value;
} else {
value = (resource.isFramework() ? ANDROID_STYLE_RESOURCE_PREFIX : STYLE_RESOURCE_PREFIX) + resource.getName();
}
}
String display = resolvedValue;
Matcher matcher = TEXT_APPEARANCE_PATTERN.matcher(resolvedValue);
if (matcher.matches()) {
display = matcher.group(5);
if (display == null) {
display = TEXT_APPEARANCE;
}
} else {
display = StringUtil.trimStart(display, ANDROID_STYLE_RESOURCE_PREFIX);
display = StringUtil.trimStart(display, STYLE_RESOURCE_PREFIX);
}
return new ValueWithDisplayString(display, value, generateHint(display, value));
}
Aggregations