Skip to content

Commit 205943d

Browse files
committed
see 08/08 log
1 parent a269b5f commit 205943d

File tree

14 files changed

+62
-194
lines changed

14 files changed

+62
-194
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.18.4-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.18.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.18.4-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.18.5-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

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

apk/output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1018004,"versionName":"1.18.4","enabled":true,"outputFile":"util_1_18_4.apk","fullName":"release","baseName":"release"},"path":"util_1_18_4.apk","properties":{}}]
1+
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1018005,"versionName":"1.18.5","enabled":true,"outputFile":"util_1_18_5.apk","fullName":"release","baseName":"release"},"path":"util_1_18_5.apk","properties":{}}]
Binary file not shown.

app/src/main/java/com/blankj/androidutilcode/feature/core/screen/ScreenAdaptActivity.java

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public static void start(Context context) {
3636
@Override
3737
public void initData(@Nullable Bundle bundle) {
3838
if (ScreenUtils.isPortrait()) {
39-
ScreenUtils.adaptScreen4VerticalSlide(this, 540);
39+
ScreenUtils.adaptScreen4VerticalSlide(this, 360);
4040
} else {
41-
ScreenUtils.adaptScreen4HorizontalSlide(this, 540);
41+
ScreenUtils.adaptScreen4HorizontalSlide(this, 360);
4242
}
4343
}
4444

@@ -49,11 +49,7 @@ public int bindLayout() {
4949

5050
@Override
5151
public void initView(Bundle savedInstanceState, View contentView) {
52-
tvUp = findViewById(R.id.tv_up);
53-
tvDown = findViewById(R.id.tv_down);
54-
if (!ScreenUtils.isPortrait()) {
55-
updateLayout();
56-
}
52+
5753
}
5854

5955
@Override
@@ -68,34 +64,11 @@ public void onWidgetClick(View view) {
6864

6965
public void toggleFullScreen(View view) {
7066
ScreenUtils.toggleFullScreen(this);
71-
updateLayout();
7267
}
7368

74-
private void updateLayout() {
75-
int statusBarHeight = BarUtils.getStatusBarHeight();
76-
int statusBarHeightInDp = SizeUtils.px2dp(this, statusBarHeight);
77-
ViewGroup.LayoutParams upLayoutParams = tvUp.getLayoutParams();
78-
ViewGroup.LayoutParams downLayoutParams = tvDown.getLayoutParams();
79-
if (ScreenUtils.isFullScreen(this)) {
80-
int height = 360 / 2;
81-
String s = height + "dp";
82-
upLayoutParams.height = SizeUtils.dp2px(this, height);
83-
tvUp.setLayoutParams(upLayoutParams);
84-
tvUp.setText(s);
85-
86-
downLayoutParams.height = SizeUtils.dp2px(this, height);
87-
tvDown.setLayoutParams(downLayoutParams);
88-
tvDown.setText(s);
89-
} else {
90-
int height = 360 / 2 - statusBarHeightInDp / 2;
91-
String s = height + "dp";
92-
upLayoutParams.height = SizeUtils.dp2px(this, height);
93-
tvUp.setLayoutParams(upLayoutParams);
94-
tvUp.setText(s);
95-
96-
downLayoutParams.height = SizeUtils.dp2px(this, height);
97-
tvDown.setLayoutParams(downLayoutParams);
98-
tvDown.setText(s);
99-
}
69+
@Override
70+
protected void onDestroy() {
71+
ScreenUtils.cancelAdaptScreen(this);
72+
super.onDestroy();
10073
}
10174
}

app/src/main/res_core/layout-land/activity_screen_adapt.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
android:id="@+id/tv_up"
2222
style="@style/TextStyle"
2323
android:layout_width="2000dp"
24-
android:layout_height="1dp"
24+
android:layout_height="180dp"
2525
android:layout_alignParentTop="true"
2626
android:layout_toRightOf="@id/tv_fullscreen"
2727
android:background="@color/colorAccentHalfTrans"
@@ -32,7 +32,7 @@
3232
android:id="@+id/tv_down"
3333
style="@style/TextStyle"
3434
android:layout_width="2000dp"
35-
android:layout_height="1dp"
35+
android:layout_height="180dp"
3636
android:layout_alignParentBottom="true"
3737
android:layout_toRightOf="@id/tv_fullscreen"
3838
android:background="@color/colorPrimaryHalfTrans"

app/src/main/res_core/layout/activity_screen.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<ScrollView
3-
xmlns:android="http://schemas.android.com/apk/res/android"
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
43
android:layout_width="match_parent"
54
android:layout_height="match_parent"
65
android:background="@color/white">
@@ -9,9 +8,7 @@
98
android:layout_width="match_parent"
109
android:layout_height="wrap_content"
1110
android:gravity="center_horizontal"
12-
android:orientation="vertical"
13-
android:paddingLeft="@dimen/spacing_16"
14-
android:paddingRight="@dimen/spacing_16">
11+
android:orientation="vertical">
1512

1613
<ImageView
1714
android:id="@+id/iv_screenshot"

config.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ ext {
66
compileSdkVersion: 27,
77
minSdkVersion : 14,
88
targetSdkVersion : 27,
9-
versionCode : 1_018_004,
10-
versionName : '1.18.4'// E.g 1.9.72 => 1,009,072
9+
versionCode : 1_018_005,
10+
versionName : '1.18.5'// E.g 1.9.72 => 1,009,072
1111
]
1212

1313
versionConfig = [
@@ -167,7 +167,7 @@ def configAppDependencies(Project pro) {
167167
// LeakCanary
168168
debugImplementation depConfig.leakcanary.android
169169
releaseImplementation depConfig.leakcanary.android_no_op
170-
// implementation 'com.blankj:utilcode:1.18.4'
170+
// implementation 'com.blankj:utilcode:1.18.5'
171171
}
172172
}
173173

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* 18/08/08 修复 ScreenUtils#adaptxx 在第三方 SDK 会出现的问题,发布 1.18.5
12
* 18/08/07 修复 ScreenUtils#adaptxx 在 API 26 以下无效的 bug,发布 1.18.4
23
* 18/08/06 修复 ScreenUtils#screenShot 中 decorView.getDrawingCache() 为空的问题,发布 1.18.3
34
* 18/08/05 修复 1.18.0 版本删去 `if (activity.getClass() == PermissionUtils.PermissionActivity.class) return;` 造成 PermissionUtils 获取栈顶 Activity 问题,发布 1.18.2

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

88

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

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -580,18 +580,7 @@ public static Bitmap view2Bitmap(final View view) {
580580
* @return value of px
581581
*/
582582
public static int dp2px(final float dpValue) {
583-
return dp2px(Utils.getApp(), dpValue);
584-
}
585-
586-
/**
587-
* Value of dp to value of px.
588-
*
589-
* @param context The context.
590-
* @param dpValue The value of dp.
591-
* @return value of px
592-
*/
593-
public static int dp2px(@NonNull final Context context, final float dpValue) {
594-
final float scale = context.getResources().getDisplayMetrics().density;
583+
final float scale = Utils.getApp().getResources().getDisplayMetrics().density;
595584
return (int) (dpValue * scale + 0.5f);
596585
}
597586

@@ -602,18 +591,7 @@ public static int dp2px(@NonNull final Context context, final float dpValue) {
602591
* @return value of dp
603592
*/
604593
public static int px2dp(final float pxValue) {
605-
return px2dp(Utils.getApp(), pxValue);
606-
}
607-
608-
/**
609-
* Value of px to value of dp.
610-
*
611-
* @param context The context.
612-
* @param pxValue The value of px.
613-
* @return value of dp
614-
*/
615-
public static int px2dp(@NonNull final Context context, final float pxValue) {
616-
final float scale = context.getResources().getDisplayMetrics().density;
594+
final float scale = Utils.getApp().getResources().getDisplayMetrics().density;
617595
return (int) (pxValue / scale + 0.5f);
618596
}
619597

@@ -624,18 +602,7 @@ public static int px2dp(@NonNull final Context context, final float pxValue) {
624602
* @return value of px
625603
*/
626604
public static int sp2px(final float spValue) {
627-
return sp2px(Utils.getApp(), spValue);
628-
}
629-
630-
/**
631-
* Value of sp to value of px.
632-
*
633-
* @param context The context.
634-
* @param spValue The value of sp.
635-
* @return value of px
636-
*/
637-
public static int sp2px(@NonNull final Context context, final float spValue) {
638-
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
605+
final float fontScale = Utils.getApp().getResources().getDisplayMetrics().scaledDensity;
639606
return (int) (spValue * fontScale + 0.5f);
640607
}
641608

@@ -646,18 +613,7 @@ public static int sp2px(@NonNull final Context context, final float spValue) {
646613
* @return value of sp
647614
*/
648615
public static int px2sp(final float pxValue) {
649-
return px2sp(Utils.getApp(), pxValue);
650-
}
651-
652-
/**
653-
* Value of px to value of sp.
654-
*
655-
* @param context The context.
656-
* @param pxValue The value of px.
657-
* @return value of sp
658-
*/
659-
public static int px2sp(@NonNull final Context context, final float pxValue) {
660-
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
616+
final float fontScale = Utils.getApp().getResources().getDisplayMetrics().scaledDensity;
661617
return (int) (pxValue / fontScale + 0.5f);
662618
}
663619

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -297,53 +297,34 @@ public static boolean isTablet() {
297297
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
298298
}
299299

300+
private static final UtilDisplayMetrics UDM = new UtilDisplayMetrics();
301+
300302
/**
301303
* Adapt the screen for vertical slide.
302304
*
303-
* @param designWidthInDp The size of design diagram's width, in dp,
304-
* e.g. the design diagram width is 720px, in XHDPI device,
305-
* the designWidthInDp = 720 / 2.
305+
* @param designWidthInPx The size of design diagram's width, in pixel.
306306
*/
307307
public static void adaptScreen4VerticalSlide(final Activity activity,
308-
final float designWidthInDp) {
309-
adaptScreen(activity, designWidthInDp, true);
308+
final int designWidthInPx) {
309+
adaptScreen(activity, designWidthInPx, true);
310310
}
311311

312312
/**
313313
* Adapt the screen for horizontal slide.
314314
*
315-
* @param designHeightInDp The size of design diagram's height, in dp,
316-
* e.g. the design diagram height is 1080px, in XXHDPI device,
317-
* the designHeightInDp = 1080 / 3.
315+
* @param designHeightInPx The size of design diagram's height, in pixel.
318316
*/
319317
public static void adaptScreen4HorizontalSlide(final Activity activity,
320-
final float designHeightInDp) {
321-
adaptScreen(activity, designHeightInDp, false);
318+
final int designHeightInPx) {
319+
adaptScreen(activity, designHeightInPx, false);
322320
}
323321

324-
/**
325-
* Cancel adapt the screen.
326-
*
327-
* @param activity The activity.
328-
*/
329-
public static void cancelAdaptScreen(final Activity activity) {
330-
final DisplayMetrics activityDm = activity.getResources().getDisplayMetrics();
331-
if (UDM.densityDpi != -1) {
332-
activityDm.density = UDM.density;
333-
activityDm.scaledDensity = UDM.scaledDensity;
334-
activityDm.densityDpi = UDM.densityDpi;
335-
} else {
336-
Log.i("ScreenUtils", "U should adapt screen first.");
337-
}
338-
}
339-
340-
341322
/**
342323
* Reference from: https://mp.weixin.qq.com/s/d9QCoBP6kV9VSWvVldVVwA
343324
*/
344-
private static void adaptScreen(final Activity activity,
345-
final float sizeInDp,
346-
final boolean isVerticalSlide) {
325+
public static void adaptScreen(final Activity activity,
326+
final int sizeInPx,
327+
final boolean isVerticalSlide) {
347328
final DisplayMetrics appDm = Utils.getApp().getResources().getDisplayMetrics();
348329
final DisplayMetrics activityDm = activity.getResources().getDisplayMetrics();
349330
if (UDM.densityDpi == -1) {
@@ -364,9 +345,9 @@ public void onLowMemory() {/**/}
364345
});
365346
}
366347
if (isVerticalSlide) {
367-
activityDm.density = activityDm.widthPixels / sizeInDp;
348+
activityDm.density = activityDm.widthPixels / (float) sizeInPx;
368349
} else {
369-
activityDm.density = activityDm.heightPixels / sizeInDp;
350+
activityDm.density = activityDm.heightPixels / (float) sizeInPx;
370351
}
371352
activityDm.scaledDensity = activityDm.density * (UDM.scaledDensity / UDM.density);
372353
activityDm.densityDpi = (int) (160 * activityDm.density);
@@ -376,7 +357,26 @@ public void onLowMemory() {/**/}
376357
appDm.densityDpi = activityDm.densityDpi;
377358
}
378359

379-
private static final UtilDisplayMetrics UDM = new UtilDisplayMetrics();
360+
/**
361+
* Cancel adapt the screen.
362+
*
363+
* @param activity The activity.
364+
*/
365+
public static void cancelAdaptScreen(final Activity activity) {
366+
final DisplayMetrics appDm = Utils.getApp().getResources().getDisplayMetrics();
367+
final DisplayMetrics activityDm = activity.getResources().getDisplayMetrics();
368+
if (UDM.densityDpi != -1) {
369+
activityDm.density = UDM.density;
370+
activityDm.scaledDensity = UDM.scaledDensity;
371+
activityDm.densityDpi = UDM.densityDpi;
372+
373+
appDm.density = UDM.density;
374+
appDm.scaledDensity = UDM.scaledDensity;
375+
appDm.densityDpi = UDM.densityDpi;
376+
} else {
377+
Log.i("ScreenUtils", "U should adapt screen first.");
378+
}
379+
}
380380

381381
private static class UtilDisplayMetrics {
382382
float density;

0 commit comments

Comments
 (0)