Skip to content

Commit 358cfa7

Browse files
committed
see 01/04 log
1 parent fe70516 commit 358cfa7

File tree

10 files changed

+478
-93
lines changed

10 files changed

+478
-93
lines changed

utilcode/README-CN.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,16 @@ create : 创建样式字符串
702702

703703
* ### SP 相关 -> [SPUtils.java][sp.java] -> [Demo][sp.demo]
704704
```
705+
putStatic : SP 中写入数据
706+
getStringStatic : SP 中读取 String
707+
getIntStatic : SP 中读取 int
708+
getLongStatic : SP 中读取 long
709+
getFloatStatic : SP 中读取 float
710+
getBooleanStatic : SP 中读取 boolean
711+
getAllStatic : SP 中获取所有键值对
712+
containsStatic : SP 中是否存在该 key
713+
removeStatic : SP 中移除该 key
714+
clearStatic : SP 中清除所有数据
705715
getInstance : 获取 SP 实例
706716
Instance.put : SP 中写入数据
707717
Instance.getString : SP 中读取 String

utilcode/lib/src/main/java/com/blankj/utilcode/util/AntiShakeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* desc : utils about anti shake
1313
* </pre>
1414
*/
15-
public class AntiShakeUtils {
15+
public final class AntiShakeUtils {
1616

1717
private static final long DEFAULT_DURATION = 200;
1818
private static final int TAG_KEY = 0x7EFFFFFF;

utilcode/lib/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,4 +1070,10 @@ private static boolean isSpace(final String s) {
10701070
}
10711071
return true;
10721072
}
1073+
1074+
///////////////////////////////////////////////////////////////////////////
1075+
// static
1076+
///////////////////////////////////////////////////////////////////////////
1077+
1078+
10731079
}

utilcode/lib/src/main/java/com/blankj/utilcode/util/ImageUtils.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,10 @@ public static boolean save(final Bitmap src,
15331533
* @return {@code true}: yes<br>{@code false}: no
15341534
*/
15351535
public static boolean isImage(final File file) {
1536-
return file != null && isImage(file.getPath());
1536+
if (file == null || !file.exists()) {
1537+
return false;
1538+
}
1539+
return isImage(file.getPath());
15371540
}
15381541

15391542
/**
@@ -1543,10 +1546,14 @@ public static boolean isImage(final File file) {
15431546
* @return {@code true}: yes<br>{@code false}: no
15441547
*/
15451548
public static boolean isImage(final String filePath) {
1546-
String path = filePath.toUpperCase();
1547-
return path.endsWith(".PNG") || path.endsWith(".JPG")
1548-
|| path.endsWith(".JPEG") || path.endsWith(".BMP")
1549-
|| path.endsWith(".GIF") || path.endsWith(".WEBP");
1549+
BitmapFactory.Options options = new BitmapFactory.Options();
1550+
options.inJustDecodeBounds = true;
1551+
try {
1552+
Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
1553+
return options.outWidth != -1 && options.outHeight != -1;
1554+
} catch (Exception e) {
1555+
return false;
1556+
}
15501557
}
15511558

15521559
/**
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//package com.blankj.utilcode.util;
2+
//
3+
//
4+
//import org.json.JSONException;
5+
//import org.json.JSONObject;
6+
//
7+
//public final class JsonUtils {
8+
//
9+
// private static byte TYPE_LONG = 0x01;
10+
// private static byte TYPE_INT = 0x02;
11+
//
12+
// private JsonUtils() {
13+
// throw new UnsupportedOperationException("u can't instantiate me...");
14+
// }
15+
//
16+
// public static long getLong(final JSONObject jsonObject,
17+
// final String key,
18+
// final long defaultValue) {
19+
// if (jsonObject == null || key == null || key.length() == 0) {
20+
// return defaultValue;
21+
// }
22+
// try {
23+
// return jsonObject.getLong(key);
24+
// } catch (JSONException e) {
25+
// return defaultValue;
26+
// }
27+
// }
28+
//
29+
// public static long getLong(final String json,
30+
// final String key,
31+
// final long defaultValue) {
32+
// if (json == null || json.length() == 0
33+
// || key == null || key.length() == 0) {
34+
// return defaultValue;
35+
// }
36+
//
37+
// try {
38+
// return getLong(new JSONObject(json), key, defaultValue);
39+
// } catch (JSONException e) {
40+
// e.printStackTrace();
41+
// return defaultValue;
42+
// }
43+
// }
44+
//
45+
// public static Object getType(final JSONObject jsonObject,
46+
// final String key,
47+
// final Object defaultValue,
48+
// final byte type) {
49+
// if (jsonObject == null || key == null || key.length() == 0) {
50+
// return defaultValue;
51+
// }
52+
// try {
53+
// if (type == TYPE_LONG) {
54+
// return jsonObject.getLong(key);
55+
// } else if (type == TYPE_INT) {
56+
// return jsonObject.getInt(key);
57+
// }
58+
// } catch (JSONException e) {
59+
// return defaultValue;
60+
// }
61+
// }
62+
//
63+
// public static long getLong(final String json,
64+
// final String key,
65+
// final long defaultValue) {
66+
// if (json == null || json.length() == 0
67+
// || key == null || key.length() == 0) {
68+
// return defaultValue;
69+
// }
70+
//
71+
// try {
72+
// return getLong(new JSONObject(json), key, defaultValue);
73+
// } catch (JSONException e) {
74+
// e.printStackTrace();
75+
// return defaultValue;
76+
// }
77+
// }
78+
//
79+
//}

utilcode/lib/src/main/java/com/blankj/utilcode/util/LogUtils.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,11 @@ static String object2Json(Object object) {
797797
if (object instanceof CharSequence) {
798798
return formatJson(object.toString());
799799
}
800-
return GSON.toJson(object);
800+
try {
801+
return GSON.toJson(object);
802+
} catch (Throwable t) {
803+
return object.toString();
804+
}
801805
}
802806

803807
static String formatXml(String xml) {

0 commit comments

Comments
 (0)