Esempio n. 1
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()));
   }
 }
Esempio n. 2
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;
 }