From e96ce53855349f73e43d5853e847e663f878b749 Mon Sep 17 00:00:00 2001
From: juniorcesar <juniorcesar.utfpr@gmail.com>
Date: Thu, 3 Oct 2013 17:07:25 -0300
Subject: [PATCH] Blocking screen orientation to start presentation

---
 android/sdremote/res/values/strings.xml                 |    2 ++
 android/sdremote/res/xml/preferences.xml                |    9 ++++++---
 .../impressremote/activity/SlideShowActivity.java       |   15 +++++++++++++++
 .../org/libreoffice/impressremote/util/Preferences.java |    1 +
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 0eefa95..8e1a0f9 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_orientation_landscape_on_title">Orientation landscape</string>
+    <string name="preferences_keep_orientation_landscape_on_summary">Keep orientation landscape 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..bd2f009 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_orientation_landscape"
+        android:summary="@string/preferences_keep_orientation_landscape_on_summary"
+        android:title="@string/preferences_keep_orientation_landscape_on_title"/>
 
-</PreferenceScreen>
\ No newline at end of file
+</PreferenceScreen>
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
index 3c41ecc..b0df8d3 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
@@ -14,6 +14,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
+import android.content.pm.ActivityInfo;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.support.v4.app.DialogFragment;
@@ -25,6 +26,7 @@ import com.actionbarsherlock.app.ActionBar;
 import com.actionbarsherlock.app.SherlockFragmentActivity;
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuItem;
+
 import org.libreoffice.impressremote.R;
 import org.libreoffice.impressremote.communication.CommunicationService;
 import org.libreoffice.impressremote.communication.SlideShow;
@@ -58,6 +60,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
         setUpHomeButton();
         setUpFragment();
         setUpKeepingScreenOn();
+        setUpKeepingOrientation();
 
         bindService();
     }
@@ -534,6 +537,18 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
     public void onServiceDisconnected(ComponentName aComponentName) {
         mCommunicationService = null;
     }
+    
+    private void setUpKeepingOrientation() {
+       	if (!isKeepingOrientationLandscapeOnRequired()) {
+       		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+       	} else {
+       		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+        }
+    }    
+    private boolean isKeepingOrientationLandscapeOnRequired() {
+        Preferences aPreferences = Preferences.getSettingsInstance(this);
+        return aPreferences.getBoolean(Preferences.Keys.KEEP_ORIENTATION_LANDSCAPE);
+    }
 }
 
 /* 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..8cd096c 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_ORIENTATION_LANDSCAPE = "keep_orientation_landscape";
     }
 
     private static final class Defaults {
-- 
1.7.10.4

