use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class NlUsageTrackerManager method getState.
/**
* Generates a {@link LayoutEditorState} containing all the state of the layout editor from the given surface.
*/
@NotNull
static LayoutEditorState getState(@Nullable DesignSurface surface) {
LayoutEditorState.Builder builder = LayoutEditorState.newBuilder();
if (surface == null) {
return builder.build();
}
builder.setMode(surface.isPreviewSurface() ? LayoutEditorState.Mode.PREVIEW_MODE : LayoutEditorState.Mode.DESIGN_MODE);
switch(surface.getLayoutType()) {
case DRAWABLE:
builder.setType(LayoutEditorState.Type.DRAWABLE);
break;
case LAYOUT:
builder.setType(LayoutEditorState.Type.LAYOUT);
break;
case MENU:
builder.setType(LayoutEditorState.Type.MENU);
break;
case PREFERENCE_SCREEN:
builder.setType(LayoutEditorState.Type.PREFERENCE_SCREEN);
break;
case UNKNOWN:
}
double scale = surface.getScale();
if (SystemInfo.isMac && UIUtil.isRetina()) {
scale *= 2;
}
Configuration configuration = surface.getConfiguration();
if (configuration != null) {
State deviceState = configuration.getDeviceState();
if (deviceState != null) {
switch(deviceState.getOrientation()) {
case PORTRAIT:
builder.setConfigOrientation(LayoutEditorState.Orientation.PORTRAIT);
break;
case LANDSCAPE:
builder.setConfigOrientation(LayoutEditorState.Orientation.LANDSCAPE);
break;
case SQUARE:
}
}
if (configuration.getTarget() != null) {
builder.setConfigApiLevel(configuration.getTarget().getVersion().getApiString());
}
}
if (scale >= 0) {
builder.setConfigZoomLevel((int) (scale * 100));
}
switch(surface.getScreenMode()) {
case SCREEN_ONLY:
builder.setSurfaces(LayoutEditorState.Surfaces.SCREEN_SURFACE);
break;
case BLUEPRINT_ONLY:
builder.setSurfaces(LayoutEditorState.Surfaces.BLUEPRINT_SURFACE);
break;
case BOTH:
builder.setSurfaces(LayoutEditorState.Surfaces.BOTH);
break;
}
return builder.build();
}
use of com.android.tools.idea.configurations.Configuration 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.tools.idea.configurations.Configuration 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.tools.idea.configurations.Configuration in project android by JetBrains.
the class ThemeEditorUtilsTest method testGetDisplayHtml.
public void testGetDisplayHtml() {
VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_1.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/attrs.xml", "res/values/attrs.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle theme = themeResolver.getTheme("AppTheme");
assertNotNull(theme);
Collection<EditedStyleItem> values = ThemeEditorTestUtils.getStyleLocalValues(theme);
assertEquals(7, values.size());
for (EditedStyleItem item : values) {
String displayHtml = ThemeEditorUtils.getDisplayHtml(item);
if ("myDeprecated".equals(item.getName())) {
assertEquals("<html><body><strike>myDeprecated</strike></body></html>", displayHtml);
} else {
assertEquals(item.getName(), displayHtml);
}
}
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class ThemeEditorUtilsTest method testGenerateToolTipText.
public void testGenerateToolTipText() throws IOException {
if (SystemInfo.isWindows) {
// Do not run tests on Windows (see http://b.android.com/222904)
return;
}
VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_1.xml", "res/values/styles.xml");
myFixture.copyFileToProject("themeEditor/attrs.xml", "res/values/attrs.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
IAndroidTarget androidTarget = configuration.getTarget();
assertNotNull(androidTarget);
sdkPlatformPath = androidTarget.getLocation();
if (LayoutLibraryLoader.USE_SDK_LAYOUTLIB) {
if (!sdkPlatformPath.endsWith("/"))
sdkPlatformPath += "/";
sdkPlatformPath += "platforms/android-" + androidTarget.getVersion().getApiString();
}
sdkPlatformPath = Files.simplifyPath(sdkPlatformPath);
ThemeResolver themeResolver = new ThemeResolver(configuration);
ConfiguredThemeEditorStyle theme = themeResolver.getTheme("AppTheme");
assertNotNull(theme);
Collection<EditedStyleItem> values = ThemeEditorTestUtils.getStyleLocalValues(theme);
assertEquals(7, values.size());
configuration.setTheme("AppTheme");
for (EditedStyleItem item : values) {
String doc = ThemeEditorUtils.generateToolTipText(item.getSelectedValue(), myModule, configuration);
compareWithGoldenFile(doc, myFixture.getTestDataPath() + "/themeEditor/tooltipDocAns/" + item.getName() + ".ans");
}
}
Aggregations