Skip to content

Commit

Permalink
Merge pull request #121 from winterDroid/develop
Browse files Browse the repository at this point in the history
Various Fixes for AndroidStudio and IntelliJ 15
  • Loading branch information
winterDroid committed Dec 16, 2015
2 parents 78fd303 + 5a7f3ad commit 254d42d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -61,23 +62,18 @@
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;

public class AndroidMultiDrawableImporter extends DialogWrapper implements MultiImporterObserver {

private final FileChooserDescriptor archiveDescriptor = new FileChooserDescriptor(true,
false,
false,
false,
true,
true,
false,
false) {
@Override
Expand Down Expand Up @@ -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);
Expand All @@ -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<Path>() {
@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<File> 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<Resolution, List<ImageInformation>> zipImages = controller.getZipImages();
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,6 @@ private class AssetSpinnerRenderer extends ListCellRendererWrapper<ImageAsset> {
@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 254d42d

Please sign in to comment.