1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
--hdpi的dimens.xml:
--xhdpi的dimens.xml:
|
1
2
3
4
5
6
7
8
9
10
11
|
android:layout_width= "match_parent"
android:layout_height= "match_parent" >
android:layout_centerInParent= "true"
android:background= "#000000"
android:layout_width= "@dimen/activity_horizontal_margin"
android:layout_height= "@dimen/activity_vertical_margin" />
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package convert;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class DimensTools {
static String oldFilePath = "src/convert/dimens.xml" ;
static String filePathHdpi= "src/convert/dimensHdpi.xml" ;
static float changes = 1 .125f;
public static void main(String[] args) {
String st = convertStreamToString(oldFilePath, changes);
DeleteFolder(filePathHdpi);
writeFile(filePathHdpi, st);
}
public static String convertStreamToString(String filepath, float f) {
StringBuilder sb = new StringBuilder();
try {
BufferedReader bf = new BufferedReader( new FileReader(filepath));
String line = null ;
System.out.println( "q1" );
String endmark = "dp" ;
String startmark = ">" ;
while ((line = bf.readLine()) != null ) {
if (line.contains(endmark)) {
int end = line.lastIndexOf(endmark);
int start = line.indexOf(startmark);
String stdp = line.substring(start + 1 , end);
//int dp = Integer.parseInt(stpx);
float dp=Float.parseFloat(stdp);
//float newdp = ((float) dp / f);
System.out.println( "dp:" +dp);
float newdp=dp/f;
System.out.println( "newdp:" +newdp);
String dpStr=String.valueOf(dp);
String newline;
if (dpStr.contains( ".0" )){
int x=dpStr.indexOf( "." );
System.out.println( "x:" +x);
dpStr= dpStr.substring( 0 ,x);
newline= line.replace(dpStr + "dp" , newdp + "dp" );
} else {
newline = line.replace(dp + "dp" , newdp + "dp" );
}
System.out.println( "newline:" +newline);
sb.append(newline + "\r\n" );
} else {
sb.append(line + "\r\n" );
}
}
// System.out.println(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
public static boolean DeleteFolder(String sPath) {
File file = new File(sPath);
if (!file.exists()) {
return true ;
} else {
if (file.isFile()) {
return deleteFile(sPath);
} else {
// return deleteDirectory(sPath);
}
}
return false ;
}
public static void writeFile(String filepath, String st) {
try {
FileWriter fw = new FileWriter(filepath);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(st);
bw.flush();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean deleteFile(String sPath) {
boolean flag = false ;
File file = new File(sPath);
if (file.isFile() && file.exists()) {
file.delete();
flag = true ;
}
return flag;
}
}
|