Skip to content

Commit a75f666

Browse files
authored
Merge pull request Blankj#822 from Blankj/1.23.3
1.23.3
2 parents 59fd054 + a56a1f4 commit a75f666

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+538
-435
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* `19/01/29` [fix] LogUtils format json when json not start with '{'. Publish v1.23.3.
2+
* `19/01/28` [fix] KeyboardUtils#fixSoftInputLeaks don't work on the device of HuaWei.
3+
* `19/01/26` [fix] NetworkUtils#getNetworkType.
14
* `19/01/25` [add] CloneUtils, PermissionUtils support request permission of WRITE_SETTINGS and DRAW_OVERLAYS. Publish v1.23.2.
25
* `19/01/24` [add] BrightnessUtils and FlashlightUtils.
36
* `19/01/23` [add] Modify the demo of utilcode use kotlin. Publish v1.23.1.

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.23.2-brightgreen.svg
44+
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.23.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.23.2-brightgreen.svg
44+
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.23.3-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: 6 additions & 5 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_023_002
9-
versionName = '1.23.2'// E.g. 1.9.72 => 1,009,072
8+
versionCode = 1_023_003
9+
versionName = '1.23.3'// E.g. 1.9.72 => 1,009,072
1010

1111
bus = [
1212
isDebug: false,
@@ -17,7 +17,7 @@ ext {
1717
// lib version
1818
kotlin_version = '1.3.0'
1919
support_version = '27.1.1'
20-
leakcanary_version = '1.5.4'
20+
leakcanary_version = '1.6.3'
2121

2222
dep = [
2323
plugin : [
@@ -38,8 +38,9 @@ ext {
3838
constraint : "com.android.support.constraint:constraint-layout:1.1.3",
3939
kotlin : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version",
4040
leakcanary : [
41-
android : "com.squareup.leakcanary:leakcanary-android:$leakcanary_version",
42-
android_no_op: "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version",
41+
android : "com.squareup.leakcanary:leakcanary-android:$leakcanary_version",
42+
android_no_op : "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version",
43+
support_fragment: "com.squareup.leakcanary:leakcanary-support-fragment:$leakcanary_version"
4344
],
4445
free_proguard: "com.blankj:free-proguard:0.0.7",
4546
adapt_screen : "com.blankj:adapt-screen:0.0.3",

config_app.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ android {
4040
dependencies {
4141
// LeakCanary
4242
debugImplementation dep.leakcanary.android
43+
debugImplementation dep.leakcanary.support_fragment
4344
releaseImplementation dep.leakcanary.android_no_op
4445
}
4546

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.23.2'
18+
// api 'com.blankj:utilcode:1.23.3'
1919
}

subutil/pkg/src/main/java/com/blankj/subutil/pkg/feature/location/LocationActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LocationActivity : BaseBackActivity() {
5151
override fun getLocation(lastLatitude: String, lastLongitude: String, latitude: String,
5252
longitude: String, country: String, locality: String, street: String) {
5353
runOnUiThread {
54-
locationAboutTv.text = SpanUtils()
54+
SpanUtils.with(locationAboutTv)
5555
.appendLine("lastLatitude: $lastLatitude")
5656
.appendLine("lastLongitude: $lastLongitude")
5757
.appendLine("latitude: $latitude")
@@ -77,7 +77,7 @@ class LocationActivity : BaseBackActivity() {
7777
override fun initView(savedInstanceState: Bundle?, contentView: View) {
7878
setTitle(R.string.demo_location)
7979

80-
locationAboutTv.text = SpanUtils()
80+
SpanUtils.with(locationAboutTv)
8181
.appendLine("lastLatitude: unknown")
8282
.appendLine("lastLongitude: unknown")
8383
.appendLine("latitude: unknown")

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.23.2'
5+
implementation 'com.blankj:utilcode:1.23.3'
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.23.2"
30+
api "com.blankj:utilcode:1.23.3"
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.23.2'
5+
implementation 'com.blankj:utilcode:1.23.3'
66
```
77

88

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ public static AppInfo getAppInfo() {
736736
* </ul>
737737
*
738738
* @param packageName The name of the package.
739-
* @return 当前应用的 AppInfo
739+
* @return the application's information
740740
*/
741741
public static AppInfo getAppInfo(final String packageName) {
742742
try {

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ public static void setStatusBarLightMode(@NonNull final Window window,
127127
if (decorView != null) {
128128
int vis = decorView.getSystemUiVisibility();
129129
if (isLightMode) {
130-
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
131130
vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
132131
} else {
133132
vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
@@ -137,6 +136,33 @@ public static void setStatusBarLightMode(@NonNull final Window window,
137136
}
138137
}
139138

139+
/**
140+
* Is the status bar light mode.
141+
*
142+
* @param activity The activity.
143+
* @return {@code true}: yes<br>{@code false}: no
144+
*/
145+
public static boolean isStatusBarLightMode(@NonNull final Activity activity) {
146+
return isStatusBarLightMode(activity.getWindow());
147+
}
148+
149+
/**
150+
* Is the status bar light mode.
151+
*
152+
* @param window The window.
153+
* @return {@code true}: yes<br>{@code false}: no
154+
*/
155+
public static boolean isStatusBarLightMode(@NonNull final Window window) {
156+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
157+
View decorView = window.getDecorView();
158+
if (decorView != null) {
159+
int vis = decorView.getSystemUiVisibility();
160+
return (vis & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) != 0;
161+
}
162+
}
163+
return false;
164+
}
165+
140166
/**
141167
* Add the top margin size equals status bar's height for view.
142168
*
@@ -437,9 +463,10 @@ public static int getNavBarHeight() {
437463
* @param activity The activity.
438464
* @param isVisible True to set navigation bar visible, false otherwise.
439465
*/
440-
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
441466
public static void setNavBarVisibility(@NonNull final Activity activity, boolean isVisible) {
467+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
442468
setNavBarVisibility(activity.getWindow(), isVisible);
469+
443470
}
444471

445472
/**
@@ -448,8 +475,8 @@ public static void setNavBarVisibility(@NonNull final Activity activity, boolean
448475
* @param window The window.
449476
* @param isVisible True to set navigation bar visible, false otherwise.
450477
*/
451-
@RequiresApi(Build.VERSION_CODES.KITKAT)
452478
public static void setNavBarVisibility(@NonNull final Window window, boolean isVisible) {
479+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
453480
final ViewGroup decorView = (ViewGroup) window.getDecorView();
454481
for (int i = 0, count = decorView.getChildCount(); i < count; i++) {
455482
final View child = decorView.getChildAt(i);

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

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

33
import android.annotation.SuppressLint;
4+
import android.content.res.Resources;
45
import android.graphics.Bitmap;
56
import android.graphics.BitmapFactory;
67
import android.graphics.Canvas;
@@ -578,7 +579,7 @@ public static Bitmap view2Bitmap(final View view) {
578579
* @return value of px
579580
*/
580581
public static int dp2px(final float dpValue) {
581-
final float scale = Utils.getApp().getResources().getDisplayMetrics().density;
582+
final float scale = Resources.getSystem().getDisplayMetrics().density;
582583
return (int) (dpValue * scale + 0.5f);
583584
}
584585

@@ -589,7 +590,7 @@ public static int dp2px(final float dpValue) {
589590
* @return value of dp
590591
*/
591592
public static int px2dp(final float pxValue) {
592-
final float scale = Utils.getApp().getResources().getDisplayMetrics().density;
593+
final float scale = Resources.getSystem().getDisplayMetrics().density;
593594
return (int) (pxValue / scale + 0.5f);
594595
}
595596

@@ -600,7 +601,7 @@ public static int px2dp(final float pxValue) {
600601
* @return value of px
601602
*/
602603
public static int sp2px(final float spValue) {
603-
final float fontScale = Utils.getApp().getResources().getDisplayMetrics().scaledDensity;
604+
final float fontScale = Resources.getSystem().getDisplayMetrics().scaledDensity;
604605
return (int) (spValue * fontScale + 0.5f);
605606
}
606607

@@ -611,7 +612,7 @@ public static int sp2px(final float spValue) {
611612
* @return value of sp
612613
*/
613614
public static int px2sp(final float pxValue) {
614-
final float fontScale = Utils.getApp().getResources().getDisplayMetrics().scaledDensity;
615+
final float fontScale = Resources.getSystem().getDisplayMetrics().scaledDensity;
615616
return (int) (pxValue / fontScale + 0.5f);
616617
}
617618

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,15 @@ public static String formatJson(final String json) {
211211

212212
public static String formatJson(final String json, final int indentSpaces) {
213213
try {
214-
if (json.startsWith("{")) {
215-
return new JSONObject(json).toString(indentSpaces);
216-
} else if (json.startsWith("[")) {
217-
return new JSONArray(json).toString(indentSpaces);
214+
for (int i = 0, len = json.length(); i < len; i++) {
215+
char c = json.charAt(i);
216+
if (c == '{') {
217+
return new JSONObject(json).toString(indentSpaces);
218+
} else if (c == '[') {
219+
return new JSONArray(json).toString(indentSpaces);
220+
} else if (!Character.isWhitespace(c)) {
221+
return json;
222+
}
218223
}
219224
} catch (JSONException e) {
220225
e.printStackTrace();

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,28 +259,26 @@ private static int getContentViewInvisibleHeight(final Activity activity) {
259259
* Fix the leaks of soft input.
260260
* <p>Call the function in {@link Activity#onDestroy()}.</p>
261261
*
262-
* @param context The context.
262+
* @param activity The activity.
263263
*/
264-
public static void fixSoftInputLeaks(final Context context) {
265-
if (context == null) return;
264+
public static void fixSoftInputLeaks(final Activity activity) {
265+
if (activity == null) return;
266266
InputMethodManager imm =
267267
(InputMethodManager) Utils.getApp().getSystemService(Context.INPUT_METHOD_SERVICE);
268-
String[] strArr = new String[]{"mCurRootView", "mServedView", "mNextServedView", "mLastSrvView"};
269-
for (int i = 0; i < 4; i++) {
268+
if (imm == null) return;
269+
String[] leakViews = new String[]{"mLastSrvView", "mCurRootView", "mServedView", "mNextServedView"};
270+
for (String leakView : leakViews) {
270271
try {
271-
//noinspection ConstantConditions
272-
Field declaredField = imm.getClass().getDeclaredField(strArr[i]);
272+
Field declaredField = InputMethodManager.class.getDeclaredField(leakView);
273273
if (declaredField == null) continue;
274274
if (!declaredField.isAccessible()) {
275275
declaredField.setAccessible(true);
276276
}
277277
Object obj = declaredField.get(imm);
278278
if (!(obj instanceof View)) continue;
279279
View view = (View) obj;
280-
if (view.getContext() == context) {
280+
if (view.getRootView() == activity.getWindow().getDecorView().getRootView()) {
281281
declaredField.set(imm, null);
282-
} else {
283-
return;
284282
}
285283
} catch (Throwable th) {
286284
th.printStackTrace();

0 commit comments

Comments
 (0)