Skip to content

Commit

Permalink
Merge pull request #134 from winterDroid/develop
Browse files Browse the repository at this point in the history
Release 0.5
  • Loading branch information
winterDroid committed Mar 10, 2016
2 parents 254d42d + 417a7b9 commit ad8879a
Show file tree
Hide file tree
Showing 3,090 changed files with 9,603 additions and 116 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
28 changes: 19 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
language: java
sudo: false

env:
matrix:
- IDEA_VERSION=IC-14.0.4
- IDEA_VERSION=IC-14.1.6
- IDEA_VERSION=IC-15.0.2
- IDEA_VERSION=LATEST-EAP-SNAPSHOT
global:
- secure: GJxFEsmA6nJDtD45okB20WgXlfCY/Zaw90aOXxBAWb3w/7eeIFrolXev4ve+gxDettCArqcsPo53vpyimjFzRI8IZB+MZRnpPEVx3Ux/5eEBf2jMqsoaxmWk5rnKp3DTXjMlaAPSnUJRhrPboxdireQG2mIMa34QGv8tCcM2aLk=
notifications:
email: false

branches:
only:
- master
- develop

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

- if [ $TRAVIS_BRANCH == 'develop' ]; then export PLUGIN_CHANNEL=nightly; fi
script:
- ./gradlew buildPlugin
- if [ $TRAVIS_PULL_REQUEST == 'false' ]; then ./gradlew publishPlugin; fi
- ./gradlew buildPlugin -PideaVersion=$IDEA_VERSION
after_success:
- curl -Lo travis_after_all.py https://raw.github.com/winterDroid/travis_after_all/master/travis_after_all.py
- python travis_after_all.py
- export $(cat .to_export_back) &> /dev/null
- if [[ $BUILD_LEADER = YES && "$BUILD_AGGREGATE_STATUS" = "others_succeeded" && $TRAVIS_PULL_REQUEST = 'false' ]]; then ./gradlew publishPlugin; fi
after_script:
- echo leader=$BUILD_LEADER status=$BUILD_AGGREGATE_STATUS
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ This plugin consists of three main features. You can access them by **right-clic
## AndroidIcons and Material Icons Drawable Import
You are able to select the asset, specify your color, change the target resource name and select all the resolutions you want to import.

All the missing folders will be created automatically. If there are already drawables with the same name, you will be warned.
All the missing folders will be created automatically. If there are already drawables with the same name, you will be warned.
You can also import Vector Drawables from the Material Icons pack.

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")
![alt text](src/main/resources/images/vector_importer.png "Vector Drawable Importer dialog")

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

Expand Down
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "org.jetbrains.intellij" version "0.0.34"
id "org.jetbrains.intellij" version "0.0.43"
}

apply plugin: 'org.jetbrains.intellij'
Expand All @@ -17,11 +17,12 @@ sourceSets {
}

