1:保存下,别人的code

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter; /**
*
*/
public class GenerateValueFiles { private int baseW;
private int baseH; private String dirStr = "./res"; private final static String WTemplate = "<dimen name=\"x{0}\">{1}px</dimen>\n";
private final static String WTemplate1 = "<dimen name=\"_x{0}\">{1}px</dimen>\n";
private final static String HTemplate = "<dimen name=\"y{0}\">{1}px</dimen>\n";
private final static String HTemplate1 = "<dimen name=\"_y{0}\">{1}px</dimen>\n";
/**
* {0}-HEIGHT
*/
private final static String VALUE_TEMPLATE = "values-{0}x{1}"; private static final String SUPPORT_DIMESION = "320,480;480,800;480,854;540,960;600,1024;720,1184;720,1196;720,1280;768,1024;768,1280;800,1280;1080,1812;1080,1920;1440,2560;"; private String supportStr = SUPPORT_DIMESION; public GenerateValueFiles(int baseX, int baseY, String supportStr) {
this.baseW = baseX;
this.baseH = baseY; if (!this.supportStr.contains(baseX + "," + baseY)) {
this.supportStr += baseX + "," + baseY + ";";
} this.supportStr += validateInput(supportStr); System.out.println(supportStr); File dir = new File(dirStr);
if (!dir.exists()) {
dir.mkdir(); }
System.out.println(dir.getAbsoluteFile()); } /**
* @param supportStr
* w,h_...w,h;
* @return
*/
private String validateInput(String supportStr) {
StringBuffer sb = new StringBuffer();
String[] vals = supportStr.split("_");
int w = -;
int h = -;
String[] wh;
for (String val : vals) {
try {
if (val == null || val.trim().length() == )
continue; wh = val.split(",");
w = Integer.parseInt(wh[]);
h = Integer.parseInt(wh[]);
} catch (Exception e) {
System.out.println("skip invalidate params : w,h = " + val);
continue;
}
sb.append(w + "," + h + ";");
} return sb.toString();
} public void generate() {
String[] vals = supportStr.split(";");
for (String val : vals) {
String[] wh = val.split(",");
generateXmlFile(Integer.parseInt(wh[]), Integer.parseInt(wh[]));
} } private void generateXmlFile(int w, int h) { StringBuffer sbForWidth = new StringBuffer();
sbForWidth.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
sbForWidth.append("<resources>");
float cellw = w * 1.0f / baseW; System.out.println("width : " + w + "," + baseW + "," + cellw);
for (int i = ; i < baseW; i++) {
sbForWidth.append(WTemplate.replace("{0}", i + "").replace("{1}",
change(cellw * i) + ""));
}
sbForWidth.append(WTemplate.replace("{0}", baseW + "").replace("{1}",
w + "")); for (int i = ; i < baseW; i++) {
sbForWidth.append(WTemplate1.replace("{0}", i + "").replace("{1}",
change(cellw * (-i)) + ""));
}
sbForWidth.append(WTemplate1.replace("{0}", baseW + "").replace("{1}",
-w + "")); sbForWidth.append("</resources>"); StringBuffer sbForHeight = new StringBuffer();
sbForHeight.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
sbForHeight.append("<resources>");
float cellh = h *1.0f/ baseH;
System.out.println("height : "+ h + "," + baseH + "," + cellh);
for (int i = ; i < baseH; i++) {
sbForHeight.append(HTemplate.replace("{0}", i + "").replace("{1}",
change(cellh * i) + ""));
} sbForHeight.append(HTemplate.replace("{0}", baseH + "").replace("{1}",
h + "")); for (int i = ; i < baseH; i++) {
sbForHeight.append(HTemplate1.replace("{0}", i + "").replace("{1}",
change(cellh * (-i)) + ""));
} sbForHeight.append(HTemplate1.replace("{0}", baseH + "").replace("{1}",
-h + "")); sbForHeight.append("</resources>"); File fileDir = new File(dirStr + File.separator
+ VALUE_TEMPLATE.replace("{0}", h + "")//
.replace("{1}", w + ""));
fileDir.mkdir(); File layxFile = new File(fileDir.getAbsolutePath(), "lay_x.xml");
File layyFile = new File(fileDir.getAbsolutePath(), "lay_y.xml");
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(layxFile));
pw.print(sbForWidth.toString());
pw.close();
pw = new PrintWriter(new FileOutputStream(layyFile));
pw.print(sbForHeight.toString());
pw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} public static float change(float a) {
int temp = (int) (a * );
return temp / 100f;
} public static void main(String[] args) {
int baseW = ;
int baseH = ;
String addition = "";
try {
if (args.length >= ) {
baseW = Integer.parseInt(args[]);
baseH = Integer.parseInt(args[]);
addition = args[];
} else if (args.length >= ) {
baseW = Integer.parseInt(args[]);
baseH = Integer.parseInt(args[]);
} else if (args.length >= ) {
addition = args[];
}
} catch (NumberFormatException e) { System.err
.println("right input params : java -jar xxx.jar width height w,h_w,h_..._w,h;");
e.printStackTrace();
System.exit(-);
} new GenerateValueFiles(baseW, baseH, addition).generate();
} }

