Added setting to disable image animation

This commit is contained in:
M66B
2023-11-12 12:08:15 +01:00
parent a041d57814
commit b38fe9e4ff
6 changed files with 46 additions and 21 deletions

View File

@@ -25,7 +25,6 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.AnimatedImageDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.pdf.PdfRenderer;
@@ -185,9 +184,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
else
ivImage.setImageDrawable(image);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P &&
image instanceof AnimatedImageDrawable)
((AnimatedImageDrawable) image).start();
ImageHelper.animate(context, image);
StringBuilder sb = new StringBuilder();

View File

@@ -45,7 +45,6 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.AnimatedImageDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.text.LineBreaker;
import android.net.Uri;
@@ -3253,15 +3252,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
SpannableStringBuilder ssb = HtmlHelper.fromDocument(context, document, new HtmlHelper.ImageGetterEx() {
@Override
public Drawable getDrawable(Element element) {
Drawable drawable = ImageHelper.decodeImage(context,
return ImageHelper.decodeImage(context,
message.id, element, show_images, zoom, scale, tvBody);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (drawable instanceof AnimatedImageDrawable)
((AnimatedImageDrawable) drawable).start();
}
return drawable;
}
}, null);

View File

@@ -213,6 +213,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swNativeArc;
private EditText etNativeArcWhitelist;
private SwitchCompat swWebp;
private SwitchCompat swAnimate;
private SwitchCompat swEasyCorrect;
private SwitchCompat swInfra;
private SwitchCompat swTldFlags;
@@ -282,7 +283,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"max_backoff_power", "logarithmic_backoff",
"exact_alarms",
"native_dkim", "native_arc", "native_arc_whitelist",
"webp", "easy_correct", "infra", "tld_flags", "dup_msgids", "thread_byref", "mdn",
"webp", "animate_images",
"easy_correct", "infra", "tld_flags", "dup_msgids", "thread_byref", "mdn",
"app_chooser", "app_chooser_share", "adjacent_links", "adjacent_documents", "adjacent_portrait", "adjacent_landscape",
"delete_confirmation", "global_keywords", "test_iab"
};
@@ -447,6 +449,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swNativeArc = view.findViewById(R.id.swNativeArc);
etNativeArcWhitelist = view.findViewById(R.id.etNativeArcWhitelist);
swWebp = view.findViewById(R.id.swWebp);
swAnimate = view.findViewById(R.id.swAnimate);
swEasyCorrect = view.findViewById(R.id.swEasyCorrect);
swInfra = view.findViewById(R.id.swInfra);
swTldFlags = view.findViewById(R.id.swTldFlags);
@@ -1530,6 +1533,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swAnimate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("animate_images", checked).apply();
}
});
swEasyCorrect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -2351,6 +2361,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
etNativeArcWhitelist.setEnabled(swNativeDkim.isEnabled() && swNativeDkim.isChecked());
etNativeArcWhitelist.setText(prefs.getString("native_arc_whitelist", null));
swWebp.setChecked(prefs.getBoolean("webp", true));
swAnimate.setChecked(prefs.getBoolean("animate_images", true));
swEasyCorrect.setChecked(prefs.getBoolean("easy_correct", false));
swInfra.setChecked(prefs.getBoolean("infra", false));
swTldFlags.setChecked(prefs.getBoolean("tld_flags", false));

View File

@@ -302,7 +302,8 @@ class ImageHelper {
}
static Drawable decodeImage(final Context context, final long id, String source, boolean show, int zoom, final float scale, final TextView view) {
return decodeImage(context, id, source, 0, 0, false, show, zoom, scale, view);
Drawable d = decodeImage(context, id, source, 0, 0, false, show, zoom, scale, view);
return animate(context, d);
}
static Drawable decodeImage(final Context context, final long id, Element img, boolean show, int zoom, final float scale, final TextView view) {
@@ -310,7 +311,8 @@ class ImageHelper {
Integer w = Helper.parseInt(img.attr("width"));
Integer h = Helper.parseInt(img.attr("height"));
boolean tracking = !TextUtils.isEmpty(img.attr("x-tracking"));
return decodeImage(context, id, source, w == null ? 0 : w, h == null ? 0 : h, tracking, show, zoom, scale, view);
Drawable d = decodeImage(context, id, source, w == null ? 0 : w, h == null ? 0 : h, tracking, show, zoom, scale, view);
return animate(context, d);
}
private static Drawable decodeImage(final Context context, final long id,
@@ -528,10 +530,7 @@ class ImageHelper {
lld.setBounds(0, 0, bounds.width(), bounds.height());
lld.setLevel(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (d instanceof AnimatedImageDrawable)
((AnimatedImageDrawable) d).start();
}
animate(context, d);
view.setText(view.getText());
@@ -869,6 +868,20 @@ class ImageHelper {
return bm;
}
static Drawable animate(Context context, Drawable drawable) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
return drawable;
if (drawable instanceof AnimatedImageDrawable) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean animate_images = prefs.getBoolean("animate_images", true);
if (animate_images)
((AnimatedImageDrawable) drawable).start();
}
return drawable;
}
static Matrix getImageRotation(File file) {
try {
ExifInterface exif = new ExifInterface(file);