From aaf64732b0e04d0b95407c5420da08c8c1752ec6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 1 Mar 2016 19:00:18 +0100 Subject: [PATCH] expert option to treat vibrate as silent mode for XA. fixes #1530 --- .../services/XmppConnectionService.java | 10 +++++++++- .../siacs/conversations/ui/SettingsActivity.java | 15 +++++++++------ src/main/res/values/strings.xml | 2 ++ src/main/res/xml/preferences.xml | 6 ++++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 85eb479fd..07a7e10b8 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -611,6 +611,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return getPreferences().getBoolean("xa_on_silent_mode", false); } + private boolean treatVibrateAsSilent() { + return getPreferences().getBoolean("treat_vibrate_as_silent", false); + } + private boolean awayWhenScreenOff() { return getPreferences().getBoolean("away_when_screen_off", false); } @@ -645,7 +649,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa private boolean isPhoneSilenced() { AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); - return audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT; + if (treatVibrateAsSilent()) { + return audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL; + } else { + return audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT; + } } private void resetAllAttemptCounts(boolean reallyAll) { diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index c028d0d69..750a74212 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -21,6 +21,7 @@ import java.security.KeyStoreException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Locale; import de.duenndns.ssl.MemorizingTrustManager; @@ -154,8 +155,13 @@ public class SettingsActivity extends XmppActivity implements } @Override - public void onSharedPreferenceChanged(SharedPreferences preferences, - String name) { + public void onSharedPreferenceChanged(SharedPreferences preferences, String name) { + final List resendPresence = Arrays.asList( + "confirm_messages", + "xa_on_silent_mode", + "away_when_screen_off", + "allow_message_correction", + "treat_vibrate_as_silent"); if (name.equals("resource")) { String resource = preferences.getString("resource", "mobile") .toLowerCase(Locale.US); @@ -174,10 +180,7 @@ public class SettingsActivity extends XmppActivity implements } } else if (name.equals("keep_foreground_service")) { xmppConnectionService.toggleForegroundService(); - } else if (name.equals("confirm_messages") - || name.equals("xa_on_silent_mode") - || name.equals("away_when_screen_off") - || name.equals("allow_message_correction")) { + } else if (resendPresence.contains(name)) { if (xmppConnectionServiceBound) { if (name.equals("away_when_screen_off")) { xmppConnectionService.toggleScreenEventReceiver(); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 69609f880..6a36233ce 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -536,6 +536,8 @@ Marks your resource as away when the screen is turned off Not available in silent mode Marks your resource as not available when device is in silent mode + Treat vibrate as silent mode + Marks your resource as not available when device is on vibrate Extended connection settings Show hostname and port settings when setting up an account xmpp.example.com diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 357995735..f505baf7c 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -189,6 +189,12 @@ android:key="xa_on_silent_mode" android:summary="@string/pref_xa_on_silent_mode_summary" android:title="@string/pref_xa_on_silent_mode"/> +