/** * Create a placemark containing the information of the picture. If the picture file does not * already exist, copy it from the original picture, and update the picture's data members. * * @param albumFile * @param picture * @return the new placemark */ public static Placemark createPlacemark( File albumFile, Picture picture, ThumbManager thumbManager) { Placemark placemark = null; boolean fileExists = true; long imageId = picture.getId(); if (!new File(albumFile, imageId + Constants.JPG).exists()) { // The image does not already exist in the album, // so retrieve it, and copy it. fileExists = false; File srcFile = null; // 1. Try to retrieve it from its mini path. String miniPath = picture.getMiniPath(); if (miniPath != null) { final File thumbFile = new File(miniPath); if (thumbFile.exists()) { srcFile = thumbFile; fileExists = true; } } // 2. Try to retrieve it from the ThumbManager if (!fileExists) { Bitmap bitmap = thumbManager.getMiniBitmap(picture); if (bitmap != null) { miniPath = picture.getMiniPath(); final File thumbFile = new File(miniPath); if (thumbFile.exists()) { srcFile = thumbFile; fileExists = true; } bitmap.recycle(); bitmap = null; } } if (srcFile != null && fileExists) { imageId = FileUtils.generateId(); final File dstFile = new File(albumFile, imageId + Constants.JPG); try { FileUtils.copy(srcFile, dstFile); // Update picture instance with new values picture.setLocal(true); picture.setId(imageId); picture.setFullPath(null); picture.setMiniPath(dstFile.getAbsolutePath()); picture.setMicroPath(null); } catch (IOException e) { fileExists = false; } } } if (fileExists) { // Set group id on picture if (albumFile != null) { picture.setGroupId(Long.valueOf(albumFile.getName())); } // Create Placemark placemark = new Placemark(); final String path = String.valueOf(imageId) + Constants.JPG; placemark.setName(path); placemark.setDescription(toHTML(path, picture.getDescription())); placemark.addTimeStamp(toTimeStamp(picture.getDate())); // - Add Point final Point point = new Point(); point.setCoordinates(toCoordinates(picture.getLatitude(), picture.getLongitude())); placemark.addPoint(point); } return placemark; }