Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mmm-rain
AndroidUtilCode
提交
fe70516b
A
AndroidUtilCode
项目概览
mmm-rain
/
AndroidUtilCode
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
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 搜索 >>
提交
fe70516b
编写于
1月 03, 2019
作者:
B
Blankj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 01/03 log
上级
df832451
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
143 addition
and
59 deletion
+143
-59
bus-gradle-plugin/src/main/java/com/blankj/util/JsonUtils.groovy
...dle-plugin/src/main/java/com/blankj/util/JsonUtils.groovy
+3
-2
utilcode/lib/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java
...rc/main/java/com/blankj/utilcode/util/CacheDiskUtils.java
+8
-4
utilcode/lib/src/main/java/com/blankj/utilcode/util/CacheDoubleUtils.java
.../main/java/com/blankj/utilcode/util/CacheDoubleUtils.java
+9
-4
utilcode/lib/src/main/java/com/blankj/utilcode/util/CacheMemoryUtils.java
.../main/java/com/blankj/utilcode/util/CacheMemoryUtils.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
-6
utilcode/lib/src/main/java/com/blankj/utilcode/util/SPUtils.java
...e/lib/src/main/java/com/blankj/utilcode/util/SPUtils.java
+9
-4
utilcode/lib/src/main/java/com/blankj/utilcode/util/ThreadUtils.java
...b/src/main/java/com/blankj/utilcode/util/ThreadUtils.java
+10
-10
utilcode/lib/src/main/java/com/blankj/utilcode/util/Utils.java
...ode/lib/src/main/java/com/blankj/utilcode/util/Utils.java
+4
-5
utilcode/lib/src/test/java/com/blankj/utilcode/util/BaseTest.java
.../lib/src/test/java/com/blankj/utilcode/util/BaseTest.java
+0
-5
utilcode/lib/src/test/java/com/blankj/utilcode/util/LogUtilsTest.java
.../src/test/java/com/blankj/utilcode/util/LogUtilsTest.java
+82
-3
utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/log/LogActivity.java
...java/com/blankj/utilcode/pkg/feature/log/LogActivity.java
+0
-4
utilcode/pkg/src/main/res/layout/activity_log.xml
utilcode/pkg/src/main/res/layout/activity_log.xml
+0
-7
utilcode/pkg/src/main/res/values/strings.xml
utilcode/pkg/src/main/res/values/strings.xml
+0
-1
未找到文件。
bus-gradle-plugin/src/main/java/com/blankj/util/JsonUtils.groovy
浏览文件 @
fe70516b
...
...
@@ -13,8 +13,9 @@ import com.google.gson.GsonBuilder
*/
final
class
JsonUtils
{
static
final
Gson
GSON
=
new
GsonBuilder
().
setPrettyPrinting
().
create
()
static
String
getFormatJson
(
Object
object
)
{
Gson
gson
=
new
GsonBuilder
().
setPrettyPrinting
().
create
()
return
gson
.
toJson
(
object
)
return
GSON
.
toJson
(
object
)
}
}
utilcode/lib/src/main/java/com/blankj/utilcode/util/CacheDiskUtils.java
浏览文件 @
fe70516b
...
...
@@ -34,7 +34,6 @@ import java.util.HashMap;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicLong
;
...
...
@@ -52,7 +51,7 @@ public final class CacheDiskUtils implements CacheConstants {
private
static
final
int
DEFAULT_MAX_COUNT
=
Integer
.
MAX_VALUE
;
private
static
final
String
CACHE_PREFIX
=
"cdu"
;
private
static
final
Map
<
String
,
CacheDiskUtils
>
CACHE_MAP
=
new
Concurrent
HashMap
<>();
private
static
final
Map
<
String
,
CacheDiskUtils
>
CACHE_MAP
=
new
HashMap
<>();
private
final
String
mCacheKey
;
private
final
File
mCacheDir
;
...
...
@@ -138,8 +137,13 @@ public final class CacheDiskUtils implements CacheConstants {
final
String
cacheKey
=
cacheDir
.
getAbsoluteFile
()
+
"_"
+
maxSize
+
"_"
+
maxCount
;
CacheDiskUtils
cache
=
CACHE_MAP
.
get
(
cacheKey
);
if
(
cache
==
null
)
{
cache
=
new
CacheDiskUtils
(
cacheKey
,
cacheDir
,
maxSize
,
maxCount
);
CACHE_MAP
.
put
(
cacheKey
,
cache
);
synchronized
(
CacheDiskUtils
.
class
)
{
cache
=
CACHE_MAP
.
get
(
cacheKey
);
if
(
cache
==
null
)
{
cache
=
new
CacheDiskUtils
(
cacheKey
,
cacheDir
,
maxSize
,
maxCount
);
CACHE_MAP
.
put
(
cacheKey
,
cache
);
}
}
}
return
cache
;
}
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/CacheDoubleUtils.java
浏览文件 @
fe70516b
...
...
@@ -11,8 +11,8 @@ import org.json.JSONArray;
import
org.json.JSONObject
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* <pre>
...
...
@@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public
final
class
CacheDoubleUtils
implements
CacheConstants
{
private
static
final
Map
<
String
,
CacheDoubleUtils
>
CACHE_MAP
=
new
Concurrent
HashMap
<>();
private
static
final
Map
<
String
,
CacheDoubleUtils
>
CACHE_MAP
=
new
HashMap
<>();
private
final
CacheMemoryUtils
mCacheMemoryUtils
;
private
final
CacheDiskUtils
mCacheDiskUtils
;
...
...
@@ -50,8 +50,13 @@ public final class CacheDoubleUtils implements CacheConstants {
final
String
cacheKey
=
cacheDiskUtils
.
toString
()
+
"_"
+
cacheMemoryUtils
.
toString
();
CacheDoubleUtils
cache
=
CACHE_MAP
.
get
(
cacheKey
);
if
(
cache
==
null
)
{
cache
=
new
CacheDoubleUtils
(
cacheMemoryUtils
,
cacheDiskUtils
);
CACHE_MAP
.
put
(
cacheKey
,
cache
);
synchronized
(
CacheDoubleUtils
.
class
)
{
cache
=
CACHE_MAP
.
get
(
cacheKey
);
if
(
cache
==
null
)
{
cache
=
new
CacheDoubleUtils
(
cacheMemoryUtils
,
cacheDiskUtils
);
CACHE_MAP
.
put
(
cacheKey
,
cache
);
}
}
}
return
cache
;
}
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/CacheMemoryUtils.java
浏览文件 @
fe70516b
...
...
@@ -5,8 +5,8 @@ import android.support.v4.util.LruCache;
import
com.blankj.utilcode.constant.CacheConstants
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* <pre>
...
...
@@ -20,7 +20,7 @@ public final class CacheMemoryUtils implements CacheConstants {
private
static
final
int
DEFAULT_MAX_COUNT
=
256
;
private
static
final
Map
<
String
,
CacheMemoryUtils
>
CACHE_MAP
=
new
Concurrent
HashMap
<>();
private
static
final
Map
<
String
,
CacheMemoryUtils
>
CACHE_MAP
=
new
HashMap
<>();
private
final
String
mCacheKey
;
private
final
LruCache
<
String
,
CacheValue
>
mMemoryCache
;
...
...
@@ -54,8 +54,13 @@ public final class CacheMemoryUtils implements CacheConstants {
public
static
CacheMemoryUtils
getInstance
(
final
String
cacheKey
,
final
int
maxCount
)
{
CacheMemoryUtils
cache
=
CACHE_MAP
.
get
(
cacheKey
);
if
(
cache
==
null
)
{
cache
=
new
CacheMemoryUtils
(
cacheKey
,
new
LruCache
<
String
,
CacheValue
>(
maxCount
));
CACHE_MAP
.
put
(
cacheKey
,
cache
);
synchronized
(
CacheMemoryUtils
.
class
)
{
cache
=
CACHE_MAP
.
get
(
cacheKey
);
if
(
cache
==
null
)
{
cache
=
new
CacheMemoryUtils
(
cacheKey
,
new
LruCache
<
String
,
CacheValue
>(
maxCount
));
CACHE_MAP
.
put
(
cacheKey
,
cache
);
}
}
}
return
cache
;
}
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/LogUtils.java
浏览文件 @
fe70516b
...
...
@@ -33,7 +33,6 @@ import java.io.StringReader;
import
java.io.StringWriter
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.reflect.Array
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Type
;
import
java.net.UnknownHostException
;
...
...
@@ -103,7 +102,8 @@ public final class LogUtils {
private
static
final
String
ARGS
=
"args"
;
private
static
final
String
PLACEHOLDER
=
" "
;
private
static
final
Config
CONFIG
=
new
Config
();
private
static
final
Gson
GSON
=
new
GsonBuilder
().
serializeNulls
().
create
();
private
static
final
Gson
GSON
=
new
GsonBuilder
()
.
setPrettyPrinting
().
serializeNulls
().
create
();
private
static
final
ThreadLocal
<
SimpleDateFormat
>
SDF_THREAD_LOCAL
=
new
ThreadLocal
<>();
...
...
@@ -794,7 +794,10 @@ public final class LogUtils {
}
static
String
object2Json
(
Object
object
)
{
return
formatJson
(
GSON
.
toJson
(
object
));
if
(
object
instanceof
CharSequence
)
{
return
formatJson
(
object
.
toString
());
}
return
GSON
.
toJson
(
object
);
}
static
String
formatXml
(
String
xml
)
{
...
...
@@ -803,7 +806,7 @@ public final class LogUtils {
StreamResult
xmlOutput
=
new
StreamResult
(
new
StringWriter
());
Transformer
transformer
=
TransformerFactory
.
newInstance
().
newTransformer
();
transformer
.
setOutputProperty
(
OutputKeys
.
INDENT
,
"yes"
);
transformer
.
setOutputProperty
(
"{http://xml.apache.org/xslt}indent-amount"
,
"
4
"
);
transformer
.
setOutputProperty
(
"{http://xml.apache.org/xslt}indent-amount"
,
"
2
"
);
transformer
.
transform
(
xmlInput
,
xmlOutput
);
xml
=
xmlOutput
.
getWriter
().
toString
().
replaceFirst
(
">"
,
">"
+
LINE_SEP
);
}
catch
(
Exception
e
)
{
...
...
@@ -966,9 +969,9 @@ public final class LogUtils {
private
static
String
formatJson
(
String
json
)
{
try
{
if
(
json
.
startsWith
(
"{"
))
{
json
=
new
JSONObject
(
json
).
toString
(
4
);
json
=
new
JSONObject
(
json
).
toString
(
2
);
}
else
if
(
json
.
startsWith
(
"["
))
{
json
=
new
JSONArray
(
json
).
toString
(
4
);
json
=
new
JSONArray
(
json
).
toString
(
2
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/SPUtils.java
浏览文件 @
fe70516b
...
...
@@ -6,9 +6,9 @@ import android.content.SharedPreferences;
import
android.support.annotation.NonNull
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* <pre>
...
...
@@ -21,7 +21,7 @@ import java.util.concurrent.ConcurrentHashMap;
@SuppressLint
(
"ApplySharedPref"
)
public
final
class
SPUtils
{
private
static
final
Map
<
String
,
SPUtils
>
SP_UTILS_MAP
=
new
Concurrent
HashMap
<>();
private
static
final
Map
<
String
,
SPUtils
>
SP_UTILS_MAP
=
new
HashMap
<>();
private
SharedPreferences
sp
;
/**
...
...
@@ -64,8 +64,13 @@ public final class SPUtils {
if
(
isSpace
(
spName
))
spName
=
"spUtils"
;
SPUtils
spUtils
=
SP_UTILS_MAP
.
get
(
spName
);
if
(
spUtils
==
null
)
{
spUtils
=
new
SPUtils
(
spName
,
mode
);
SP_UTILS_MAP
.
put
(
spName
,
spUtils
);
synchronized
(
SPUtils
.
class
)
{
spUtils
=
SP_UTILS_MAP
.
get
(
spName
);
if
(
spUtils
==
null
)
{
spUtils
=
new
SPUtils
(
spName
,
mode
);
SP_UTILS_MAP
.
put
(
spName
,
spUtils
);
}
}
}
return
spUtils
;
}
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/ThreadUtils.java
浏览文件 @
fe70516b
...
...
@@ -6,9 +6,10 @@ import android.support.annotation.IntRange;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.util.Log
;
import
android.util.SparseArray
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
...
...
@@ -29,10 +30,8 @@ import java.util.concurrent.atomic.AtomicLong;
*/
public
final
class
ThreadUtils
{
private
static
final
Map
<
Integer
,
Map
<
Integer
,
ExecutorService
>>
TYPE_PRIORITY_POOLS
=
new
ConcurrentHashMap
<>();
private
static
final
Map
<
Task
,
ScheduledExecutorService
>
TASK_SCHEDULED
=
new
ConcurrentHashMap
<>();
private
static
final
SparseArray
<
SparseArray
<
ExecutorService
>>
TYPE_PRIORITY_POOLS
=
new
SparseArray
<>();
private
static
final
Map
<
Task
,
ScheduledExecutorService
>
TASK_SCHEDULED
=
new
HashMap
<>();
private
static
final
byte
TYPE_SINGLE
=
-
1
;
private
static
final
byte
TYPE_CACHED
=
-
2
;
...
...
@@ -878,7 +877,7 @@ public final class ThreadUtils {
},
initialDelay
,
period
,
unit
);
}
private
static
ScheduledExecutorService
getScheduledByTask
(
final
Task
task
)
{
private
s
ynchronized
s
tatic
ScheduledExecutorService
getScheduledByTask
(
final
Task
task
)
{
ScheduledExecutorService
scheduled
=
TASK_SCHEDULED
.
get
(
task
);
if
(
scheduled
==
null
)
{
UtilsThreadFactory
factory
=
new
UtilsThreadFactory
(
"scheduled"
,
Thread
.
MAX_PRIORITY
);
...
...
@@ -888,7 +887,7 @@ public final class ThreadUtils {
return
scheduled
;
}
private
static
void
removeScheduleByTask
(
final
Task
task
)
{
private
s
ynchronized
s
tatic
void
removeScheduleByTask
(
final
Task
task
)
{
ScheduledExecutorService
scheduled
=
TASK_SCHEDULED
.
get
(
task
);
if
(
scheduled
!=
null
)
{
TASK_SCHEDULED
.
remove
(
task
);
...
...
@@ -900,11 +899,11 @@ public final class ThreadUtils {
return
getPoolByTypeAndPriority
(
type
,
Thread
.
NORM_PRIORITY
);
}
private
static
ExecutorService
getPoolByTypeAndPriority
(
final
int
type
,
final
int
priority
)
{
private
s
ynchronized
s
tatic
ExecutorService
getPoolByTypeAndPriority
(
final
int
type
,
final
int
priority
)
{
ExecutorService
pool
;
Map
<
Integer
,
ExecutorService
>
priorityPools
=
TYPE_PRIORITY_POOLS
.
get
(
type
);
SparseArray
<
ExecutorService
>
priorityPools
=
TYPE_PRIORITY_POOLS
.
get
(
type
);
if
(
priorityPools
==
null
)
{
priorityPools
=
new
ConcurrentHashMap
<>();
priorityPools
=
new
SparseArray
<>();
pool
=
createPoolByTypeAndPriority
(
type
,
priority
);
priorityPools
.
put
(
priority
,
pool
);
TYPE_PRIORITY_POOLS
.
put
(
type
,
priorityPools
);
...
...
@@ -921,6 +920,7 @@ public final class ThreadUtils {
private
static
ExecutorService
createPoolByTypeAndPriority
(
final
int
type
,
final
int
priority
)
{
switch
(
type
)
{
case
TYPE_SINGLE:
System
.
out
.
println
(
"hehe"
);
return
Executors
.
newSingleThreadExecutor
(
new
UtilsThreadFactory
(
"single"
,
priority
)
);
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/Utils.java
浏览文件 @
fe70516b
...
...
@@ -11,13 +11,13 @@ import android.support.v4.content.FileProvider;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* <pre>
...
...
@@ -158,10 +158,9 @@ public final class Utils {
static
class
ActivityLifecycleImpl
implements
ActivityLifecycleCallbacks
{
final
LinkedList
<
Activity
>
mActivityList
=
new
LinkedList
<>();
final
Map
<
Object
,
OnAppStatusChangedListener
>
mStatusListenerMap
=
new
ConcurrentHashMap
<>();
final
Map
<
Activity
,
Set
<
OnActivityDestroyedListener
>>
mDestroyedListenerMap
=
new
ConcurrentHashMap
<>();
final
LinkedList
<
Activity
>
mActivityList
=
new
LinkedList
<>();
final
Map
<
Object
,
OnAppStatusChangedListener
>
mStatusListenerMap
=
new
HashMap
<>();
final
Map
<
Activity
,
Set
<
OnActivityDestroyedListener
>>
mDestroyedListenerMap
=
new
HashMap
<>();
private
int
mForegroundCount
=
0
;
private
int
mConfigCount
=
0
;
...
...
utilcode/lib/src/test/java/com/blankj/utilcode/util/BaseTest.java
浏览文件 @
fe70516b
package
com.blankj.utilcode.util
;
import
android.util.Log
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.RobolectricTestRunner
;
...
...
@@ -29,9 +27,6 @@ public class BaseTest {
@Test
public
void
test
()
throws
Exception
{
Log
.
e
(
"haha"
,
"test: "
);
// final CountDownLatch countDownLatch = new CountDownLatch(1);
// final Scanner scanner = new Scanner(System.in);
// ExecutorService singlePool = ThreadUtils.getSinglePool();
...
...
utilcode/lib/src/test/java/com/blankj/utilcode/util/LogUtilsTest.java
浏览文件 @
fe70516b
package
com.blankj.utilcode.util
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* <pre>
* author: Blankj
...
...
@@ -12,10 +20,16 @@ import org.junit.Test;
*/
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
=
"{\"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
}};
private
static
final
ArrayList
<
String
>
LIST
=
new
ArrayList
<>();
private
static
final
Map
<
String
,
String
>
MAP
=
new
HashMap
<>();
@Test
public
void
testV
()
{
LogUtils
.
v
();
LogUtils
.
v
(
""
);
LogUtils
.
v
(
null
);
LogUtils
.
v
(
"hello"
);
...
...
@@ -25,6 +39,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testVTag
()
{
LogUtils
.
vTag
(
""
);
LogUtils
.
vTag
(
""
,
""
);
LogUtils
.
vTag
(
"TAG"
,
null
);
LogUtils
.
vTag
(
"TAG"
,
"hello"
);
...
...
@@ -34,6 +49,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testD
()
{
LogUtils
.
d
();
LogUtils
.
d
(
""
);
LogUtils
.
d
(
null
);
LogUtils
.
d
(
"hello"
);
...
...
@@ -43,6 +59,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testDTag
()
{
LogUtils
.
dTag
(
""
);
LogUtils
.
dTag
(
""
,
""
);
LogUtils
.
dTag
(
"TAG"
,
null
);
LogUtils
.
dTag
(
"TAG"
,
"hello"
);
...
...
@@ -52,6 +69,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testI
()
{
LogUtils
.
i
();
LogUtils
.
i
(
""
);
LogUtils
.
i
(
null
);
LogUtils
.
i
(
"hello"
);
...
...
@@ -61,6 +79,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testITag
()
{
LogUtils
.
iTag
(
""
);
LogUtils
.
iTag
(
""
,
""
);
LogUtils
.
iTag
(
"TAG"
,
null
);
LogUtils
.
iTag
(
"TAG"
,
"hello"
);
...
...
@@ -70,6 +89,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testW
()
{
LogUtils
.
w
();
LogUtils
.
w
(
""
);
LogUtils
.
w
(
null
);
LogUtils
.
w
(
"hello"
);
...
...
@@ -79,6 +99,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testWTag
()
{
LogUtils
.
wTag
(
""
);
LogUtils
.
wTag
(
""
,
""
);
LogUtils
.
wTag
(
"TAG"
,
null
);
LogUtils
.
wTag
(
"TAG"
,
"hello"
);
...
...
@@ -88,6 +109,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testE
()
{
LogUtils
.
e
();
LogUtils
.
e
(
""
);
LogUtils
.
e
(
null
);
LogUtils
.
e
(
"hello"
);
...
...
@@ -97,6 +119,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testETag
()
{
LogUtils
.
eTag
(
""
);
LogUtils
.
eTag
(
""
,
""
);
LogUtils
.
eTag
(
"TAG"
,
null
);
LogUtils
.
eTag
(
"TAG"
,
"hello"
);
...
...
@@ -106,6 +129,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testA
()
{
LogUtils
.
a
();
LogUtils
.
a
(
""
);
LogUtils
.
a
(
null
);
LogUtils
.
a
(
"hello"
);
...
...
@@ -115,6 +139,7 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testATag
()
{
LogUtils
.
aTag
(
""
);
LogUtils
.
aTag
(
""
,
""
);
LogUtils
.
aTag
(
"TAG"
,
null
);
LogUtils
.
aTag
(
"TAG"
,
"hello"
);
...
...
@@ -124,14 +149,68 @@ public class LogUtilsTest extends BaseTest {
@Test
public
void
testJson
()
{
//
LogUtils.json(JSON);
LogUtils
.
json
(
new
Person
(
"B
\n
lankj"
));
LogUtils
.
json
(
JSON
);
LogUtils
.
json
(
new
Person
(
"Blankj"
));
}
@Test
public
void
testXml
()
{
LogUtils
.
xml
(
XML
);
}
@Test
public
void
testObject
()
{
LIST
.
add
(
"hello"
);
LIST
.
add
(
"log"
);
LIST
.
add
(
"utils"
);
MAP
.
put
(
"name"
,
"AndroidUtilCode"
);
MAP
.
put
(
"class"
,
"LogUtils"
);
LogUtils
.
d
((
Object
)
ONE_D_ARRAY
);
LogUtils
.
d
((
Object
)
TWO_D_ARRAY
);
LogUtils
.
d
(
LIST
);
LogUtils
.
d
(
MAP
);
LogUtils
.
d
(
formatJson
(
array2String
(
TWO_D_ARRAY
)));
}
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
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
json
;
}
static
String
array2String
(
Object
object
)
{
if
(
object
instanceof
Object
[])
{
return
Arrays
.
deepToString
((
Object
[])
object
);
}
else
if
(
object
instanceof
boolean
[])
{
return
Arrays
.
toString
((
boolean
[])
object
);
}
else
if
(
object
instanceof
byte
[])
{
return
Arrays
.
toString
((
byte
[])
object
);
}
else
if
(
object
instanceof
char
[])
{
return
Arrays
.
toString
((
char
[])
object
);
}
else
if
(
object
instanceof
double
[])
{
return
Arrays
.
toString
((
double
[])
object
);
}
else
if
(
object
instanceof
float
[])
{
return
Arrays
.
toString
((
float
[])
object
);
}
else
if
(
object
instanceof
int
[])
{
return
Arrays
.
toString
((
int
[])
object
);
}
else
if
(
object
instanceof
long
[])
{
return
Arrays
.
toString
((
long
[])
object
);
}
else
if
(
object
instanceof
short
[])
{
return
Arrays
.
toString
((
short
[])
object
);
}
throw
new
IllegalArgumentException
(
"Array has incompatible type: "
+
object
.
getClass
());
}
static
class
Person
{
String
name
;
...
...
utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/log/LogActivity.java
浏览文件 @
fe70516b
...
...
@@ -53,7 +53,6 @@ public class LogActivity extends BaseBackActivity {
private
static
final
Intent
INTENT
=
new
Intent
();
private
static
final
ArrayList
<
String
>
LIST
=
new
ArrayList
<>();
private
static
final
Map
<
String
,
String
>
MAP
=
new
HashMap
<>();
private
static
final
Object
OBJECT
=
new
Config
();
private
static
final
String
LONG_STR
;
...
...
@@ -298,9 +297,6 @@ public class LogActivity extends BaseBackActivity {
}
else
if
(
i1
==
R
.
id
.
btn_log_map
)
{
LogUtils
.
e
(
MAP
);
}
else
if
(
i1
==
R
.
id
.
btn_log_object
)
{
LogUtils
.
e
(
OBJECT
);
}
}
...
...
utilcode/pkg/src/main/res/layout/activity_log.xml
浏览文件 @
fe70516b
...
...
@@ -188,11 +188,4 @@
android:layout_height=
"wrap_content"
android:text=
"@string/log_map"
/>
<Button
android:id=
"@+id/btn_log_object"
style=
"@style/WideBtnStyle"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/log_object"
/>
</LinearLayout>
\ No newline at end of file
utilcode/pkg/src/main/res/values/strings.xml
浏览文件 @
fe70516b
...
...
@@ -208,7 +208,6 @@
<string
name=
"log_intent"
>
Log Intent
</string>
<string
name=
"log_array_list"
>
Log Array List
</string>
<string
name=
"log_map"
>
Log Map
</string>
<string
name=
"log_object"
>
Log Object
</string>
<!--Permission 相关-->
<string
name=
"permission_open_app_settings"
>
Open App Settings
</string>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录