Skip to content

Commit d9ef585

Browse files
committed
see 05/28 log
1 parent f835ce5 commit d9ef585

File tree

10 files changed

+106
-25
lines changed

10 files changed

+106
-25
lines changed

README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
4343

44-
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.16.2-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.16.3-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

4747
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen
4141

4242
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
4343

44-
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.16.2-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.16.3-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

4747
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

app/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ dependencies {
5454
implementation "com.android.support:design:$support_version"
5555
implementation 'com.r0adkll:slidableactivity:2.0.5'
5656
// LeakCanary
57+
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
5758
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
5859
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version"
59-
// implementation 'com.blankj:utilcode:1.16.2'
60+
// implementation 'com.blankj:utilcode:1.16.3'
6061
}
61-
62-

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,44 @@
33
package="com.blankj.androidutilcode">
44

55
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
6-
76
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
87

9-
<!--bar-->
8+
<!-- bar -->
109
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
1110

12-
<!--读写内存-->
11+
<!-- 读写内存 -->
1312
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
1413
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1514

16-
<!--network-->
15+
<!-- network -->
1716
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
1817
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
1918
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2019
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
2120
<uses-permission android:name="android.permission.INTERNET" />
2221

23-
<!--permission-->
22+
<!-- permission -->
2423
<uses-permission android:name="android.permission.READ_CALENDAR" />
2524
<uses-permission android:name="android.permission.RECORD_AUDIO" />
2625

27-
<!--phone-->
26+
<!-- phone -->
2827
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
2928
<uses-permission android:name="android.permission.CALL_PHONE" />
3029
<uses-permission android:name="android.permission.SEND_SMS" />
3130
<uses-permission android:name="android.permission.READ_SMS" />
3231
<uses-permission android:name="android.permission.READ_CONTACTS" />
3332

34-
<!--process-->
33+
<!-- process -->
3534
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
3635

37-
<!--screen-->
36+
<!-- screen -->
3837
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
3938

40-
<!--flashlight-->
39+
<!-- flashlight -->
4140
<uses-permission android:name="android.permission.CAMERA" />
4241
<uses-permission android:name="android.permission.FLASHLIGHT" />
4342

44-
<!--location-->
43+
<!-- location -->
4544
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
4645
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
4746

@@ -57,11 +56,12 @@
5756
android:windowSoftInputMode="stateHidden|adjustPan">
5857
<intent-filter>
5958
<action android:name="android.intent.action.MAIN" />
59+
6060
<category android:name="android.intent.category.LAUNCHER" />
6161
</intent-filter>
6262
</activity>
6363

64-
<!--core-->
64+
<!-- core -->
6565
<activity
6666
android:name=".feature.core.CoreUtilActivity"
6767
android:launchMode="singleTop" />
@@ -162,7 +162,7 @@
162162
android:name=".feature.core.toast.ToastActivity"
163163
android:launchMode="singleTop" />
164164

