Added option to remove EXIF location

pull/178/head
M66B 6 years ago
parent a1669915e7
commit 873d568d23

@ -97,6 +97,7 @@ import androidx.constraintlayout.widget.Group;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.cursoradapter.widget.SimpleCursorAdapter; import androidx.cursoradapter.widget.SimpleCursorAdapter;
import androidx.documentfile.provider.DocumentFile; import androidx.documentfile.provider.DocumentFile;
import androidx.exifinterface.media.ExifInterface;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
@ -460,7 +461,7 @@ public class FragmentCompose extends FragmentBase {
etBody.setInputContentListener(new EditTextCompose.IInputContentListener() { etBody.setInputContentListener(new EditTextCompose.IInputContentListener() {
@Override @Override
public void onInputContent(Uri uri) { public void onInputContent(Uri uri) {
onAddAttachment(Arrays.asList(uri), true, 0); onAddAttachment(Arrays.asList(uri), true, 0, false);
} }
}); });
@ -1701,7 +1702,7 @@ public class FragmentCompose extends FragmentBase {
case REQUEST_ATTACHMENT: case REQUEST_ATTACHMENT:
case REQUEST_RECORD_AUDIO: case REQUEST_RECORD_AUDIO:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
onAddAttachment(getUris(data), false, 0); onAddAttachment(getUris(data), false, 0, false);
break; break;
case REQUEST_OPENPGP: case REQUEST_OPENPGP:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
@ -1876,16 +1877,18 @@ public class FragmentCompose extends FragmentBase {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean add_inline = prefs.getBoolean("add_inline", true); boolean add_inline = prefs.getBoolean("add_inline", true);
boolean resize_images = prefs.getBoolean("resize_images", true); boolean resize_images = prefs.getBoolean("resize_images", true);
boolean privacy_images = prefs.getBoolean("privacy_images", false);
int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE); int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE);
onAddAttachment(uri, add_inline, resize_images ? resize : 0); onAddAttachment(uri, add_inline, resize_images ? resize : 0, privacy_images);
} }
private void onAddAttachment(List<Uri> uris, boolean image, int resize) { private void onAddAttachment(List<Uri> uris, boolean image, int resize, boolean privacy) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", working); args.putLong("id", working);
args.putParcelableArrayList("uris", new ArrayList<>(uris)); args.putParcelableArrayList("uris", new ArrayList<>(uris));
args.putBoolean("image", image); args.putBoolean("image", image);
args.putInt("resize", resize); args.putInt("resize", resize);
args.putBoolean("privacy", privacy);
args.putCharSequence("body", etBody.getText()); args.putCharSequence("body", etBody.getText());
args.putInt("start", etBody.getSelectionStart()); args.putInt("start", etBody.getSelectionStart());
@ -1896,13 +1899,14 @@ public class FragmentCompose extends FragmentBase {
List<Uri> uris = args.getParcelableArrayList("uris"); List<Uri> uris = args.getParcelableArrayList("uris");
boolean image = args.getBoolean("image"); boolean image = args.getBoolean("image");
int resize = args.getInt("resize"); int resize = args.getInt("resize");
boolean privacy = args.getBoolean("privacy");
CharSequence body = args.getCharSequence("body"); CharSequence body = args.getCharSequence("body");
int start = args.getInt("start"); int start = args.getInt("start");
SpannableStringBuilder s = new SpannableStringBuilder(body); SpannableStringBuilder s = new SpannableStringBuilder(body);
for (Uri uri : uris) { for (Uri uri : uris) {
EntityAttachment attachment = addAttachment(context, id, uri, image, resize); EntityAttachment attachment = addAttachment(context, id, uri, image, resize, privacy);
if (!image) if (!image)
continue; continue;
@ -2710,8 +2714,8 @@ public class FragmentCompose extends FragmentBase {
} }
private static EntityAttachment addAttachment( private static EntityAttachment addAttachment(
Context context, long id, Uri uri, boolean image, int resize) throws IOException { Context context, long id, Uri uri, boolean image, int resize, boolean privacy) throws IOException {
Log.w("Add attachment uri=" + uri + " image=" + image + " resize=" + resize); Log.w("Add attachment uri=" + uri + " image=" + image + " resize=" + resize + " privacy=" + privacy);
if (!"content".equals(uri.getScheme()) && if (!"content".equals(uri.getScheme()) &&
!Helper.hasPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)) { !Helper.hasPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)) {
@ -2832,6 +2836,20 @@ public class FragmentCompose extends FragmentBase {
if (resize > 0) if (resize > 0)
resizeAttachment(context, attachment, resize); resizeAttachment(context, attachment, resize);
if (privacy)
try {
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, null);
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, null);
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, null);
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, null);
exif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF, null);
exif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE, null);
exif.saveAttributes();
} catch (IOException ex) {
Log.w(ex);
}
} catch (Throwable ex) { } catch (Throwable ex) {
// Reset progress on failure // Reset progress on failure
Log.e(ex); Log.e(ex);
@ -3446,7 +3464,7 @@ public class FragmentCompose extends FragmentBase {
if (uris != null) if (uris != null)
for (Uri uri : uris) for (Uri uri : uris)
try { try {
addAttachment(context, data.draft.id, uri, false, 0); addAttachment(context, data.draft.id, uri, false, 0, false);
} catch (IOException ex) { } catch (IOException ex) {
Log.e(ex); Log.e(ex);
} }
@ -4697,6 +4715,7 @@ public class FragmentCompose extends FragmentBase {
boolean add_inline = prefs.getBoolean("add_inline", true); boolean add_inline = prefs.getBoolean("add_inline", true);
boolean resize_images = prefs.getBoolean("resize_images", true); boolean resize_images = prefs.getBoolean("resize_images", true);
int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE); int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE);
boolean privacy_images = prefs.getBoolean("privacy_images", false);
boolean image_dialog = prefs.getBoolean("image_dialog", true); boolean image_dialog = prefs.getBoolean("image_dialog", true);
final ViewGroup dview = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.dialog_add_image, null); final ViewGroup dview = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.dialog_add_image, null);
@ -4704,12 +4723,14 @@ public class FragmentCompose extends FragmentBase {
final CheckBox cbResize = dview.findViewById(R.id.cbResize); final CheckBox cbResize = dview.findViewById(R.id.cbResize);
final Spinner spResize = dview.findViewById(R.id.spResize); final Spinner spResize = dview.findViewById(R.id.spResize);
final TextView tvResize = dview.findViewById(R.id.tvResize); final TextView tvResize = dview.findViewById(R.id.tvResize);
final CheckBox cbPrivacy = dview.findViewById(R.id.cbPrivacy);
final CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain); final CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain);
final TextView tvNotAgain = dview.findViewById(R.id.tvNotAgain); final TextView tvNotAgain = dview.findViewById(R.id.tvNotAgain);
rgAction.check(add_inline ? R.id.rbInline : R.id.rbAttach); rgAction.check(add_inline ? R.id.rbInline : R.id.rbAttach);
cbResize.setChecked(resize_images); cbResize.setChecked(resize_images);
spResize.setEnabled(resize_images); spResize.setEnabled(resize_images);
cbPrivacy.setChecked(privacy_images);
final int[] resizeValues = getResources().getIntArray(R.array.resizeValues); final int[] resizeValues = getResources().getIntArray(R.array.resizeValues);
for (int pos = 0; pos < resizeValues.length; pos++) for (int pos = 0; pos < resizeValues.length; pos++)
@ -4747,6 +4768,14 @@ public class FragmentCompose extends FragmentBase {
} }
}); });
cbPrivacy.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("privacy_images", isChecked).apply();
spResize.setEnabled(isChecked);
}
});
cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

