Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mmm-rain
AndroidUtilCode
提交
8174076e
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 搜索 >>
提交
8174076e
编写于
5月 05, 2020
作者:
B
Blankj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 05/05 log
上级
f6367ba8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
43 addition
and
18 deletion
+43
-18
buildApp.gradle
buildApp.gradle
+1
-1
buildSrc/src/main/groovy/Config.groovy
buildSrc/src/main/groovy/Config.groovy
+1
-1
lib/utilcode/src/main/java/com/blankj/utilcode/util/ToastUtils.java
...de/src/main/java/com/blankj/utilcode/util/ToastUtils.java
+31
-16
lib/utilcode/src/main/java/com/blankj/utilcode/util/UtilsBridge.java
...e/src/main/java/com/blankj/utilcode/util/UtilsBridge.java
+10
-0
未找到文件。
buildApp.gradle
浏览文件 @
8174076e
...
...
@@ -66,7 +66,7 @@ android {
dependencies
{
// LeakCanary
debugImplementation
Config
.
depConfig
.
leakcanary
_android
.
dep
debugImplementation
Config
.
depConfig
.
leakcanary
.
dep
debugImplementation
Config
.
depConfig
.
lib_utildebug
.
dep
releaseImplementation
Config
.
depConfig
.
lib_utildebug_no_op
.
dep
...
...
buildSrc/src/main/groovy/Config.groovy
浏览文件 @
8174076e
...
...
@@ -67,7 +67,7 @@ class Config {
kotlin
:
new
DepConfig
(
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
),
leakcanary
_android
:
new
DepConfig
(
"com.squareup.leakcanary:leakcanary-android:2.1"
),
leakcanary
:
new
DepConfig
(
"com.squareup.leakcanary:leakcanary-android:2.1"
),
free_proguard
:
new
DepConfig
(
"com.blankj:free-proguard:1.0.2"
),
swipe_panel
:
new
DepConfig
(
"com.blankj:swipe-panel:1.2"
),
...
...
lib/utilcode/src/main/java/com/blankj/utilcode/util/ToastUtils.java
浏览文件 @
8174076e
...
...
@@ -449,15 +449,26 @@ public final class ToastUtils {
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
N_MR1
)
{
mWM
=
(
WindowManager
)
context
.
getSystemService
(
Context
.
WINDOW_SERVICE
);
mParams
.
type
=
WindowManager
.
LayoutParams
.
TYPE_TOAST
;
}
else
if
(
UtilsBridge
.
isGrantedDrawOverlays
())
{
mWM
=
(
WindowManager
)
context
.
getSystemService
(
Context
.
WINDOW_SERVICE
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
mParams
.
type
=
WindowManager
.
LayoutParams
.
TYPE_APPLICATION_OVERLAY
;
}
else
{
mParams
.
type
=
WindowManager
.
LayoutParams
.
TYPE_PHONE
;
}
}
else
{
Context
topActivityOrApp
=
UtilsBridge
.
getTopActivityOrApp
();
if
(!(
topActivityOrApp
instanceof
Activity
))
{
Log
.
e
(
"ToastUtils"
,
"Couldn't get top Activity."
);
Log
.
w
(
"ToastUtils"
,
"Couldn't get top Activity."
);
// try to use system toast
new
SystemToast
(
mToast
).
show
();
return
;
}
Activity
topActivity
=
(
Activity
)
topActivityOrApp
;
if
(
topActivity
.
isFinishing
()
||
topActivity
.
isDestroyed
())
{
Log
.
e
(
"ToastUtils"
,
topActivity
+
" is useless"
);
Log
.
w
(
"ToastUtils"
,
topActivity
+
" is useless"
);
// try to use system toast
new
SystemToast
(
mToast
).
show
();
return
;
}
mWM
=
topActivity
.
getWindowManager
();
...
...
@@ -465,9 +476,26 @@ public final class ToastUtils {
UtilsBridge
.
addActivityLifecycleCallbacks
(
topActivity
,
getActivityLifecycleCallbacks
());
}
setToastParams
();
try
{
if
(
mWM
!=
null
)
{
mWM
.
addView
(
mView
,
mParams
);
}
}
catch
(
Exception
ignored
)
{
/**/
}
UtilsBridge
.
runOnUiThreadDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
cancel
();
}
},
mToast
.
getDuration
()
==
Toast
.
LENGTH_SHORT
?
2000
:
3500
);
}
private
void
setToastParams
()
{
mParams
.
height
=
WindowManager
.
LayoutParams
.
WRAP_CONTENT
;
mParams
.
width
=
WindowManager
.
LayoutParams
.
WRAP_CONTENT
;
mParams
.
format
=
PixelFormat
.
TRANS
LUC
ENT
;
mParams
.
format
=
PixelFormat
.
TRANS
PAR
ENT
;
mParams
.
windowAnimations
=
android
.
R
.
style
.
Animation_Toast
;
mParams
.
setTitle
(
"ToastWithoutNotification"
);
mParams
.
flags
=
WindowManager
.
LayoutParams
.
FLAG_KEEP_SCREEN_ON
...
...
@@ -487,19 +515,6 @@ public final class ToastUtils {
mParams
.
y
=
mToast
.
getYOffset
();
mParams
.
horizontalMargin
=
mToast
.
getHorizontalMargin
();
mParams
.
verticalMargin
=
mToast
.
getVerticalMargin
();
try
{
if
(
mWM
!=
null
)
{
mWM
.
addView
(
mView
,
mParams
);
}
}
catch
(
Exception
ignored
)
{
/**/
}
UtilsBridge
.
runOnUiThreadDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
cancel
();
}
},
mToast
.
getDuration
()
==
Toast
.
LENGTH_SHORT
?
2000
:
3500
);
}
private
Utils
.
ActivityLifecycleCallbacks
getActivityLifecycleCallbacks
()
{
...
...
lib/utilcode/src/main/java/com/blankj/utilcode/util/UtilsBridge.java
浏览文件 @
8174076e
...
...
@@ -7,8 +7,10 @@ import android.content.Intent;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.Drawable
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Parcelable
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.RequiresApi
;
import
android.support.annotation.RequiresPermission
;
import
android.view.View
;
...
...
@@ -399,6 +401,14 @@ class UtilsBridge {
LanguageUtils
.
applyLanguage
(
activity
);
}
///////////////////////////////////////////////////////////////////////////
// PermissionUtils
///////////////////////////////////////////////////////////////////////////
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
M
)
static
boolean
isGrantedDrawOverlays
()
{
return
PermissionUtils
.
isGrantedDrawOverlays
();
}
///////////////////////////////////////////////////////////////////////////
// ProcessUtils
///////////////////////////////////////////////////////////////////////////
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录