From aac2f07531e6f1e41c7226fbfcda9ee083da2eec Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 17 Apr 2019 12:54:46 +0200 Subject: [PATCH] Added option to set target image size --- FAQ.md | 4 +- .../eu/faircode/email/FragmentCompose.java | 12 +++--- .../eu/faircode/email/FragmentOptions.java | 41 +++++++++++++++---- app/src/main/res/layout/fragment_options.xml | 21 +++++++++- app/src/main/res/values/strings.xml | 37 +++++++++++------ 5 files changed, 86 insertions(+), 29 deletions(-) diff --git a/FAQ.md b/FAQ.md index 1ee74d227b..7f7b64334c 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1121,9 +1121,9 @@ If your provider requires an unsupported authentication method, you'll likely ge Large inline or attached [PNG](https://en.wikipedia.org/wiki/Portable_Network_Graphics) and [JPEG](https://en.wikipedia.org/wiki/JPEG) images will automatically be resized for displaying on screens. This is because email messages are limited in size, depending on the provider mostly between 10 and 50 MB. -Image will be resized to a maximum width and height of about 1440 pixels and saved with a compression ratio of 90 %. +Image will by default be resized to a maximum width and height of about 1440 pixels and saved with a compression ratio of 90 %. Images are scaled down using whole number factors to reduce memory usage and to retain image quality. -There is an advanced option to disable automatically resizing of image attachments. Inline (embedded) images will always be resized. +There is an advanced option to disable automatically resizing and to set the target image size.
diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 9dcc78b52b..deba15f85e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -182,8 +182,8 @@ public class FragmentCompose extends FragmentBase { private boolean encrypt = false; private OpenPgpServiceConnection pgpService; - private static final int REDUCED_IMAGE_SIZE = 1440; // pixels - private static final int REDUCED_IMAGE_QUALITY = 90; // percent + static final int REDUCED_IMAGE_SIZE = 1280; // pixels + static final int REDUCED_IMAGE_QUALITY = 90; // percent @Override public void onCreate(Bundle savedInstanceState) { @@ -1534,15 +1534,17 @@ public class FragmentCompose extends FragmentBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean autoresize = prefs.getBoolean("autoresize", true); - if ((image || autoresize) && + if (autoresize && ("image/jpeg".equals(attachment.type) || "image/png".equals(attachment.type))) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(file.getAbsolutePath(), options); + int resize = prefs.getInt("resize", REDUCED_IMAGE_SIZE); + int factor = 1; - while (options.outWidth / factor > REDUCED_IMAGE_SIZE || - options.outHeight / factor > REDUCED_IMAGE_SIZE) + while (options.outWidth / factor > resize || + options.outHeight / factor > resize) factor *= 2; Matrix rotation = ("image/jpeg".equals(attachment.type) ? getImageRotation(file) : null); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index effcffa2a2..5ba8c479e8 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -48,7 +48,6 @@ import android.widget.TimePicker; import java.text.SimpleDateFormat; import java.util.Calendar; -import java.util.Objects; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -96,6 +95,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O private SwitchCompat swAutoRead; private SwitchCompat swAutoMove; private SwitchCompat swAutoResize; + private Spinner spAutoResize; + private TextView tvAutoResize; private SwitchCompat swSender; private SwitchCompat swAutoSend; @@ -176,6 +177,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O swAutoRead = view.findViewById(R.id.swAutoRead); swAutoMove = view.findViewById(R.id.swAutoMove); swAutoResize = view.findViewById(R.id.swAutoResize); + spAutoResize = view.findViewById(R.id.spAutoResize); + tvAutoResize = view.findViewById(R.id.tvAutoResize); swSender = view.findViewById(R.id.swSender); swAutoSend = view.findViewById(R.id.swAutoSend); @@ -297,13 +300,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O spDownload.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int position, long id) { - Integer prev = (Integer) adapterView.getTag(); - if (!Objects.equals(prev, position)) { - adapterView.setTag(position); - - int[] values = getResources().getIntArray(R.array.downloadValues); - prefs.edit().putInt("download", values[position]).apply(); - } + int[] values = getResources().getIntArray(R.array.downloadValues); + prefs.edit().putInt("download", values[position]).apply(); } @Override @@ -479,6 +477,21 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("autoresize", checked).apply(); + spAutoResize.setEnabled(checked); + } + }); + + spAutoResize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + int[] values = getResources().getIntArray(R.array.resizeValues); + prefs.edit().putInt("resize", values[position]).apply(); + tvAutoResize.setText(getString(R.string.title_advanced_resize_pixels, values[position])); + } + + @Override + public void onNothingSelected(AdapterView parent) { + prefs.edit().remove("resize").apply(); } }); @@ -618,7 +631,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O int[] downloadValues = getResources().getIntArray(R.array.downloadValues); for (int pos = 0; pos < downloadValues.length; pos++) if (downloadValues[pos] == download) { - spDownload.setTag(pos); spDownload.setSelection(pos); break; } @@ -657,6 +669,17 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O swAutoRead.setChecked(prefs.getBoolean("autoread", false)); swAutoMove.setChecked(!prefs.getBoolean("automove", false)); swAutoResize.setChecked(prefs.getBoolean("autoresize", true)); + + int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE); + int[] resizeValues = getResources().getIntArray(R.array.resizeValues); + for (int pos = 0; pos < resizeValues.length; pos++) + if (resizeValues[pos] == resize) { + spAutoResize.setSelection(pos); + tvAutoResize.setText(getString(R.string.title_advanced_resize_pixels, resizeValues[pos])); + break; + } + spAutoResize.setEnabled(swAutoResize.isChecked()); + swSender.setChecked(prefs.getBoolean("sender", false)); swAutoSend.setChecked(!prefs.getBoolean("autosend", false)); diff --git a/app/src/main/res/layout/fragment_options.xml b/app/src/main/res/layout/fragment_options.xml index 315c34b19c..1b12ad4fe7 100644 --- a/app/src/main/res/layout/fragment_options.xml +++ b/app/src/main/res/layout/fragment_options.xml @@ -657,6 +657,25 @@ app:layout_constraintTop_toBottomOf="@id/swAutoMove" app:switchPadding="12dp" /> + + + + Automatically mark messages read on moving messages Confirm moving messages Automatically resize images for displaying on screens + < %1$d pixels Allow editing sender address Confirm sending messages @@ -591,18 +592,6 @@ Please describe what you were doing when the app crashed: FairEmail %1$s issue - - 16 KB - 32 KB - 64 KB - 128 KB - 256 KB - 512 KB - 1 MB - 2 MB - - - unified folders @@ -615,6 +604,18 @@ Accounts + + 16 KB + 32 KB + 64 KB + 128 KB + 256 KB + 512 KB + 1 MB + 2 MB + + + 16384 32768 @@ -627,6 +628,18 @@ 0 + + Small + Medium + Large + + + + 1080 + 1440 + 1920 + + @color/red @color/pink