intellij {
version 'IC-14.1.5'
version project.hasProperty('ideaVersion') ? ideaVersion : 'IC-15.0.4'
pluginName 'android-drawable-importer-intellij-plugin'
plugins 'android'
updateSinceUntilBuild false
downloadSources !(System.getenv('CI') ?: 'false')
sameSinceUntilBuild false
downloadSources !Boolean.valueOf(System.getenv('CI'))

publish {
username 'Prengepower'
Expand All @@ -34,8 +35,8 @@ intellij {

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

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

repositories {
mavenCentral()
Expand Down
1 change: 1 addition & 0 deletions json_generator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'marcprengemann'
2 changes: 1 addition & 1 deletion json_generator.py → json_generator/json_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def handle_material_icons():
for category in categories:
category_root = join(iconpack_root, category)
resolutions = [s.split('-')[1] for s in list_dirs_only(category_root)]
raw_assets = [extract_data(f) for f in list_images(join(category_root, 'drawable-' + resolutions[0]))]
raw_assets = [extract_data(f) for f in list_images(join(category_root, 'drawable-' + resolutions[1]))]
colors = []
sizes = []
for current_item, next_item in izip(raw_assets, islice(raw_assets, 1, None)):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2015 Marc Prengemann
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
* the specific language governing permissions and limitations under the License.
*/

package de.mprengemann.intellij.plugin.androidicons.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import de.mprengemann.intellij.plugin.androidicons.dialogs.VectorImporter;
import de.mprengemann.intellij.plugin.androidicons.util.AndroidFacetUtils;
import icons.AndroidIcons;
import org.jetbrains.annotations.NotNull;

public class VectorsAction extends AnAction {

public VectorsAction() {
super("Vector Drawable Importer",
"Creates a new Android Vector Asset by the use of Google\'s Material Icons",
AndroidIcons.Android);
}

@Override
public void actionPerformed(@NotNull AnActionEvent event) {
Project project = getEventProject(event);
Module module = event.getData(DataKeys.MODULE);

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

@Override
public void update(@NotNull AnActionEvent e) {
AndroidFacetUtils.updateActionVisibility(e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
public class DefaultsController implements IDefaultsController {

public static final HashSet<Resolution> DEFAULT_RESOLUTIONS = new HashSet<Resolution>(Arrays.asList(Resolution.MDPI,
Resolution.HDPI,
Resolution.XHDPI,
Resolution.XXHDPI,
Resolution.XXXHDPI));
Resolution.HDPI,
Resolution.XHDPI,
Resolution.XXHDPI,
Resolution.XXXHDPI));
public static final Resolution DEFAULT_SOURCE_RESOLUTION = Resolution.XHDPI;
public static final ResizeAlgorithm DEFAULT_ALGORITHM = ResizeAlgorithm.SCALR;
public static final String DEFAULT_METHOD = DEFAULT_ALGORITHM.getMethods().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -42,21 +43,39 @@ public IconsImporterController(IDefaultsController defaultsController,

final ImageAsset defaultImageAsset = defaultsController.getImageAsset();
if (defaultImageAsset == null) {
final String category = androidIconsController.getCategories().get(0);
this.selectedAsset = androidIconsController.getAssets(category).get(0);
this.selectedSize = selectedAsset.getSizes().get(0);
this.selectedColor = selectedAsset.getColors().get(0);
final String category = materialIconsController.getCategories().get(0);
setSelectedAsset(materialIconsController.getAssets(category).get(0));
} else {
this.selectedAsset = defaultImageAsset;
this.selectedSize = defaultsController.getSize();
this.selectedColor = defaultsController.getColor();
setSelectedAsset(defaultImageAsset);
}

this.format = Format.PNG;
this.exportName = null;
this.exportResolutions = defaultsController.getResolutions();
}

public IconsImporterController(IDefaultsController defaultsController,
IMaterialIconsController materialIconsController) {
this.androidIconsController = null;
this.materialIconsController = materialIconsController;
this.observerSet = new HashSet<IconsImporterObserver>();

final ImageAsset defaultImageAsset = defaultsController.getImageAsset();
if (defaultImageAsset == null ||
!defaultImageAsset.getIconPack().equals(materialIconsController.getIconPack().getId())) {
final String category = materialIconsController.getCategories().get(0);
setSelectedAsset(materialIconsController.getAssets(category).get(0));
} else {
setSelectedAsset(defaultImageAsset);
}

this.exportName = null;
this.format = Format.XML;
this.exportResolutions = Collections.singleton(Resolution.ANYDPI);
}

@Override
public void addObserver(IconsImporterObserver observer) {
observerSet.add(observer);
Expand Down Expand Up @@ -97,10 +116,11 @@ public void setSelectedIconPack(String iconPack) {
@NotNull
private IIconPackController getControllerForIconPackId(String iconPack) {
IIconPackController controller;
if (androidIconsController.getId().equals(iconPack)) {
controller = androidIconsController;
} else if (materialIconsController.getId().equals(iconPack)) {
if (materialIconsController.getId().equals(iconPack)) {
controller = materialIconsController;
} else if (androidIconsController != null &&
androidIconsController.getId().equals(iconPack)) {
controller = androidIconsController;
} else {
throw new IllegalArgumentException(iconPack + " not found!");
}
Expand Down Expand Up @@ -278,16 +298,18 @@ public RefactoringTask getTask(Project project) {
for (Resolution resolution : exportResolutions) {
ImageInformation.Builder imageInformationBuilder = ImageInformation.newBuilder(baseInformation);
imageInformationBuilder.setTargetResolution(resolution);
imageInformationBuilder.setVector(resolution == Resolution.ANYDPI);
final File selectedImageFile;
if (getSelectedAsset().getResolutions().contains(resolution)) {
selectedImageFile = getSelectedImageFile(resolution);
} else {
if (getSelectedIconPack().getId().equals("android_icons")) {
selectedImageFile = getSelectedImageFile(Resolution.XXHDPI);
imageInformationBuilder.setFactor(RefactorUtils.getScaleFactor(resolution, Resolution.XXHDPI));
} else if (getSelectedIconPack().getId().equals("material_icons")) {
if (getSelectedIconPack().getId().equals(materialIconsController.getIconPack().getId())) {
selectedImageFile = getSelectedImageFile(Resolution.HDPI);
imageInformationBuilder.setFactor(RefactorUtils.getScaleFactor(resolution, Resolution.HDPI));
} else if (androidIconsController != null &&
getSelectedIconPack().getId().equals(androidIconsController.getIconPack().getId())) {
selectedImageFile = getSelectedImageFile(Resolution.XXHDPI);
imageInformationBuilder.setFactor(RefactorUtils.getScaleFactor(resolution, Resolution.XXHDPI));
} else {
throw new IllegalStateException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface IIconPackController {

IconPack getIconPack();

boolean supportsVectors();

Resolution getThumbnailResolution();

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public IconPack getIconPack() {
return iconPack;
}

@Override
public boolean supportsVectors() {
return false;
}

@Override
public Resolution getThumbnailResolution() {
return Resolution.LDPI;
Expand Down Expand Up @@ -53,6 +58,9 @@ public File getImageFile(ImageAsset asset, String color, Resolution resolution)

@Override
public File getImageFile(ImageAsset asset, String color, String size, Resolution resolution) {
if (resolution == Resolution.ANYDPI) {
throw new IllegalStateException("Vectors not supported by AndroidIcons");
}
final String localPath = String.format("%s/%s/%s.png",
color,
resolution.toString().toLowerCase(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
import de.mprengemann.intellij.plugin.androidicons.controllers.icons.IIconPackController;

public interface IMaterialIconsController extends IIconPackController {

void openHelp();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public IconPack getIconPack() {
return iconPack;
}

@Override
public boolean supportsVectors() {
return true;
}

@Override
public Resolution getThumbnailResolution() {
return Resolution.MDPI;
Expand Down Expand Up @@ -79,13 +84,29 @@ public File getImageFile(ImageAsset asset, String color, Resolution resolution)

@Override
public File getImageFile(ImageAsset asset, String color, String size, Resolution resolution) {
final String localPath = String.format("%s/drawable-%s/%s_%s_%s.png",
final String localPath;
if (resolution == Resolution.ANYDPI) {
localPath = getVectorFilePath(asset);
} else {
localPath = getImageFilePath(asset, color, size, resolution);
}
return ResourceLoader.getAssetResource(new File(iconPack.getPath(), localPath).getPath());
}

private String getImageFilePath(ImageAsset asset, String color, String size, Resolution resolution) {
return String.format("%s/drawable-%s/%s_%s_%s.png",
asset.getCategory(),
resolution.toString().toLowerCase(),
asset.getName(),
color,
size);
return ResourceLoader.getAssetResource(new File(iconPack.getPath(), localPath).getPath());
}

private String getVectorFilePath(ImageAsset asset) {
return String.format("%s/drawable-%s-v21/%s_black_24dp.xml",
asset.getCategory(),
Resolution.ANYDPI.toString().toLowerCase(),
asset.getName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ public void addZipImage(File source, Resolution resolution) {
if (!zipImageInformationMap.containsKey(resolution)) {
zipImageInformationMap.put(resolution, new ArrayList<ImageInformation>());
}
final String fileName = FilenameUtils.getBaseName(source.getName())
.replaceAll("(?i)[-_]+" + resolution.toString(), "");
zipImageInformationMap.get(resolution).add(ImageInformation.newBuilder()
.setImageFile(source)
.setTargetResolution(resolution)
.setFormat(format)
.setNinePatch(source.getName().endsWith(".9.png"))
.setExportName(FilenameUtils.getBaseName(source.getName()))
.setExportName(fileName)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ private void initInternal() {
initExportRoot();
init();
pack();
setResizable(false);

controller.addObserver(this);
}

Expand Down Expand Up @@ -286,7 +284,7 @@ private void updateAlgorithmMethod() {
private void updateFormat() {
formatSpinner.removeActionListener(formatListener);
formatSpinner.removeAllItems();
for (Format format : Format.values()) {
for (Format format : Format.nonVectorValues()) {
formatSpinner.addItem(format);
}
formatSpinner.setSelectedItem(controller.getFormat());
Expand All @@ -308,7 +306,7 @@ private void updateTargetSize() {
private void updateSourceResolution() {
sourceResolutionSpinner.removeActionListener(sourceResolutionListener);
sourceResolutionSpinner.removeAllItems();
for (Resolution resolution : Resolution.values()) {
for (Resolution resolution : Resolution.nonVectorValues()) {
sourceResolutionSpinner.addItem(resolution);
}
sourceResolutionSpinner.setSelectedItem(controller.getSourceResolution());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public AndroidBatchScaleImporter(final Project project, final Module module) {
initTable();
init();
pack();
setResizable(false);
}

private void initButtons(final Project project) {
Expand Down
Loading

0 comments on commit ad8879a

Please sign in to comment.