Added option to set target image size

pull/155/head
M66B 6 years ago
parent 4a6ede366e
commit aac2f07531

@ -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.
<br />

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

@ -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,14 +300,9 @@ 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();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
@ -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));

@ -657,6 +657,25 @@
app:layout_constraintTop_toBottomOf="@id/swAutoMove"
app:switchPadding="12dp" />
<Spinner
android:id="@+id/spAutoResize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:entries="@array/resizeNames"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoResize" />
<TextView
android:id="@+id/tvAutoResize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_advanced_resize_pixels"
app:layout_constraintBottom_toBottomOf="@id/spAutoResize"
app:layout_constraintStart_toEndOf="@id/spAutoResize"
app:layout_constraintTop_toTopOf="@id/spAutoResize" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSender"
android:layout_width="match_parent"
@ -666,7 +685,7 @@
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_sender"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoResize"
app:layout_constraintTop_toBottomOf="@id/spAutoResize"
app:switchPadding="12dp" />
<TextView

@ -185,6 +185,7 @@
<string name="title_advanced_autoread">Automatically mark messages read on moving messages</string>
<string name="title_advanced_automove">Confirm moving messages</string>
<string name="title_advanced_autoresize">Automatically resize images for displaying on screens</string>
<string name="title_advanced_resize_pixels">&lt; %1$d pixels</string>
<string name="title_advanced_sender">Allow editing sender address</string>
<string name="title_advanced_autosend">Confirm sending messages</string>
@ -591,18 +592,6 @@
<string name="title_crash_info_remark">Please describe what you were doing when the app crashed:</string>
<string name="title_issue_subject" translatable="false">FairEmail %1$s issue</string>
<string-array name="downloadNames">
<item>16 KB</item>
<item>32 KB</item>
<item>64 KB</item>
<item>128 KB</item>
<item>256 KB</item>
<item>512 KB</item>
<item>1 MB</item>
<item>2 MB</item>
<item>&#8734;</item>
</string-array>
<string-array name="startupValues" translatable="false">
<item>unified</item>
<item>folders</item>
@ -615,6 +604,18 @@
<item>Accounts</item>
</string-array>
<string-array name="downloadNames">
<item>16 KB</item>
<item>32 KB</item>
<item>64 KB</item>
<item>128 KB</item>
<item>256 KB</item>
<item>512 KB</item>
<item>1 MB</item>
<item>2 MB</item>
<item>&#8734;</item>
</string-array>
<integer-array name="downloadValues" translatable="false">
<item>16384</item>
<item>32768</item>
@ -627,6 +628,18 @@
<item>0</item>
</integer-array>
<string-array name="resizeNames">
<item>Small</item>
<item>Medium</item>
<item>Large</item>
</string-array>
<integer-array name="resizeValues" translatable="false">
<item>1080</item>
<item>1440</item>
<item>1920</item>
</integer-array>
<array name="colorPicker">
<item>@color/red</item>
<item>@color/pink</item>

Loading…
Cancel
Save