@ -72,6 +72,17 @@
app:layout_constraintStart_toEndOf="@id/spResize" app:layout_constraintStart_toEndOf="@id/spResize"
app:layout_constraintTop_toTopOf="@id/spResize" /> app:layout_constraintTop_toTopOf="@id/spResize" />
<CheckBox
android:id="@+id/cbPrivacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_add_image_privacy"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spResize" />
<CheckBox <CheckBox
android:id="@+id/cbNotAgain" android:id="@+id/cbNotAgain"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -80,7 +91,7 @@
android:text="@string/title_no_ask_again" android:text="@string/title_no_ask_again"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spResize" /> app:layout_constraintTop_toBottomOf="@id/cbPrivacy" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvNotAgain" android:id="@+id/tvNotAgain"

@ -838,6 +838,7 @@
<string name="title_add_image_inline">Insert</string> <string name="title_add_image_inline">Insert</string>
<string name="title_add_image_attach">Attach</string> <string name="title_add_image_attach">Attach</string>
<string name="title_add_image_resize">Resize</string> <string name="title_add_image_resize">Resize</string>
<string name="title_add_image_privacy">Remove location</string>
<string name="title_add_resize_pixels">&lt; %1$d pixels</string> <string name="title_add_resize_pixels">&lt; %1$d pixels</string>
<string name="title_add_image_select">Select file</string> <string name="title_add_image_select">Select file</string>
<string name="title_add_attachment">Add attachment</string> <string name="title_add_attachment">Add attachment</string>

Loading…
Cancel
Save