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"; }
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); } }
public static String getFileEPubPath(Issue issue) { String jsonData = readFile(getConfigPath(issue)); try { JSONObject jobj = new JSONObject(jsonData); JSONObject detail = jobj.getJSONObject("detail"); if (detail.getString("content_type").equals("epub")) { JSONArray pages = jobj.getJSONArray("pages"); JSONObject page = pages.getJSONObject(0); String path = page.getString("link"); String lastPath = path.substring(path.lastIndexOf('/') + 1); String filePath = Helper.getBookDirectory() + "/" + issue.path + "/" + lastPath; return filePath; } } catch (JSONException e) { e.printStackTrace(); return null; } return null; }