Search in sources :

Example 76 with Configuration

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();
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) State(com.android.sdklib.devices.State) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with Configuration

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;
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver)

Example 78 with Configuration

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 "";
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with Configuration

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);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Example 80 with Configuration

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");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) IAndroidTarget(com.android.sdklib.IAndroidTarget) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Aggregations

Configuration (com.android.tools.idea.configurations.Configuration)95 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)23 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)21 ResourceResolver (com.android.ide.common.resources.ResourceResolver)16 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)14 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 Module (com.intellij.openapi.module.Module)9 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 Device (com.android.sdklib.devices.Device)7 State (com.android.sdklib.devices.State)7 NotNull (org.jetbrains.annotations.NotNull)7 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)6 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)5 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)4 PsiFile (com.intellij.psi.PsiFile)4 ResourceFolderType (com.android.resources.ResourceFolderType)3