Skip to content

Commit 3e4e6a1

Browse files
committed
see 10/14 log
1 parent 240e13f commit 3e4e6a1

File tree

7 files changed

+68
-19
lines changed

7 files changed

+68
-19
lines changed

utilcode/src/main/java/com/blankj/utilcode/utils/CrashUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class CrashUtils implements Thread.UncaughtExceptionHandler {
2828
private static CrashUtils mInstance = new CrashUtils();
2929
private UncaughtExceptionHandler mHandler;
3030
private boolean mInitialized;
31-
private static String dir;
31+
private static String crashDir;
3232
private String versionName;
3333
private int versionCode;
3434

@@ -54,9 +54,9 @@ public static CrashUtils getInstance() {
5454
public boolean init(Context context) {
5555
if (mInitialized) return true;
5656
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
57-
dir = context.getExternalCacheDir().getPath() + File.separator;
57+
crashDir = context.getExternalCacheDir().getPath() + File.separator + "crash" + File.separator;
5858
} else {
59-
dir = context.getCacheDir().getPath() + File.separator;
59+
crashDir = context.getCacheDir().getPath() + File.separator + "crash" + File.separator;
6060
}
6161
try {
6262
PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
@@ -74,7 +74,7 @@ public boolean init(Context context) {
7474
@Override
7575
public void uncaughtException(Thread thread, Throwable throwable) {
7676
String now = new SimpleDateFormat("yy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date());
77-
String fullPath = dir + "crash_" + now + ".txt";
77+
String fullPath = crashDir + now + ".txt";
7878
if (!FileUtils.createOrExistsFile(fullPath)) return;
7979
PrintWriter pw = null;
8080
try {

utilcode/src/main/java/com/blankj/utilcode/utils/IntentUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public static Intent getComponentIntent(String packageName, String className, Bu
174174
*
175175
* @return intent
176176
*/
177-
public static Intent getShutdownIntnet() {
177+
public static Intent getShutdownIntent() {
178178
Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
179179
return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
180180
}

utilcode/src/main/java/com/blankj/utilcode/utils/KeyboardUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static void hideSoftInput(Context context, EditText edit) {
6060
* <p>参照以下注释代码</p>
6161
*/
6262
public static void clickBlankArea2HideSoftInput0() {
63-
Log.i("tips", "U should copy the following code.");
63+
Log.d("tips", "U should copy the following code.");
6464
/*
6565
@Override
6666
public boolean onTouchEvent (MotionEvent event){
@@ -80,7 +80,7 @@ public boolean onTouchEvent (MotionEvent event){
8080
* <p>参照以下注释代码</p>
8181
*/
8282
public static void clickBlankArea2HideSoftInput1() {
83-
Log.i("tips", "U should copy the following code.");
83+
Log.d("tips", "U should copy the following code.");
8484
/*
8585
@Override
8686
public boolean dispatchTouchEvent(MotionEvent ev) {

utilcode/src/main/java/com/blankj/utilcode/utils/LogUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public static void init(Context context, boolean logSwitch, boolean log2FileSwit
6363
*/
6464
public static Builder getBuilder(Context context) {
6565
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
66-
dir = context.getExternalCacheDir().getPath() + File.separator;
66+
dir = context.getExternalCacheDir().getPath() + File.separator + "log" + File.separator;
6767
} else {
68-
dir = context.getCacheDir().getPath() + File.separator;
68+
dir = context.getCacheDir().getPath() + File.separator + "log" + File.separator;
6969
}
7070
return new Builder();
7171
}
@@ -291,7 +291,7 @@ private synchronized static void log2File(char type, String tag, String content)
291291
if (content == null) return;
292292
Date now = new Date();
293293
String date = new SimpleDateFormat("MM-dd", Locale.getDefault()).format(now);
294-
String fullPath = dir + "log_" + date + ".txt";
294+
String fullPath = dir + date + ".txt";
295295
if (!FileUtils.createOrExistsFile(fullPath)) return;
296296
String time = new SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.getDefault()).format(now);
297297
String dateLogContent = time + ":" + type + ":" + tag + ":" + content + '\n';

utilcode/src/main/java/com/blankj/utilcode/utils/PhoneUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ public static List<HashMap<String, String>> getAllContactInfo(Context context) {
239239
* 打开手机联系人界面点击联系人后便获取该号码
240240
* <p>参照以下注释代码</p>
241241
*/
242-
public static void getContantNum() {
243-
Log.i("tips", "U should copy the following code.");
242+
public static void getContactNum() {
243+
Log.d("tips", "U should copy the following code.");
244244
/*
245245
Intent intent = new Intent();
246246
intent.setAction("android.intent.action.PICK");

utilcode/src/main/java/com/blankj/utilcode/utils/SizeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static void setListener(onGetSizeListener listener) {
142142
* @param view 视图
143143
*/
144144
public static void measureViewInLV(View view) {
145-
Log.i("tips", "U should copy the following code.");
145+
Log.d("tips", "U should copy the following code.");
146146
/*
147147
ViewGroup.LayoutParams p = view.getLayoutParams();
148148
if (p == null) {

utilcode/src/test/java/com/blankj/utilcode/utils/TestUtils.java

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,22 @@ public static Context getContext() {
4040

4141
@Test
4242
public void readme2Eng() throws Exception {
43-
File readme = new File(new File(System.getProperty("user.dir")).getParent() + SEP + "README-CN.md");
43+
formatCN();
44+
File readmeCN = new File(new File(System.getProperty("user.dir")).getParent() + SEP + "README-CN.md");
4445
File readmeEng = new File(new File(System.getProperty("user.dir")).getParent() + SEP + "README.md");
45-
List<String> list = FileUtils.readFile2List(readme, "UTF-8");
46+
List<String> list = FileUtils.readFile2List(readmeCN, "UTF-8");
4647
StringBuilder sb = new StringBuilder("## Android developers should collect the following utils\r\n" +
4748
"**[中文版README][readme-cn.md]→[How to get this README from README-CN][trans]**\r\n" +
4849
"***\r\n" +
4950
"Directory is shown below: \r\n");
5051
List<String> lines = list.subList(4, list.size());
5152
for (String line : lines) {
52-
if (line.length() >= 3 && line.startsWith("> -") && line.contains("Utils")) {
53+
if (line.contains("> -") && line.contains("Utils")) {
5354
String utilsName = line.substring(line.indexOf("[") + 1, line.indexOf("Utils"));
5455
sb.append("> - **About ").append(utilsName).append(line.substring(line.indexOf("→")));
55-
} else if (line.length() >= 3 && line.startsWith("> ")) {
56-
sb.append("> - ").append(line.substring(line.indexOf("*")));
57-
} else if (line.length() >= 2 && line.startsWith("**做")) {
56+
} else if (line.contains(" : ")) {
57+
sb.append(line.substring(0, line.indexOf(':')).trim());
58+
} else if (line.contains("**做")) {
5859
sb.append("**I'm so sorry for that the code is annotated with Chinese.**");
5960
} else {
6061
sb.append(line);
@@ -63,4 +64,52 @@ public void readme2Eng() throws Exception {
6364
}
6465
FileUtils.writeFileFromString(readmeEng, sb.toString(), false);
6566
}
67+
68+
@Test
69+
public void formatCN() throws Exception {
70+
File readmeCN = new File(new File(System.getProperty("user.dir")).getParent() + SEP + "README-CN.md");
71+
List<String> list = FileUtils.readFile2List(readmeCN, "UTF-8");
72+
StringBuilder sb = new StringBuilder();
73+
for (int i = 0; i < 4; i++) {
74+
sb.append(list.get(i)).append("\r\n");
75+
}
76+
String space = " ";
77+
for (int i = 4, len = list.size(); i < len; ++i) {
78+
String line = list.get(i);
79+
if (line.contains("> -") && line.contains("Utils")) {
80+
sb.append(line).append("\r\n");
81+
int maxLen = 0;
82+
line = list.get(++i);
83+
// 获取需填充最大空格数
84+
for (int j = i; !line.equals(""); line = list.get(++j)) {
85+
if (line.equals(" ```")) continue;
86+
maxLen = Math.max(maxLen, line.replace(" ", "").replace(",", ", ").indexOf(':'));
87+
}
88+
line = list.get(i);
89+
for (; !line.equals(""); line = list.get(++i)) {
90+
if (line.equals(" ```")) {
91+
sb.append(" ```").append("\r\n");
92+
continue;
93+
}
94+
String noSpaceLine = line.replace(" ", "");
95+
int l = maxLen - line.replace(" ", "").replace(",", ", ").indexOf(':');
96+
String spaces = "";
97+
for (int j = 0; j < l; j++) {
98+
spaces += space;
99+
}
100+
String temp = noSpaceLine.substring(0, noSpaceLine.indexOf(':')) + spaces + " : " + noSpaceLine.substring(noSpaceLine.indexOf(':') + 1) + "\r\n";
101+
sb.append(temp.replace(",", ", "));
102+
}
103+
} else {
104+
sb.append(line);
105+
}
106+
sb.append("\r\n");
107+
}
108+
FileUtils.writeFileFromString(readmeCN, sb.toString(), false);
109+
}
110+
111+
@Test
112+
public void test() throws Exception {
113+
114+
}
66115
}

0 commit comments

Comments
 (0)