Change summary
src/main/java/eu/siacs/conversations/ui/fragment/settings/NotificationsSettingsFragment.java | 46
src/main/res/drawable/ic_smartphone_24dp.xml | 12
src/main/res/values/strings.xml | 2
src/main/res/xml/preferences_notifications.xml | 5
4 files changed, 64 insertions(+), 1 deletion(-)
Detailed changes
@@ -1,11 +1,15 @@
package eu.siacs.conversations.ui.fragment.settings;
-import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
+import android.provider.Settings;
import android.util.Log;
+import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.NonNull;
@@ -56,12 +60,14 @@ public class NotificationsSettingsFragment extends XmppPreferenceFragment {
@Nullable final Bundle savedInstanceState, final @Nullable String rootKey) {
setPreferencesFromResource(R.xml.preferences_notifications, rootKey);
final var messageNotificationSettings = findPreference("message_notification_settings");
+ final var fullscreenNotification = findPreference("fullscreen_notification");
final var notificationRingtone = findPreference(AppSettings.NOTIFICATION_RINGTONE);
final var notificationHeadsUp = findPreference(AppSettings.NOTIFICATION_HEADS_UP);
final var notificationVibrate = findPreference(AppSettings.NOTIFICATION_VIBRATE);
final var notificationLed = findPreference(AppSettings.NOTIFICATION_LED);
final var foregroundService = findPreference(AppSettings.KEEP_FOREGROUND_SERVICE);
if (messageNotificationSettings == null
+ || fullscreenNotification == null
|| notificationRingtone == null
|| notificationHeadsUp == null
|| notificationVibrate == null
@@ -78,6 +84,44 @@ public class NotificationsSettingsFragment extends XmppPreferenceFragment {
} else {
messageNotificationSettings.setVisible(false);
}
+ fullscreenNotification.setOnPreferenceClickListener(this::manageAppUseFullScreen);
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE
+ || requireContext()
+ .getSystemService(NotificationManager.class)
+ .canUseFullScreenIntent()) {
+ fullscreenNotification.setVisible(false);
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ final var fullscreenNotification = findPreference("fullscreen_notification");
+ if (fullscreenNotification == null) {
+ return;
+ }
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE
+ || requireContext()
+ .getSystemService(NotificationManager.class)
+ .canUseFullScreenIntent()) {
+ fullscreenNotification.setVisible(false);
+ }
+ }
+
+ private boolean manageAppUseFullScreen(final Preference preference) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
+ return false;
+ }
+ final var intent = new Intent(Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT);
+ intent.setData(Uri.parse(String.format("package:%s", requireContext().getPackageName())));
+ try {
+ startActivity(intent);
+ } catch (final ActivityNotFoundException e) {
+ Toast.makeText(requireContext(), R.string.no_application_found, Toast.LENGTH_SHORT)
+ .show();
+ return false;
+ }
+ return true;
}
@Override
@@ -0,0 +1,12 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="?colorControlNormal"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M17,1.01L7,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V3c0,-1.1 -0.9,-1.99 -2,-1.99zM17,19H7V5h10v14z" />
+
+</vector>
@@ -1062,5 +1062,7 @@
<string name="pref_backup_summary">Create one-off, Schedule recurring</string>
<string name="pref_create_backup_one_off_summary">Create one-off backup</string>
<string name="pref_backup_recurring">Recurring backup</string>
+ <string name="pref_fullscreen_notification">Full screen notifications</string>
+ <string name="pref_fullscreen_notification_summary">Allow this app to show incoming call notifications that take up the full screen when the device is locked.</string>
</resources>
@@ -46,6 +46,11 @@
android:ringtoneType="ringtone"
android:summary="@string/pref_call_ringtone_summary"
android:title="@string/pref_ringtone" />
+ <Preference
+ android:icon="@drawable/ic_smartphone_24dp"
+ android:key="fullscreen_notification"
+ android:summary="@string/pref_fullscreen_notification_summary"
+ android:title="@string/pref_fullscreen_notification" />
<ListPreference
android:defaultValue="@integer/grace_period"
android:entries="@array/grace_periods"