Skip to content

Commit

Permalink
see 08/10 log
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankj committed Aug 10, 2018
1 parent 15726d6 commit a31510e
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 67 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.6-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.19.0-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.6-brightgreen.svg
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.19.0-brightgreen.svg
[auc]: https://github.com/Blankj/AndroidUtilCode

[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.blankj.androidutilcode.feature.core.CoreUtilActivity;
import com.blankj.androidutilcode.feature.sub.SubUtilActivity;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.ScreenUtils;

/**
* <pre>
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/blankj/androidutilcode/UtilsApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
import com.squareup.leakcanary.LeakCanary;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.view.LayoutInflater;
import android.view.View;

import com.blankj.utilcode.util.ScreenUtils;

/**
* <pre>
* author: Blankj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseActivity;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;

/**
* <pre>
Expand All @@ -36,9 +32,9 @@ public static void start(Context context) {
@Override
public void initData(@Nullable Bundle bundle) {
if (ScreenUtils.isPortrait()) {
ScreenUtils.adaptScreen4VerticalSlide(this, 360);
ScreenUtils.adaptScreen4VerticalSlide(this, 720);
} else {
ScreenUtils.adaptScreen4HorizontalSlide(this, 360);
ScreenUtils.adaptScreen4HorizontalSlide(this, 720);
}
}

Expand Down
8 changes: 4 additions & 4 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,23 +21,23 @@
android:id="@+id/tv_up"
style="@style/TextStyle"
android:layout_width="2000dp"
android:layout_height="180dp"
android:layout_height="360dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/tv_fullscreen"
android:background="@color/colorAccentHalfTrans"
android:gravity="center_vertical"
android:text="180dp" />
android:text="360dp" />

<TextView
android:id="@+id/tv_down"
style="@style/TextStyle"
android:layout_width="2000dp"
android:layout_height="180dp"
android:layout_height="360dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/tv_fullscreen"
android:background="@color/colorPrimaryHalfTrans"
android:gravity="center_vertical"
android:text="180dp" />
android:text="360dp" />


</RelativeLayout>
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res_core/layout-port/activity_screen_adapt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@

<TextView
style="@style/TextStyle"
android:layout_width="180dp"
android:layout_width="360dp"
android:layout_height="2000dp"
android:layout_alignParentLeft="true"
android:layout_below="@id/tv_fullscreen"
android:background="@color/colorAccentHalfTrans"
android:gravity="center_horizontal"
android:text="180dp" />
android:text="360dp" />

<TextView
style="@style/TextStyle"
android:layout_width="180dp"
android:layout_width="360dp"
android:layout_height="2000dp"
android:layout_alignParentRight="true"
android:layout_below="@id/tv_fullscreen"
android:background="@color/colorPrimaryHalfTrans"
android:gravity="center_horizontal"
android:text="180dp" />
android:text="360dp" />

</RelativeLayout>
</ScrollView>
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_006,
versionName : '1.18.6'// E.g 1.9.72 => 1,009,072
versionCode : 1_019_000,
versionName : '1.19.0'// 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.6'
// implementation 'com.blankj:utilcode:1.18.7'
}
}

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/10 修复 ScreenUtils#adaptxx 导致获取状态栏和导航栏尺寸不对问题,发布 1.19.0
* 18/08/09 新增 IntentUtils#isIntentAvailable,ToastUtils 传入空显示 null,发布 1.18.6
* 18/08/08 修复 ScreenUtils#adaptxx 在第三方 SDK 会出现的问题,发布 1.18.5
* 18/08/07 修复 ScreenUtils#adaptxx 在 API 26 以下无效的 bug,发布 1.18.4
Expand Down
3 changes: 2 additions & 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.6'
implementation 'com.blankj:utilcode:1.19.0'
```


Expand Down Expand Up @@ -543,6 +543,7 @@ isTablet : 判断是否是平板
adaptScreen4VerticalSlide : 适配垂直滑动的屏幕
adaptScreen4HorizontalSlide: 适配水平滑动的屏幕
cancelAdaptScreen : 取消适配屏幕
isAdaptScreen : 是否适配屏幕
```

* ### SD 卡相关 -> [SDCardUtils.java][sdcard.java] -> [Demo][sdcard.demo]
Expand Down
3 changes: 2 additions & 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.6'
implementation 'com.blankj:utilcode:1.19.0'
```


Expand Down Expand Up @@ -543,6 +543,7 @@ isTablet
adaptScreen4VerticalSlide
adaptScreen4HorizontalSlide
cancelAdaptScreen
isAdaptScreen
```

* ### About SDCard -> [SDCardUtils.java][sdcard.java] -> [Demo][sdcard.demo]
Expand Down
4 changes: 2 additions & 2 deletions utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private BarUtils() {
* @return the status bar's height
*/
public static int getStatusBarHeight() {
Resources resources = Utils.getApp().getResources();
Resources resources = Resources.getSystem();
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
return resources.getDimensionPixelSize(resourceId);
}
Expand Down Expand Up @@ -595,7 +595,7 @@ private static void invokePanels(final String methodName) {
* @return the navigation bar's height
*/
public static int getNavBarHeight() {
Resources res = Utils.getApp().getResources();
Resources res = Resources.getSystem();
int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId != 0) {
return res.getDimensionPixelSize(resourceId);
Expand Down
60 changes: 21 additions & 39 deletions utilcode/src/main/java/com/blankj/utilcode/util/ScreenUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.app.Activity;
import android.app.KeyguardManager;
import android.content.ComponentCallbacks;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
Expand All @@ -14,7 +13,6 @@
import android.support.annotation.NonNull;
import android.support.annotation.RequiresPermission;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Surface;
import android.view.View;
import android.view.Window;
Expand Down Expand Up @@ -297,8 +295,6 @@ public static boolean isTablet() {
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

private static final UtilDisplayMetrics UDM = new UtilDisplayMetrics();

/**
* Adapt the screen for vertical slide.
*
Expand All @@ -324,34 +320,18 @@ public static void adaptScreen4HorizontalSlide(final Activity activity,
/**
* Reference from: https://mp.weixin.qq.com/s/d9QCoBP6kV9VSWvVldVVwA
*/
public static void adaptScreen(final Activity activity,
final int sizeInPx,
final boolean isVerticalSlide) {
private static void adaptScreen(final Activity activity,
final int sizeInPx,
final boolean isVerticalSlide) {
final DisplayMetrics systemDm = Resources.getSystem().getDisplayMetrics();
final DisplayMetrics appDm = Utils.getApp().getResources().getDisplayMetrics();
final DisplayMetrics activityDm = activity.getResources().getDisplayMetrics();
if (UDM.densityDpi == -1) {
UDM.density = activityDm.density;
UDM.scaledDensity = activityDm.scaledDensity;
UDM.densityDpi = activityDm.densityDpi;
Utils.getApp().registerComponentCallbacks(new ComponentCallbacks() {
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (newConfig != null && newConfig.fontScale > 0) {
UDM.scaledDensity =
Utils.getApp().getResources().getDisplayMetrics().scaledDensity;
}
}

@Override
public void onLowMemory() {/**/}
});
}
if (isVerticalSlide) {
activityDm.density = activityDm.widthPixels / (float) sizeInPx;
} else {
activityDm.density = activityDm.heightPixels / (float) sizeInPx;
}
activityDm.scaledDensity = activityDm.density * (UDM.scaledDensity / UDM.density);
activityDm.scaledDensity = activityDm.density * (systemDm.scaledDensity / systemDm.density);
activityDm.densityDpi = (int) (160 * activityDm.density);

appDm.density = activityDm.density;
Expand All @@ -365,24 +345,26 @@ public void onLowMemory() {/**/}
* @param activity The activity.
*/
public static void cancelAdaptScreen(final Activity activity) {
final DisplayMetrics systemDm = Resources.getSystem().getDisplayMetrics();
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;
activityDm.density = systemDm.density;
activityDm.scaledDensity = systemDm.scaledDensity;
activityDm.densityDpi = systemDm.densityDpi;

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

private static class UtilDisplayMetrics {
float density;
float scaledDensity;
int densityDpi = -1;
/**
* Return whether adapt screen.
*
* @return {@code true}: yes<br>{@code false}: no
*/
public static boolean isAdaptScreen() {
final DisplayMetrics systemDm = Resources.getSystem().getDisplayMetrics();
final DisplayMetrics appDm = Utils.getApp().getResources().getDisplayMetrics();
return systemDm.density != appDm.density;
}
}

0 comments on commit a31510e

Please sign in to comment.