From 4f319d6a9f623baa0d07c22607364c6e573a4c08 Mon Sep 17 00:00:00 2001 From: henjue Date: Mon, 14 Mar 2016 16:56:59 +0800 Subject: [PATCH] add mipmap support --- META-INF/plugin.xml | 16 +++++++++++++- src/Constants.java | 8 ++++--- src/SelectorChapekAction.java | 7 +++--- src/SelectorDetector.java | 41 +++++++++++++++++++++-------------- src/SelectorGenerator.java | 4 ++-- src/ValidFolder.java | 14 ++++++++++++ 6 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 src/ValidFolder.java diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml index 98a9c6f..b1831ee 100644 --- a/META-INF/plugin.xml +++ b/META-INF/plugin.xml @@ -1,7 +1,7 @@ eu.inmite.android.plugin.selectorchapek SelectorChapek for Android - 1.0.2 + 1.0.5 Inmite +1.0.5 (03/14/2016) +
    +
  • add mipmap support +
+1.0.4 (02/08/20135 +
    +
  • 解决生成的文件有两个_selector的问题 +
+1.0.3 (01/25/2014) +
    +
  • 生成的文件添加_selector +
  • 解决使用xml作为Drawable时生成的文件中包含多余的.xml +
+ 1.0.2 (09/03/2013)
  • Support for all drawable directories diff --git a/src/Constants.java b/src/Constants.java index c5e46bb..1558c43 100644 --- a/src/Constants.java +++ b/src/Constants.java @@ -14,6 +14,7 @@ * limitations under the License. */ +import java.util.ArrayList; import java.util.HashMap; import java.util.regex.Pattern; @@ -33,11 +34,12 @@ public class Constants { public static final String ACTIVATED = "_activated"; public static final String WINDOW_FOCUSED = "_windowfocused"; public static String[] SUFFIXES = new String[]{NORMAL, PRESSED, FOCUSED, SELECTED, CHECKED, DISABLED, HOVERED, CHECKABLE, ACTIVATED, WINDOW_FOCUSED}; - public static Pattern VALID_FOLDER_PATTERN = Pattern.compile("^drawable(-[a-zA-Z0-9]+)*$"); - public static String EXPORT_FOLDER = "drawable"; public static HashMap sMapping; - + public static ArrayList VALID_FOLDERS=new ArrayList<>(); static { + + VALID_FOLDERS.add(new ValidFolder(Pattern.compile("^drawable(-[a-zA-Z0-9]+)*$"),"drawable")); + VALID_FOLDERS.add(new ValidFolder(Pattern.compile("^mipmap(-[a-zA-Z0-9]+)*$"),"mipmap")); // mapping from file suffixes into android attributes and their default values sMapping = new HashMap(); sMapping.put(FOCUSED, new State("state_focused", false)); diff --git a/src/SelectorChapekAction.java b/src/SelectorChapekAction.java index accc514..f298938 100644 --- a/src/SelectorChapekAction.java +++ b/src/SelectorChapekAction.java @@ -58,9 +58,10 @@ public void update(AnActionEvent e) { private boolean isCorrectFolderSelected(VirtualFile selectedFile) { if (selectedFile != null && selectedFile.isDirectory()) { - Matcher matcher = Constants.VALID_FOLDER_PATTERN.matcher(selectedFile.getName()); - if (matcher.matches()) { - return true; + for(ValidFolder validFolder:Constants.VALID_FOLDERS){ + if(validFolder.VALID_PATTERN.matcher(selectedFile.getName()).matches()){ + return true; + } } } return false; diff --git a/src/SelectorDetector.java b/src/SelectorDetector.java index 99f6804..db32713 100644 --- a/src/SelectorDetector.java +++ b/src/SelectorDetector.java @@ -40,7 +40,8 @@ public SelectorDetector(Project project) { public void detectAndCreateSelectors(VirtualFile selectedFolder) { VirtualFile[] children = selectedFolder.getChildren(); - for (VirtualFile child : children) { + for(int i=0;i suffixes = detectSuffixes(child); Log.d("suffixes: " + suffixes); @@ -82,27 +83,35 @@ private void createFile(final VirtualFile file, final VirtualFile folder, List detectorResults) { + public static void generate(VirtualFile newFile,String sourceTypeName, List detectorResults) { Log.d("generating XML:"); Element root = new Element("selector"); root.addNamespaceDeclaration(NS, SCHEMA); @@ -51,7 +51,7 @@ public static void generate(VirtualFile newFile, List d for (SelectorDetector.Result result : detectorResults) { Log.d("fileName=" + result.drawableName + ", states:" + result.states); Element item = new Element("item"); - Attribute attribute = new Attribute("drawable", "@drawable/" + result.drawableName); + Attribute attribute = new Attribute("drawable", "@"+sourceTypeName+"/" + result.drawableName); attribute.setNamespace(NS, SCHEMA); item.addAttribute(attribute); for (String state : allStatesWithoutNormal) { diff --git a/src/ValidFolder.java b/src/ValidFolder.java new file mode 100644 index 0000000..1d7f130 --- /dev/null +++ b/src/ValidFolder.java @@ -0,0 +1,14 @@ +import java.util.regex.Pattern; + +/** + * Created by apple on 16/3/14. + */ +public class ValidFolder { + public final Pattern VALID_PATTERN; + public final String EXPORT_FOLDER; + + public ValidFolder(Pattern valid_pattern, String export_folder) { + VALID_PATTERN = valid_pattern; + EXPORT_FOLDER = export_folder; + } +}