Skip to content

Commit

Permalink
Merge pull request winterDroid#119 from winterDroid/develop
Browse files Browse the repository at this point in the history
Release 0.4
  • Loading branch information
winterDroid committed Dec 16, 2015
2 parents 235917a + c5ed4ee commit 97e1831
Show file tree
Hide file tree
Showing 54,583 changed files with 2,389 additions and 645 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: java
sudo: false

notifications:
email: false

branches:
only:
- master
- develop

before_script:
- if [ $TRAVIS_BRANCH == 'develop' ]; then export PLUGIN_CHANNEL=nightly; fi

script:
- ./gradlew buildPlugin
- if [ $TRAVIS_PULL_REQUEST == 'false' ]; then ./gradlew publishPlugin; fi
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ You are able to select the asset, specify your color, change the target resource

All the missing folders will be created automatically. If there are already drawables with the same name, you will be warned.

You can even search for your desired asset.

*Currently Material Icons 2.0 is not supported, but it will be added soon.*
You can even search for your desired asset by just start typing when the first spinner has focus.

![alt text](src/main/resources/images/icons_importer.png "Icons Import dialog")

*You can download AndroidIcons [here](http://www.androidicons.com/) and Material Icons [here](https://github.com/google/material-design-icons) for free.*

## Batch Drawable Import
Select an asset and specify the source resolution. You can change the source size of the image as well. Specify all resolutions, to which the drawable should be resized to.
Select assets (or a whole folder) and specify the source resolutions. You can change the source size of every image as well. Specify all resolutions, to which it should be resized to.

This also works with 9-Patch-Images. But take care: sometimes it's necessary to remove / add about one "pixel" in the 9-Patch-Editor. But just try it :)
This works also with 9-Patch-Images. But take care: sometimes it's necessary to remove / add the one or other "pixel" in the 9-Patch-Editor. But just give it a try :)

![alt text](src/main/resources/images/scale.png "Batch Drawable Import dialog")
![alt text](src/main/resources/images/scale_add.png "Batch Drawable Import Add dialog")
![alt text](src/main/resources/images/scale_batch_edit.png "Batch Drawable Import batch edit dialog")

## Multisource-Drawable
Ever got a zip with drawables for your Android project by your designer with the following structure?
Expand All @@ -37,10 +36,12 @@ Ever got a zip with drawables for your Android project by your designer with the
```
No problem! Now you can just select for every resolution a different asset, specify one name for them, and the rest is done by the plugin.
Or even easier, you can select the whole zip, and this plugin will auto extract the asset to the best matching folder.

![alt text](src/main/resources/images/multi.png "Multi drawable sources import dialog")
![alt text](src/main/resources/images/multi_zip.png "Multi drawable sources import dialog for ZIP archives")

*Hint: When you select an asset, you can also just drag a file from your finder / explorer to the text field and drop it there.*
*Hint: When you select an asset, you can also just drag a file from your explorer to the text field and drop it there.*

## Install Instructions (IntelliJ, Android Studio)

Expand Down Expand Up @@ -87,6 +88,8 @@ Afterwards click on the *Close* button. If IntelliJ asks you to restart, allow i

# Contribution

[![Build Status](https://travis-ci.org/winterDroid/android-drawable-importer-intellij-plugin.svg)](https://travis-ci.org/winterDroid/android-drawable-importer-intellij-plugin)

1. Fork it
2. Checkout develop branch
`git checkout develop && git pull`
Expand Down
28 changes: 23 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
plugins {
id "org.jetbrains.intellij" version "0.0.25"
id "org.jetbrains.intellij" version "0.0.34"
}

apply plugin: 'org.jetbrains.intellij'
apply plugin: 'java'

sourceCompatibility = 1.6

sourceSets {
main {
resources {
exclude 'assets/android_icons'
exclude 'assets/material_icons'
}
}
}

intellij {
version '14.1.5'
version 'IC-14.1.5'
pluginName 'android-drawable-importer-intellij-plugin'
plugins 'android'
updateSinceUntilBuild false
downloadSources !(System.getenv('CI') ?: 'false')

publish {
username 'Prengepower'
pluginId '7658'

password System.getenv('PLUGIN_PASSWORD')
channel System.getenv('PLUGIN_CHANNEL') ?: ''
}
}

group 'de.mprengemann.intellij.plugin.androidicons'
version '0.3.3'

def majorVersion = '0.4'
version "${System.getenv('CI') ? "$majorVersion-${System.getenv('TRAVIS_JOB_NUMBER')}" : "$majorVersion"}"

repositories {
mavenCentral()
Expand All @@ -24,7 +43,6 @@ repositories {
dependencies {
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-math3:3.4.1'
compile 'net.java.dev.glazedlists:glazedlists_java15:1.9.1'
compile 'org.imgscalr:imgscalr-lib:4.2'
compile 'net.coobird:thumbnailator:0.4.8'
compile 'com.google.code.gson:gson:2.3.1'
Expand Down
59 changes: 57 additions & 2 deletions json_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,54 @@
from itertools import izip, islice
from os.path import join

from PIL import Image


root = 'src/main/resources/assets/'
android_icons_url = 'http://www.androidicons.com/'
material_icons_url = 'https://www.google.com/design/icons/'

def convert_image(file):
pil_img = Image.open(file)
if pil_img.mode == '1':
img = Image.open(file)
img = img.convert('RGBA')
datas = img.getdata()
newData = []
for item in datas:
if item[0] == 0 and item[1] == 0 and item[2] == 0:
newData.append((0, 0, 0, 0))
else:
newData.append(item)

img.putdata(newData)
img.save(file)

def convert_images():
iconpack_root = join(root, 'android_icons')
for color in list_dirs_only(iconpack_root):
color_root = join(iconpack_root, color)
for resolution in list_dirs_only(color_root):
resolution_root = join(color_root, resolution)
for image in list_images(resolution_root):
convert_image(join(resolution_root, image))

iconpack_root = join(root, 'material_icons')
for category in list_dirs_only(iconpack_root):
category_root = join(iconpack_root, category)
for resolution in list_dirs_only(category_root):
resolution_root = join(category_root, resolution)
for image in list_images(resolution_root):
convert_image(join(resolution_root, image))


def get_android_icons_file(color, resolution, name):
iconpack_root = join(root, 'android_icons')
color_root = join(iconpack_root, color)
resolution_root = join(color_root, resolution)
full_name = name + '.png'
return join(resolution_root, full_name)


def handle_android_icons():
iconpack_root = join(root, 'android_icons')
Expand All @@ -24,7 +68,8 @@ def handle_android_icons():
}
assetdata = []
for asset in assets:
data = {'name': os.path.splitext(asset)[0],
name = os.path.splitext(asset)[0]
data = {'name': name,
'pack': id,
'category': 'all',
'resolutions': resolutions,
Expand All @@ -39,6 +84,7 @@ def handle_android_icons():
def list_dirs_only(dir):
return [f for f in os.listdir(dir) if os.path.isdir(join(dir, f))]


def list_images(dir):
return [f for f in os.listdir(dir) if f.endswith('.png')]

Expand All @@ -54,6 +100,14 @@ def extract_data(icon_file_name):
return name, color, size


def get_material_icons_file(category, color, size, resolution, name):
iconpack_root = join(root, 'material_icons')
category_root = join(iconpack_root, category)
resolution_root = join(category_root, 'drawable-' + resolution)
full_name = "_".join([name, color, size]) + '.png'
return join(resolution_root, full_name)


def handle_material_icons():
iconpack_root = join(root, 'material_icons')
categories = list_dirs_only(iconpack_root)
Expand All @@ -62,7 +116,7 @@ def handle_material_icons():
'id': id,
'url': material_icons_url,
'path': 'material_icons/',
'categories':categories
'categories': categories
}
assetdata = []
for category in categories:
Expand Down Expand Up @@ -90,6 +144,7 @@ def handle_material_icons():
return packdata


convert_images()
android_icons_data = handle_android_icons()
material_icons_data = handle_material_icons()
packs = [android_icons_data, material_icons_data]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.mprengemann.intellij.plugin.androidicons;

import com.intellij.openapi.components.ProjectComponent;

public interface IProjectSettingsComponent extends ProjectComponent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
import com.google.gson.reflect.TypeToken;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.util.io.ZipUtil;
import de.mprengemann.intellij.plugin.androidicons.controllers.DefaultControllerFactory;
import de.mprengemann.intellij.plugin.androidicons.controllers.IControllerFactory;
import de.mprengemann.intellij.plugin.androidicons.model.IconPack;
import de.mprengemann.intellij.plugin.androidicons.model.Resolution;
import de.mprengemann.intellij.plugin.androidicons.resources.ResourceLoader;
import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class IconApplication implements ApplicationComponent {

Expand All @@ -36,17 +42,53 @@ public void initComponent() {
IconPack androidIcons = null;
IconPack materialIcons = null;
try {
final InputStream bundledIconPackPropertiesFile = ResourceLoader.getBundledResourceStream("icon_packs.properties");
final Properties bundledIconPackProperties = new Properties();
bundledIconPackProperties.load(bundledIconPackPropertiesFile);

final boolean export;
final File localIconPackPropertiesFile = new File(ResourceLoader.getExportPath(), "icon_packs.properties");
if (!localIconPackPropertiesFile.exists()) {
export = true;
} else {
final Properties localIconPackProperties = new Properties();
localIconPackProperties.load(FileUtils.openInputStream(localIconPackPropertiesFile));

export = Integer.parseInt(bundledIconPackProperties.getProperty("version")) !=
Integer.parseInt(localIconPackProperties.getProperty("version"));
}

final File contentFile = ResourceLoader.getBundledResource("content.json");
assert contentFile != null;
final FileReader fileReader = new FileReader(contentFile);
final Type listType = new TypeToken<ArrayList<IconPack>>() {}.getType();
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Resolution.class, new Resolution.Deserializer());
final Gson gson = gsonBuilder.create();
final List<IconPack> iconPacks = gson.fromJson(fileReader, listType);
final File archiveFile = ResourceLoader.getBundledResource("icon_packs.zip");
ZipUtil.extract(archiveFile, ResourceLoader.getExportPath(), null, false);
androidIcons = iconPacks.get(0);
materialIcons = iconPacks.get(1);

if (export) {
new Task.Modal(null, "Prepare Android Drawable Importer", false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
progressIndicator.setIndeterminate(true);
final File archiveFile = ResourceLoader.getBundledResource("icon_packs.zip");
final File bundledResource = ResourceLoader.getBundledResource("icon_packs.properties");
final File localResource = new File(ResourceLoader.getExportPath(), "icon_packs.properties");

try {
assert archiveFile != null;
ZipUtil.extract(archiveFile, ResourceLoader.getExportPath(), null, true);
assert bundledResource != null;
FileUtils.copyFile(bundledResource, localResource);
} catch (IOException e) {
LOGGER.error(e);
}
}
}.queue();
}
} catch (Exception e) {
LOGGER.error(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.mprengemann.intellij.plugin.androidicons;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.project.Project;
import de.mprengemann.intellij.plugin.androidicons.controllers.IControllerFactory;
import org.jetbrains.annotations.NotNull;

public class ProjectSettingsComponent extends AbstractProjectComponent implements IProjectSettingsComponent {
private IControllerFactory controllerFactory;

protected ProjectSettingsComponent(Project project) {
super(project);
}

@Override
public void projectOpened() {
this.controllerFactory.setProject(myProject);
}

@Override
public void initComponent() {
super.initComponent();
final IconApplication iconApplication = ApplicationManager.getApplication().getComponent(IconApplication.class);
this.controllerFactory = iconApplication.getControllerFactory();
}

@Override
public void disposeComponent() {
super.disposeComponent();
this.controllerFactory = null;
}

@NotNull
@Override
public String getComponentName() {
return "ProjectSettingsComponent";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void actionPerformed(@NotNull AnActionEvent event) {
Project project = getEventProject(event);
Module module = event.getData(DataKeys.MODULE);

IconImporter dialog = new IconImporter(project, module);
final IconImporter dialog = new IconImporter(project, module);
dialog.show();
}

Expand Down
Loading

0 comments on commit 97e1831

Please sign in to comment.