@Override public void setVisible(boolean visible) { super.setVisible(visible); // We update the image selection here rather than in {@link #createControl} because // that method is called when the wizard is created, and we want to wait until the // user has chosen a project before attempting to look up the right default image to use if (visible) { // Clear out old previews - important if the user goes back to page one, changes // asset type and steps into page 2 - at that point we arrive here and we might // display the old previews for a brief period until the preview delay timer expires. for (Control c : mPreviewArea.getChildren()) { c.dispose(); } mPreviewArea.layout(true); // Update asset type configuration: will show/hide parameter controls depending // on which asset type is chosen CreateAssetSetWizard wizard = (CreateAssetSetWizard) getWizard(); AssetType type = wizard.getAssetType(); assert type != null; configureAssetType(type); // Initial image - use the most recently used image, or the default launcher // icon created in our default projects, if there if (sImagePath == null) { IProject project = wizard.getProject(); if (project != null) { IResource icon = project.findMember("res/drawable-hdpi/icon.png"); // $NON-NLS-1$ if (icon != null) { IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); IPath workspacePath = workspace.getLocation(); sImagePath = workspacePath.append(icon.getFullPath()).toOSString(); } } } if (sImagePath != null) { mImagePathText.setText(sImagePath); } validatePage(); requestUpdatePreview(true /*quickly*/); if (mTextRadio.getSelection()) { mText.setFocus(); } } }
Map<String, Map<String, BufferedImage>> generateImages(boolean previewOnly) { // Map of ids to images: Preserve insertion order (the densities) Map<String, Map<String, BufferedImage>> categoryMap = new LinkedHashMap<String, Map<String, BufferedImage>>(); CreateAssetSetWizard wizard = (CreateAssetSetWizard) getWizard(); AssetType type = wizard.getAssetType(); boolean crop = mTrimCheckBox.getSelection(); BufferedImage sourceImage = null; if (mImageRadio.getSelection()) { // Load the image // TODO: Only do this when the source image type is image String path = mImagePathText.getText().trim(); if (path.length() == 0) { setErrorMessage("Enter a filename"); return Collections.emptyMap(); } File file = new File(path); if (!file.exists()) { setErrorMessage(String.format("%1$s does not exist", file.getPath())); return Collections.emptyMap(); } setErrorMessage(null); sourceImage = getImage(path, false); if (sourceImage != null) { if (crop) { sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB); } int padding = getPadding(); if (padding != 0) { sourceImage = Util.paddedImage(sourceImage, padding); } } } else if (mTextRadio.getSelection()) { String text = mText.getText(); TextRenderUtil.Options options = new TextRenderUtil.Options(); options.font = getSelectedFont(); int color; if (type.needsColors()) { color = 0xFF000000 | (mFgColor.red << 16) | (mFgColor.green << 8) | mFgColor.blue; } else { color = 0xFFFFFFFF; } options.foregroundColor = color; sourceImage = TextRenderUtil.renderTextImage(text, getPadding(), options); if (crop) { sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB); } int padding = getPadding(); if (padding != 0) { sourceImage = Util.paddedImage(sourceImage, padding); } } else { assert mClipartRadio.getSelection(); assert mSelectedClipart != null; try { sourceImage = GraphicGenerator.getClipartImage(mSelectedClipart); if (crop) { sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB); } if (type.needsColors()) { int color = 0xFF000000 | (mFgColor.red << 16) | (mFgColor.green << 8) | mFgColor.blue; Paint paint = new java.awt.Color(color); sourceImage = Util.filledImage(sourceImage, paint); } int padding = getPadding(); if (padding != 0) { sourceImage = Util.paddedImage(sourceImage, padding); } } catch (IOException e) { AdtPlugin.log(e, null); return categoryMap; } } GraphicGenerator generator = null; GraphicGenerator.Options options = null; switch (type) { case LAUNCHER: { generator = new LauncherIconGenerator(); LauncherIconGenerator.LauncherOptions launcherOptions = new LauncherIconGenerator.LauncherOptions(); launcherOptions.shape = mCircleButton.getSelection() ? GraphicGenerator.Shape.CIRCLE : GraphicGenerator.Shape.SQUARE; launcherOptions.crop = mCropRadio.getSelection(); if (SUPPORT_LAUNCHER_ICON_TYPES) { launcherOptions.style = mFancyRadio.getSelection() ? GraphicGenerator.Style.FANCY : mGlossyRadio.getSelection() ? GraphicGenerator.Style.GLOSSY : GraphicGenerator.Style.SIMPLE; } else { launcherOptions.style = GraphicGenerator.Style.SIMPLE; } int color = (mBgColor.red << 16) | (mBgColor.green << 8) | mBgColor.blue; launcherOptions.backgroundColor = color; // Flag which tells the generator iterator to include a web graphic launcherOptions.isWebGraphic = !previewOnly; options = launcherOptions; break; } case MENU: generator = new MenuIconGenerator(); options = new GraphicGenerator.Options(); break; case ACTIONBAR: { generator = new ActionBarIconGenerator(); ActionBarIconGenerator.ActionBarOptions actionBarOptions = new ActionBarIconGenerator.ActionBarOptions(); actionBarOptions.theme = mHoloDarkRadio.getSelection() ? ActionBarIconGenerator.Theme.HOLO_DARK : ActionBarIconGenerator.Theme.HOLO_LIGHT; options = actionBarOptions; break; } case NOTIFICATION: { generator = new NotificationIconGenerator(); NotificationIconGenerator.NotificationOptions notificationOptions = new NotificationIconGenerator.NotificationOptions(); notificationOptions.shape = mCircleButton.getSelection() ? GraphicGenerator.Shape.CIRCLE : GraphicGenerator.Shape.SQUARE; options = notificationOptions; break; } case TAB: generator = new TabIconGenerator(); options = new TabIconGenerator.TabOptions(); break; default: AdtPlugin.log(IStatus.ERROR, "Unsupported asset type: %1$s", type); return categoryMap; } options.sourceImage = sourceImage; IProject project = wizard.getProject(); Pair<Integer, Integer> v = ManifestInfo.computeSdkVersions(project); options.minSdk = v.getFirst(); String baseName = wizard.getBaseName(); generator.generate(null, categoryMap, this, options, baseName); return categoryMap; }