diff --git a/src/main/java/de/mprengemann/intellij/plugin/androidicons/dialogs/AndroidMultiDrawableImporter.java b/src/main/java/de/mprengemann/intellij/plugin/androidicons/dialogs/AndroidMultiDrawableImporter.java index eae62d83d..16776eb96 100644 --- a/src/main/java/de/mprengemann/intellij/plugin/androidicons/dialogs/AndroidMultiDrawableImporter.java +++ b/src/main/java/de/mprengemann/intellij/plugin/androidicons/dialogs/AndroidMultiDrawableImporter.java @@ -47,6 +47,7 @@ import de.mprengemann.intellij.plugin.androidicons.widgets.FileBrowserField; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -61,14 +62,9 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -76,8 +72,8 @@ public class AndroidMultiDrawableImporter extends DialogWrapper implements Multi private final FileChooserDescriptor archiveDescriptor = new FileChooserDescriptor(true, false, - false, - false, + true, + true, false, false) { @Override @@ -308,7 +304,7 @@ private void importZipArchive(VirtualFile virtualFile) { } final File tempDir = new File(ImageInformation.getTempDir(), virtualFile.getNameWithoutExtension()); final String archiveName = virtualFile.getName(); - new Task.Modal(project, "Import Archive", true) { + new Task.Modal(project, "Importing Archive...", true) { @Override public void run(@NotNull final ProgressIndicator progressIndicator) { progressIndicator.setIndeterminate(true); @@ -324,31 +320,27 @@ public boolean accept(File dir, String name) { }, true); progressIndicator.checkCanceled(); - final Path root = Paths.get(tempDir.toURI()); - Files.walkFileTree(root, new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - progressIndicator.checkCanceled(); - if (!attrs.isRegularFile() || Files.isHidden(file)) { - return FileVisitResult.CONTINUE; - } - final String fileRoot = file.getParent().toString().toUpperCase(); - final String name = FilenameUtils.getBaseName(file.toString()); - if (name.startsWith(".") || - fileRoot.contains("__MACOSX")) { - return FileVisitResult.CONTINUE; - } - for (Resolution resolution : RESOLUTIONS) { - if (name.toUpperCase().contains("-" + resolution) || - name.toUpperCase().contains("_" + resolution) || - fileRoot.contains(resolution.toString())) { - controller.addZipImage(new File(file.toUri()), resolution); - return FileVisitResult.CONTINUE; - } + final Iterator fileIterator = FileUtils.iterateFiles(tempDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); + while (fileIterator.hasNext()) { + File file = fileIterator.next(); + if (file.isDirectory() || file.isHidden()) { + continue; + } + final String fileRoot = file.getParent().toUpperCase(); + final String name = FilenameUtils.getBaseName(file.toString()); + if (name.startsWith(".") || + fileRoot.contains("__MACOSX")) { + continue; + } + for (Resolution resolution : RESOLUTIONS) { + if (name.toUpperCase().contains("-" + resolution) || + name.toUpperCase().contains("_" + resolution) || + fileRoot.contains(resolution.toString())) { + controller.addZipImage(file, resolution); + break; } - return FileVisitResult.CONTINUE; } - }); + } progressIndicator.checkCanceled(); final Map> zipImages = controller.getZipImages(); @@ -363,15 +355,15 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO } progressIndicator.checkCanceled(); - final String title = String.format("Import '%s'", archiveName); - if (foundResolutions.size() == 0 || foundAssets == 0) { - Messages.showErrorDialog("No assets found.", title); - FileUtils.deleteQuietly(tempDir); - return; - } final int finalFoundAssets = foundAssets; UIUtil.invokeLaterIfNeeded(new DumbAwareRunnable() { public void run() { + final String title = String.format("Import '%s'", archiveName); + if (foundResolutions.size() == 0 || finalFoundAssets == 0) { + Messages.showErrorDialog("No assets found.", title); + FileUtils.deleteQuietly(tempDir); + return; + } final String[] options = new String[] {"Import", "Cancel"}; final String description = String.format("Import %d assets for %s to %s.", finalFoundAssets, diff --git a/src/main/java/de/mprengemann/intellij/plugin/androidicons/dialogs/IconImporter.java b/src/main/java/de/mprengemann/intellij/plugin/androidicons/dialogs/IconImporter.java index 8ff26c250..96b472d7a 100644 --- a/src/main/java/de/mprengemann/intellij/plugin/androidicons/dialogs/IconImporter.java +++ b/src/main/java/de/mprengemann/intellij/plugin/androidicons/dialogs/IconImporter.java @@ -432,9 +432,6 @@ private class AssetSpinnerRenderer extends ListCellRendererWrapper { @Override public void customize(JList list, ImageAsset imageAsset, int index, boolean selected, boolean hasFocus) { LayeredIcon layeredIcon = new LayeredIcon(2); - if (controller == null) { - return; - } File imageFile = controller.getThumbnailFile(imageAsset); if (imageFile != null && imageFile.exists()) { final ImageIcon icon = new ImageIcon(imageFile.getAbsolutePath()); diff --git a/src/main/java/de/mprengemann/intellij/plugin/androidicons/images/RefactoringTask.java b/src/main/java/de/mprengemann/intellij/plugin/androidicons/images/RefactoringTask.java index d3ba411c8..f721c0238 100644 --- a/src/main/java/de/mprengemann/intellij/plugin/androidicons/images/RefactoringTask.java +++ b/src/main/java/de/mprengemann/intellij/plugin/androidicons/images/RefactoringTask.java @@ -52,12 +52,11 @@ public class RefactoringTask extends Task.Backgroundable { private ProgressIndicator progressIndicator; public RefactoringTask(Project project) { - super(project, "Import Images", true); + super(project, "Importing Images...", true); this.project = project; } private void refactor() throws IOException, ProcessCanceledException { - progressIndicator.setText("Import Images"); progressIndicator.checkCanceled(); progressIndicator.setIndeterminate(false); for (int i = 0; i < imageInformationList.size(); i++) { @@ -69,7 +68,7 @@ private void refactor() throws IOException, ProcessCanceledException { } progressIndicator.setIndeterminate(true); - progressIndicator.setText2(""); + progressIndicator.setText2("Finishing"); UIUtil.invokeLaterIfNeeded(new DumbAwareRunnable() { public void run() { try { diff --git a/src/main/java/de/mprengemann/intellij/plugin/androidicons/model/ImageInformation.java b/src/main/java/de/mprengemann/intellij/plugin/androidicons/model/ImageInformation.java index d659ece3e..0285ae614 100644 --- a/src/main/java/de/mprengemann/intellij/plugin/androidicons/model/ImageInformation.java +++ b/src/main/java/de/mprengemann/intellij/plugin/androidicons/model/ImageInformation.java @@ -124,7 +124,7 @@ public static class Builder { private boolean ninePatch = false; private Resolution targetResolution = Resolution.XHDPI; private ResizeAlgorithm algorithm = DefaultsController.DEFAULT_ALGORITHM; - private Object method = DefaultsController.DEFAULT_METHOD; + private Object method = DefaultsController.DEFAULT_ALGORITHM.getMethod(DefaultsController.DEFAULT_METHOD); private Format format = DefaultsController.DEFAULT_FORMAT; private Builder() { diff --git a/src/main/java/de/mprengemann/intellij/plugin/androidicons/widgets/FileBrowserField.java b/src/main/java/de/mprengemann/intellij/plugin/androidicons/widgets/FileBrowserField.java index 3f91625a5..e46b768f0 100644 --- a/src/main/java/de/mprengemann/intellij/plugin/androidicons/widgets/FileBrowserField.java +++ b/src/main/java/de/mprengemann/intellij/plugin/androidicons/widgets/FileBrowserField.java @@ -96,9 +96,8 @@ public void init(Project project, ISettingsController settingsController) { private void initFileChooser() { addBrowseFolderListener(new TextBrowseFolderListener(descriptor) { @Override - @SuppressWarnings("deprecation") // Otherwise not compatible to AndroidStudio - protected void onFileChoosen(@NotNull VirtualFile chosenFile) { - super.onFileChoosen(chosenFile); + protected void onFileChosen(@NotNull VirtualFile chosenFile) { + super.onFileChosen(chosenFile); if (settingsController != null) { settingsController.saveLastImageFolder(chosenFile.getCanonicalPath()); }