Esempio n. 1
0
 public Bitmap getThumbnail(Message message, int size, boolean cacheOnly)
     throws FileNotFoundException {
   final String uuid = message.getUuid();
   final LruCache<String, Bitmap> cache = mXmppConnectionService.getBitmapCache();
   Bitmap thumbnail = cache.get(uuid);
   if ((thumbnail == null) && (!cacheOnly)) {
     synchronized (cache) {
       thumbnail = cache.get(uuid);
       if (thumbnail != null) {
         return thumbnail;
       }
       DownloadableFile file = getFile(message);
       if (file.getMimeType().startsWith("video/")) {
         thumbnail = getVideoPreview(file, size);
       } else {
         Bitmap fullsize = getFullsizeImagePreview(file, size);
         if (fullsize == null) {
           throw new FileNotFoundException();
         }
         thumbnail = resize(fullsize, size);
         thumbnail = rotate(thumbnail, getRotation(file));
       }
       this.mXmppConnectionService.getBitmapCache().put(uuid, thumbnail);
     }
   }
   return thumbnail;
 }
Esempio n. 2
0
 public DownloadableFile getFile(Message message, boolean decrypted) {
   final boolean encrypted =
       !decrypted
           && (message.getEncryption() == Message.ENCRYPTION_PGP
               || message.getEncryption() == Message.ENCRYPTION_DECRYPTED);
   final DownloadableFile file;
   String path = message.getRelativeFilePath();
   if (path == null) {
     String filename =
         fileDateFormat.format(new Date(message.getTimeSent()))
             + "_"
             + message.getUuid().substring(0, 4);
     path = filename;
   }
   if (path.startsWith("/")) {
     file = new DownloadableFile(path);
   } else {
     String mime = message.getMimeType();
     if (mime != null && mime.startsWith("image")) {
       file = new DownloadableFile(getConversationsImageDirectory() + path);
     } else if (mime != null && mime.startsWith("video")) {
       file = new DownloadableFile(getConversationsVideoDirectory() + path);
     } else if (mime != null && mime.startsWith("audio")) {
       file = new DownloadableFile(getConversationsAudioDirectory() + path);
     } else {
       file = new DownloadableFile(getConversationsFileDirectory() + path);
     }
   }
   if (encrypted) {
     return new DownloadableFile(getConversationsFileDirectory() + file.getName() + ".pgp");
   } else {
     return file;
   }
 }
Esempio n. 3
0
 public void updateFileParams(Message message, URL url) {
   DownloadableFile file = getFile(message);
   final String mime = file.getMimeType();
   boolean image =
       message.getType() == Message.TYPE_IMAGE || (mime != null && mime.startsWith("image/"));
   boolean video = mime != null && mime.startsWith("video/");
   if (image || video) {
     try {
       Dimensions dimensions = image ? getImageDimensions(file) : getVideoDimensions(file);
       if (url == null) {
         message.setBody(
             Long.toString(file.getSize()) + '|' + dimensions.width + '|' + dimensions.height);
       } else {
         message.setBody(
             url.toString()
                 + "|"
                 + Long.toString(file.getSize())
                 + '|'
                 + dimensions.width
                 + '|'
                 + dimensions.height);
       }
       return;
     } catch (NotAVideoFile notAVideoFile) {
       Log.d(Config.LOGTAG, "file with mime type " + file.getMimeType() + " was not a video file");
       // fall threw
     }
   }
   if (url != null) {
     message.setBody(url.toString() + "|" + Long.toString(file.getSize()));
   } else {
     message.setBody(Long.toString(file.getSize()));
   }
 }