Skip to content

Commit d17818a

Browse files
committed
优化plugin流程代码
1 parent e2d4151 commit d17818a

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

screen-plugin/src/main/groovy/vip/ruoyun/screen/DimenTools.groovy

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ class DimenTools {
2929
this.sourcePath = sourcePath
3030
}
3131

32-
public void dimensCovert() {
33-
clear()
34-
read()
35-
for (Integer path : screenExt.smallestWidths) {
36-
String outPutFile = sourcePath + "/src/main/res/values-sw" + path + "dp/dimens.xml"
37-
// LogM.log(outPutFile)
38-
write(outPutFile, path)
39-
}
32+
//流程
33+
void dimensCovert() {
34+
clear()//1.清除之前的文件
35+
read()//2.读取dimens文件
36+
write()//3.创建文件,写入配置
4037
}
41-
42-
38+
/**
39+
* 清除之前的文件
40+
*/
4341
private void clear() {
4442
try {
4543
//找到文件res 下 values-sw 的文件
@@ -61,6 +59,9 @@ class DimenTools {
6159
}
6260
}
6361

62+
/**
63+
* 读取文件
64+
*/
6465
private void read() {
6566
try {
6667
File file = new File(sourcePath + "/src/main/res/values/" + screenExt.dimensFileName + ".xml")
@@ -83,6 +84,16 @@ class DimenTools {
8384
}
8485
}
8586

87+
/**
88+
* 写入文件
89+
*/
90+
private void write() {
91+
for (Integer path : screenExt.smallestWidths) {
92+
String outPutFile = sourcePath + "/src/main/res/values-sw" + path + "dp/dimens.xml"
93+
// LogM.log(outPutFile)
94+
writeSingleFile(outPutFile, path)
95+
}
96+
}
8697
/**
8798
* 1920 * 1080 480 dpi的设备
8899
* 计算公式 : px / (DPI / 160) = dp
@@ -91,7 +102,7 @@ class DimenTools {
91102
* @param fileName
92103
* @param size
93104
*/
94-
private void write(String fileName, int size) {
105+
private void writeSingleFile(String fileName, int size) {
95106
Document document = DocumentHelper.createDocument()
96107
Element rootElement = document.addElement("resources") //创建跟节点 resources
97108
DecimalFormat decimalFormat = new DecimalFormat(screenExt.decimalFormat) //格式化小数点位数,四舍五入

0 commit comments

Comments
 (0)