Skip to content

Commit

Permalink
💄 Compatible with the height of MIX 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Flyge committed Oct 8, 2017
1 parent f71b13e commit 372505c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ class ImageDetailActivity : BaseActivity(), PageBackgApplyCallback {
contentView.paddingRight, contentView.paddingBottom)
}

// + DeviceUtils.getNavigationBarHeightByUiVisibility(this) 是为了兼容 MIX 2
backgroundImageView.layoutParams?.let {
it.width = resources.displayMetrics.widthPixels
it.height = resources.displayMetrics.heightPixels
it.height = resources.displayMetrics.heightPixels + DeviceUtils.getWindowHeightSupplement(this)
backgroundImageView.layoutParams = it
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ class MainActivity : BaseActivity(), AppListFragment.GetAppListTagStripListener,
}

private fun initViews() {
// + DeviceUtils.getNavigationBarHeightByUiVisibility(this) 是为了兼容 MIX 2
backgroundImageView.layoutParams?.let {
it.width = resources.displayMetrics.widthPixels
it.height = resources.displayMetrics.heightPixels
it.height = resources.displayMetrics.heightPixels + DeviceUtils.getWindowHeightSupplement(this)
backgroundImageView.layoutParams = it
}

backgroundImageView.setOptions(ImageOptions.WINDOW_BACKGROUND)

// + DeviceUtils.getNavigationBarHeightByUiVisibility(this) 是为了兼容 MIX 2
menuBackgroundImageView.layoutParams?.let {
it.width = resources.displayMetrics.widthPixels
it.height = resources.displayMetrics.heightPixels
it.height = resources.displayMetrics.heightPixels + DeviceUtils.getWindowHeightSupplement(this)
menuBackgroundImageView.layoutParams = it
}

Expand Down
54 changes: 54 additions & 0 deletions sample/src/main/java/me/xiaopan/sketchsample/util/DeviceUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package me.xiaopan.sketchsample.util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.util.Log;
import android.view.View;

public class DeviceUtils {
private static final String ATTR_NAME_STATUS_BAR_HEIGHT = "status_bar_height";
Expand Down Expand Up @@ -31,4 +36,53 @@ private static int getInternalDimensionSize(Resources res, String key) {
return result;
}

@SuppressLint("LongLogTag")
public static int getWindowHeightSupplement(Activity activity) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
int uiVisibility = activity.getWindow().getDecorView().getSystemUiVisibility();
int navigationBarHeight = getNavigationBarHeight(activity.getResources());

String uiVisibilityName = null;
switch (uiVisibility) {
case View.SYSTEM_UI_FLAG_FULLSCREEN:
uiVisibilityName = "SYSTEM_UI_FLAG_FULLSCREEN";
break;
case View.SYSTEM_UI_FLAG_HIDE_NAVIGATION:
uiVisibilityName = "SYSTEM_UI_FLAG_HIDE_NAVIGATION";
break;
case View.SYSTEM_UI_FLAG_IMMERSIVE:
uiVisibilityName = "SYSTEM_UI_FLAG_IMMERSIVE";
break;
case View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY:
uiVisibilityName = "SYSTEM_UI_FLAG_IMMERSIVE_STICKY";
break;
case View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN:
uiVisibilityName = "SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN";
break;
case View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION:
uiVisibilityName = "SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION";
break;
case View.SYSTEM_UI_FLAG_LAYOUT_STABLE:
uiVisibilityName = "SYSTEM_UI_FLAG_LAYOUT_STABLE";
break;
case View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR:
uiVisibilityName = "SYSTEM_UI_FLAG_LIGHT_STATUS_BAR";
break;
case View.SYSTEM_UI_FLAG_LOW_PROFILE:
uiVisibilityName = "SYSTEM_UI_FLAG_LOW_PROFILE";
break;
case View.SYSTEM_UI_FLAG_VISIBLE:
uiVisibilityName = "SYSTEM_UI_FLAG_VISIBLE";
break;
}

Log.d("getWindowHeightSupplement", Build.BRAND + " " + Build.MODEL + ". uiVisibilityName: " + uiVisibilityName + ", navigationBarHeight: " + navigationBarHeight);

if (uiVisibility == View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) {
return navigationBarHeight;
}
}
return 0;
}

}

0 comments on commit 372505c

Please sign in to comment.