Skip to content

Commit

Permalink
see 08/08 log
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankj committed Aug 8, 2018
1 parent a269b5f commit 205943d
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 194 deletions.
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

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

[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.18.4-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.18.5-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode

[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen

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

[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.18.4-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.18.5-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode

[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
Expand Down
2 changes: 1 addition & 1 deletion apk/output.json
Original file line number Diff line number Diff line change
@@ -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":{}}]
[{"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 renamed apk/util_1_18_4.apk → apk/util_1_18_5.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public static void start(Context context) {
@Override
public void initData(@Nullable Bundle bundle) {
if (ScreenUtils.isPortrait()) {
ScreenUtils.adaptScreen4VerticalSlide(this, 540);
ScreenUtils.adaptScreen4VerticalSlide(this, 360);
} else {
ScreenUtils.adaptScreen4HorizontalSlide(this, 540);
ScreenUtils.adaptScreen4HorizontalSlide(this, 360);
}
}

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

@Override
public void initView(Bundle savedInstanceState, View contentView) {
tvUp = findViewById(R.id.tv_up);
tvDown = findViewById(R.id.tv_down);
if (!ScreenUtils.isPortrait()) {
updateLayout();
}

}

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

public void toggleFullScreen(View view) {
ScreenUtils.toggleFullScreen(this);
updateLayout();
}

private void updateLayout() {
int statusBarHeight = BarUtils.getStatusBarHeight();
int statusBarHeightInDp = SizeUtils.px2dp(this, statusBarHeight);
ViewGroup.LayoutParams upLayoutParams = tvUp.getLayoutParams();
ViewGroup.LayoutParams downLayoutParams = tvDown.getLayoutParams();
if (ScreenUtils.isFullScreen(this)) {
int height = 360 / 2;
String s = height + "dp";
upLayoutParams.height = SizeUtils.dp2px(this, height);
tvUp.setLayoutParams(upLayoutParams);
tvUp.setText(s);

downLayoutParams.height = SizeUtils.dp2px(this, height);
tvDown.setLayoutParams(downLayoutParams);
tvDown.setText(s);
} else {
int height = 360 / 2 - statusBarHeightInDp / 2;
String s = height + "dp";
upLayoutParams.height = SizeUtils.dp2px(this, height);
tvUp.setLayoutParams(upLayoutParams);
tvUp.setText(s);

downLayoutParams.height = SizeUtils.dp2px(this, height);
tvDown.setLayoutParams(downLayoutParams);
tvDown.setText(s);
}
@Override
protected void onDestroy() {
ScreenUtils.cancelAdaptScreen(this);
super.onDestroy();
}
}
4 changes: 2 additions & 2 deletions app/src/main/res_core/layout-land/activity_screen_adapt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
android:id="@+id/tv_up"
style="@style/TextStyle"
android:layout_width="2000dp"
android:layout_height="1dp"
android:layout_height="180dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/tv_fullscreen"
android:background="@color/colorAccentHalfTrans"
Expand All @@ -32,7 +32,7 @@
android:id="@+id/tv_down"
style="@style/TextStyle"
android:layout_width="2000dp"
android:layout_height="1dp"
android:layout_height="180dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/tv_fullscreen"
android:background="@color/colorPrimaryHalfTrans"
Expand Down
7 changes: 2 additions & 5 deletions app/src/main/res_core/layout/activity_screen.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
Expand All @@ -9,9 +8,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="@dimen/spacing_16"
android:paddingRight="@dimen/spacing_16">
android:orientation="vertical">

<ImageView
android:id="@+id/iv_screenshot"
Expand Down
6 changes: 3 additions & 3 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ ext {
compileSdkVersion: 27,
minSdkVersion : 14,
targetSdkVersion : 27,
versionCode : 1_018_004,
versionName : '1.18.4'// E.g 1.9.72 => 1,009,072
versionCode : 1_018_005,
versionName : '1.18.5'// E.g 1.9.72 => 1,009,072
]

versionConfig = [
Expand Down Expand Up @@ -167,7 +167,7 @@ def configAppDependencies(Project pro) {
// LeakCanary
debugImplementation depConfig.leakcanary.android
releaseImplementation depConfig.leakcanary.android_no_op
// implementation 'com.blankj:utilcode:1.18.4'
// implementation 'com.blankj:utilcode:1.18.5'
}
}

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

Gradle:
```groovy
implementation 'com.blankj:utilcode:1.18.4'
implementation 'com.blankj:utilcode:1.18.5'
```


Expand Down
2 changes: 1 addition & 1 deletion utilcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gradle:
```groovy
implementation 'com.blankj:utilcode:1.18.4'
implementation 'com.blankj:utilcode:1.18.5'
```


Expand Down
52 changes: 4 additions & 48 deletions utilcode/src/main/java/com/blankj/utilcode/util/ConvertUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,18 +580,7 @@ public static Bitmap view2Bitmap(final View view) {
* @return value of px
*/
public static int dp2px(final float dpValue) {
return dp2px(Utils.getApp(), dpValue);
}

/**
* Value of dp to value of px.
*
* @param context The context.
* @param dpValue The value of dp.
* @return value of px
*/
public static int dp2px(@NonNull final Context context, final float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
final float scale = Utils.getApp().getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}

Expand All @@ -602,18 +591,7 @@ public static int dp2px(@NonNull final Context context, final float dpValue) {
* @return value of dp
*/
public static int px2dp(final float pxValue) {
return px2dp(Utils.getApp(), pxValue);
}

/**
* Value of px to value of dp.
*
* @param context The context.
* @param pxValue The value of px.
* @return value of dp
*/
public static int px2dp(@NonNull final Context context, final float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
final float scale = Utils.getApp().getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}

Expand All @@ -624,18 +602,7 @@ public static int px2dp(@NonNull final Context context, final float pxValue) {
* @return value of px
*/
public static int sp2px(final float spValue) {
return sp2px(Utils.getApp(), spValue);
}

/**
* Value of sp to value of px.
*
* @param context The context.
* @param spValue The value of sp.
* @return value of px
*/
public static int sp2px(@NonNull final Context context, final float spValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
final float fontScale = Utils.getApp().getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * fontScale + 0.5f);
}

Expand All @@ -646,18 +613,7 @@ public static int sp2px(@NonNull final Context context, final float spValue) {
* @return value of sp
*/
public static int px2sp(final float pxValue) {
return px2sp(Utils.getApp(), pxValue);
}

/**
* Value of px to value of sp.
*
* @param context The context.
* @param pxValue The value of px.
* @return value of sp
*/
public static int px2sp(@NonNull final Context context, final float pxValue) {
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
final float fontScale = Utils.getApp().getResources().getDisplayMetrics().scaledDensity;
return (int) (pxValue / fontScale + 0.5f);
}

Expand Down
66 changes: 33 additions & 33 deletions utilcode/src/main/java/com/blankj/utilcode/util/ScreenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,53 +297,34 @@ public static boolean isTablet() {
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

private static final UtilDisplayMetrics UDM = new UtilDisplayMetrics();

/**
* Adapt the screen for vertical slide.
*
* @param designWidthInDp The size of design diagram's width, in dp,
* e.g. the design diagram width is 720px, in XHDPI device,
* the designWidthInDp = 720 / 2.
* @param designWidthInPx The size of design diagram's width, in pixel.
*/
public static void adaptScreen4VerticalSlide(final Activity activity,
final float designWidthInDp) {
adaptScreen(activity, designWidthInDp, true);
final int designWidthInPx) {
adaptScreen(activity, designWidthInPx, true);
}

/**
* Adapt the screen for horizontal slide.
*
* @param designHeightInDp The size of design diagram's height, in dp,
* e.g. the design diagram height is 1080px, in XXHDPI device,
* the designHeightInDp = 1080 / 3.
* @param designHeightInPx The size of design diagram's height, in pixel.
*/
public static void adaptScreen4HorizontalSlide(final Activity activity,
final float designHeightInDp) {
adaptScreen(activity, designHeightInDp, false);
final int designHeightInPx) {
adaptScreen(activity, designHeightInPx, false);
}

/**
* Cancel adapt the screen.
*
* @param activity The activity.
*/
public static void cancelAdaptScreen(final Activity activity) {
final DisplayMetrics activityDm = activity.getResources().getDisplayMetrics();
if (UDM.densityDpi != -1) {
activityDm.density = UDM.density;
activityDm.scaledDensity = UDM.scaledDensity;
activityDm.densityDpi = UDM.densityDpi;
} else {
Log.i("ScreenUtils", "U should adapt screen first.");
}
}


/**
* Reference from: https://mp.weixin.qq.com/s/d9QCoBP6kV9VSWvVldVVwA
*/
private static void adaptScreen(final Activity activity,
final float sizeInDp,
final boolean isVerticalSlide) {
public static void adaptScreen(final Activity activity,
final int sizeInPx,
final boolean isVerticalSlide) {
final DisplayMetrics appDm = Utils.getApp().getResources().getDisplayMetrics();
final DisplayMetrics activityDm = activity.getResources().getDisplayMetrics();
if (UDM.densityDpi == -1) {
Expand All @@ -364,9 +345,9 @@ public void onLowMemory() {/**/}
});
}
if (isVerticalSlide) {
activityDm.density = activityDm.widthPixels / sizeInDp;
activityDm.density = activityDm.widthPixels / (float) sizeInPx;
} else {
activityDm.density = activityDm.heightPixels / sizeInDp;
activityDm.density = activityDm.heightPixels / (float) sizeInPx;
}
activityDm.scaledDensity = activityDm.density * (UDM.scaledDensity / UDM.density);
activityDm.densityDpi = (int) (160 * activityDm.density);
Expand All @@ -376,7 +357,26 @@ public void onLowMemory() {/**/}
appDm.densityDpi = activityDm.densityDpi;
}

private static final UtilDisplayMetrics UDM = new UtilDisplayMetrics();
/**
* Cancel adapt the screen.
*
* @param activity The activity.
*/
public static void cancelAdaptScreen(final Activity activity) {
final DisplayMetrics appDm = Utils.getApp().getResources().getDisplayMetrics();
final DisplayMetrics activityDm = activity.getResources().getDisplayMetrics();
if (UDM.densityDpi != -1) {
activityDm.density = UDM.density;
activityDm.scaledDensity = UDM.scaledDensity;
activityDm.densityDpi = UDM.densityDpi;

appDm.density = UDM.density;
appDm.scaledDensity = UDM.scaledDensity;
appDm.densityDpi = UDM.densityDpi;
} else {
Log.i("ScreenUtils", "U should adapt screen first.");
}
}

private static class UtilDisplayMetrics {
float density;
Expand Down
Loading

0 comments on commit 205943d

Please sign in to comment.