Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
* `18/12/19` [fix] AdaptScreenUtils not work in MIUI on Android 5.1.1. Publish v1.22.5.
* `18/12/22` [fix] AdaptScreenUtils#pt2px don't work when start webview. Publish v1.22.6.
* `18/12/21` [add] LogUtils support print Map, Collection and Object to String.
* `18/12/19` [fix] AdaptScreenUtils don't work in MIUI on Android 5.1.1. Publish v1.22.5.
* `18/12/18` [fix] ToastUtils multi show crash when run API 25. Publish v1.22.4.
* `18/12/18` [fix] ImageUtils recycle ret equals src. Publish v1.22.3.
* `18/12/17` [fix] Utils$FileProvider4UtilCode not found. Publish v1.22.3.
Expand Down
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

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

[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.5-brightgreen.svg
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.6-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode

[apiSvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen

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

[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.5-brightgreen.svg
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.6-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode

[apiSvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
Expand Down
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ ext {
compileSdkVersion = 27
minSdkVersion = 14
targetSdkVersion = 27
versionCode = 1_022_005
versionName = '1.22.5'// E.g. 1.9.72 => 1,009,072
versionCode = 1_022_006
versionName = '1.22.6'// E.g. 1.9.72 => 1,009,072

bus = [
isDebug: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ dependencies {
api dep.free_proguard
api 'com.r0adkll:slidableactivity:2.0.5'
compileOnly dep.leakcanary.android_no_op
// api 'com.blankj:utilcode:1.22.5'
// api 'com.blankj:utilcode:1.22.6'
}
2 changes: 1 addition & 1 deletion utilcode/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gradle:
```groovy
implementation 'com.blankj:utilcode:1.22.5'
implementation 'com.blankj:utilcode:1.22.6'
```


Expand Down
2 changes: 1 addition & 1 deletion utilcode/README-STATIC-BUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ apply plugin: "com.blankj.bus"
给 base 模块添加 [AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode) 依赖:

```groovy
api "com.blankj:utilcode:1.22.5"
api "com.blankj:utilcode:1.22.6"
```

比如 module0 中存在的 `Module0Activity.java`,我们通常都是在它内部写一个 `start` 函数来启动它,现在我们给它添加 `@BusUtils.Subscribe` 注解,并给注解的 `name` 赋唯一值,要注意,函数务必要 `public static` 哦:
Expand Down
2 changes: 1 addition & 1 deletion utilcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gradle:
```groovy
implementation 'com.blankj:utilcode:1.22.5'
implementation 'com.blankj:utilcode:1.22.6'
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@
import java.io.StringWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Formatter;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -345,7 +351,9 @@ private static String formatObject(Object object) {
if (object instanceof Throwable) return LogFormatter.throwable2String((Throwable) object);
if (object instanceof Bundle) return LogFormatter.bundle2String((Bundle) object);
if (object instanceof Intent) return LogFormatter.intent2String((Intent) object);
return object.toString();
if (object instanceof Map) return LogFormatter.map2String((Map) object);
if (object instanceof Collection) return LogFormatter.collection2String((Collection) object);
return LogFormatter.object2String(object);
}

private static void print2Console(final int type,
Expand Down Expand Up @@ -982,6 +990,58 @@ static String intent2String(Intent intent) {
return sb.toString();
}

static String map2String(Map map) {
JSONObject jsonObject = new JSONObject(map);
return jsonObject.toString();
}

static String collection2String(Collection collection) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("size", collection.size());
jsonObject.put("data", collection);
return jsonObject.toString();
} catch (JSONException ignore) {
return collection.toString();
}
}

static String object2String(Object object) {
if (object instanceof String || object instanceof JSONObject ||
object instanceof JSONArray) {
return object.toString();
}
Class<?> clazz = object.getClass();
List<Field> tmp = Arrays.asList(clazz.getDeclaredFields());
ArrayList<Field> list = new ArrayList<>(tmp);
while (clazz != Object.class) {
clazz = clazz.getSuperclass();
if (clazz == null) {
break;
}
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
int modifier = field.getModifiers();
if (Modifier.isPublic(modifier)) {
list.add(field);
}
}
}
Field[] a = new Field[list.size()];
Field[] fields = list.toArray(a);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("object", object.toString());
for (Field field : fields) {
String fieldName = field.getName();
Object obj = field.get(object);
jsonObject.put(fieldName, obj);
}
} catch (Exception ignore) {
}
return jsonObject.toString();
}

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private static void clipData2String(ClipData clipData, StringBuilder sb) {
ClipData.Item item = clipData.getItemAt(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public static String getBroadcastIpAddress() {
NetworkInterface ni = nis.nextElement();
if (!ni.isUp() || ni.isLoopback()) continue;
List<InterfaceAddress> ias = ni.getInterfaceAddresses();
for (int i = 0; i < ias.size(); i++) {
for (int i = 0, size = ias.size(); i < size; i++) {
InterfaceAddress ia = ias.get(i);
InetAddress broadcast = ia.getBroadcast();
if (broadcast != null) {
Expand Down