use of im.actor.core.entity.content.FastThumb in project actor-platform by actorapp.
the class AndroidMessenger method sendPhoto.
public void sendPhoto(Peer peer, String fullFilePath, String fileName) {
try {
Bitmap bmp = ImageHelper.loadOptimizedHQ(fullFilePath);
if (bmp == null) {
return;
}
Bitmap fastThumb = ImageHelper.scaleFit(bmp, 90, 90);
byte[] fastThumbData = ImageHelper.save(fastThumb);
boolean isGif = fullFilePath.endsWith(".gif");
String resultFileName = getExternalUploadTempFile("image", isGif ? "gif" : "jpg");
if (resultFileName == null) {
return;
}
if (isGif) {
IOUtils.copy(new File(fullFilePath), new File(resultFileName));
sendAnimation(peer, fileName, bmp.getWidth(), bmp.getHeight(), new FastThumb(fastThumb.getWidth(), fastThumb.getHeight(), fastThumbData), resultFileName);
} else {
ImageHelper.save(bmp, resultFileName);
sendPhoto(peer, fileName, bmp.getWidth(), bmp.getHeight(), new FastThumb(fastThumb.getWidth(), fastThumb.getHeight(), fastThumbData), resultFileName);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
use of im.actor.core.entity.content.FastThumb in project actor-platform by actorapp.
the class AndroidMessenger method sendVideo.
public void sendVideo(Peer peer, String fullFilePath, String fileName) {
try {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(fullFilePath);
int duration = (int) (Long.parseLong(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)) / 1000L);
Bitmap img = retriever.getFrameAtTime(0);
int width = img.getWidth();
int height = img.getHeight();
Bitmap smallThumb = ImageHelper.scaleFit(img, 90, 90);
byte[] smallThumbData = ImageHelper.save(smallThumb);
FastThumb thumb = new FastThumb(smallThumb.getWidth(), smallThumb.getHeight(), smallThumbData);
sendVideo(peer, fileName, width, height, duration, thumb, fullFilePath);
} catch (Throwable e) {
e.printStackTrace();
}
}
use of im.actor.core.entity.content.FastThumb in project actor-platform by actorapp.
the class JsMessenger method sendAnimation.
public void sendAnimation(final Peer peer, final JsFile file) {
Log.d(TAG, "Resizing animation");
JsImageResize.resize(file, new JsResizeListener() {
@Override
public void onResized(String thumb, int thumbW, int thumbH, int fullW, int fullH) {
Log.d(TAG, "Animation resized");
int index = thumb.indexOf("base64,");
if (index < 0) {
Log.d(TAG, "Unable to find base64");
return;
}
String rawData = thumb.substring(index + "base64,".length());
byte[] thumbData = Base64Utils.fromBase64(rawData);
String descriptor = fileSystemProvider.registerUploadFile(file);
sendAnimation(peer, file.getName(), fullW, fullH, new FastThumb(thumbW, thumbH, thumbData), descriptor);
}
});
}
use of im.actor.core.entity.content.FastThumb in project actor-platform by actorapp.
the class JsMessenger method sendPhoto.
public void sendPhoto(final Peer peer, final String fileName, final JsBlob blob) {
Log.d(TAG, "Resizing photo");
JsImageResize.resize(blob, new JsResizeListener() {
@Override
public void onResized(String thumb, int thumbW, int thumbH, int fullW, int fullH) {
Log.d(TAG, "Photo resized");
int index = thumb.indexOf("base64,");
if (index < 0) {
Log.d(TAG, "Unable to find base64");
return;
}
String rawData = thumb.substring(index + "base64,".length());
byte[] thumbData = Base64Utils.fromBase64(rawData);
String descriptor = fileSystemProvider.registerUploadFile(blob);
sendPhoto(peer, fileName, fullW, fullH, new FastThumb(thumbW, thumbH, thumbData), descriptor);
}
});
}
use of im.actor.core.entity.content.FastThumb in project actor-platform by actorapp.
the class AndroidMessenger method sendDocument.
public void sendDocument(Peer peer, String fullFilePath, String fileName) {
int dot = fileName.indexOf('.');
String mimeType = null;
if (dot >= 0) {
String ext = fileName.substring(dot + 1);
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
}
if (mimeType == null) {
mimeType = "application/octet-stream";
}
Bitmap fastThumb = ImageHelper.loadOptimizedHQ(fullFilePath);
if (fastThumb != null) {
fastThumb = ImageHelper.scaleFit(fastThumb, 90, 90);
byte[] fastThumbData = ImageHelper.save(fastThumb);
sendDocument(peer, fileName, mimeType, new FastThumb(fastThumb.getWidth(), fastThumb.getHeight(), fastThumbData), fullFilePath);
} else {
sendDocument(peer, fileName, mimeType, fullFilePath);
}
}
Aggregations