提交 8174076e 编写于 作者: B Blankj

see 05/05 log

上级 f6367ba8
......@@ -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
......
......@@ -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"),
......
......@@ -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.TRANSLUCENT;
mParams.format = PixelFormat.TRANSPARENT;
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() {
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册