content: package cn.settile.fanboxviewer.Util;
  
  import android.annotation.SuppressLint;
  import android.content.Context;
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.graphics.Canvas;
  import android.graphics.drawable.Drawable;
  import android.net.Uri;
  import android.os.Environment;
  
  import org.json.JSONArray;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.List;
  
  import cn.settile.fanboxviewer.App;
  
  public class Util {
      public static List<Object> toList(JSONArray array) throws Exception{
          List<Object> result = new ArrayList<>();
          for (int i = 0; i < array.length(); i++)
              result.add(array.get(i));
          return result;
      }
  
      public static Bitmap toBitmap(Drawable drawable){
          try {
              Bitmap bitmap;
  
              bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
  
              Canvas canvas = new Canvas(bitmap);
              drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
              drawable.draw(canvas);
              return bitmap;
          } catch (OutOfMemoryError e) {
              return null;
          }
      }
  
      @SuppressLint("DefaultLocale")
      public static String sizeToString(long bytes) {
          String s = bytes < 0 ? "-" : "";
          long b = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes);
          return b < 1000L ? bytes + " B"
                  : b < 999_950L ? String.format("%s%.1f kB", s, b / 1e3)
                  : (b /= 1000) < 999_950L ? String.format("%s%.1f MB", s, b / 1e3)
                  : (b /= 1000) < 999_950L ? String.format("%s%.1f GB", s, b / 1e3)
                  : (b /= 1000) < 999_950L ? String.format("%s%.1f TB", s, b / 1e3)
                  : (b /= 1000) < 999_950L ? String.format("%s%.1f PB", s, b / 1e3)
                  : String.format("%s%.1f EB", s, b / 1e6);
      }
  
      public static File createImageFile(String name) throws Exception{
          File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
          return new File(storageDir, name);
      }
  
      public static void galleryAddPic(String imagePath) {
          Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
          File f = new File(imagePath);
          Uri contentUri = Uri.fromFile(f);
          mediaScanIntent.setData(contentUri);
          App.getContext().sendBroadcast(mediaScanIntent);
      }
  }
  