Search in sources :

Example 1 with FastThumb

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();
    }
}
Also used : Bitmap(android.graphics.Bitmap) File(java.io.File) FastThumb(im.actor.core.entity.content.FastThumb)

Example 2 with FastThumb

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();
    }
}
Also used : Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever) FastThumb(im.actor.core.entity.content.FastThumb)

Example 3 with FastThumb

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);
        }
    });
}
Also used : JsResizeListener(im.actor.core.js.images.JsResizeListener) FastThumb(im.actor.core.entity.content.FastThumb)

Example 4 with FastThumb

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);
        }
    });
}
Also used : JsResizeListener(im.actor.core.js.images.JsResizeListener) FastThumb(im.actor.core.entity.content.FastThumb)

Example 5 with FastThumb

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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) FastThumb(im.actor.core.entity.content.FastThumb)

Aggregations

FastThumb (im.actor.core.entity.content.FastThumb)6 Bitmap (android.graphics.Bitmap)4 JsResizeListener (im.actor.core.js.images.JsResizeListener)2 MediaMetadataRetriever (android.media.MediaMetadataRetriever)1 ImageHelper (im.actor.core.utils.ImageHelper)1 File (java.io.File)1