diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 51e4b8f6d9..8547441451 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -652,11 +652,13 @@ public class FragmentCompose extends FragmentBase { Log.i("Received input uri=" + uri); boolean resize_paste = prefs.getBoolean("resize_paste", true); int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE); + boolean resize_width_only = prefs.getBoolean("resize_width_only", false); onAddAttachment( Arrays.asList(uri), type == null ? null : new String[]{type}, true, resize_paste ? resize : 0, + resize_width_only, false, false); } @@ -3386,7 +3388,7 @@ public class FragmentCompose extends FragmentBase { case REQUEST_ATTACHMENT: case REQUEST_RECORD_AUDIO: if (resultCode == RESULT_OK && data != null) - onAddAttachment(getUris(data), null, false, 0, false, false); + onAddAttachment(getUris(data), null, false, 0, false, false, false); break; case REQUEST_OPENPGP: if (resultCode == RESULT_OK && data != null) @@ -3735,18 +3737,20 @@ public class FragmentCompose extends FragmentBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean add_inline = prefs.getBoolean("add_inline", true); boolean resize_images = prefs.getBoolean("resize_images", true); + boolean resize_width_only = prefs.getBoolean("resize_width_only", false); boolean privacy_images = prefs.getBoolean("privacy_images", false); int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE); - onAddAttachment(uri, null, add_inline, resize_images ? resize : 0, privacy_images, focus); + onAddAttachment(uri, null, add_inline, resize_images ? resize : 0, resize_width_only, privacy_images, focus); } - private void onAddAttachment(List uris, String[] types, boolean image, int resize, boolean privacy, boolean focus) { + private void onAddAttachment(List uris, String[] types, boolean image, int resize, boolean resize_width_only, boolean privacy, boolean focus) { Bundle args = new Bundle(); args.putLong("id", working); args.putParcelableArrayList("uris", new ArrayList<>(uris)); args.putStringArray("types", types); args.putBoolean("image", image); args.putInt("resize", resize); + args.putBoolean("resize_width_only", resize_width_only); args.putInt("zoom", zoom); args.putBoolean("privacy", privacy); args.putCharSequence("body", etBody.getText()); @@ -3761,6 +3765,7 @@ public class FragmentCompose extends FragmentBase { String[] types = args.getStringArray("types"); boolean image = args.getBoolean("image"); int resize = args.getInt("resize"); + boolean resize_width_only = args.getBoolean("resize_width_only"); int zoom = args.getInt("zoom"); boolean privacy = args.getBoolean("privacy"); CharSequence body = args.getCharSequence("body"); @@ -3777,7 +3782,7 @@ public class FragmentCompose extends FragmentBase { Uri uri = uris.get(i); String type = (types != null && i < types.length ? types[i] : null); - EntityAttachment attachment = addAttachment(context, id, uri, type, image, resize, privacy); + EntityAttachment attachment = addAttachment(context, id, uri, type, image, resize, resize_width_only, privacy); if (attachment == null) continue; if (!image || !attachment.isImage()) @@ -3897,7 +3902,7 @@ public class FragmentCompose extends FragmentBase { if (info.isImage()) images.add(uri); else - addAttachment(context, id, uri, null, false, 0, false); + addAttachment(context, id, uri, null, false, 0, false, false); } catch (IOException ex) { Log.e(ex); } @@ -5372,8 +5377,8 @@ public class FragmentCompose extends FragmentBase { } private static EntityAttachment addAttachment( - Context context, long id, Uri uri, String type, boolean image, int resize, boolean privacy) throws IOException, SecurityException { - Log.w("Add attachment uri=" + uri + " image=" + image + " resize=" + resize + " privacy=" + privacy); + Context context, long id, Uri uri, String type, boolean image, int resize, boolean resize_width_only, boolean privacy) throws IOException, SecurityException { + Log.w("Add attachment uri=" + uri + " image=" + image + " resize=" + resize + "/" + resize_width_only + " privacy=" + privacy); NoStreamException.check(uri, context); @@ -5500,7 +5505,7 @@ public class FragmentCompose extends FragmentBase { Log.i("Authority=" + uri.getAuthority()); if (resize > 0) - resizeAttachment(context, attachment, resize); + resizeAttachment(context, attachment, resize, resize_width_only); if (privacy) try { @@ -5577,7 +5582,7 @@ public class FragmentCompose extends FragmentBase { return attachment; } - private static void resizeAttachment(Context context, EntityAttachment attachment, int resize) throws IOException { + private static void resizeAttachment(Context context, EntityAttachment attachment, int resize, boolean resize_width_only) throws IOException { File file = attachment.getFile(context); if (!file.exists()) // Upload cancelled; return; @@ -5604,7 +5609,7 @@ public class FragmentCompose extends FragmentBase { int factor = 1; while (options.outWidth / factor > resize || - options.outHeight / factor > resize) + (!resize_width_only && options.outHeight / factor > resize)) factor *= 2; Matrix rotation = ("image/jpeg".equals(attachment.type) ? ImageHelper.getImageRotation(file) : null); @@ -6455,7 +6460,7 @@ public class FragmentCompose extends FragmentBase { if (info.isImage()) images.add(uri); else - addAttachment(context, data.draft.id, uri, null, false, 0, false); + addAttachment(context, data.draft.id, uri, null, false, 0, false, false); } catch (IOException | SecurityException ex) { Log.e(ex); } @@ -6517,7 +6522,7 @@ public class FragmentCompose extends FragmentBase { if (resize_reply && ("reply".equals(action) || "reply_all".equals(action))) - resizeAttachment(context, attachment, REDUCED_IMAGE_SIZE); + resizeAttachment(context, attachment, REDUCED_IMAGE_SIZE, true); } else args.putBoolean("incomplete", true); } diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogAddImage.java b/app/src/main/java/eu/faircode/email/FragmentDialogAddImage.java index cea286cfb5..6a86826aef 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogAddImage.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogAddImage.java @@ -55,6 +55,7 @@ public class FragmentDialogAddImage extends FragmentDialogBase { boolean add_inline = prefs.getBoolean("add_inline", true); boolean resize_images = prefs.getBoolean("resize_images", true); int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE); + boolean resize_width_only = prefs.getBoolean("resize_width_only", false); boolean privacy_images = prefs.getBoolean("privacy_images", false); boolean image_dialog = prefs.getBoolean("image_dialog", true); @@ -65,6 +66,7 @@ public class FragmentDialogAddImage extends FragmentDialogBase { final CheckBox cbResize = dview.findViewById(R.id.cbResize); final ImageButton ibResize = dview.findViewById(R.id.ibResize); final Spinner spResize = dview.findViewById(R.id.spResize); + final CheckBox cbResizeWidthOnly = dview.findViewById(R.id.cbResizeWidthOnly); final TextView tvResize = dview.findViewById(R.id.tvResize); final TextView tvResizeRemark = dview.findViewById(R.id.tvResizeRemark); final CheckBox cbPrivacy = dview.findViewById(R.id.cbPrivacy); @@ -76,6 +78,7 @@ public class FragmentDialogAddImage extends FragmentDialogBase { rgAction.check(add_inline ? R.id.rbInline : R.id.rbAttach); cbResize.setChecked(resize_images); spResize.setEnabled(resize_images); + cbResizeWidthOnly.setChecked(resize_width_only); tvResizeRemark.setText(getString(R.string.title_add_image_resize_remark, "JPEG, PNG, WebP")); cbPrivacy.setChecked(privacy_images); @@ -133,6 +136,13 @@ public class FragmentDialogAddImage extends FragmentDialogBase { } }); + cbResizeWidthOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + prefs.edit().putBoolean("resize_width_only", isChecked).apply(); + } + }); + cbPrivacy.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { diff --git a/app/src/main/res/layout/dialog_add_image.xml b/app/src/main/res/layout/dialog_add_image.xml index b75aa7464f..0028049e77 100644 --- a/app/src/main/res/layout/dialog_add_image.xml +++ b/app/src/main/res/layout/dialog_add_image.xml @@ -106,6 +106,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/cbResize" /> + + + app:layout_constraintTop_toBottomOf="@id/cbResizeWidthOnly" /> Insert Attach Resize + Limit width only Remove privacy sensitive data Geographic location, serial numbers, file names, etc. < %1$d pixels