Search in sources :

Example 1 with AssetStudioAssetGenerator

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);
        }
    });
}
Also used : AssetStudioAssetGenerator(com.android.tools.idea.npw.AssetStudioAssetGenerator) Document(javax.swing.text.Document) ActionListener(java.awt.event.ActionListener) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AssetStudioAssetGenerator

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);
    }
}
Also used : TemplateWizardState(com.android.tools.idea.wizard.template.TemplateWizardState) AssetStudioAssetGenerator(com.android.tools.idea.npw.AssetStudioAssetGenerator) Map(java.util.Map)

Example 3 with AssetStudioAssetGenerator

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);
}
Also used : AssetStudioAssetGenerator(com.android.tools.idea.npw.AssetStudioAssetGenerator)

Example 4 with AssetStudioAssetGenerator

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);
    }
}
Also used : AssetStudioAssetGenerator(com.android.tools.idea.npw.AssetStudioAssetGenerator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Aggregations

AssetStudioAssetGenerator (com.android.tools.idea.npw.AssetStudioAssetGenerator)4 File (java.io.File)2 TemplateWizardState (com.android.tools.idea.wizard.template.TemplateWizardState)1 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ActionListener (java.awt.event.ActionListener)1 Map (java.util.Map)1 Document (javax.swing.text.Document)1 Nullable (org.jetbrains.annotations.Nullable)1