Add WebP library for API 16.

This commit is contained in:
akwizgran
2021-05-24 15:09:19 +01:00
parent b4a2725f03
commit 7345d5c22c
3 changed files with 12 additions and 1 deletions

View File

@@ -121,6 +121,7 @@ dependencies {
exclude group: 'com.android.support'
exclude module: 'disklrucache' // when there's no disk cache, we can't accidentally use it
}
implementation "com.github.zjupure:webpdecoder:2.0.$glideVersion"
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"

View File

@@ -3,6 +3,8 @@ package org.briarproject.briar.android.attachment.media;
import android.graphics.BitmapFactory;
import android.webkit.MimeTypeMap;
import com.bumptech.glide.integration.webp.WebpBitmapFactory;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.io.InputStream;
@@ -25,6 +27,10 @@ class ImageHelperImpl implements ImageHelper {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
if (options.outWidth < 1 || options.outHeight < 1) {
// BitmapFactory doesn't fully support WebP on API < 17
WebpBitmapFactory.decodeStream(is, null, options);
}
String mimeType = options.outMimeType;
if (mimeType == null) mimeType = "";
return new DecodeResult(options.outWidth, options.outHeight,

View File

@@ -4,6 +4,8 @@ import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.integration.webp.decoder.WebpDrawable;
import com.bumptech.glide.integration.webp.decoder.WebpDrawableTransformation;
import com.bumptech.glide.load.Transformation;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@@ -80,7 +82,9 @@ class ImageViewHolder extends ViewHolder {
.load(a.getHeader())
.diskCacheStrategy(NONE)
.error(ERROR_RES)
.transform(transformation)
.optionalTransform(transformation)
.optionalTransform(WebpDrawable.class,
new WebpDrawableTransformation(transformation))
.transition(withCrossFade())
.into(imageView)
.waitForLayout();