Android @1x,@2x,@3x 资源文件自动分包工具
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 < ) {
println(USAGE_TEXT);
return;
}
String resPathString = "";
String desPathString = "";
if (args.length == ) {
resPathString = args[];
desPathString = args[];
} else {
resPathString = args[];
desPathString = args[];
} 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();
} if (!desFile.exists()) {
// desfile.createNewFile();
println(" file '" + desFile.getAbsolutePath()
+ "' is not exists or not readable.");
println(USAGE_TEXT);
System.exit();
return;
} else {
for (int i = ; i <= ; 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 == ) {
println(filePath + " is have't file exit!!");
System.exit();
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[])) { onePlus.put(fileName, currentFilePath);
String fileNameString = InputCode(fileName);
fromToAnotherDes(currentFilePath, newFilePath.get()
.toString() + fileNameString);
} else if (fileName.contains(spiltName[])) { twoPlus.put(fileName, newFilePath.get().toString()
+ fileName);
String fileNameString = InputCode(fileName);
fromToAnotherDes(currentFilePath, newFilePath.get()
.toString() + fileNameString);
} else if (fileName.contains(spiltName[])) { threePlus.put(fileName, newFilePath.get().toString()
+ fileName);
String fileNameString = InputCode(fileName);
fromToAnotherDes(currentFilePath, newFilePath.get()
.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 = ; i < strs.length; i++) {
if (i == strs.length - )
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 = ;
byte[] buf = new byte[];
while ((len = fis.read(buf)) != -) {
fos.write(buf, , 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("@")[]; 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() > )) { int i = filename.lastIndexOf('.'); if ((i > -) && (i < (filename.length() - ))) { return filename.substring(i); }
}
return "";
} }
下载地址 http://pan.baidu.com/s/1pK7qdLp
version 1.2 版本:http://pan.baidu.com/s/1boNnLoV
Android @1x,@2x,@3x 资源文件自动分包工具的更多相关文章
- huhamhire-hosts — Hosts文件自动配置工具
https://www.anotherhome.net/1376 推荐配合EasyGoAgent使用: EasyGoAgent — 开箱即用的GoAgent Update 2015.5.15 数据文件 ...
- Android屏幕适配-资源文件夹命名与匹配规则
说明:本文档目的为分析android工程res目录下的资源文件夹(drawable,values,layout等)在屏幕适配方面的限定与适配方法. 1. Res下文件夹命名方式 1. 可用的命名属性 ...
- intellij idea让资源文件自动更新
intellij idea默认文件是自动保存的,但是手头有个项目jsp文件改动后,在tomcat中不能立即响应变化.要jsp文件改动后立刻看到变化,有个配置.在idea tomcat 中server的 ...
- android 修改framework下资源文件后如何编译
在framework/base/core/res/res 下添加资源文件后需要先编译资源 然后编译framework 才可正常引用 进入项目根目录 cd frameworks/base/core/re ...
- 最简单的Android项目(含有资源文件)
上次的项目没有使用资源文件,打包出的apk安装后是系统默认图标,程序标题也是包名加类名. 添加资源需要对编译的命令做一点调整. 首先在项目根目录新建res和assets目录,在res内新建drawab ...
- Android中通过数组资源文件xml与适配器两种方式给ListView列表视图设置数据源
场景 实现效果如下 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改 ...
- Android学习笔记数组资源文件
在android中我们可以通过数组资源文件,定义数组元素. 数组资源文件是位于values目录下的 array.xml <?xml version="1.0" encodin ...
- SpringMVC+FreeMarker实现静态资源文件自动添加版本号(md5)
近日切换java开发,开始学习springframework.在实现静态资源文件自动计算版本号的实例时,因为不熟悉框架,走了不少弯路,好在最终解决了问题.这里写篇文章记录一下实现,也希望对大家有些用处 ...
- Android反编译获取资源文件-android学习之旅(69)
有时候你看到一些很好看的布局,会考虑别人怎么实现的,回想参考一下,那么这时候反编译一下是很必要的. 要用到的工具apktool.bat和aapt.exe和apktool.jar(要最新版本) 下载前两 ...
随机推荐
- loj#115. 无源汇有上下界可行流
\(\color{#0066ff}{ 题目描述 }\) 这是一道模板题. \(n\) 个点,\(m\) 条边,每条边 \(e\) 有一个流量下界 \(\text{lower}(e)\) 和流量上界 \ ...
- 模板 ST表
ST表 询问静态最值. code: #include <iostream> #include <cstdio> using namespace std; inline int ...
- 13.Convert BST to Greater Tree(将树转为更大树)
Level: Easy 题目描述: Given a Binary Search Tree (BST), convert it to a Greater Tree such that every k ...
- Kibana6.x.x——【Running "run:optimizeBuild" (run) task】出现警告信息
Warning: non-zero exit code 64 Use --force to continue. 还未找到解决方法,先记录下来.
- windows server 2003和window2008区别
windows 2003与windows 2008简介 windows 2003是微软老一代的服务器系统,自带iis 6,操作界面类似于windows XP,因为国内很多IDC都喜欢用盗版window ...
- Sublime Text 3 3126 安装+注册码
首先,到官网下载且安装,个人是安装版本的 https://www.sublimetext.com/3 接着,写入注册码.2016/11/26 亲测有效 —– BEGIN LICENSE —– Mich ...
- my11_mysql事务隔离
概述 ************************************************ Mysql有四个事务隔离级别,默认隔离级别为RR,开启一个事务可以使用 START TRANSA ...
- Sublime text中文乱码解决办法
ConvertToUTF8 安装这个插件可以解决编码混乱问题 首先必须先配一下Sublime text ,安装 Package Control 1. 用Sublimt text 打开任意一个文件,C ...
- 从零开始使用vue-cli搭建一个vue项目及注意事项
一.安装node.js 1.根据电脑的自行下载node.js安装包http://nodejs.cn 2.点击安装,按照正常的的一路点击下去 3.验证安装是否成功,按键win+r,输入cmd打开命令行工 ...
- free -m命令输出详解
free -m输出有3行: Mem:表示物理内存 -/+ buffers/cached:表示物理内存缓存 Swap:表示硬盘交换分区 其中Mem中的total.used.free.shared.buf ...