content: package cn.szx.simplescanner.base;
  
  import android.content.Context;
  import android.content.res.Configuration;
  import android.graphics.Point;
  import android.view.Display;
  import android.view.WindowManager;
  
  public class DisplayUtils {
      /**
       * 获取屏幕宽高
       */
      public static Point getScreenResolution(Context context) {
          WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
          Display display = wm.getDefaultDisplay();
          Point screenResolution = new Point();
          if (android.os.Build.VERSION.SDK_INT >= 13) {
              display.getSize(screenResolution);
          } else {
              screenResolution.set(display.getWidth(), display.getHeight());
          }
  
          return screenResolution;
      }
  
      /**
       * 根据屏幕宽和高谁大，来判断是横屏还是竖屏
       */
      public static int getScreenOrientation(Context context) {
          WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
          Display display = wm.getDefaultDisplay();
  
          int orientation = Configuration.ORIENTATION_UNDEFINED;
          if (display.getWidth() == display.getHeight()) {
              orientation = Configuration.ORIENTATION_SQUARE;
          } else {
              if (display.getWidth() < display.getHeight()) {
                  orientation = Configuration.ORIENTATION_PORTRAIT;
              } else {
                  orientation = Configuration.ORIENTATION_LANDSCAPE;
              }
          }
          return orientation;
      }
  }