Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xiaoxuan_i809
AndroidUtilCode
提交
a56a1f42
A
AndroidUtilCode
项目概览
xiaoxuan_i809
/
AndroidUtilCode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
AndroidUtilCode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a56a1f42
编写于
1月 29, 2019
作者:
B
Blankj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 01/29 log
上级
96e51ef5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
47 addition
and
17 deletion
+47
-17
CHANGELOG.md
CHANGELOG.md
+3
-2
utilcode/lib/src/main/java/com/blankj/utilcode/util/JsonUtils.java
...lib/src/main/java/com/blankj/utilcode/util/JsonUtils.java
+9
-4
utilcode/lib/src/main/java/com/blankj/utilcode/util/LogUtils.java
.../lib/src/main/java/com/blankj/utilcode/util/LogUtils.java
+9
-4
utilcode/lib/src/test/java/com/blankj/utilcode/util/CloneUtilsTest.java
...rc/test/java/com/blankj/utilcode/util/CloneUtilsTest.java
+12
-2
utilcode/lib/src/test/java/com/blankj/utilcode/util/LogUtilsTest.java
.../src/test/java/com/blankj/utilcode/util/LogUtilsTest.java
+14
-5
未找到文件。
CHANGELOG.md
浏览文件 @
a56a1f42
*
`19/01/28`
[fix] KeyboardUtils#fixSoftInputLeaks didn't work on the device of HuaWei.
*
`19/01/27`
[upd] demo
*
`19/01/29`
[fix] LogUtils format json when json not start with '{'. Publish v1.23.3.
*
`19/01/28`
[fix] KeyboardUtils#fixSoftInputLeaks don't work on the device of HuaWei.
*
`19/01/26`
[fix] NetworkUtils#getNetworkType.
*
`19/01/25`
[add] CloneUtils, PermissionUtils support request permission of WRITE_SETTINGS and DRAW_OVERLAYS. Publish v1.23.2.
*
`19/01/24`
[add] BrightnessUtils and FlashlightUtils.
*
`19/01/23`
[add] Modify the demo of utilcode use kotlin. Publish v1.23.1.
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/JsonUtils.java
浏览文件 @
a56a1f42
...
...
@@ -211,10 +211,15 @@ public final class JsonUtils {
public
static
String
formatJson
(
final
String
json
,
final
int
indentSpaces
)
{
try
{
if
(
json
.
startsWith
(
"{"
))
{
return
new
JSONObject
(
json
).
toString
(
indentSpaces
);
}
else
if
(
json
.
startsWith
(
"["
))
{
return
new
JSONArray
(
json
).
toString
(
indentSpaces
);
for
(
int
i
=
0
,
len
=
json
.
length
();
i
<
len
;
i
++)
{
char
c
=
json
.
charAt
(
i
);
if
(
c
==
'{'
)
{
return
new
JSONObject
(
json
).
toString
(
indentSpaces
);
}
else
if
(
c
==
'['
)
{
return
new
JSONArray
(
json
).
toString
(
indentSpaces
);
}
else
if
(!
Character
.
isWhitespace
(
c
))
{
return
json
;
}
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/LogUtils.java
浏览文件 @
a56a1f42
...
...
@@ -1030,10 +1030,15 @@ public final class LogUtils {
private
static
String
formatJson
(
String
json
)
{
try
{
if
(
json
.
startsWith
(
"{"
))
{
json
=
new
JSONObject
(
json
).
toString
(
2
);
}
else
if
(
json
.
startsWith
(
"["
))
{
json
=
new
JSONArray
(
json
).
toString
(
2
);
for
(
int
i
=
0
,
len
=
json
.
length
();
i
<
len
;
i
++)
{
char
c
=
json
.
charAt
(
i
);
if
(
c
==
'{'
)
{
return
new
JSONObject
(
json
).
toString
(
2
);
}
else
if
(
c
==
'['
)
{
return
new
JSONArray
(
json
).
toString
(
2
);
}
else
if
(!
Character
.
isWhitespace
(
c
))
{
return
json
;
}
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
...
...
utilcode/lib/src/test/java/com/blankj/utilcode/util/CloneUtilsTest.java
浏览文件 @
a56a1f42
...
...
@@ -35,7 +35,9 @@ public class CloneUtilsTest {
@Override
public
String
toString
()
{
return
"{\"code\":"
+
code
+
",\"message\":"
+
message
+
",\"data\":"
+
data
+
"}"
;
return
"{\"code\":"
+
primitive2String
(
code
)
+
",\"message\":"
+
primitive2String
(
message
)
+
",\"data\":"
+
primitive2String
(
data
)
+
"}"
;
}
}
...
...
@@ -51,7 +53,15 @@ public class CloneUtilsTest {
@Override
public
String
toString
()
{
return
"{\"name\":"
+
name
+
",\"gender\":"
+
gender
+
",\"address\":"
+
address
+
"}"
;
return
"{\"name\":"
+
primitive2String
(
name
)
+
",\"gender\":"
+
primitive2String
(
gender
)
+
",\"address\":"
+
primitive2String
(
address
)
+
"}"
;
}
}
private
static
String
primitive2String
(
final
Object
obj
)
{
if
(
obj
==
null
)
return
"null"
;
if
(
obj
instanceof
CharSequence
)
return
"\""
+
obj
.
toString
()
+
"\""
;
return
obj
.
toString
();
}
}
\ No newline at end of file
utilcode/lib/src/test/java/com/blankj/utilcode/util/LogUtilsTest.java
浏览文件 @
a56a1f42
...
...
@@ -16,7 +16,7 @@ import java.util.Map;
*/
public
class
LogUtilsTest
extends
BaseTest
{
private
static
final
String
JSON
=
"{\"tools\": [{ \"name\":\"css format\" , \"site\":\"http://tools.w3cschool.cn/code/css\" },{ \"name\":\"JSON format\" , \"site\":\"http://tools.w3cschool.cn/code/JSON\" },{ \"name\":\"pwd check\" , \"site\":\"http://tools.w3cschool.cn/password/my_password_safe\" }]}"
;
private
static
final
String
JSON
=
"
\r\n
{\"tools\": [{ \"name\":\"css format\" , \"site\":\"http://tools.w3cschool.cn/code/css\" },{ \"name\":\"JSON format\" , \"site\":\"http://tools.w3cschool.cn/code/JSON\" },{ \"name\":\"pwd check\" , \"site\":\"http://tools.w3cschool.cn/password/my_password_safe\" }]}"
;
private
static
final
String
XML
=
"<books><book><author>Jack Herrington</author><title>PHP Hacks</title><publisher>O'Reilly</publisher></book><book><author>Jack Herrington</author><title>Podcasting Hacks</title><publisher>O'Reilly</publisher></book></books>"
;
private
static
final
int
[]
ONE_D_ARRAY
=
new
int
[]{
1
,
2
,
3
};
private
static
final
int
[][]
TWO_D_ARRAY
=
new
int
[][]{{
1
,
2
,
3
},
{
4
,
5
,
6
},
{
7
,
8
,
9
}};
...
...
@@ -166,10 +166,6 @@ public class LogUtilsTest extends BaseTest {
LogUtils
.
d
((
Object
)
TWO_D_ARRAY
);
LogUtils
.
d
(
LIST
);
LogUtils
.
d
(
MAP
);
Object
o
=
GsonUtils
.
fromJson
(
GsonUtils
.
toJson
(
LIST
),
GsonUtils
.
getListType
(
String
.
class
));
System
.
out
.
println
(
o
);
}
static
class
Person
{
...
...
@@ -193,5 +189,18 @@ public class LogUtilsTest extends BaseTest {
private
static
boolean
equals
(
final
Object
o1
,
final
Object
o2
)
{
return
o1
==
o2
||
(
o1
!=
null
&&
o1
.
equals
(
o2
));
}
@Override
public
String
toString
()
{
return
"{\"name\":"
+
primitive2String
(
name
)
+
",\"gender\":"
+
primitive2String
(
gender
)
+
",\"address\":"
+
primitive2String
(
address
)
+
"}"
;
}
}
private
static
String
primitive2String
(
final
Object
obj
)
{
if
(
obj
==
null
)
return
"null"
;
if
(
obj
instanceof
CharSequence
)
return
"\""
+
obj
.
toString
()
+
"\""
;
return
obj
.
toString
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录