use of com.android.tools.idea.npw.AssetStudioAssetGenerator in project android by JetBrains.
the class IconStep method init.
@Override
public void init() {
super.init();
myAssetGenerator = new AssetStudioAssetGenerator(new ScopedStateStoreAdapter(myState));
myState.put(ATTR_ASSET_TYPE, AssetType.LAUNCHER);
String relativeTemplatePath = FileUtil.join(Template.CATEGORY_PROJECTS, WizardConstants.MODULE_TEMPLATE_NAME, "root", "res", "mipmap-xhdpi", "ic_launcher.png");
myState.put(ATTR_IMAGE_PATH, new File(TemplateManager.getTemplateRootFolder(), relativeTemplatePath).getAbsolutePath());
register(ATTR_OUTPUT_FOLDER, mySourceSetComboBox);
register(ATTR_IMAGE_PATH, myImageFile);
register(ATTR_TEXT, myText);
register(ATTR_PADDING, myPaddingSlider);
register(ATTR_PADDING, myPaddingTextField, new ComponentBinding<Integer, JTextField>() {
@Override
public void setValue(@Nullable Integer newValue, @NotNull JTextField component) {
component.setText(newValue == null ? "" : String.valueOf(newValue));
}
@Nullable
@Override
public Integer getValue(@NotNull JTextField component) {
try {
// so the user already receives enough feedback.
return Math.max(0, Math.min(Integer.parseInt(component.getText()), 100));
} catch (NumberFormatException e) {
return 0;
}
}
@Override
public void addActionListener(@NotNull ActionListener listener, @NotNull JTextField component) {
component.addActionListener(listener);
}
@Nullable
@Override
public Document getDocument(@NotNull JTextField component) {
return component.getDocument();
}
});
register(ATTR_TRIM, myTrimBlankSpace);
register(ATTR_FONT, myFontFamily);
register(ATTR_SOURCE_TYPE, ImmutableMap.of(myImageRadioButton, SourceType.IMAGE, myClipartRadioButton, SourceType.CLIPART, myTextRadioButton, SourceType.TEXT));
register(ATTR_FOREGROUND_COLOR, myForegroundColor);
register(ATTR_BACKGROUND_COLOR, myBackgroundColor);
register(ATTR_ASSET_NAME, myResourceNameField);
register(ATTR_CLIPART_NAME, myChooseClipart, new ComponentBinding<String, JButton>() {
@Override
public void setValue(@Nullable String newValue, @NotNull JButton component) {
component.setIcon(getClipartIcon(newValue));
component.setText(newValue);
}
});
}
use of com.android.tools.idea.npw.AssetStudioAssetGenerator in project android by JetBrains.
the class AssetStudioAssetGeneratorTest method assertThemeUsed.
private static void assertThemeUsed(ActionBarIconGenerator.Theme theme, @Nullable Color color) throws Exception {
ArgumentCaptor<ActionBarIconGenerator.ActionBarOptions> argument = ArgumentCaptor.forClass(ActionBarIconGenerator.ActionBarOptions.class);
ActionBarIconGenerator generator = mock(ActionBarIconGenerator.class);
TemplateWizardState state = new TemplateWizardState();
AssetStudioAssetGenerator studioGenerator = new AssetStudioAssetGenerator(new TemplateWizardContextAdapter(state), generator, null, null, null);
pickImage(state);
state.put(ATTR_ASSET_TYPE, AssetType.ACTIONBAR.name());
state.put(ATTR_ASSET_THEME, theme.name());
state.put(ATTR_FOREGROUND_COLOR, color);
studioGenerator.generateImages(true);
verify(generator, times(1)).generate(isNull(String.class), any(Map.class), eq(studioGenerator), argument.capture(), anyString());
assertEquals(theme, argument.getValue().theme);
if (color != null && theme.equals(ActionBarIconGenerator.Theme.CUSTOM)) {
assertEquals(color.getRGB(), argument.getValue().customThemeColor);
}
}
use of com.android.tools.idea.npw.AssetStudioAssetGenerator in project android by JetBrains.
the class AssetStudioAssetGeneratorTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
myNotificationIconGenerator = mock(NotificationIconGenerator.class);
myActionBarIconGenerator = mock(ActionBarIconGenerator.class);
myLauncherIconGenerator = mock(LauncherIconGenerator.class);
myVectorIconGenerator = mock(VectorIconGenerator.class);
myAssetGenerator = new AssetStudioAssetGenerator(new TemplateWizardContextAdapter(myState), myActionBarIconGenerator, myNotificationIconGenerator, myLauncherIconGenerator, myVectorIconGenerator);
pickImage(myState);
myState.put(ATTR_ASSET_NAME, ASSET_NAME);
}
use of com.android.tools.idea.npw.AssetStudioAssetGenerator in project android by JetBrains.
the class TemplateTest method createProject.
private void createProject(@NotNull IdeaProjectTestFixture myFixture, @NotNull NewProjectWizardState projectWizardState, boolean syncModel) throws Exception {
ApplicationManager.getApplication().runWriteAction(() -> {
AssetStudioAssetGenerator assetGenerator = new AssetStudioAssetGenerator(projectWizardState);
createProject(projectWizardState, myFixture.getProject(), assetGenerator);
FileDocumentManager.getInstance().saveAllDocuments();
});
// Sync model
if (syncModel) {
String projectName = projectWizardState.getString(ATTR_MODULE_NAME);
File projectRoot = new File(projectWizardState.getString(ATTR_PROJECT_LOCATION));
assertEquals(projectRoot, virtualToIoFile(myFixture.getProject().getBaseDir()));
importProject(projectName, projectRoot, null);
}
}
Aggregations