165-
<!--sub-->
165+
<!-- sub -->
166166
<activity
167167
android:name=".feature.sub.SubUtilActivity"
168168
android:launchMode="singleTop" />

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ ext {
4444
min_sdk_version = 14
4545
target_sdk_version = 27
4646

47-
version_code = 1_016_002
48-
version_name = '1.16.2'// E.g 1.9.72 => 1,009,072
47+
version_code = 1_016_003
48+
version_name = '1.16.3'// E.g 1.9.72 => 1,009,072
4949

5050
// App dependencies
5151
support_version = '27.1.0'

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* 18/05/30 修复 ToastUtils 在 targetSdkVersion 为 27 在 api 25 机器快速 show 两次崩溃的异常,发布 1.16.3 版本
12
* 18/05/29 完善 TimeUtils 的 timeSpan 带符号位,ToastUtils 去除弱引用,发布 1.16.2 版本
23
* 18/05/25 新增 AppUtils#registerAppStatusChangedListener 和 AppUtils#unregisterAppStatusChangedListener,发布 1.16.1 版本
34
* 18/05/22 新增 ThreadUtils,发布 1.16.0 版本

utilcode/README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.16.2'
5+
implementation 'com.blankj:utilcode:1.16.3'
66
```
77

88

utilcode/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.16.2'
5+
implementation 'com.blankj:utilcode:1.16.3'
66
```
77

88

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

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.blankj.utilcode.util;
22

33
import android.content.Context;
4+
import android.content.ContextWrapper;
45
import android.graphics.Color;
56
import android.graphics.PorterDuff;
67
import android.graphics.PorterDuffColorFilter;
@@ -14,11 +15,17 @@
1415
import android.support.annotation.LayoutRes;
1516
import android.support.annotation.NonNull;
1617
import android.support.annotation.StringRes;
18+
import android.util.Log;
19+
import android.view.Display;
1720
import android.view.LayoutInflater;
1821
import android.view.View;
22+
import android.view.ViewGroup;
23+
import android.view.WindowManager;
1924
import android.widget.TextView;
2025
import android.widget.Toast;
2126

27+
import java.lang.reflect.Field;
28+
2229
/**
2330
* <pre>
2431
* author: Blankj
@@ -214,7 +221,6 @@ public static View showCustomLong(@LayoutRes final int layoutId) {
214221
public static void cancel() {
215222
if (sToast != null) {
216223
sToast.cancel();
217-
sToast = null;
218224
}
219225
}
220226

@@ -247,7 +253,7 @@ public void run() {
247253
sToast.setGravity(sGravity, sXOffset, sYOffset);
248254
}
249255
setBg(tvMessage);
250-
sToast.show();
256+
showToast();
251257
}
252258
});
253259
}
@@ -264,11 +270,24 @@ public void run() {
264270
sToast.setGravity(sGravity, sXOffset, sYOffset);
265271
}
266272
setBg();
267-
sToast.show();
273+
showToast();
268274
}
269275
});
270276
}
271277

278+
private static void showToast() {
279+
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1) {
280+
try {
281+
Field field = View.class.getDeclaredField("mContext");
282+
field.setAccessible(true);
283+
field.set(sToast.getView(), new ApplicationContextWrapperForApi25());
284+
} catch (Throwable throwable) {
285+
throwable.printStackTrace();
286+
}
287+
}
288+
sToast.show();
289+
}
290+
272291
private static void setBg() {
273292
if (sBgResource != -1) {
274293
final View toastView = sToast.getView();
@@ -317,4 +336,67 @@ private static View getView(@LayoutRes final int layoutId) {
317336
(LayoutInflater) Utils.getApp().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
318337
return inflate != null ? inflate.inflate(layoutId, null) : null;
319338
}
339+
340+
private static final class ApplicationContextWrapperForApi25 extends ContextWrapper {
341+
342+
ApplicationContextWrapperForApi25() {
343+
super(Utils.getApp());
344+
}
345+
346+
@Override
347+
public Context getApplicationContext() {
348+
return this;
349+
}
350+
351+
@Override
352+
public Object getSystemService(@NonNull String name) {
353+
if (Context.WINDOW_SERVICE.equals(name)) {
354+
// noinspection ConstantConditions
355+
return new WindowManagerWrapper(
356+
(WindowManager) getBaseContext().getSystemService(name)
357+
);
358+
}
359+
return super.getSystemService(name);
360+
}
361+
362+
private static final class WindowManagerWrapper implements WindowManager {
363+
364+
private final WindowManager base;
365+
366+
private WindowManagerWrapper(@NonNull WindowManager base) {
367+
this.base = base;
368+
}
369+
370+
@Override
371+
public Display getDefaultDisplay() {
372+
return base.getDefaultDisplay();
373+
}
374+
375+
@Override
376+
public void removeViewImmediate(View view) {
377+
base.removeViewImmediate(view);
378+
}
379+
380+
@Override
381+
public void addView(View view, ViewGroup.LayoutParams params) {
382+
try {
383+
base.addView(view, params);
384+
} catch (BadTokenException e) {
385+
Log.e("WindowManagerWrapper", e.getMessage());
386+
} catch (Throwable throwable) {
387+
Log.e("WindowManagerWrapper", "[addView]", throwable);
388+
}
389+
}
390+
391+
@Override
392+
public void updateViewLayout(View view, ViewGroup.LayoutParams params) {
393+
base.updateViewLayout(view, params);
394+
}
395+
396+
@Override
397+
public void removeView(View view) {
398+
base.removeView(view);
399+
}
400+
}
401+
}
320402
}

utilcode/src/test/java/com/blankj/utilcode/util/CacheUtilsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ public void tearDown() {
264264
mCacheUtils2.clear();
265265
}
266266

267-
268267
static class ParcelableTest implements Parcelable {
269268
String author;
270269
String className;

0 commit comments

Comments
 (0)