Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mmm-rain
AndroidUtilCode
提交
f61eb1a9
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,发现更多精彩内容 >>
提交
f61eb1a9
编写于
5月 07, 2019
作者:
B
Blankj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 05/07 log
上级
5dea602b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
130 addition
and
35 deletion
+130
-35
config_app.gradle
config_app.gradle
+77
-3
utilcode/lib/src/main/java/com/blankj/utilcode/util/PermissionUtils.java
...c/main/java/com/blankj/utilcode/util/PermissionUtils.java
+26
-10
utilcode/lib/src/main/java/com/blankj/utilcode/util/ShellUtils.java
...ib/src/main/java/com/blankj/utilcode/util/ShellUtils.java
+27
-22
未找到文件。
config_app.gradle
浏览文件 @
f61eb1a9
import
java.text.SimpleDateFormat
apply
{
plugin
"com.android.application"
plugin
"kotlin-android"
...
...
@@ -84,9 +86,81 @@ def configApkName(Project pro) {
variant
.
getPackageApplicationProvider
().
get
().
outputDirectory
=
new
File
(
"${rootDir.path}/apk"
)
variant
.
getPackageApplicationProvider
().
get
().
outputScope
.
apkDatas
.
forEach
{
apkData
->
apkData
.
outputFileName
=
"util"
+
suffix
+
"_"
+
variant
.
versionName
.
replace
(
"."
,
"_"
)
+
".apk"
"_"
+
variant
.
versionName
.
replace
(
"."
,
"_"
)
+
".apk"
}
}
}
}
// 打印每一个任务的时间.
class
TimingsListener
implements
TaskExecutionListener
,
BuildListener
{
private
long
startTime
private
timings
=
[]
private
String
filePath
TimingsListener
(
String
filePath
)
{
this
.
filePath
=
filePath
}
@Override
void
beforeExecute
(
Task
task
)
{
startTime
=
System
.
currentTimeMillis
()
}
@Override
void
afterExecute
(
Task
task
,
TaskState
taskState
)
{
def
ms
=
System
.
currentTimeMillis
()
-
startTime
timings
.
add
([
ms
,
task
.
path
])
}
@Override
void
buildFinished
(
BuildResult
result
)
{
ArrayList
array
=
new
ArrayList
()
for
(
timing
in
timings
)
{
if
(
timing
[
0
]
>=
100
)
{
array
.
add
(
timing
)
}
}
try
{
if
(!
array
.
isEmpty
())
{
Collections
.
sort
(
array
,
new
Comparator
()
{
@Override
int
compare
(
Object
o1
,
Object
o2
)
{
return
o2
[
0
]
-
o1
[
0
]
}
})
println
"Task timings:"
FileWriter
fw
=
new
FileWriter
(
new
File
(
filePath
),
true
)
array
.
each
{
fw
.
write
(
String
.
format
(
"%7sms %s\n"
,
it
[
0
],
it
[
1
]))
printf
"%7sms %s\n"
,
it
}
fw
.
flush
()
fw
.
close
()
}
else
{
new
File
(
filePath
).
delete
()
}
}
catch
(
Exception
e
)
{
}
array
.
clear
()
}
}
\ No newline at end of file
@Override
void
buildStarted
(
Gradle
gradle
)
{}
@Override
void
projectsEvaluated
(
Gradle
gradle
)
{}
@Override
void
projectsLoaded
(
Gradle
gradle
)
{}
@Override
void
settingsEvaluated
(
Settings
settings
)
{}
}
def
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd-HH-mm-ss"
)
def
file
=
new
File
(
rootProject
.
buildDir
.
getAbsolutePath
(),
"buildTime_"
+
sdf
.
format
(
new
Date
(
System
.
currentTimeMillis
()))
+
".txt"
)
gradle
.
addListener
(
new
TimingsListener
(
file
.
getAbsolutePath
()))
\ No newline at end of file
utilcode/lib/src/main/java/com/blankj/utilcode/util/PermissionUtils.java
浏览文件 @
f61eb1a9
...
...
@@ -143,21 +143,37 @@ public final class PermissionUtils {
*/
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
M
)
public
static
boolean
isGrantedDrawOverlays
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
AppOpsManager
aom
=
(
AppOpsManager
)
Utils
.
getApp
().
getSystemService
(
Context
.
APP_OPS_SERVICE
);
if
(
aom
==
null
)
return
false
;
int
mode
=
aom
.
checkOpNoThrow
(
"android:system_alert_window"
,
android
.
os
.
Process
.
myUid
(),
Utils
.
getApp
().
getPackageName
()
);
return
mode
==
AppOpsManager
.
MODE_ALLOWED
||
mode
==
AppOpsManager
.
MODE_IGNORED
;
}
return
Settings
.
canDrawOverlays
(
Utils
.
getApp
());
}
/**
* Return whether the app can draw on top of other apps.
*
* @return {@code true}: yes<br>{@code false}: no
*/
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
M
)
public
static
boolean
isGrantedDrawOverlays
(
final
Utils
.
Callback
<
Boolean
>
callback
)
{
return
Utils
.
UTIL_HANDLER
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
callback
.
onCall
(
isGrantedDrawOverlays
());
}
},
200
);
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
M
)
public
static
void
requestDrawOverlays
(
final
SimpleCallback
callback
)
{
isGrantedDrawOverlays
(
new
Utils
.
Callback
<
Boolean
>()
{
@Override
public
void
onCall
(
Boolean
data
)
{
if
(
data
)
{
if
(
callback
!=
null
)
callback
.
onGranted
();
return
;
}
sSimpleCallback4DrawOverlays
=
callback
;
PermissionActivity
.
start
(
Utils
.
getApp
(),
PermissionActivity
.
TYPE_DRAW_OVERLAYS
);
}
});
if
(
isGrantedDrawOverlays
())
{
if
(
callback
!=
null
)
callback
.
onGranted
();
return
;
...
...
utilcode/lib/src/main/java/com/blankj/utilcode/util/ShellUtils.java
浏览文件 @
f61eb1a9
...
...
@@ -30,11 +30,12 @@ public final class ShellUtils {
* @param command The command.
* @param isRooted True to use root, false otherwise.
* @param callback The callback.
* @return the task
*/
public
static
void
execCmdAsync
(
final
String
command
,
final
boolean
isRooted
,
final
Utils
.
Callback
<
CommandResult
>
callback
)
{
execCmdAsync
(
new
String
[]{
command
},
isRooted
,
true
,
callback
);
public
static
Utils
.
Task
<
CommandResult
>
execCmdAsync
(
final
String
command
,
final
boolean
isRooted
,
final
Utils
.
Callback
<
CommandResult
>
callback
)
{
return
execCmdAsync
(
new
String
[]{
command
},
isRooted
,
true
,
callback
);
}
/**
...
...
@@ -43,11 +44,12 @@ public final class ShellUtils {
* @param commands The commands.
* @param isRooted True to use root, false otherwise.
* @param callback The callback.
* @return the task
*/
public
static
void
execCmdAsync
(
final
List
<
String
>
commands
,
final
boolean
isRooted
,
final
Utils
.
Callback
<
CommandResult
>
callback
)
{
execCmdAsync
(
commands
==
null
?
null
:
commands
.
toArray
(
new
String
[]{}),
isRooted
,
true
,
callback
);
public
static
Utils
.
Task
<
CommandResult
>
execCmdAsync
(
final
List
<
String
>
commands
,
final
boolean
isRooted
,
final
Utils
.
Callback
<
CommandResult
>
callback
)
{
return
execCmdAsync
(
commands
==
null
?
null
:
commands
.
toArray
(
new
String
[]{}),
isRooted
,
true
,
callback
);
}
/**
...
...
@@ -56,11 +58,12 @@ public final class ShellUtils {
* @param commands The commands.
* @param isRooted True to use root, false otherwise.
* @param callback The callback.
* @return the task
*/
public
static
void
execCmdAsync
(
final
String
[]
commands
,
final
boolean
isRooted
,
final
Utils
.
Callback
<
CommandResult
>
callback
)
{
execCmdAsync
(
commands
,
isRooted
,
true
,
callback
);
public
static
Utils
.
Task
<
CommandResult
>
execCmdAsync
(
final
String
[]
commands
,
final
boolean
isRooted
,
final
Utils
.
Callback
<
CommandResult
>
callback
)
{
return
execCmdAsync
(
commands
,
isRooted
,
true
,
callback
);
}
/**
...
...
@@ -70,12 +73,13 @@ public final class ShellUtils {
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @param callback The callback.
* @return the task
*/
public
static
void
execCmdAsync
(
final
String
command
,
final
boolean
isRooted
,
final
boolean
isNeedResultMsg
,
final
Utils
.
Callback
<
CommandResult
>
callback
)
{
execCmdAsync
(
new
String
[]{
command
},
isRooted
,
isNeedResultMsg
,
callback
);
public
static
Utils
.
Task
<
CommandResult
>
execCmdAsync
(
final
String
command
,
final
boolean
isRooted
,
final
boolean
isNeedResultMsg
,
final
Utils
.
Callback
<
CommandResult
>
callback
)
{
return
execCmdAsync
(
new
String
[]{
command
},
isRooted
,
isNeedResultMsg
,
callback
);
}
/**
...
...
@@ -85,12 +89,13 @@ public final class ShellUtils {
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @param callback The callback.
* @return the task
*/
public
static
void
execCmdAsync
(
final
List
<
String
>
commands
,
final
boolean
isRooted
,
final
boolean
isNeedResultMsg
,
final
Utils
.
Callback
<
CommandResult
>
callback
)
{
execCmdAsync
(
commands
==
null
?
null
:
commands
.
toArray
(
new
String
[]{}),
public
static
Utils
.
Task
<
CommandResult
>
execCmdAsync
(
final
List
<
String
>
commands
,
final
boolean
isRooted
,
final
boolean
isNeedResultMsg
,
final
Utils
.
Callback
<
CommandResult
>
callback
)
{
return
execCmdAsync
(
commands
==
null
?
null
:
commands
.
toArray
(
new
String
[]{}),
isRooted
,
isNeedResultMsg
,
callback
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录