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_frameworks_base by crdroidandroid.
the class Main method getSessionParams.
/**
* Uses Theme.Material and Target sdk version as 22.
*/
private SessionParams getSessionParams(LayoutPullParser layoutParser, ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback, String themeName, boolean isProjectTheme, RenderingMode renderingMode, int targetSdk) {
FolderConfiguration config = configGenerator.getFolderConfig();
ResourceResolver resourceResolver = ResourceResolver.create(sProjectResources.getConfiguredResources(config), sFrameworkRepo.getConfiguredResources(config), themeName, isProjectTheme);
SessionParams sessionParams = new SessionParams(layoutParser, renderingMode, null, /*used for caching*/
configGenerator.getHardwareConfig(), resourceResolver, layoutLibCallback, 0, targetSdk, getLayoutLog());
sessionParams.setFlag(RenderParamsFlags.FLAG_DO_NOT_RENDER_ON_CREATE, true);
return sessionParams;
}
Aggregations