Skip to content

Commit a712286

Browse files
authored
Merge pull request Blankj#761 from Blankj/1.22.5
1.22.5
2 parents 07ad520 + ea41f12 commit a712286

File tree

10 files changed

+121
-27
lines changed

10 files changed

+121
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
* `18/12/19` [fix] ToastUtils multi show crash when run API 25. Publish v1.22.4.
1+
* `18/12/19` [fix] AdaptScreenUtils not work in MIUI on Android 5.1.1. Publish v1.22.5.
2+
* `18/12/18` [fix] ToastUtils multi show crash when run API 25. Publish v1.22.4.
23
* `18/12/18` [fix] ImageUtils recycle ret equals src. Publish v1.22.3.
34
* `18/12/17` [fix] Utils$FileProvider4UtilCode not found. Publish v1.22.3.
45
* `18/12/17` [fix] ToastUtils leak. Publish v1.22.2.

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.22.4-brightgreen.svg
44+
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.5-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.22.4-brightgreen.svg
44+
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.22.5-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

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

config.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ ext {
55
compileSdkVersion = 27
66
minSdkVersion = 14
77
targetSdkVersion = 27
8-
versionCode = 1_022_004
9-
versionName = '1.22.4'// E.g. 1.9.72 => 1,009,072
8+
versionCode = 1_022_005
9+
versionName = '1.22.5'// E.g. 1.9.72 => 1,009,072
1010

1111
bus = [
1212
isDebug: false,

lib/base/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ dependencies {
1515
api dep.free_proguard
1616
api 'com.r0adkll:slidableactivity:2.0.5'
1717
compileOnly dep.leakcanary.android_no_op
18-
// api 'com.blankj:utilcode:1.22.4'
18+
// api 'com.blankj:utilcode:1.22.5'
1919
}

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.22.4'
5+
implementation 'com.blankj:utilcode:1.22.5'
66
```
77

88

utilcode/README-STATIC-BUS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ apply plugin: "com.blankj.bus"
2727
给 base 模块添加 [AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode) 依赖:
2828

2929
```groovy
30-
api "com.blankj:utilcode:1.22.4"
30+
api "com.blankj:utilcode:1.22.5"
3131
```
3232

3333
比如 module0 中存在的 `Module0Activity.java`,我们通常都是在它内部写一个 `start` 函数来启动它,现在我们给它添加 `@BusUtils.Subscribe` 注解,并给注解的 `name` 赋唯一值,要注意,函数务必要 `public static` 哦:

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.22.4'
5+
implementation 'com.blankj:utilcode:1.22.5'
66
```
77

88

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
import android.content.res.Resources;
44
import android.util.DisplayMetrics;
5+
import android.util.Log;
6+
7+
import java.lang.reflect.Field;
58

69

710
public final class AdaptScreenUtils {
811

12+
private static boolean isInitMiui = false;
13+
private static Field mTmpMetrics;
14+
915
private static DisplayMetrics appDm;
1016

1117
/**
1218
* Adapt for the horizontal screen, and call it in [android.app.Activity.getResources].
1319
*/
1420
public static Resources adaptWidth(Resources resources, int designWidth) {
15-
DisplayMetrics dm = resources.getDisplayMetrics();
21+
DisplayMetrics dm = getDisplayMetrics(resources);
1622
float newXdpi = dm.xdpi = (dm.widthPixels * 72f) / designWidth;
1723
setAppDmXdpi(newXdpi);
1824
return resources;
@@ -22,7 +28,7 @@ public static Resources adaptWidth(Resources resources, int designWidth) {
2228
* Adapt for the vertical screen, and call it in [android.app.Activity.getResources].
2329
*/
2430
public static Resources adaptHeight(Resources resources, int designHeight) {
25-
DisplayMetrics dm = resources.getDisplayMetrics();
31+
DisplayMetrics dm = getDisplayMetrics(resources);
2632
float newXdpi = dm.xdpi = (dm.heightPixels * 72f) / designHeight;
2733
setAppDmXdpi(newXdpi);
2834
return resources;
@@ -33,7 +39,7 @@ public static Resources adaptHeight(Resources resources, int designHeight) {
3339
* @return the resource
3440
*/
3541
public static Resources closeAdapt(Resources resources) {
36-
DisplayMetrics dm = resources.getDisplayMetrics();
42+
DisplayMetrics dm = getDisplayMetrics(resources);
3743
float newXdpi = dm.xdpi = dm.density * 72;
3844
setAppDmXdpi(newXdpi);
3945
return resources;
@@ -67,4 +73,34 @@ private static void setAppDmXdpi(final float xdpi) {
6773
}
6874
appDm.xdpi = xdpi;
6975
}
76+
77+
private static DisplayMetrics getDisplayMetrics(Resources resources) {
78+
DisplayMetrics miuiDisplayMetrics = getMiuiTmpMetrics(resources);
79+
if (miuiDisplayMetrics == null) return resources.getDisplayMetrics();
80+
return miuiDisplayMetrics;
81+
}
82+
83+
private static DisplayMetrics getMiuiTmpMetrics(Resources resources) {
84+
if (!isInitMiui) {
85+
DisplayMetrics ret = null;
86+
String simpleName = resources.getClass().getSimpleName();
87+
if ("MiuiResources".equals(simpleName) || "XResources".equals(simpleName)) {
88+
try {
89+
mTmpMetrics = Resources.class.getDeclaredField("mTmpMetrics");
90+
mTmpMetrics.setAccessible(true);
91+
ret = (DisplayMetrics) mTmpMetrics.get(resources);
92+
} catch (Exception e) {
93+
Log.e("AdaptScreenUtils", "no field of mTmpMetrics in resources.");
94+
}
95+
}
96+
isInitMiui = true;
97+
return ret;
98+
}
99+
if (mTmpMetrics == null) return null;
100+
try {
101+
return (DisplayMetrics) mTmpMetrics.get(resources);
102+
} catch (Exception e) {
103+
return null;
104+
}
105+
}
70106
}

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

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import java.lang.annotation.Retention;
88
import java.lang.annotation.RetentionPolicy;
99
import java.lang.annotation.Target;
10-
import java.util.Map;
11-
import java.util.concurrent.ConcurrentHashMap;
1210

1311
/**
1412
* <pre>
@@ -22,8 +20,7 @@
2220
*/
2321
public final class BusUtils {
2422

25-
private static final Object NULL = new Object();
26-
private static final Map<Object, String> BUSES = new ConcurrentHashMap<>();
23+
private static final Object NULL = new Object();
2724

2825
public static <T> T post(final String name, final Object... objects) {
2926
if (name == null || name.length() == 0) return null;
@@ -35,17 +32,6 @@ public static <T> T post(final String name, final Object... objects) {
3532
return (T) o;
3633
}
3734

38-
39-
public static void register(final Object bus) {
40-
41-
}
42-
43-
public static void unregister(final Object bus) {
44-
45-
}
46-
47-
48-
4935
private static Object injectShell(final String name, final Object[] objects) {
5036
return NULL;
5137
}
@@ -54,5 +40,76 @@ private static Object injectShell(final String name, final Object[] objects) {
5440
@Retention(RetentionPolicy.CLASS)
5541
public @interface Subscribe {
5642
String name() default "";
43+
44+
int priority() default 0;
5745
}
46+
47+
// private static final Map<String, TreeSet<Bus>> BUSES = new ConcurrentHashMap<>();
48+
49+
// public static void register(final Object bus) {
50+
// Class c = null;
51+
// if (bus.getClass().equals(c)) {
52+
//
53+
// }
54+
// }
55+
56+
// public static void unregister(final Object bus) {
57+
// if (bus == null) return;
58+
// Class busClass = bus.getClass();
59+
// if (BUSES.containsKey(busClass)) {
60+
//
61+
// }
62+
// }
63+
64+
// private static Object inject(final String name, int priority ){
65+
// if (!BUSES.containsKey(name)) return NULL;
66+
// TreeSet<Bus> buses = BUSES.get(name);
67+
// for (Bus bus : buses) {
68+
// bus.
69+
// }
70+
// return NULL;
71+
// }
72+
73+
// static class Bus implements Comparable<Bus> {
74+
//
75+
// TreeMap<Object, Integer> mTreeMap;
76+
//
77+
// Bus(Object object) {
78+
// this(object, 0);
79+
// }
80+
//
81+
// Bus(Object object, int priority) {
82+
// mTreeMap = new TreeMap<>();
83+
// this.priority = priority;
84+
// }
85+
//
86+
// @Override
87+
// public int compareTo(@NonNull Bus o) {
88+
// return (this.priority < o.priority) ? 1 : ((this.priority == o.priority) ? 0 : -1);
89+
// }
90+
//
91+
// @Override
92+
// public boolean equals(Object obj) {
93+
// return ObjectUtils.equals(this, obj);
94+
// }
95+
//
96+
// @Override
97+
// public String toString() {
98+
// return mObject.toString() + ": " + priority;
99+
// }
100+
// }
101+
//
102+
// public static void main(String[] args) {
103+
// TreeSet<Bus> queue = new TreeSet<>();
104+
// Bus bus0 = new Bus("", 1);
105+
// Bus bus1 = new Bus("", 2);
106+
// Bus bus2 = new Bus("", 3);
107+
// Bus bus3 = new Bus("", 3);
108+
// queue.add(bus1);
109+
// queue.add(bus2);
110+
// queue.add(bus0);
111+
//
112+
// System.out.println(queue);
113+
//
114+
// }
58115
}

0 commit comments

Comments
 (0)