Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mmm-rain
AndroidUtilCode
提交
28dcee3e
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,发现更多精彩内容 >>
提交
28dcee3e
编写于
9月 29, 2016
作者:
C
cmj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 09/29 log
上级
8abb3627
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
281 addition
and
135 deletion
+281
-135
utilcode/src/main/java/com/blankj/utilcode/utils/AppUtils.java
...ode/src/main/java/com/blankj/utilcode/utils/AppUtils.java
+60
-23
utilcode/src/main/java/com/blankj/utilcode/utils/CleanUtils.java
...e/src/main/java/com/blankj/utilcode/utils/CleanUtils.java
+39
-57
utilcode/src/main/java/com/blankj/utilcode/utils/EmptyUtils.java
...e/src/main/java/com/blankj/utilcode/utils/EmptyUtils.java
+36
-2
utilcode/src/main/java/com/blankj/utilcode/utils/FileUtils.java
...de/src/main/java/com/blankj/utilcode/utils/FileUtils.java
+83
-33
utilcode/src/main/java/com/blankj/utilcode/utils/NetworkUtils.java
...src/main/java/com/blankj/utilcode/utils/NetworkUtils.java
+9
-9
utilcode/src/main/java/com/blankj/utilcode/utils/ThreadPoolUtils.java
.../main/java/com/blankj/utilcode/utils/ThreadPoolUtils.java
+1
-2
utilcode/src/main/java/com/blankj/utilcode/utils/ToastUtils.java
...e/src/main/java/com/blankj/utilcode/utils/ToastUtils.java
+12
-0
utilcode/src/main/java/com/blankj/utilcode/utils/VibrationUtils.java
...c/main/java/com/blankj/utilcode/utils/VibrationUtils.java
+12
-0
utilcode/src/main/java/com/blankj/utilcode/utils/ZipUtils.java
...ode/src/main/java/com/blankj/utilcode/utils/ZipUtils.java
+1
-3
utilcode/src/test/java/com/blankj/utilcode/utils/EmptyUtilsTest.java
...c/test/java/com/blankj/utilcode/utils/EmptyUtilsTest.java
+14
-2
utilcode/src/test/java/com/blankj/utilcode/utils/FileUtilsTest.java
...rc/test/java/com/blankj/utilcode/utils/FileUtilsTest.java
+5
-0
utilcode/src/test/java/com/blankj/utilcode/utils/TestUtils.java
...de/src/test/java/com/blankj/utilcode/utils/TestUtils.java
+9
-4
未找到文件。
utilcode/src/main/java/com/blankj/utilcode/utils/AppUtils.java
浏览文件 @
28dcee3e
...
...
@@ -2,7 +2,6 @@ package com.blankj.utilcode.utils;
import
android.app.Activity
;
import
android.app.ActivityManager
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.pm.ApplicationInfo
;
import
android.content.pm.PackageInfo
;
...
...
@@ -36,8 +35,7 @@ public class AppUtils {
* @return {@code true}: 已安装<br>{@code false}: 未安装
*/
public
static
boolean
isInstallApp
(
Context
context
,
String
packageName
)
{
return
!
StringUtils
.
isSpace
(
packageName
)
&&
context
.
getPackageManager
().
getLaunchIntentForPackage
(
packageName
)
!=
null
;
return
!
StringUtils
.
isSpace
(
packageName
)
&&
IntentUtils
.
getLaunchAppIntent
(
context
,
packageName
)
!=
null
;
}
/**
...
...
@@ -335,21 +333,21 @@ public class AppUtils {
}
/**
* 判断
是否是系统App
* 判断
App是否是系统应用
*
* @param context 上下文
* @return {@code true}: 是<br>{@code false}:
不是
* @return {@code true}: 是<br>{@code false}:
否
*/
public
static
boolean
isSystemApp
(
Context
context
)
{
return
isSystemApp
(
context
,
context
.
getPackageName
());
}
/**
* 判断
是否是系统App
* 判断
App是否是系统应用
*
* @param context 上下文
* @param packageName 包名
* @return {@code true}: 是<br>{@code false}:
不是
* @return {@code true}: 是<br>{@code false}:
否
*/
public
static
boolean
isSystemApp
(
Context
context
,
String
packageName
)
{
if
(
StringUtils
.
isSpace
(
packageName
))
return
false
;
...
...
@@ -363,6 +361,33 @@ public class AppUtils {
return
false
;
}
/**
* 判断App是否处于前台
* <p>需添加权限 {@code <uses-permission android:name="android.permission.GET_TASKS"/>}</p>
* <p>并且必须是系统应用该方法才有效</p>
*
* @param context 上下文
* @return {@code true}: 是<br>{@code false}: 否
*/
public
static
boolean
isAppForeground
(
Context
context
)
{
return
isAppForeground
(
context
,
context
.
getPackageName
());
}
/**
* 判断App是否处于前台
* <p>需添加权限 {@code <uses-permission android:name="android.permission.GET_TASKS"/>}</p>
* <p>并且必须是系统应用该方法才有效</p>
*
* @param context 上下文
* @return {@code true}: 是<br>{@code false}: 否
*/
public
static
boolean
isAppForeground
(
Context
context
,
String
packageName
)
{
ActivityManager
am
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
@SuppressWarnings
(
"deprecation"
)
List
<
ActivityManager
.
RunningTaskInfo
>
tasks
=
am
.
getRunningTasks
(
1
);
return
!
tasks
.
isEmpty
()
&&
tasks
.
get
(
0
).
topActivity
.
getPackageName
().
equals
(
packageName
);
}
/**
* 封装App信息的Bean类
*/
...
...
@@ -521,7 +546,7 @@ public class AppUtils {
* @param context 上下文
* @return 所有已安装的AppInfo列表
*/
public
static
List
<
AppInfo
>
getA
llA
ppsInfo
(
Context
context
)
{
public
static
List
<
AppInfo
>
getAppsInfo
(
Context
context
)
{
List
<
AppInfo
>
list
=
new
ArrayList
<>();
PackageManager
pm
=
context
.
getPackageManager
();
// 获取系统中安装的所有软件信息
...
...
@@ -535,23 +560,35 @@ public class AppUtils {
}
/**
* 判断当前App处于前台还是后台
* <p>需添加权限 {@code <uses-permission android:name="android.permission.GET_TASKS"/>}</p>
* <p>并且必须是系统应用该方法才有效</p>
* 清除App所有数据
*
* @param context 上下文
* @
return {@code true}: 后台<br>{@code false}: 前台
* @param context
上下文
* @
param dirPaths 目录路径
*/
public
static
boolean
isAppBackground
(
Context
context
)
{
ActivityManager
am
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
@SuppressWarnings
(
"deprecation"
)
List
<
ActivityManager
.
RunningTaskInfo
>
tasks
=
am
.
getRunningTasks
(
1
);
if
(!
tasks
.
isEmpty
())
{
ComponentName
topActivity
=
tasks
.
get
(
0
).
topActivity
;
if
(!
topActivity
.
getPackageName
().
equals
(
context
.
getPackageName
()))
{
return
true
;
}
public
static
boolean
cleanAppData
(
Context
context
,
String
...
dirPaths
)
{
File
[]
dirs
=
new
File
[
dirPaths
.
length
];
int
i
=
0
;
for
(
String
dirPath
:
dirPaths
)
{
dirs
[
i
++]
=
new
File
(
dirPath
);
}
return
false
;
return
cleanAppData
(
context
,
dirs
);
}
/**
* 清除App所有数据
*
* @param context 上下文
* @param dirs 目录
*/
public
static
boolean
cleanAppData
(
Context
context
,
File
...
dirs
)
{
boolean
isSuccess
=
CleanUtils
.
cleanInternalCache
(
context
);
isSuccess
&=
CleanUtils
.
cleanInternalDbs
(
context
);
isSuccess
&=
CleanUtils
.
cleanInternalSP
(
context
);
isSuccess
&=
CleanUtils
.
cleanInternalFiles
(
context
);
isSuccess
&=
CleanUtils
.
cleanExternalCache
(
context
);
for
(
File
dir
:
dirs
)
{
isSuccess
&=
CleanUtils
.
cleanCustomCache
(
dir
);
}
return
isSuccess
;
}
}
\ No newline at end of file
utilcode/src/main/java/com/blankj/utilcode/utils/CleanUtils.java
浏览文件 @
28dcee3e
package
com.blankj.utilcode.utils
;
import
android.content.Context
;
import
android.os.Environment
;
import
java.io.File
;
...
...
@@ -20,106 +19,89 @@ public class CleanUtils {
}
/**
* 清除本应用所有的数据
* 清除内部缓存
* <p>/data/data/com.xxx.xxx/cache</p>
*
* @param context
上下文
* @
param filePath 文件路径
* @param context 上下文
* @
return {@code true}: 清除成功<br>{@code false}: 清除失败
*/
public
static
void
cleanApplicationData
(
Context
context
,
String
...
filePath
)
{
cleanInternalCache
(
context
);
cleanExternalCache
(
context
);
cleanDatabases
(
context
);
cleanSharedPreference
(
context
);
cleanFiles
(
context
);
for
(
String
fp
:
filePath
)
{
cleanCustomCache
(
fp
);
}
public
static
boolean
cleanInternalCache
(
Context
context
)
{
return
FileUtils
.
deleteFilesInDir
(
context
.
getCacheDir
());
}
/**
* 清除
应用内部缓存
* <p>/data/data/com.xxx.xxx/
cache
</p>
* 清除
内部文件
* <p>/data/data/com.xxx.xxx/
files
</p>
*
* @param context 上下文
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
*/
public
static
void
cleanInternalCache
(
Context
context
)
{
deleteFilesByDirectory
(
context
.
getCache
Dir
());
public
static
boolean
cleanInternalFiles
(
Context
context
)
{
return
FileUtils
.
deleteFilesInDir
(
context
.
getFiles
Dir
());
}
/**
* 清除
应用所有
数据库
* 清除
内部
数据库
* <p>/data/data/com.xxx.xxx/databases</p>
*
* @param context 上下文
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
*/
public
static
void
cleanDatabases
(
Context
context
)
{
deleteFilesByDirectory
(
new
File
(
context
.
getFilesDir
().
getPath
()
+
context
.
getPackageName
()
+
File
.
separator
+
"databases"
));
public
static
boolean
cleanInternalDbs
(
Context
context
)
{
return
FileUtils
.
deleteFilesInDir
(
context
.
getFilesDir
().
getParent
()
+
File
.
separator
+
"databases"
);
}
/**
* 按名字清除应用数据库
* 根据名称清除数据库
* <p>/data/data/com.xxx.xxx/databases/dbName</p>
*
* @param context 上下文
* @param dbName 数据库名称
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
*/
public
static
void
cleanDatabase
ByName
(
Context
context
,
String
dbName
)
{
context
.
deleteDatabase
(
dbName
);
public
static
boolean
cleanInternalDb
ByName
(
Context
context
,
String
dbName
)
{
return
context
.
deleteDatabase
(
dbName
);
}
/**
* 清除
应用sp
* 清除
内部SP
* <p>/data/data/com.xxx.xxx/shared_prefs</p>
*
* @param context 上下文
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
*/
public
static
void
cleanSharedPreference
(
Context
context
)
{
deleteFilesByDirectory
(
new
File
(
context
.
getFilesDir
().
getPath
()
+
context
.
getPackageName
()
+
File
.
separator
+
"shared_prefs"
));
}
/**
* 清除应用文件下的内容
* <p>/data/data/com.xxx.xxx/files</p>
*
* @param context 上下文
*/
public
static
void
cleanFiles
(
Context
context
)
{
deleteFilesByDirectory
(
context
.
getFilesDir
());
public
static
boolean
cleanInternalSP
(
Context
context
)
{
return
FileUtils
.
deleteFilesInDir
(
context
.
getFilesDir
().
getParent
()
+
File
.
separator
+
"shared_prefs"
);
}
/**
* 清除外部
cache下的内容
* <p>/
mnt/sdcard
/android/data/com.xxx.xxx/cache<p/>
* 清除外部
缓存
* <p>/
storage/emulated/0
/android/data/com.xxx.xxx/cache<p/>
*
* @param context 上下文
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
*/
public
static
void
cleanExternalCache
(
Context
context
)
{
if
(
Environment
.
getExternalStorageState
().
equals
(
Environment
.
MEDIA_MOUNTED
))
{
deleteFilesByDirectory
(
context
.
getExternalCacheDir
());
}
public
static
boolean
cleanExternalCache
(
Context
context
)
{
return
SDCardUtils
.
isSDCardEnable
()
&&
FileUtils
.
deleteFilesInDir
(
context
.
getExternalCacheDir
());
}
/**
* 清除自定义
路径
下的文件
* 清除自定义
目录
下的文件
*
* @param dirPath 文件路径
* @param dirPath 目录路径
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
*/
public
static
void
cleanCustomCache
(
String
dirPath
)
{
if
(
StringUtils
.
isSpace
(
dirPath
))
return
;
FileUtils
.
deleteDir
(
dirPath
);
public
static
boolean
cleanCustomCache
(
String
dirPath
)
{
return
FileUtils
.
deleteFilesInDir
(
dirPath
);
}
/**
*
删除方法 这里只会删除某个文件夹下的文件,如果传入的directory是个文件,将不做处理
*
清除自定义目录下的文件
*
* @param directory 文件夹File对象
* @param dir 目录
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
*/
private
static
void
deleteFilesByDirectory
(
File
directory
)
{
if
(
directory
!=
null
&&
directory
.
exists
()
&&
directory
.
isDirectory
())
{
for
(
File
item
:
directory
.
listFiles
())
{
item
.
delete
();
}
}
public
static
boolean
cleanCustomCache
(
File
dir
)
{
return
FileUtils
.
deleteFilesInDir
(
dir
);
}
}
utilcode/src/main/java/com/blankj/utilcode/utils/EmptyUtils.java
浏览文件 @
28dcee3e
...
...
@@ -15,7 +15,7 @@ import java.util.Map;
* author: Blankj
* blog : http://blankj.com
* time : 2016/9/28
* desc :
* desc :
判空相关工具类
* </pre>
*/
public
class
EmptyUtils
{
...
...
@@ -24,6 +24,12 @@ public class EmptyUtils {
throw
new
UnsupportedOperationException
(
"u can't instantiate me..."
);
}
/**
* 判断对象是否为空
*
* @param obj 对象
* @return {@code true}: 为空<br>{@code false}: 不为空
*/
public
static
boolean
isEmpty
(
Object
obj
)
{
if
(
obj
==
null
)
{
return
true
;
...
...
@@ -49,7 +55,35 @@ public class EmptyUtils {
return
false
;
}
/**
* 判断对象是否非空
* <p>不要问我为什么不直接调用{@code !isEmpty(obj);}</p>
*
* @param obj 对象
* @return {@code true}: 非空<br>{@code false}: 空
*/
public
static
boolean
isNotEmpty
(
Object
obj
)
{
return
!
isEmpty
(
obj
);
if
(
obj
==
null
)
{
return
false
;
}
else
if
(
obj
instanceof
String
&&
obj
.
toString
().
length
()
==
0
)
{
return
false
;
}
else
if
(
obj
.
getClass
().
isArray
()
&&
Array
.
getLength
(
obj
)
==
0
)
{
return
false
;
}
else
if
(
obj
instanceof
Collection
&&
((
Collection
)
obj
).
isEmpty
())
{
return
false
;
}
else
if
(
obj
instanceof
Map
&&
((
Map
)
obj
).
isEmpty
())
{
return
false
;
}
else
if
(
obj
instanceof
SparseArray
&&
((
SparseArray
)
obj
).
size
()
==
0
)
{
return
false
;
}
else
if
(
obj
instanceof
SparseBooleanArray
&&
((
SparseBooleanArray
)
obj
).
size
()
==
0
)
{
return
false
;
}
else
if
(
obj
instanceof
SparseIntArray
&&
((
SparseIntArray
)
obj
).
size
()
==
0
)
{
return
false
;
}
else
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
JELLY_BEAN_MR2
)
{
if
(
obj
instanceof
SparseLongArray
&&
((
SparseLongArray
)
obj
).
size
()
==
0
)
{
return
false
;
}
}
return
true
;
}
}
utilcode/src/main/java/com/blankj/utilcode/utils/FileUtils.java
浏览文件 @
28dcee3e
...
...
@@ -381,11 +381,13 @@ public class FileUtils {
if
(!
dir
.
isDirectory
())
return
false
;
// 现在文件存在且是文件夹
File
[]
files
=
dir
.
listFiles
();
for
(
File
file
:
files
)
{
if
(
file
.
isFile
())
{
if
(!
deleteFile
(
file
))
return
false
;
}
else
if
(
file
.
isDirectory
())
{
if
(!
deleteDir
(
file
))
return
false
;
if
(
files
!=
null
&&
files
.
length
!=
0
)
{
for
(
File
file
:
files
)
{
if
(
file
.
isFile
())
{
if
(!
deleteFile
(
file
))
return
false
;
}
else
if
(
file
.
isDirectory
())
{
if
(!
deleteDir
(
file
))
return
false
;
}
}
}
return
dir
.
delete
();
...
...
@@ -411,6 +413,42 @@ public class FileUtils {
return
file
!=
null
&&
(!
file
.
exists
()
||
file
.
isFile
()
&&
file
.
delete
());
}
/**
* 删除目录下的所有文件
*
* @param dirPath 目录路径
* @return {@code true}: 删除成功<br>{@code false}: 删除失败
*/
public
static
boolean
deleteFilesInDir
(
String
dirPath
)
{
return
deleteFilesInDir
(
getFileByPath
(
dirPath
));
}
/**
* 删除目录下的所有文件
*
* @param dir 目录
* @return {@code true}: 删除成功<br>{@code false}: 删除失败
*/
public
static
boolean
deleteFilesInDir
(
File
dir
)
{
if
(
dir
==
null
)
return
false
;
// 目录不存在返回true
if
(!
dir
.
exists
())
return
true
;
// 不是目录返回false
if
(!
dir
.
isDirectory
())
return
false
;
// 现在文件存在且是文件夹
File
[]
files
=
dir
.
listFiles
();
if
(
files
!=
null
&&
files
.
length
!=
0
)
{
for
(
File
file
:
files
)
{
if
(
file
.
isFile
())
{
if
(!
deleteFile
(
file
))
return
false
;
}
else
if
(
file
.
isDirectory
())
{
if
(!
deleteDir
(
file
))
return
false
;
}
}
}
return
true
;
}
/**
* 获取目录下所有文件
*
...
...
@@ -457,10 +495,12 @@ public class FileUtils {
if
(
dir
==
null
||
!
isDir
(
dir
))
return
null
;
List
<
File
>
list
=
new
ArrayList
<>();
File
[]
files
=
dir
.
listFiles
();
for
(
File
file
:
files
)
{
list
.
add
(
file
);
if
(
file
.
isDirectory
())
{
list
.
addAll
(
listFilesInDir
(
file
));
if
(
files
!=
null
&&
files
.
length
!=
0
)
{
for
(
File
file
:
files
)
{
list
.
add
(
file
);
if
(
file
.
isDirectory
())
{
list
.
addAll
(
listFilesInDir
(
file
));
}
}
}
return
list
;
...
...
@@ -493,9 +533,11 @@ public class FileUtils {
if
(
dir
==
null
||
!
isDir
(
dir
))
return
null
;
List
<
File
>
list
=
new
ArrayList
<>();
File
[]
files
=
dir
.
listFiles
();
for
(
File
file
:
files
)
{
if
(
file
.
getName
().
toUpperCase
().
endsWith
(
suffix
.
toUpperCase
()))
{
list
.
add
(
file
);
if
(
files
!=
null
&&
files
.
length
!=
0
)
{
for
(
File
file
:
files
)
{
if
(
file
.
getName
().
toUpperCase
().
endsWith
(
suffix
.
toUpperCase
()))
{
list
.
add
(
file
);
}
}
}
return
list
;
...
...
@@ -525,12 +567,14 @@ public class FileUtils {
if
(
dir
==
null
||
!
isDir
(
dir
))
return
null
;
List
<
File
>
list
=
new
ArrayList
<>();
File
[]
files
=
dir
.
listFiles
();
for
(
File
file
:
files
)
{
if
(
file
.
getName
().
toUpperCase
().
endsWith
(
suffix
.
toUpperCase
()))
{
list
.
add
(
file
);
}
if
(
file
.
isDirectory
())
{
list
.
addAll
(
listFilesInDirWithFilter
(
file
,
suffix
));
if
(
files
!=
null
&&
files
.
length
!=
0
)
{
for
(
File
file
:
files
)
{
if
(
file
.
getName
().
toUpperCase
().
endsWith
(
suffix
.
toUpperCase
()))
{
list
.
add
(
file
);
}
if
(
file
.
isDirectory
())
{
list
.
addAll
(
listFilesInDirWithFilter
(
file
,
suffix
));
}
}
}
return
list
;
...
...
@@ -561,9 +605,11 @@ public class FileUtils {
if
(
dir
==
null
||
!
isDir
(
dir
))
return
null
;
List
<
File
>
list
=
new
ArrayList
<>();
File
[]
files
=
dir
.
listFiles
();
for
(
File
file
:
files
)
{
if
(
filter
.
accept
(
file
.
getParentFile
(),
file
.
getName
()))
{
list
.
add
(
file
);
if
(
files
!=
null
&&
files
.
length
!=
0
)
{
for
(
File
file
:
files
)
{
if
(
filter
.
accept
(
file
.
getParentFile
(),
file
.
getName
()))
{
list
.
add
(
file
);
}
}
}
return
list
;
...
...
@@ -591,12 +637,14 @@ public class FileUtils {
if
(
dir
==
null
||
!
isDir
(
dir
))
return
null
;
List
<
File
>
list
=
new
ArrayList
<>();
File
[]
files
=
dir
.
listFiles
();
for
(
File
file
:
files
)
{
if
(
filter
.
accept
(
file
.
getParentFile
(),
file
.
getName
()))
{
list
.
add
(
file
);
}
if
(
file
.
isDirectory
())
{
list
.
addAll
(
listFilesInDirWithFilter
(
file
,
filter
));
if
(
files
!=
null
&&
files
.
length
!=
0
)
{
for
(
File
file
:
files
)
{
if
(
filter
.
accept
(
file
.
getParentFile
(),
file
.
getName
()))
{
list
.
add
(
file
);
}
if
(
file
.
isDirectory
())
{
list
.
addAll
(
listFilesInDirWithFilter
(
file
,
filter
));
}
}
}
return
list
;
...
...
@@ -626,12 +674,14 @@ public class FileUtils {
if
(
dir
==
null
||
!
isDir
(
dir
))
return
null
;
List
<
File
>
list
=
new
ArrayList
<>();
File
[]
files
=
dir
.
listFiles
();
for
(
File
file
:
files
)
{
if
(
file
.
getName
().
toUpperCase
().
equals
(
fileName
.
toUpperCase
()))
{
list
.
add
(
file
);
}
if
(
file
.
isDirectory
())
{
list
.
addAll
(
listFilesInDirWithFilter
(
file
,
fileName
));
if
(
files
!=
null
&&
files
.
length
!=
0
)
{
for
(
File
file
:
files
)
{
if
(
file
.
getName
().
toUpperCase
().
equals
(
fileName
.
toUpperCase
()))
{
list
.
add
(
file
);
}
if
(
file
.
isDirectory
())
{
list
.
addAll
(
searchFileInDir
(
file
,
fileName
));
}
}
}
return
list
;
...
...
utilcode/src/main/java/com/blankj/utilcode/utils/NetworkUtils.java
浏览文件 @
28dcee3e
...
...
@@ -28,21 +28,21 @@ public class NetworkUtils {
throw
new
UnsupportedOperationException
(
"u can't instantiate me..."
);
}
public
static
final
int
NETWORK_WIFI
=
1
;
// wifi network
public
static
final
int
NETWORK_4G
=
4
;
// "4G" networks
public
static
final
int
NETWORK_3G
=
3
;
// "3G" networks
public
static
final
int
NETWORK_2G
=
2
;
// "2G" networks
public
static
final
int
NETWORK_WIFI
=
1
;
// wifi network
public
static
final
int
NETWORK_4G
=
4
;
// "4G" networks
public
static
final
int
NETWORK_3G
=
3
;
// "3G" networks
public
static
final
int
NETWORK_2G
=
2
;
// "2G" networks
public
static
final
int
NETWORK_UNKNOWN
=
5
;
// unknown network
public
static
final
int
NETWORK_NO
=
-
1
;
// no network
public
static
final
int
NETWORK_NO
=
-
1
;
// no network
private
static
final
int
NETWORK_TYPE_GSM
=
16
;
private
static
final
int
NETWORK_TYPE_TD_SCDMA
=
17
;
private
static
final
int
NETWORK_TYPE_IWLAN
=
18
;
private
static
final
String
CMCC_ISP
=
"46000"
;
//中国移动
private
static
final
String
CMCC_ISP
=
"46000"
;
//中国移动
private
static
final
String
CMCC2_ISP
=
"46002"
;
//中国移动
private
static
final
String
CU_ISP
=
"46001"
;
//中国联通
private
static
final
String
CT_ISP
=
"46003"
;
//中国电信
private
static
final
String
CU_ISP
=
"46001"
;
//中国联通
private
static
final
String
CT_ISP
=
"46003"
;
//中国电信
/**
* 打开网络设置界面
...
...
@@ -99,7 +99,7 @@ public class NetworkUtils {
* <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
*
* @param context 上下文
* @return {@code true}: 是<br>{@code false}:
不是
* @return {@code true}: 是<br>{@code false}:
否
*/
public
static
boolean
is4G
(
Context
context
)
{
NetworkInfo
info
=
getActiveNetworkInfo
(
context
);
...
...
utilcode/src/main/java/com/blankj/utilcode/utils/ThreadPoolUtils.java
浏览文件 @
28dcee3e
...
...
@@ -48,8 +48,7 @@ public class ThreadPoolUtils {
switch
(
type
)
{
case
FixedThread:
// 构造一个固定线程数目的线程池
// ThreadPoolExecutor(corePoolSize, corePoolSize, 0L, TimeUnit.MILLISECONDS, new
// LinkedBlockingQueue<Runnable>());
// ThreadPoolExecutor(corePoolSize, corePoolSize, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
exec
=
Executors
.
newFixedThreadPool
(
corePoolSize
);
break
;
case
SingleThread:
...
...
utilcode/src/main/java/com/blankj/utilcode/utils/ToastUtils.java
0 → 100644
浏览文件 @
28dcee3e
package
com.blankj.utilcode.utils
;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/9/29
* desc :
* </pre>
*/
public
class
ToastUtils
{
}
utilcode/src/main/java/com/blankj/utilcode/utils/VibrationUtils.java
0 → 100644
浏览文件 @
28dcee3e
package
com.blankj.utilcode.utils
;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/9/29
* desc :
* </pre>
*/
public
class
VibrationUtils
{
}
utilcode/src/main/java/com/blankj/utilcode/utils/ZipUtils.java
浏览文件 @
28dcee3e
...
...
@@ -157,7 +157,6 @@ public class ZipUtils {
return
zipFile
(
resFile
,
""
,
zos
,
comment
);
}
finally
{
if
(
zos
!=
null
)
{
zos
.
finish
();
FileUtils
.
closeIO
(
zos
);
}
}
...
...
@@ -179,7 +178,7 @@ public class ZipUtils {
if
(
resFile
.
isDirectory
())
{
File
[]
fileList
=
resFile
.
listFiles
();
// 如果是空文件夹那么创建它,我把'/'换为File.separator测试就不成功,eggPain
if
(
fileList
.
length
<=
0
)
{
if
(
fileList
==
null
||
fileList
.
length
<=
0
)
{
ZipEntry
entry
=
new
ZipEntry
(
rootPath
+
'/'
);
if
(!
StringUtils
.
isEmpty
(
comment
))
entry
.
setComment
(
comment
);
zos
.
putNextEntry
(
entry
);
...
...
@@ -368,7 +367,6 @@ public class ZipUtils {
return
getComments
(
FileUtils
.
getFileByPath
(
zipFilePath
));
}
/**
* 获取压缩文件中的注释链表
*
...
...
utilcode/src/test/java/com/blankj/utilcode/utils/EmptyUtilsTest.java
浏览文件 @
28dcee3e
...
...
@@ -22,11 +22,11 @@ import static com.google.common.truth.Truth.assertThat;
* author: Blankj
* blog : http://blankj.com
* time : 2016/9/28
* desc :
* desc :
EmptyUtils单元测试
* </pre>
*/
@RunWith
(
RobolectricTestRunner
.
class
)
@Config
(
manifest
=
Config
.
NONE
,
sdk
=
2
1
)
@Config
(
manifest
=
Config
.
NONE
,
sdk
=
2
3
)
public
class
EmptyUtilsTest
{
@TargetApi
(
Build
.
VERSION_CODES
.
JELLY_BEAN_MR2
)
...
...
@@ -42,6 +42,7 @@ public class EmptyUtilsTest {
SparseBooleanArray
sba
=
new
SparseBooleanArray
();
SparseIntArray
sia
=
new
SparseIntArray
();
SparseLongArray
sla
=
new
SparseLongArray
();
assertThat
(
EmptyUtils
.
isEmpty
(
string
)).
isTrue
();
assertThat
(
EmptyUtils
.
isEmpty
(
string1
)).
isFalse
();
assertThat
(
EmptyUtils
.
isEmpty
(
arr
)).
isTrue
();
...
...
@@ -52,5 +53,16 @@ public class EmptyUtilsTest {
assertThat
(
EmptyUtils
.
isEmpty
(
sba
)).
isTrue
();
assertThat
(
EmptyUtils
.
isEmpty
(
sia
)).
isTrue
();
assertThat
(
EmptyUtils
.
isEmpty
(
sla
)).
isTrue
();
assertThat
(!
EmptyUtils
.
isNotEmpty
(
string
)).
isTrue
();
assertThat
(!
EmptyUtils
.
isNotEmpty
(
string1
)).
isFalse
();
assertThat
(!
EmptyUtils
.
isNotEmpty
(
arr
)).
isTrue
();
assertThat
(!
EmptyUtils
.
isNotEmpty
(
arr1
)).
isTrue
();
assertThat
(!
EmptyUtils
.
isNotEmpty
(
list
)).
isTrue
();
assertThat
(!
EmptyUtils
.
isNotEmpty
(
map
)).
isTrue
();
assertThat
(!
EmptyUtils
.
isNotEmpty
(
sa
)).
isTrue
();
assertThat
(!
EmptyUtils
.
isNotEmpty
(
sba
)).
isTrue
();
assertThat
(!
EmptyUtils
.
isNotEmpty
(
sia
)).
isTrue
();
assertThat
(!
EmptyUtils
.
isNotEmpty
(
sla
)).
isTrue
();
}
}
\ No newline at end of file
utilcode/src/test/java/com/blankj/utilcode/utils/FileUtilsTest.java
浏览文件 @
28dcee3e
...
...
@@ -111,6 +111,11 @@ public class FileUtilsTest {
assertThat
(
deleteFile
(
path
+
"del.txt"
)).
isTrue
();
}
@Test
public
void
testDeleteFilesInDir
()
throws
Exception
{
assertThat
(
deleteFilesInDir
(
path
+
"child"
)).
isTrue
();
}
@Test
public
void
testListFilesInDir
()
throws
Exception
{
System
.
out
.
println
(
listFilesInDir
(
path
,
false
).
toString
());
...
...
utilcode/src/test/java/com/blankj/utilcode/utils/TestUtils.java
浏览文件 @
28dcee3e
...
...
@@ -2,6 +2,7 @@ package com.blankj.utilcode.utils;
import
android.content.Context
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.RobolectricTestRunner
;
import
org.robolectric.RuntimeEnvironment
;
...
...
@@ -9,6 +10,9 @@ import org.robolectric.annotation.Config;
import
java.io.File
;
import
static
com
.
blankj
.
utilcode
.
utils
.
TimeUtils
.
milliseconds2String
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
/**
* <pre>
* author: Blankj
...
...
@@ -21,10 +25,6 @@ import java.io.File;
@Config
(
manifest
=
Config
.
NONE
)
public
class
TestUtils
{
private
TestUtils
()
{
throw
new
UnsupportedOperationException
(
"u can't instantiate me..."
);
}
public
static
final
char
SEP
=
File
.
separatorChar
;
public
static
final
String
BASEPATH
=
System
.
getProperty
(
"user.dir"
)
...
...
@@ -33,4 +33,9 @@ public class TestUtils {
public
static
Context
getContext
()
{
return
RuntimeEnvironment
.
application
;
}
@Test
public
void
test
()
throws
Exception
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录