Decode/start GIFs on Android 9+

pull/162/head
M66B 5 years ago
parent 0e136e6ef4
commit d67cf4ffa7

@ -55,12 +55,12 @@ For authorizing:
* ~~More compact folder view~~ * ~~More compact folder view~~
* ~~Compose lists and tables~~ (this requires a rich text editor, see [this FAQ](#user-content-faq99)) * ~~Compose lists and tables~~ (this requires a rich text editor, see [this FAQ](#user-content-faq99))
* ~~Pinch zoom text size~~ * ~~Pinch zoom text size~~
* ~~Display GIFs~~
* Send as attachment * Send as attachment
* Themes * Themes
* Search for settings * Search for settings
* Select any day for time conditions * Select any day for time conditions
* Widget for selected account * Widget for selected account
* Display GIFs
Anything on this list is in random order and *might* be added in the near future. Anything on this list is in random order and *might* be added in the near future.

@ -38,6 +38,7 @@ import android.database.Cursor;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.AnimatedImageDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
@ -2515,7 +2516,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Spanned spanned = HtmlHelper.fromHtml(html, new Html.ImageGetter() { Spanned spanned = HtmlHelper.fromHtml(html, new Html.ImageGetter() {
@Override @Override
public Drawable getDrawable(String source) { public Drawable getDrawable(String source) {
return HtmlHelper.decodeImage(context, message.id, source, show_images, tvBody); Drawable drawable = HtmlHelper.decodeImage(context, message.id, source, show_images, tvBody);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable)
((AnimatedImageDrawable) drawable).start();
}
return drawable;
} }
}, null); }, null);
@ -3777,6 +3785,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override @Override
protected void onExecuted(Bundle args, Drawable drawable) { protected void onExecuted(Bundle args, Drawable drawable) {
pv.setImageDrawable(drawable); pv.setImageDrawable(drawable);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable)
((AnimatedImageDrawable) drawable).start();
}
} }
@Override @Override

@ -24,10 +24,12 @@ import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.ImageDecoder;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LevelListDrawable; import android.graphics.drawable.LevelListDrawable;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.text.Html; import android.text.Html;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
@ -412,8 +414,41 @@ public class HtmlHelper {
d.setBounds(0, 0, px, px); d.setBounds(0, 0, px, px);
return d; return d;
} else { } else {
Bitmap bm = Helper.decodeImage(attachment.getFile(context), int scaleToPixels = res.getDisplayMetrics().widthPixels;
res.getDisplayMetrics().widthPixels); if ("image/gif".equals(attachment.type) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ImageDecoder.Source isource = ImageDecoder.createSource(attachment.getFile(context));
Drawable gif;
try {
gif = ImageDecoder.decodeDrawable(isource, new ImageDecoder.OnHeaderDecodedListener() {
@Override
public void onHeaderDecoded(
@NonNull ImageDecoder decoder,
@NonNull ImageDecoder.ImageInfo info,
@NonNull ImageDecoder.Source source) {
int factor = 1;
while (info.getSize().getWidth() / factor > scaleToPixels)
factor *= 2;
decoder.setTargetSampleSize(factor);
}
});
} catch (IOException ex) {
Log.w(ex);
gif = null;
}
if (gif == null) {
Log.i("GIF not decodable CID=" + cid);
Drawable d = res.getDrawable(R.drawable.baseline_broken_image_24, theme);
d.setBounds(0, 0, px, px);
return d;
} else {
if (view != null)
fitDrawable(gif, a, view);
return gif;
}
} else {
Bitmap bm = Helper.decodeImage(attachment.getFile(context), scaleToPixels);
if (bm == null) { if (bm == null) {
Log.i("Image not decodable CID=" + cid); Log.i("Image not decodable CID=" + cid);
Drawable d = res.getDrawable(R.drawable.baseline_broken_image_24, theme); Drawable d = res.getDrawable(R.drawable.baseline_broken_image_24, theme);
@ -429,6 +464,7 @@ public class HtmlHelper {
} }
} }
} }
}
// Data URI // Data URI
if (data && (show || inline)) if (data && (show || inline))

Loading…
Cancel
Save