Skip to content

Commit

Permalink
bugfix: essential phone getRealScreenHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed Jul 13, 2018
1 parent 992eb4d commit 1ea6b77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 8 additions & 3 deletions qmui/src/main/java/com/qmuiteam/qmui/util/QMUIDisplayHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public static int getScreenHeight(Context context) {
*/

public static int[] getRealScreenSize(Context context) {
if(QMUIDeviceHelper.isEssentialPhone() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
// Essential Phone 8.0版本后,Display size 会根据挖孔屏的设置而得到不同的结果,不能信任 cache
return doGetRealScreenSize(context);
}
int orientation = context.getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_LANDSCAPE){
if(sLandscapeRealSizeCache == null){
Expand Down Expand Up @@ -171,11 +175,11 @@ public static int getUsefulScreenWidth(Context context){
int orientation = context.getResources().getConfiguration().orientation;
boolean isLandscape = orientation == Configuration.ORIENTATION_LANDSCAPE;
if(!QMUINotchHelper.hasNotch(context)){
if(isLandscape && QMUIDeviceHelper.isEssentialPhone()){
if(isLandscape && QMUIDeviceHelper.isEssentialPhone()
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
// https://arstechnica.com/gadgets/2017/09/essential-phone-review-impressive-for-a-new-company-but-not-competitive/
// 这里说挖孔屏是状态栏高度的两倍, 但横屏好像小了一点点
result -= 2 * QMUIStatusBarHelper.getStatusbarHeight(context);
return result;
}
return result;
}
Expand Down Expand Up @@ -207,7 +211,8 @@ public static int getUsefulScreenHeight(Context context){
int orientation = context.getResources().getConfiguration().orientation;
boolean isPortrait = orientation == Configuration.ORIENTATION_PORTRAIT;
if(!QMUINotchHelper.hasNotch(context)){
if(isPortrait && QMUIDeviceHelper.isEssentialPhone()){
if(isPortrait && QMUIDeviceHelper.isEssentialPhone()
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
// https://arstechnica.com/gadgets/2017/09/essential-phone-review-impressive-for-a-new-company-but-not-competitive/
// 这里说挖孔屏是状态栏高度的两倍
result -= 2 * QMUIStatusBarHelper.getStatusbarHeight(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
Expand All @@ -29,6 +30,7 @@

@Widget(group = Group.Helper, name = "QMUINotchHelper", iconRes = R.mipmap.icon_grid_span)
public class QDNotchHelperFragment extends BaseFragment {
private static final String TAG = "QDNotchHelperFragment";
@BindView(R.id.not_safe_bg) FrameLayout mNoSafeBgLayout;
@BindView(R.id.safe_area_tv) TextView mSafeAreaTv;
@BindView(R.id.topbar) QMUITopBarLayout mTopBar;
Expand Down Expand Up @@ -56,6 +58,18 @@ protected View onCreateView() {
QMUINotchHelper.getSafeInsetRight(getContext()),
QMUINotchHelper.getSafeInsetBottom(getContext())
);
mNoSafeBgLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
int height = bottom - top;
int width = right - left;
int screenUsefulWidth = QMUIDisplayHelper.getUsefulScreenWidth(getContext());
int screenUsefulHeight = QMUIDisplayHelper.getUsefulScreenHeight(getContext());
Log.i(TAG, "width = " + width + "; height = " + height +
"; screenUsefulWidth = " + screenUsefulWidth +
"; screenUsefulHeight = " + screenUsefulHeight);
}
});
return layout;
}

Expand Down

0 comments on commit 1ea6b77

Please sign in to comment.