From 455c6e3dd78040d868bd06fff5c1d5a76cd055a2 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 9 Aug 2022 09:03:25 +0200 Subject: [PATCH] Added option to disable Android photo picker --- .../java/eu/faircode/email/FragmentCompose.java | 15 +++++++++------ .../faircode/email/FragmentOptionsBehavior.java | 14 +++++++++++++- .../main/res/layout/fragment_options_behavior.xml | 12 ++++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 33a388a94f..903771bc17 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -3034,7 +3034,8 @@ public class FragmentCompose extends FragmentBase { } private void onAddImage(boolean photo) { - PackageManager pm = getContext().getPackageManager(); + Context context = getContext(); + PackageManager pm = context.getPackageManager(); if (photo) { // https://developer.android.com/training/camera/photobasics Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); @@ -3049,26 +3050,28 @@ public class FragmentCompose extends FragmentBase { }); snackbar.show(); } else { - File dir = new File(getContext().getFilesDir(), "photo"); + File dir = new File(context.getFilesDir(), "photo"); if (!dir.exists()) dir.mkdir(); File file = new File(dir, working + ".jpg"); try { - photoURI = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID, file); + photoURI = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file); intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); startActivityForResult(intent, REQUEST_TAKE_PHOTO); } catch (Throwable ex) { // java.lang.IllegalArgumentException: Failed to resolve canonical path for ... - Helper.reportNoViewer(getContext(), intent, ex); + Helper.reportNoViewer(context, intent, ex); } } } else { // https://developer.android.com/reference/android/provider/MediaStore#ACTION_PICK_IMAGES // Android 12: cmd device_config put storage_native_boot picker_intent_enabled true + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean photo_picker = prefs.getBoolean("photo_picker", true); Intent picker = new Intent(MediaStore.ACTION_PICK_IMAGES); picker.setType("image/*"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && - picker.resolveActivity(pm) != null) { + photo_picker && picker.resolveActivity(pm) != null) { Log.i("Using photo picker"); picker.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit()); startActivityForResult(picker, REQUEST_IMAGE_FILE); @@ -3082,7 +3085,7 @@ public class FragmentCompose extends FragmentBase { if (intent.resolveActivity(pm) == null) // GET_CONTENT whitelisted noStorageAccessFramework(); else - startActivityForResult(Helper.getChooser(getContext(), intent), REQUEST_IMAGE_FILE); + startActivityForResult(Helper.getChooser(context, intent), REQUEST_IMAGE_FILE); } } } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java index d2154db2e7..5a2544803a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsBehavior.java @@ -67,6 +67,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private SwitchCompat swConversationActionsReplies; private SwitchCompat swLanguageDetection; private EditText etDefaultSnooze; + private SwitchCompat swPhotoPicker; private SwitchCompat swPull; private SwitchCompat swAutoScroll; private SwitchCompat swQuickFilter; @@ -104,7 +105,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe private final static String[] RESET_OPTIONS = new String[]{ "restore_on_launch", "sync_on_launch", "double_back", "conversation_actions", "conversation_actions_replies", "language_detection", - "default_snooze", + "photo_picker", "default_snooze", "pull", "autoscroll", "quick_filter", "quick_scroll", "swipe_sensitivity", "foldernav", "doubletap", "swipenav", "volumenav", "reversed", "swipe_close", "swipe_move", "autoexpand", "expand_first", "expand_all", "expand_one", "collapse_multiple", @@ -133,6 +134,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe swConversationActionsReplies = view.findViewById(R.id.swConversationActionsReplies); swLanguageDetection = view.findViewById(R.id.swLanguageDetection); etDefaultSnooze = view.findViewById(R.id.etDefaultSnooze); + swPhotoPicker = view.findViewById(R.id.swPhotoPicker); swPull = view.findViewById(R.id.swPull); swAutoScroll = view.findViewById(R.id.swAutoScroll); swQuickFilter = view.findViewById(R.id.swQuickFilter); @@ -249,6 +251,14 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe } }); + swPhotoPicker.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ? View.GONE : View.VISIBLE); + swPhotoPicker.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("photo_picker", checked).apply(); + } + }); + swPull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -548,6 +558,8 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe etDefaultSnooze.setText(default_snooze == 1 ? null : Integer.toString(default_snooze)); etDefaultSnooze.setHint("1"); + swPhotoPicker.setChecked(prefs.getBoolean("photo_picker", true)); + swPull.setChecked(prefs.getBoolean("pull", true)); swAutoScroll.setChecked(prefs.getBoolean("autoscroll", false)); swQuickFilter.setChecked(prefs.getBoolean("quick_filter", false)); diff --git a/app/src/main/res/layout/fragment_options_behavior.xml b/app/src/main/res/layout/fragment_options_behavior.xml index c3de8612f1..ce4aa10a1a 100644 --- a/app/src/main/res/layout/fragment_options_behavior.xml +++ b/app/src/main/res/layout/fragment_options_behavior.xml @@ -215,6 +215,18 @@ app:layout_constraintBottom_toBottomOf="@+id/etDefaultSnooze" app:layout_constraintStart_toEndOf="@+id/etDefaultSnooze" app:layout_constraintTop_toTopOf="@+id/etDefaultSnooze" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dd6629071a..8d8bcf1185 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -598,6 +598,7 @@ Suggest actions (Android 10+) Suggest reply texts (Android 10+) Detect message text language + Use the Android photo picker Pull down to refresh Scroll to top on receiving new messages Double tap to mark message read/unread