content: package com.lzy.imagepicker;
  
  import android.app.Activity;
  import android.content.Context;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.graphics.Matrix;
  import android.os.Environment;
  import android.util.DisplayMetrics;
  
  import java.io.File;
  import java.io.FileOutputStream;
  import java.util.Random;
  
  /**
   * ================================================
   * 作    者：jeasonlzy（廖子尧 Github地址：https://github.com/jeasonlzy0216
   * 版    本：1.0
   * 创建日期：2016/5/19
   * 描    述：
   * 修订历史：
   * ================================================
   */
  public class Utils {
  
      /** 获得状态栏的高度 */
      public static int getStatusHeight(Context context) {
          int statusHeight = -1;
          try {
              Class<?> clazz = Class.forName("com.android.internal.R$dimen");
              Object object = clazz.newInstance();
              int height = Integer.parseInt(clazz.getField("status_bar_height").get(object).toString());
              statusHeight = context.getResources().getDimensionPixelSize(height);
          } catch (Exception e) {
              e.printStackTrace();
          }
          return statusHeight;
      }
  
      /** 根据屏幕宽度与密度计算GridView显示的列数， 最少为三列，并获取Item宽度 */
      public static int getImageItemWidth(Activity activity) {
          int screenWidth = activity.getResources().getDisplayMetrics().widthPixels;
          int densityDpi = activity.getResources().getDisplayMetrics().densityDpi;
          int cols = screenWidth / densityDpi;
          cols = cols < 3 ? 3 : cols;
          int columnSpace = (int) (2 * activity.getResources().getDisplayMetrics().density);
          return (screenWidth - columnSpace * (cols - 1)) / cols;
      }
  
      /**
       * 判断SDCard是否可用
       */
      public static boolean existSDCard() {
          return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
      }
  
      /**
       * 获取手机大小（分辨率）
       */
      public static DisplayMetrics getScreenPix(Activity activity) {
          DisplayMetrics displaysMetrics = new DisplayMetrics();
          activity.getWindowManager().getDefaultDisplay().getMetrics(displaysMetrics);
          return displaysMetrics;
      }
  }
  