content: package cn.jack.suspensionwindow.util;
  
  import android.content.Context;
  import android.util.DisplayMetrics;
  import android.util.TypedValue;
  import android.view.WindowManager;
  
  import cn.jack.suspensionwindow.App;
  
  /**
   * Created by manji
   * Date：2018/9/30 下午5:56
   * Desc：
   */
  public class DisplayUtil {
  
  
      public static int getScreenWidth(Context context) {
          WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
          DisplayMetrics outMetrics = new DisplayMetrics();
          if (wm != null) {
              wm.getDefaultDisplay().getMetrics(outMetrics);
          }
          return outMetrics.widthPixels;
      }
  
      public static int getScreenHeight(Context context) {
          WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
          DisplayMetrics outMetrics = new DisplayMetrics();
          if (wm != null) {
              wm.getDefaultDisplay().getMetrics(outMetrics);
          }
          return outMetrics.heightPixels;
      }
  
      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().getDimensionPixelOffset(resourceId);
          }
          return result;
      }
  
      public static int getRealHeight(Context context) {
          return getScreenHeight(context) - getStatusBarHeight(context);
      }
  
      public static int dip2px(float dip) {
          return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, App.getInstance().getResources().getDisplayMetrics());
      }
  
  }