Skip to content

Commit 8174076

Browse files
committed
see 05/05 log
1 parent f6367ba commit 8174076

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

buildApp.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ android {
6666

6767
dependencies {
6868
// LeakCanary
69-
debugImplementation Config.depConfig.leakcanary_android.dep
69+
debugImplementation Config.depConfig.leakcanary.dep
7070

7171
debugImplementation Config.depConfig.lib_utildebug.dep
7272
releaseImplementation Config.depConfig.lib_utildebug_no_op.dep

buildSrc/src/main/groovy/Config.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Config {
6767

6868
kotlin : new DepConfig("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"),
6969

70-
leakcanary_android : new DepConfig("com.squareup.leakcanary:leakcanary-android:2.1"),
70+
leakcanary : new DepConfig("com.squareup.leakcanary:leakcanary-android:2.1"),
7171

7272
free_proguard : new DepConfig("com.blankj:free-proguard:1.0.2"),
7373
swipe_panel : new DepConfig("com.blankj:swipe-panel:1.2"),

lib/utilcode/src/main/java/com/blankj/utilcode/util/ToastUtils.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -449,25 +449,53 @@ private void realShow() {
449449
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
450450
mWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
451451
mParams.type = WindowManager.LayoutParams.TYPE_TOAST;
452+
} else if (UtilsBridge.isGrantedDrawOverlays()) {
453+
mWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
454+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
455+
mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
456+
} else {
457+
mParams.type = WindowManager.LayoutParams.TYPE_PHONE;
458+
}
452459
} else {
453460
Context topActivityOrApp = UtilsBridge.getTopActivityOrApp();
454461
if (!(topActivityOrApp instanceof Activity)) {
455-
Log.e("ToastUtils", "Couldn't get top Activity.");
462+
Log.w("ToastUtils", "Couldn't get top Activity.");
463+
// try to use system toast
464+
new SystemToast(mToast).show();
456465
return;
457466
}
458467
Activity topActivity = (Activity) topActivityOrApp;
459468
if (topActivity.isFinishing() || topActivity.isDestroyed()) {
460-
Log.e("ToastUtils", topActivity + " is useless");
469+
Log.w("ToastUtils", topActivity + " is useless");
470+
// try to use system toast
471+
new SystemToast(mToast).show();
461472
return;
462473
}
463474
mWM = topActivity.getWindowManager();
464475
mParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
465476
UtilsBridge.addActivityLifecycleCallbacks(topActivity, getActivityLifecycleCallbacks());
466477
}
467478

479+
setToastParams();
480+
481+
try {
482+
if (mWM != null) {
483+
mWM.addView(mView, mParams);
484+
}
485+
} catch (Exception ignored) {/**/}
486+
487+
UtilsBridge.runOnUiThreadDelayed(new Runnable() {
488+
@Override
489+
public void run() {
490+
cancel();
491+
}
492+
}, mToast.getDuration() == Toast.LENGTH_SHORT ? 2000 : 3500);
493+
}
494+
495+
private void setToastParams() {
468496
mParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
469497
mParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
470-
mParams.format = PixelFormat.TRANSLUCENT;
498+
mParams.format = PixelFormat.TRANSPARENT;
471499
mParams.windowAnimations = android.R.style.Animation_Toast;
472500
mParams.setTitle("ToastWithoutNotification");
473501
mParams.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
@@ -487,19 +515,6 @@ private void realShow() {
487515
mParams.y = mToast.getYOffset();
488516
mParams.horizontalMargin = mToast.getHorizontalMargin();
489517
mParams.verticalMargin = mToast.getVerticalMargin();
490-
491-
try {
492-
if (mWM != null) {
493-
mWM.addView(mView, mParams);
494-
}
495-
} catch (Exception ignored) {/**/}
496-
497-
UtilsBridge.runOnUiThreadDelayed(new Runnable() {
498-
@Override
499-
public void run() {
500-
cancel();
501-
}
502-
}, mToast.getDuration() == Toast.LENGTH_SHORT ? 2000 : 3500);
503518
}
504519

505520
private Utils.ActivityLifecycleCallbacks getActivityLifecycleCallbacks() {

lib/utilcode/src/main/java/com/blankj/utilcode/util/UtilsBridge.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import android.graphics.Bitmap;
88
import android.graphics.drawable.Drawable;
99
import android.net.Uri;
10+
import android.os.Build;
1011
import android.os.Parcelable;
1112
import android.support.annotation.NonNull;
13+
import android.support.annotation.RequiresApi;
1214
import android.support.annotation.RequiresPermission;
1315
import android.view.View;
1416

@@ -399,6 +401,14 @@ static void applyLanguage(final Activity activity) {
399401
LanguageUtils.applyLanguage(activity);
400402
}
401403

404+
///////////////////////////////////////////////////////////////////////////
405+
// PermissionUtils
406+
///////////////////////////////////////////////////////////////////////////
407+
@RequiresApi(api = Build.VERSION_CODES.M)
408+
static boolean isGrantedDrawOverlays() {
409+
return PermissionUtils.isGrantedDrawOverlays();
410+
}
411+
402412
///////////////////////////////////////////////////////////////////////////
403413
// ProcessUtils
404414
///////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)