content: package com.android.androidsidebar;
  
  import android.app.Activity;
  import android.content.Context;
  import android.graphics.Color;
  import android.graphics.Point;
  import android.os.Build;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.view.Display;
  import android.view.View;
  import android.view.Window;
  import android.view.WindowManager;
  
  /**
   * ================================================
   * 项    目：AndroidSidebar
   * 作    者：zj
   * 版    本：1.0
   * 创建日期：2019/5/09
   * 描    述：屏幕工具
   * 修订历史：
   * ================================================
   */
  public class ScreenInfoUtils {
      /**
       * 通过设置全屏，设置状态栏透明
       *
       * @param activity 上下文
       */
      public static void fullScreen(Activity activity) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
              if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                  //5.x开始需要把颜色设置透明，否则导航栏会呈现系统默认的浅灰色
                  Window window = activity.getWindow();
                  View decorView = window.getDecorView();
                  //两个 flag 要结合使用，表示让应用的主体内容占用系统状态栏的空间
                  int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                          | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
                  decorView.setSystemUiVisibility(option);
                  window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                  window.setStatusBarColor(Color.TRANSPARENT);
                  //导航栏颜色也可以正常设置
  //                window.setNavigationBarColor(Color.TRANSPARENT);
              } else {
                  Window window = activity.getWindow();
                  WindowManager.LayoutParams attributes = window.getAttributes();
                  int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
                  int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
                  attributes.flags |= flagTranslucentStatus;
  //                attributes.flags |= flagTranslucentNavigation;
                  window.setAttributes(attributes);
              }
          }
      }
  
      /**
       * 获取状态栏高度
       *
       * @param context 上下文
       * @return 100
       */
      public static int getStatusBarHeight(Context context) {
          int result = 0;
          int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
          if (resourceId > 0) {
              result = context.getResources().getDimensionPixelSize(resourceId);
          }
          return result;
      }
  
      /**
       * 获取屏幕宽度
       *
       * @param activity 上下文
       * @return 100
       */
      public static int getWindowWidth(Activity activity) {
          return activity.getWindowManager().getDefaultDisplay().getWidth();
      }
  
      /**
       * 获取屏幕高度(全面屏手机获取高度有问题)
       *
       * @param activity 上下文
       * @return 100
       */
      public static int getWindowHeight(Activity activity) {
          return activity.getWindowManager().getDefaultDisplay().getHeight();
      }
  
      /**
       * 获取屏幕高度(全面屏手机获取高度有问题)
       *
       * @param activity 上下文
       * @return 100
       */
      public static int getFullActivityHeight(@Nullable Context context) {
          if (!isAllScreenDevice(context)) {
              return getScreenHeight(context);
          }
          return getScreenRealHeight(context);
      }
  
      @NonNull
      private volatile static Point[] mRealSizes = new Point[2];
  
      public static int getScreenRealHeight(@Nullable Context context) {
          if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
              return getScreenHeight(context);
          }
  
          int orientation = context.getResources().getConfiguration().orientation;
  
          if (mRealSizes[orientation] == null) {
              WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
              if (windowManager == null) {
                  return getScreenHeight(context);
              }
              Display display = windowManager.getDefaultDisplay();
              Point point = new Point();
              display.getRealSize(point);
              mRealSizes[orientation] = point;
          }
          return mRealSizes[orientation].y;
      }
  
      public static int getScreenHeight(@Nullable Context context) {
          if (context != null) {
              return context.getResources().getDisplayMetrics().heightPixels;
          }
          return 0;
      }
  
      private volatile static boolean mHasCheckAllScreen;
      private volatile static boolean mIsAllScreenDevice;
  
      public static boolean isAllScreenDevice(Context context) {
          if (mHasCheckAllScreen) {
              return mIsAllScreenDevice;
          }
          mHasCheckAllScreen = true;
          mIsAllScreenDevice = false;
          // 低于 API 21的，都不会是全面屏。。。
          if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
              return false;
          }
          WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
          if (windowManager != null) {
              Display display = windowManager.getDefaultDisplay();
              Point point = new Point();
              display.getRealSize(point);
              float width, height;
              if (point.x < point.y) {
                  width = point.x;
                  height = point.y;
              } else {
                  width = point.y;
                  height = point.x;
              }
              if (height / width >= 1.97f) {
                  mIsAllScreenDevice = true;
              }
          }
          return mIsAllScreenDevice;
      }
  }
  