use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class ThemeResolverTest method testFrameworkThemeRead.
/*
* The test SDK only includes some resources. It only includes a few incomplete styles.
*/
public void testFrameworkThemeRead() {
VirtualFile myLayout = myFixture.copyFileToProject("xmlpull/layout.xml", "res/layout/layout1.xml");
Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myLayout);
ThemeResolver themeResolver = new ThemeResolver(configuration);
// It's system theme and we're not specifying namespace so it will fail.
assertNull(themeResolver.getTheme("Theme.Holo.Light"));
ConfiguredThemeEditorStyle theme = themeResolver.getTheme("android:Theme.Holo.Light");
assertEquals("Theme.Holo.Light", theme.getName());
// Only framework themes.
assertEquals(themeResolver.getThemesCount(), themeResolver.getFrameworkThemes().size());
assertEmpty(themeResolver.getLocalThemes());
assertNull("Theme resolver shouldn't resolve styles", themeResolver.getTheme("android:TextAppearance"));
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class ThemeResolverTest method testConfigurationUpdate.
/** Check that, after a configuration update, the resolver updates the list of themes */
public void testConfigurationUpdate() {
myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v17.xml", "res/values-v17/styles.xml");
myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v19.xml", "res/values-v19/styles.xml");
VirtualFile file = myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v20.xml", "res/values-v20/styles.xml");
ConfigurationManager configurationManager = myFacet.getConfigurationManager();
Configuration configuration = configurationManager.getConfiguration(file);
ThemeEditorContext context = new ThemeEditorContext(configuration);
ThemeResolver resolver = context.getThemeResolver();
assertNotNull(resolver.getTheme("V20OnlyTheme"));
assertNotNull(resolver.getTheme("V19OnlyTheme"));
assertNotNull(resolver.getTheme("V17OnlyTheme"));
// Set API level 17 and check that only the V17 theme can be resolved
//noinspection ConstantConditions
configuration.setTarget(new CompatibilityRenderTarget(configurationManager.getHighestApiTarget(), 17, null));
context = new ThemeEditorContext(configuration);
resolver = context.getThemeResolver();
assertNull(resolver.getTheme("V20OnlyTheme"));
assertNull(resolver.getTheme("V19OnlyTheme"));
assertNotNull(resolver.getTheme("V17OnlyTheme"));
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class NewStyleDialogTest method testGetStyleParentName.
public void testGetStyleParentName() {
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);
ThemeEditorContext context = new ThemeEditorContext(configuration);
String styleName = "android:TextAppearance.Medium";
NewStyleDialog dialog = new NewStyleDialog(false, context, styleName, "textAppearance", null);
assertEquals(styleName, dialog.getStyleParentName());
assertEquals("TextAppearance.Medium.textAppearance", dialog.getStyleName());
// Calling .doCancelAction to dispose dialog object and avoid memory leaks
dialog.doCancelAction();
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class FileChooserActionListener method openDeviceChoiceDialog.
/**
* Open a dialog asking to choose a device whose dimensions match those of the image
*/
private static void openDeviceChoiceDialog(VirtualFile virtualFile, @NotNull NlProperty fileProperty, @Nullable NlProperty cropProperty) {
if (virtualFile.exists() && !virtualFile.isDirectory()) {
try {
final Image probe = PixelProbe.probe(virtualFile.getInputStream());
final BufferedImage image = probe.getMergedImage();
if (image == null) {
return;
}
final NlModel model = fileProperty.getModel();
final Configuration configuration = model.getConfiguration();
final Device device = configuration.getDevice();
if (device == null) {
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
final DeviceSelectionPopup deviceSelectionPopup = new DeviceSelectionPopup(model.getProject(), configuration, image);
if (deviceSelectionPopup.showAndGet()) {
saveMockupFile(virtualFile, fileProperty, cropProperty);
}
});
} catch (IOException e1) {
LOGGER.warn("Unable to open this file\n" + e1.getMessage());
}
}
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class MockupTest method testGetBounds_Normal_Position.
public void testGetBounds_Normal_Position() {
final NlModel model = createModel1Mockup(MOCKUP_PSD, "0 0 -1 -1 10 10 120 50");
DesignSurface mockSurface = mock(DesignSurface.class);
when(mockSurface.getScale()).thenReturn(1.0);
Configuration configuration = mock(Configuration.class);
when(configuration.getDensity()).thenReturn(Density.DPI_280);
ScreenView screenView = mock(ScreenView.class);
when(screenView.getX()).thenReturn(0);
when(screenView.getY()).thenReturn(0);
when(screenView.getSize()).thenReturn(new Dimension(1000, 2000));
when(screenView.getSize(anyObject())).thenReturn(new Dimension(1000, 2000));
when(screenView.getScale()).thenReturn(2.);
when(screenView.getConfiguration()).thenReturn(configuration);
final Mockup mockup = Mockup.create(model.getComponents().get(0));
assertNotNull(mockup);
assertEquals(new Rectangle(10, 10, 120, 50), mockup.getBounds());
final Rectangle swingBounds = mockup.getScreenBounds(screenView);
assertEquals(Coordinates.getSwingXDip(screenView, 10), swingBounds.x, 2.);
assertEquals(Coordinates.getSwingXDip(screenView, 10), swingBounds.y, 2.);
assertEquals(Coordinates.getSwingDimensionDip(screenView, 110), swingBounds.width, 2.);
assertEquals(Coordinates.getSwingDimensionDip(screenView, 40), swingBounds.height, 2.);
}
Aggregations