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();
}
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();
}
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();
}
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);
}
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());
}
Aggregations