Search in sources :

Example 6 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class LayoutParamsManagerTest method testSetAttribute.

public void testSetAttribute() {
    DefaultValues layoutParams = new DefaultValues(0, 0);
    Configuration configurationMock = mock(Configuration.class);
    when(configurationMock.getResourceResolver()).thenReturn(null);
    when(configurationMock.getDensity()).thenReturn(Density.HIGH);
    NlModel nlModelMock = mock(NlModel.class);
    when(nlModelMock.getConfiguration()).thenReturn(configurationMock);
    when(nlModelMock.getModule()).thenReturn(myModule);
    assertThat(LayoutParamsManager.setAttribute(layoutParams, "intAttribute", "123456", nlModelMock)).isTrue();
    assertThat(layoutParams.intAttribute).isEqualTo(123456);
    // Incompatible types
    assertThat(LayoutParamsManager.setAttribute(layoutParams, "intAttribute", "true", nlModelMock)).isFalse();
    assertThat(layoutParams.intAttribute).isEqualTo(123456);
    // Restore default value
    assertThat(LayoutParamsManager.setAttribute(layoutParams, "intAttribute", null, nlModelMock)).isTrue();
    assertThat(layoutParams.intAttribute).isEqualTo(-50);
    assertThat(LayoutParamsManager.setAttribute(layoutParams, "stringAttribute", "Hello world", nlModelMock)).isTrue();
    assertThat(layoutParams.stringAttribute).isEqualTo("Hello world");
    // Restore default value
    assertThat(LayoutParamsManager.setAttribute(layoutParams, "stringAttribute", null, nlModelMock)).isTrue();
    assertThat(layoutParams.stringAttribute).isEqualTo("content");
    // Check dimension conversions
    assertThat(LayoutParamsManager.setAttribute(layoutParams, "width", "123dp", nlModelMock)).isTrue();
    assertThat(layoutParams.width).isEqualTo(185);
    assertThat(LayoutParamsManager.setAttribute(layoutParams, "width", "123px", nlModelMock)).isTrue();
    assertThat(layoutParams.width).isEqualTo(123);
    // Restore default value
    assertThat(LayoutParamsManager.setAttribute(layoutParams, "width", null, nlModelMock)).isTrue();
    assertThat(layoutParams.width).isEqualTo(0);
    assertThat(LayoutParamsManager.setAttribute(layoutParams, "notExistent", null, nlModelMock)).isFalse();
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration)

Example 7 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class SaveScreenshotAction method getDeviceName.

@Nullable
private String getDeviceName() {
    Configuration config = mySurface.getConfiguration();
    if (config == null) {
        return null;
    }
    Device device = config.getDevice();
    if (device == null) {
        return null;
    }
    return device.getDisplayName();
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) Device(com.android.sdklib.devices.Device) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class NlPreviewImagePanel method setDesignSurface.

public void setDesignSurface(@Nullable DesignSurface designSurface) {
    Module oldModule = null;
    Configuration oldConfiguration = myDesignSurface != null ? myDesignSurface.getConfiguration() : null;
    if (oldConfiguration != null) {
        oldModule = oldConfiguration.getModule();
        oldConfiguration.removeListener(myConfigurationListener);
    }
    if (myDesignSurface != null) {
        myDesignSurface.removePanZoomListener(myZoomListener);
    }
    myDesignSurface = designSurface;
    Module newModule = null;
    Configuration newConfiguration = myDesignSurface != null ? myDesignSurface.getConfiguration() : null;
    if (newConfiguration != null) {
        newModule = newConfiguration.getModule();
        newConfiguration.addListener(myConfigurationListener);
    }
    if (myDesignSurface != null) {
        myDesignSurface.addPanZoomListener(myZoomListener);
    }
    if (newModule != oldModule) {
        ResourceNotificationManager manager = ResourceNotificationManager.getInstance(myDependencyManager.getProject());
        AndroidFacet oldFacet = oldModule != null ? AndroidFacet.getInstance(oldModule) : null;
        if (oldFacet != null) {
            manager.removeListener(myResourceChangeListener, oldFacet, null, null);
        }
        AndroidFacet newFacet = newModule != null ? AndroidFacet.getInstance(newModule) : null;
        if (newFacet != null) {
            manager.addListener(myResourceChangeListener, newFacet, null, null);
        }
    }
    myImage = null;
    myPreviewGenerationDone = false;
    setTransferHandler(designSurface != null ? new ItemTransferHandler(myDesignSurface, this::getItem, myIconPreviewFactory) : null);
    invalidateUI();
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) ResourceNotificationManager(com.android.tools.idea.res.ResourceNotificationManager) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 9 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class NlOldPalettePanel method setColors.

private void setColors() {
    Color background;
    Color foreground;
    Configuration configuration = null;
    if (myDesignSurface != null) {
        configuration = myDesignSurface.getConfiguration();
    }
    ResourceResolver resolver = null;
    if (configuration != null) {
        resolver = configuration.getResourceResolver();
    }
    if (resolver == null || myMode != Mode.PREVIEW) {
        foreground = UIUtil.getTreeForeground();
        background = UIUtil.getTreeBackground();
    } else {
        ResourceValue windowBackground = resolver.findItemInTheme("colorBackground", true);
        background = ResourceHelper.resolveColor(resolver, windowBackground, myProject);
        if (background == null) {
            background = UIUtil.getTreeBackground();
        }
        ResourceValue textForeground = resolver.findItemInTheme("colorForeground", true);
        foreground = ResourceHelper.resolveColor(resolver, textForeground, myProject);
        if (foreground == null) {
            foreground = UIUtil.getTreeForeground();
        }
        // Ensure the colors can be differentiated:
        if (Math.abs(ImageUtils.getBrightness(background.getRGB()) - ImageUtils.getBrightness(foreground.getRGB())) < 64) {
            if (ImageUtils.getBrightness(background.getRGB()) < 128) {
                foreground = JBColor.WHITE;
            } else {
                foreground = JBColor.BLACK;
            }
        }
    }
    myPaletteTree.setBackground(background);
    myPaletteTree.setForeground(foreground);
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) JBColor(com.intellij.ui.JBColor) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ResourceValue(com.android.ide.common.rendering.api.ResourceValue)

Example 10 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class EditedStyleItem method isPublicAttribute.

public boolean isPublicAttribute() {
    if (!getSelectedValue().isFrameworkAttr()) {
        return true;
    }
    Configuration configuration = mySourceTheme.getConfiguration();
    IAndroidTarget target = configuration.getRealTarget();
    if (target == null) {
        LOG.error("Unable to get IAndroidTarget.");
        return false;
    }
    AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, configuration.getModule());
    if (androidTargetData == null) {
        LOG.error("Unable to get AndroidTargetData.");
        return false;
    }
    return androidTargetData.isResourcePublic(ResourceType.ATTR.getName(), getName());
}
Also used : FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData)

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