Added setting to disable image animation

pull/214/head
M66B 10 months ago
parent a041d57814
commit b38fe9e4ff

@ -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();

@ -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);

@ -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));

@ -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);

@ -1568,6 +1568,17 @@
app:layout_constraintTop_toBottomOf="@id/etNativeArcWhitelist"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAnimate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_animate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swWebp"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swEasyCorrect"
android:layout_width="0dp"
@ -1576,7 +1587,7 @@
android:text="@string/title_advanced_easy_correct"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swWebp"
app:layout_constraintTop_toBottomOf="@id/swAnimate"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

@ -918,6 +918,7 @@
<string name="title_advanced_native_dkim" translatable="false">Native DKIM verification</string>
<string name="title_advanced_native_arc" translatable="false">Native ARC verification</string>
<string name="title_advanced_webp" translatable="false">WebP</string>
<string name="title_advanced_animate" translatable="false">Animate images (GIF, etc.)</string>
<string name="title_advanced_easy_correct" translatable="false">Easy correct</string>
<string name="title_advanced_infra" translatable="false">Show infrastructure</string>
<string name="title_advanced_tld_flags" translatable="false">Show TLD flags</string>

Loading…
Cancel
Save