From 8b7bca3edab6c810b37097cec7109a698dadfcef Mon Sep 17 00:00:00 2001
From: juniorcesar <juniorcesar.utfpr@gmail.com>
Date: Thu, 3 Oct 2013 14:02:06 -0300
Subject: [PATCH] Adding silent mode to start the slideshow

---
 android/sdremote/res/values/strings.xml            |    2 ++
 android/sdremote/res/xml/preferences.xml           |    7 +++++--
 .../impressremote/activity/SlideShowActivity.java  |   21 +++++++++++++++++++-
 .../impressremote/util/Preferences.java            |    1 +
 4 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 0eefa95..8f8b285 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -64,6 +64,8 @@
     <string name="preferences_volume_keys_actions_summary">Switch slides and activate animations using volume keys</string>
     <string name="preferences_keep_screen_on_title">Screen on</string>
     <string name="preferences_keep_screen_on_summary">Keep screen on while presenting</string>
+    <string name="preferences_keep_silent_mode_on_title">Silent mode on</string>
+    <string name="preferences_keep_silent_mode_on_summary">Keep silent mode on while presenting</string>
 
     <string name="requirements_libreoffice_version">LibreOffice version 4.0.3 or higher running on a computer.</string>
     <string name="requirements_libreoffice_general_enabled">Impress Remote enabled at “Tools → Options → LibreOffice Impress → General” in LibreOffice Impress.</string>
diff --git a/android/sdremote/res/xml/preferences.xml b/android/sdremote/res/xml/preferences.xml
index 104c528..b4e9122 100644
--- a/android/sdremote/res/xml/preferences.xml
+++ b/android/sdremote/res/xml/preferences.xml
@@ -3,14 +3,17 @@
 
     <CheckBoxPreference
         android:key="volume_keys_actions"
-        android:defaultValue="true"
         android:title="@string/preferences_volume_keys_actions_title"
         android:summary="@string/preferences_volume_keys_actions_summary"/>
 
     <CheckBoxPreference
         android:key="keep_screen_on"
-        android:defaultValue="true"
         android:title="@string/preferences_keep_screen_on_title"
         android:summary="@string/preferences_keep_screen_on_summary"/>
+    
+    <CheckBoxPreference 
+        android:key="keep_silent_mode_on"
+        android:summary="@string/preferences_keep_silent_mode_on_summary"
+        android:title="@string/preferences_keep_silent_mode_on_title"/>
 
 </PreferenceScreen>
\ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
index 3c41ecc..dd66126 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
@@ -38,6 +38,7 @@ import org.libreoffice.impressremote.util.Fragments;
 import org.libreoffice.impressremote.util.Intents;
 import org.libreoffice.impressremote.util.Preferences;
 import org.libreoffice.impressremote.util.SavedStates;
+import android.media.AudioManager;
 
 public class SlideShowActivity extends SherlockFragmentActivity implements ServiceConnection {
     public static enum Mode {
@@ -48,6 +49,8 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
 
     private CommunicationService mCommunicationService;
     private IntentsReceiver mIntentsReceiver;
+    private AudioManager audioManager;
+    private int ringerMode;
 
     @Override
     protected void onCreate(Bundle aSavedInstanceState) {
@@ -58,7 +61,8 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
         setUpHomeButton();
         setUpFragment();
         setUpKeepingScreenOn();
-
+        setUpKeepingSilentModeOn();
+        
         bindService();
     }
 
@@ -534,6 +538,21 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
     public void onServiceDisconnected(ComponentName aComponentName) {
         mCommunicationService = null;
     }
+    
+    private void setUpKeepingSilentModeOn() {
+    	audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
+    	ringerMode = audioManager.getRingerMode();
+    	if (!isKeepingSilentModeOnRequired()) {
+    	audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
+    	} else {
+    	audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
+    	}
+    }
+    
+    private boolean isKeepingSilentModeOnRequired() {
+    	Preferences aPreferences = Preferences.getSettingsInstance(this);
+    	return aPreferences.getBoolean(Preferences.Keys.KEEP_SILENT_MODE_ON);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
index 5a9b0c7..7ade4db 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
@@ -32,6 +32,7 @@ public final class Preferences {
 
         public static final String VOLUME_KEYS_ACTIONS = "volume_keys_actions";
         public static final String KEEP_SCREEN_ON = "keep_screen_on";
+        public static final String KEEP_SILENT_MODE_ON = "keep_silent_mode_on";
     }
 
     private static final class Defaults {
-- 
1.7.10.4

