Skip to content

Commit 368926c

Browse files
committed
see 01/07 log
1 parent 1e20b86 commit 368926c

21 files changed

+229
-104
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* `19/01/04` [add] CacheDiskStaticUtils, CacheDoubleStaticUtils, CacheMemoryStaticUtils.
2+
* `19/01/03` [add] SPStaticUtils.
13
* `19/01/02` [fix] LogUtils log object. Publish v1.22.10.
24
* `19/01/01` [add] GsonUtils.
35
* `18/12/29` [add] AntiShakeUtils and VibrateUtils. Publish v1.22.9.

README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
4343

44-
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.10-brightgreen.svg
44+
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.11-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

4747
[apiSvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen
4141

4242
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
4343

44-
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.10-brightgreen.svg
44+
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.11-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

4747
[apiSvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

config.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ ext {
55
compileSdkVersion = 27
66
minSdkVersion = 14
77
targetSdkVersion = 27
8-
versionCode = 1_022_010
9-
versionName = '1.22.10'// E.g. 1.9.72 => 1,009,072
8+
versionCode = 1_022_011
9+
versionName = '1.22.11'// E.g. 1.9.72 => 1,009,072
1010

1111
bus = [
1212
isDebug: false,

lib/base/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ dependencies {
1515
api dep.free_proguard
1616
api 'com.r0adkll:slidableactivity:2.0.5'
1717
compileOnly dep.leakcanary.android_no_op
18-
// api 'com.blankj:utilcode:1.22.10'
18+
// api 'com.blankj:utilcode:1.22.11'
1919
}

utilcode/README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.22.10'
5+
implementation 'com.blankj:utilcode:1.22.11'
66
```
77

88

utilcode/README-STATIC-BUS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ apply plugin: "com.blankj.bus"
2727
给 base 模块添加 [AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode) 依赖:
2828

2929
```groovy
30-
api "com.blankj:utilcode:1.22.10"
30+
api "com.blankj:utilcode:1.22.11"
3131
```
3232

3333
比如 module0 中存在的 `Module0Activity.java`,我们通常都是在它内部写一个 `start` 函数来启动它,现在我们给它添加 `@BusUtils.Subscribe` 注解,并给注解的 `name` 赋唯一值,要注意,函数务必要 `public static` 哦:

utilcode/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.22.10'
5+
implementation 'com.blankj:utilcode:1.22.11'
66
```
77

88

Lines changed: 207 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,207 @@
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-
//}
1+
package com.blankj.utilcode.util;
2+
3+
4+
import android.util.Log;
5+
6+
import org.json.JSONArray;
7+
import org.json.JSONException;
8+
import org.json.JSONObject;
9+
10+
public final class JsonUtils {
11+
12+
private static final byte TYPE_BOOLEAN = 0x00;
13+
private static final byte TYPE_INT = 0x01;
14+
private static final byte TYPE_LONG = 0x02;
15+
private static final byte TYPE_DOUBLE = 0x03;
16+
private static final byte TYPE_STRING = 0x04;
17+
private static final byte TYPE_JSON_OBJECT = 0x05;
18+
private static final byte TYPE_JSON_ARRAY = 0x06;
19+
20+
private JsonUtils() {
21+
throw new UnsupportedOperationException("u can't instantiate me...");
22+
}
23+
24+
public static boolean getBoolean(final JSONObject jsonObject,
25+
final String key) {
26+
return getBoolean(jsonObject, key, false);
27+
}
28+
29+
public static boolean getBoolean(final JSONObject jsonObject,
30+
final String key,
31+
final boolean defaultValue) {
32+
return getValueByType(jsonObject, key, defaultValue, TYPE_BOOLEAN);
33+
}
34+
35+
public static boolean getBoolean(final String json,
36+
final String key) {
37+
return getBoolean(json, key, false);
38+
}
39+
40+
public static boolean getBoolean(final String json,
41+
final String key,
42+
final boolean defaultValue) {
43+
return getValueByType(json, key, defaultValue, TYPE_BOOLEAN);
44+
}
45+
46+
public static int getInt(final JSONObject jsonObject,
47+
final String key) {
48+
return getInt(jsonObject, key, -1);
49+
}
50+
51+
public static int getInt(final JSONObject jsonObject,
52+
final String key,
53+
final int defaultValue) {
54+
return getValueByType(jsonObject, key, defaultValue, TYPE_INT);
55+
}
56+
57+
public static int getInt(final String json,
58+
final String key) {
59+
return getInt(json, key, -1);
60+
}
61+
62+
public static int getInt(final String json,
63+
final String key,
64+
final int defaultValue) {
65+
return getValueByType(json, key, defaultValue, TYPE_INT);
66+
}
67+
68+
public static long getLong(final JSONObject jsonObject,
69+
final String key) {
70+
return getLong(jsonObject, key, -1);
71+
}
72+
73+
public static long getLong(final JSONObject jsonObject,
74+
final String key,
75+
final long defaultValue) {
76+
return getValueByType(jsonObject, key, defaultValue, TYPE_LONG);
77+
}
78+
79+
public static long getLong(final String json,
80+
final String key) {
81+
return getLong(json, key, -1);
82+
}
83+
84+
public static long getLong(final String json,
85+
final String key,
86+
final long defaultValue) {
87+
return getValueByType(json, key, defaultValue, TYPE_LONG);
88+
}
89+
90+
public static double getDouble(final JSONObject jsonObject,
91+
final String key) {
92+
return getDouble(jsonObject, key, -1);
93+
}
94+
95+
public static double getDouble(final JSONObject jsonObject,
96+
final String key,
97+
final double defaultValue) {
98+
return getValueByType(jsonObject, key, defaultValue, TYPE_DOUBLE);
99+
}
100+
101+
public static double getDouble(final String json,
102+
final String key) {
103+
return getDouble(json, key, -1);
104+
}
105+
106+
public static double getDouble(final String json,
107+
final String key,
108+
final double defaultValue) {
109+
return getValueByType(json, key, defaultValue, TYPE_DOUBLE);
110+
}
111+
112+
public static String getString(final JSONObject jsonObject,
113+
final String key) {
114+
return getString(jsonObject, key, "");
115+
}
116+
117+
public static String getString(final JSONObject jsonObject,
118+
final String key,
119+
final String defaultValue) {
120+
return getValueByType(jsonObject, key, defaultValue, TYPE_STRING);
121+
}
122+
123+
public static String getString(final String json,
124+
final String key) {
125+
return getString(json, key, "");
126+
}
127+
128+
public static String getString(final String json,
129+
final String key,
130+
final String defaultValue) {
131+
return getValueByType(json, key, defaultValue, TYPE_STRING);
132+
}
133+
134+
public static JSONObject getJSONObject(final JSONObject jsonObject,
135+
final String key,
136+
final JSONObject defaultValue) {
137+
return getValueByType(jsonObject, key, defaultValue, TYPE_JSON_OBJECT);
138+
}
139+
140+
public static JSONObject getJSONObject(final String json,
141+
final String key,
142+
final JSONObject defaultValue) {
143+
return getValueByType(json, key, defaultValue, TYPE_JSON_OBJECT);
144+
}
145+
146+
public static JSONArray getJSONArray(final JSONObject jsonObject,
147+
final String key,
148+
final JSONArray defaultValue) {
149+
return getValueByType(jsonObject, key, defaultValue, TYPE_JSON_ARRAY);
150+
}
151+
152+
public static JSONArray getJSONArray(final String json,
153+
final String key,
154+
final JSONArray defaultValue) {
155+
return getValueByType(json, key, defaultValue, TYPE_JSON_ARRAY);
156+
}
157+
158+
private static <T> T getValueByType(final JSONObject jsonObject,
159+
final String key,
160+
final T defaultValue,
161+
final byte type) {
162+
if (jsonObject == null || key == null || key.length() == 0) {
163+
return defaultValue;
164+
}
165+
try {
166+
Object ret;
167+
if (type == TYPE_BOOLEAN) {
168+
ret = jsonObject.getBoolean(key);
169+
} else if (type == TYPE_INT) {
170+
ret = jsonObject.getInt(key);
171+
} else if (type == TYPE_LONG) {
172+
ret = jsonObject.getLong(key);
173+
} else if (type == TYPE_DOUBLE) {
174+
ret = jsonObject.getDouble(key);
175+
} else if (type == TYPE_STRING) {
176+
ret = jsonObject.getString(key);
177+
} else if (type == TYPE_JSON_OBJECT) {
178+
ret = jsonObject.getJSONObject(key);
179+
} else if (type == TYPE_JSON_ARRAY) {
180+
ret = jsonObject.getJSONArray(key);
181+
} else {
182+
return defaultValue;
183+
}
184+
//noinspection unchecked
185+
return (T) ret;
186+
} catch (JSONException e) {
187+
Log.e("JsonUtils", "getValueByType: ", e);
188+
return defaultValue;
189+
}
190+
}
191+
192+
private static <T> T getValueByType(final String json,
193+
final String key,
194+
final T defaultValue,
195+
final byte type) {
196+
if (json == null || json.length() == 0
197+
|| key == null || key.length() == 0) {
198+
return defaultValue;
199+
}
200+
try {
201+
return getValueByType(new JSONObject(json), key, defaultValue, type);
202+
} catch (JSONException e) {
203+
Log.e("JsonUtils", "getValueByType: ", e);
204+
return defaultValue;
205+
}
206+
}
207+
}

utilcode/lib/src/test/java/com/blankj/utilcode/util/CacheMemoryStaticUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* desc : test CacheMemoryStaticUtils
1515
* </pre>
1616
*/
17-
public class CacheMemoryStaticUtilsTest {
17+
public class CacheMemoryStaticUtilsTest extends BaseTest {
1818

1919
private CacheMemoryUtils mCacheMemoryUtils = CacheMemoryUtils.getInstance(3);
2020

utilcode/lib/src/test/java/com/blankj/utilcode/util/CacheMemoryUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* desc : test CacheMemoryUtils
1515
* </pre>
1616
*/
17-
public class CacheMemoryUtilsTest {
17+
public class CacheMemoryUtilsTest extends BaseTest {
1818

1919
private CacheMemoryUtils mCacheMemoryUtils1 = CacheMemoryUtils.getInstance();
2020
private CacheMemoryUtils mCacheMemoryUtils2 = CacheMemoryUtils.getInstance(3);

utilcode/lib/src/test/java/com/blankj/utilcode/util/ConvertUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* desc : test ConvertUtils
2121
* </pre>
2222
*/
23-
public class ConvertUtilsTest {
23+
public class ConvertUtilsTest extends BaseTest {
2424

2525
private byte[] mBytes = new byte[]{0x00, 0x08, (byte) 0xdb, 0x33, 0x45, (byte) 0xab, 0x02, 0x23};
2626
private String hexString = "0008DB3345AB0223";

utilcode/lib/src/test/java/com/blankj/utilcode/util/FileIOUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* desc : test FileIOUtils
1818
* </pre>
1919
*/
20-
public class FileIOUtilsTest {
20+
public class FileIOUtilsTest extends BaseTest {
2121

2222
@Test
2323
public void writeFileFromIS() throws Exception {

0 commit comments

Comments
 (0)