2:jar包

链接: https://pan.baidu.com/s/1qYhZMrE 密码: gv2x

Android适配文件dimen自动生成代码的更多相关文章

  1. 安卓自动生成代码插件-Android code Generator(转)

    编辑推荐:稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! 介绍 A ...

  2. mybatis 自动生成代码(mybatis generator)

    pom.xml 文件配置 引入 mybatis generator <properties> <mysql.connector.version>5.1.44</mysql ...

  3. ButterKnife的使用以及不能自动生成代码问题的解决

    ButterKnife的使用以及不能自动生成代码问题的解决 转载请注明出处:http://www.cnblogs.com/zhengjunfei/p/5910497.html 最近换了个工作刚入职,又 ...

  4. Eclipse 使用mybatis generator插件自动生成代码

    Eclipse 使用mybatis generator插件自动生成代码 标签: mybatis 2016-12-07 15:10 5247人阅读 评论(0) 收藏 举报 .embody{ paddin ...

  5. 组件化框架设计之apt编译时期自动生成代码&动态类加载(二)

    阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680 本篇文章将继续从以下两个内容来介绍组件化框架设计: apt编译时 ...

  6. mybatis generator maven插件自动生成代码

    如果你正为无聊Dao代码的编写感到苦恼,如果你正为怕一个单词拼错导致Dao操作失败而感到苦恼,那么就可以考虑一些Mybatis generator这个差价,它会帮我们自动生成代码,类似于Hiberna ...

  7. java如何在eclipse编译时自动生成代码

    用eclipse写java代码,自动编译时,如何能够触发一个动作,这个动作是生成本项目的代码,并且编译完成后,自动生成的代码也编译好了, java编辑器中就可以做到对新生成的代码的自动提示? 不生成代 ...

  8. MyBatis自动生成代码示例

    在项目中使用到mybatis时,都会选择自动生成实体类,Mapper,SqlMap这三个东东. 手头上在用的又不方便,找了下网上,其实有很多文章,但有些引用外部文件时不成功,也不方便,所以重新整理了下 ...

  9. Eclipse中R文件不能自动生成

       R文件不能自动生成主要是因为编译有错误,这时你想什么办法都是没有用的,clean, fix properties,都不是从根上解决问题.    R文件主要是自动生成资源文件的id的,里边静态子类 ...

随机推荐

  1. :before和:after结合使用

    <div class="slider-block" id="block" style="left: 15.5px;" data=&qu ...

  2. vue 登录验证码

    vue 登录验证码 最近在开发pc端项目,配合elementui使用 createCode() { var code = ""; var codeLength = 4; //验证码 ...

  3. 【剑指Offer】34、第一个只出现一次的字符

      题目描述:   在一个字符串(0<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 -1(需要区分大小写).   解题思路: ...

  4. SQL第一节课

    phpmyadmin create table 表名( 列名 数据类型 是否为空 (是否主键|是否唯一|外键关系), 列名 数据类型...(最后一列不加逗号)) create database 数据库 ...

  5. 利用pandas库中的read_html方法快速抓取网页中常见的表格型数据

    本文转载自:https://www.makcyun.top/web_scraping_withpython2.html 需要学习的地方: (1)read_html的用法 作用:快速获取在html中页面 ...

  6. Linux 中,基础命令 command not found...问题

    linux中出现基本命令找不到的问题,经过查找发现是/etc/profile文件出现了问题,解决方案如下: 问题详细: [root@master ~]# ll bash: ls: command no ...

  7. 1. 构建第一个SpringBoot工程

    1.File -  New - Module 2.选项的是Spring Initializr(官方的构建插件,需要联网) ,一定要选择jdk 3.填写项目基本信息 Group:组织ID,一般分为多个段 ...

  8. android debug签名文件

    现象 可以运行程序,但不能启动安装成功的软件 并且run application的时候也不弹出界面. 路径: C:\Users\sunfb\.android 下替换debug.keystore 就OK

  9. Ali-Tomcat在eclipse多开的解决方法

    关于如何在eclipse配置Ali-Tomcat https://help.aliyun.com/document_detail/99410.html?spm=a2c4g.11186623.6.609 ...

  10. 如何彻底卸载系统自带的IE浏览器

    IE浏览器是windows系统上自带的浏览器,有时我们想要用其他的浏览器,例如chrome,卸载IE浏览器,那么应该如何卸载呢?下面就以win7上的IE9为例,告诉大家如何卸载IE浏览器. 方法/步骤 ...