@1x,@2x,@3x 资源文件自动分包工具-android 篇
来源:互联网 发布:淘宝gxg官方店是正品吗 编辑:程序博客网 时间:2024/05/16 10:35
version 1.2
1.修改不用输入扩展名
2.输出路径可选。默认会在输入路径下建文件夹
前沿:
现在开发中ios,android会使用一套图,但是ui设计师给的图命名是以@1x,@2x,@3x这样命名的,android 客户端使用起来就略嫌麻烦了,这个小工具可以实现简单的分包。
原理:
I/o流读取 testPicture中的@1x,@2x,@3x 文件进行整理,按序输出旧文件文字同时,需要输入一个新文件名 + 后缀名,然后动态进行分组到desPicture中的文件夹1,文件夹2,文件夹3。1,2,3文件夹分别对应@1x,@2x,@3x.
Eg:尽量配对出现 @1x,@2x,@3x.
1.首先需要两个文件夹,一个里面存放着待处理的文件,另一个存放处理后的文件
testPicture
desPicture
步骤:
1.进入dos窗口
Window+r —–>cmd
2.进入mutiFile.jar 根目录 输入
java -jar MutiFile-x.x.x.jar srcFile outputDir
其中:MutiFile-x.x.x.jar ,是工具类
srcFile 为待处理文件夹路径
outputDir 为处理后的文件输出路径
处理后的文件,已经进行分组成 @1x,@2x,@3x
贴出来源码:
package com.nuoyuan.mutiFile;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Scanner;/** * version 1.2 * 1. 增加支持 不写后缀名字 * 2. 增加输入输出路径可选 * @author weichyang * */public class MutiFile { private static final String USAGE_TEXT = "Usage: java -jar MutiFile-x.x.x.jar srcFile outputDir "; private static Map<String, String> onePlus = new HashMap(); private static Map<String, String> twoPlus = new HashMap(); private static Map<String, String> threePlus = new HashMap(); private static List newFilePath = new ArrayList<String>(); private static String[] spiltName = { "@1x", "@2x", "@3x" }; private static ArrayList<String> filelist = new ArrayList<String>(); private static String tempFileName = "xx@xx"; private static String beforeName = "&6%"; public static void main(String[] args) throws IOException { if (args.length < 1) { println(USAGE_TEXT); return; } String resPathString = ""; String desPathString = ""; if (args.length == 1) { resPathString = args[0]; desPathString = args[0]; } else { resPathString = args[0]; desPathString = args[1]; } File resFile = new File(resPathString); File desFile = new File(desPathString); if (!resFile.exists()) { println(" file '" + desPathString + "' is not exists or not readable."); println(USAGE_TEXT); System.exit(1); } if (!desFile.exists()) { // desfile.createNewFile(); println(" file '" + desFile.getAbsolutePath() + "' is not exists or not readable."); println(USAGE_TEXT); System.exit(1); return; } else { for (int i = 1; i <= 3; i++) { String newPathString = desPathString + "\\" + i; new File(newPathString).mkdirs(); newFilePath.add(newPathString + "\\"); } } // 打印资源文件 println("res File: " + resFile.getAbsolutePath()); println("output File: " + desFile.getAbsolutePath()); // 资源存在是否为null getFiles(resFile); } /* * 通过递归得到某一路径下所有的目录及其文件 */ public static void getFiles(File filePath) throws FileNotFoundException, IOException { File[] files = filePath.listFiles(); if (files.length == 0) { println(filePath + " is have't file exit!!"); System.exit(1); return; } for (File file : files) { if (file.isDirectory()) { /* * 递归调用 */ getFiles(file); filelist.add(file.getAbsolutePath()); System.out.println("show " + filePath + "下所有子目录及其文件" + file.getAbsolutePath()); } else { String currentFilePath = file.getAbsolutePath().toString(); String fileName = splitFileName(currentFilePath); System.out.println("current file name is:" + fileName); if (!fileName.contains("@")) { continue; } if (fileName.contains(spiltName[0])) { onePlus.put(fileName, currentFilePath); String fileNameString = InputCode(fileName); fromToAnotherDes(currentFilePath, newFilePath.get(0) .toString() + fileNameString); } else if (fileName.contains(spiltName[1])) { twoPlus.put(fileName, newFilePath.get(1).toString() + fileName); String fileNameString = InputCode(fileName); fromToAnotherDes(currentFilePath, newFilePath.get(1) .toString() + fileNameString); } else if (fileName.contains(spiltName[2])) { threePlus.put(fileName, newFilePath.get(2).toString() + fileName); String fileNameString = InputCode(fileName); fromToAnotherDes(currentFilePath, newFilePath.get(2) .toString() + fileNameString); } } } System.out.print("/****** File rename Success *********/\n"); System.out.print("共修改@1x 文件 " + onePlus.size() + "个\n"); System.out.print("共修改@2x 文件 " + twoPlus.size() + "个\n"); System.out.print("共修改@3x 文件 " + threePlus.size() + "个\n"); System.out.print("总共修文件 " + threePlus.size() + onePlus.size() + twoPlus.size() + "个\n"); System.out.print("/**************************************/\n"); } /** * 分割文件名字 * * @param str * @return */ public static String splitFileName(String str) { String[] strs = str.split("\\\\"); StringBuffer sb = new StringBuffer(); for (int i = 0; i < strs.length; i++) { if (i == strs.length - 1) sb.append(strs[i]); } return sb.toString(); } /** * 拷貝一個文件到另一個問價中 * * @param srcFile * @param desFile * @throws FileNotFoundException * @throws IOException */ public static void fromToAnotherDes(String srcFile, String desFile) { try { FileInputStream fis = new FileInputStream(srcFile); FileOutputStream fos = new FileOutputStream(desFile); int len = 0; byte[] buf = new byte[1024]; while ((len = fis.read(buf)) != -1) { fos.write(buf, 0, len); } fis.close(); fos.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 接受输入的数字进行设置文件名字 一次输入使用三次 * * @return */ public static String InputCode(String fileName) { String extNameString = getExtension(fileName); String realNameString = fileName.split("@")[0]; if (realNameString.equals(beforeName)) { return tempFileName + extNameString; } Scanner scanner = new Scanner(System.in);// 创建输入流扫描器 System.out.print("please input file name:\n");// 提示用户输入 // 获取用户输入的一行文本 String line = scanner.nextLine(); // 打印对输入文本的描述 tempFileName = line; beforeName = realNameString; return line + extNameString; } public static void println(String msg) { System.out.println(msg); } /** * 截取扩展名字 * * @param filename * @param defExt * @return */ public static String getExtension(String filename) { if ((filename != null) && (filename.length() > 0)) { int i = filename.lastIndexOf('.'); if ((i > -1) && (i < (filename.length() - 1))) { return filename.substring(i); } } return ""; }}
下载地址 http://pan.baidu.com/s/1pK7qdLp
version 1.2 版本:http://pan.baidu.com/s/1boNnLoV
1 0
- @1x,@2x,@3x 资源文件自动分包工具-android 篇
- 自制工具:Cocos2d-x Android.mk文件自动修改器
- 1^x + 2 ^ x + 3 ^x + …… + n^x
- 输出(x/1!)+(x*x*x/3!)+(x*x*x*x*x/5!)+````
- 通过PDF矢量图片自动生成@1x, @2x, @3x切图
- iOS自动生成图片@1x,@2x ,@3x图片
- 切图常说的@1X@2X@3X是什么意思?
- point vs pixel @1x,@2x,@3x
- @1x @2x和@3x.png 的区别
- RTImageAssets插件--@3x可自动生成@2x图片
- cocos2d-x 文件工具类
- cocos2d-x 动画工具 Flash2Cocos2d-x(1)
- x^1 + x ^2 +...+x ^n = m 求x
- x=x&(x-1)
- x=x&(x-1)
- x = x&(x-1)
- x = x&(x-1)
- $X
- Linux下查看哪些进程占用的CPU、内存资源最多
- Android 浮动窗口进阶——画中画,浮动视频
- 根据IP地址查询
- 类加载器详解 (转至http://blog.csdn.net/jiangwei0910410003/article/details/17733153)
- Android--hw_get_module解析
- @1x,@2x,@3x 资源文件自动分包工具-android 篇
- Qt5.7.1支持gstreamer1.0
- android TV架构启动流程分析(三)
- 前端面试问题三
- FloatMath.sqrt android6.0 23报错
- Web前端研发工程师编程能力提升之路
- C# 中的 ConfigurationManager类引用方法
- angularjs checkbox双向绑定
- Android获取屏幕长宽