Пример #1
0
 public static String getConfigPath(Issue issue) {
   String savePath = Helper.getBookDirectory() + "/" + issue.path; // issue.path = folder name
   if (!Helper.fileExits(savePath)) {
     Helper.createDirectory(savePath);
   }
   return savePath + "/" + issue.path + ".json";
 }
Пример #2
0
  public static void createThumbnail(String filePath, String folderName) {
    FileInputStream epubInputStream = null;
    BufferedOutputStream bos = null;
    try {
      epubInputStream = new FileInputStream(new File(filePath));
      String lastPath = filePath.substring(filePath.lastIndexOf('/') + 1);
      String savePath = getThumbnailDirectory(folderName) + "/" + lastPath;

      if (!Helper.fileExits(savePath)) {
        byte[] cis = FileEncrypt.decrypt_data(epubInputStream);
        if (cis == null) return;

        FileOutputStream outputStream = new FileOutputStream(new File(savePath));
        bos = new BufferedOutputStream(outputStream);
        bos.write(cis, 0, cis.length);
        bos.flush();
        bos.close();

        byte[] imageData = null;

        // PDFView pdfView = new PDFView(getApplicationContext(),null);

        Bitmap imageBitmap = decodeFile(new File(savePath));

        int targetWidth = 150;

        double aspectRatio = (double) imageBitmap.getHeight() / (double) imageBitmap.getWidth();
        int targetHeight = (int) (targetWidth * aspectRatio);

        // imageBitmap = Bitmap.createScaledBitmap(imageBitmap,(int)(imageBitmap.getWidth()*0.4),
        // (int)(imageBitmap.getHeight()*0.4), true);
        imageBitmap = Bitmap.createScaledBitmap(imageBitmap, targetWidth, targetHeight, true);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        imageBitmap.compress(Bitmap.CompressFormat.JPEG, 90, baos);
        imageData = baos.toByteArray();

        outputStream = new FileOutputStream(new File(savePath));
        bos = new BufferedOutputStream(outputStream);
        bos.write(imageData, 0, imageData.length);
        bos.flush();
        bos.close();

        Thread.sleep(10);
      }
      // InputStream is = new ByteArrayInputStream(cis);
      // imageView.setImageBitmap(decodeFile(new File(savePath)));
    } catch (OutOfMemoryError e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
      // imageView.setImageResource(R.drawable.no_image_detail);
    }
  }