[Libreoffice-commits] core.git: 2 commits - android/sdremote

Artur Dryomov artur.dryomov at gmail.com
Thu Sep 5 09:46:59 PDT 2013


 android/sdremote/AndroidManifest.xml                                                 |    5 
 android/sdremote/res/menu/menu_action_bar_computers.xml                              |    5 
 android/sdremote/res/values/strings.xml                                              |    7 
 android/sdremote/res/xml/preferences.xml                                             |   14 +
 android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java   |    9 +
 android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java    |   54 +++++++
 android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java   |   72 +++++++++-
 android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java |    1 
 android/sdremote/src/org/libreoffice/impressremote/util/Intents.java                 |    5 
 android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java             |   28 +++
 10 files changed, 194 insertions(+), 6 deletions(-)

New commits:
commit f98a01f061d6d8895a3a2397a1545f052769ba3d
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Thu Sep 5 19:12:43 2013 +0300

    Remove triggering next transitions on last slide.
    
    The current server-side code calls finishing of a slide show multiple
    times so we cannot rely on this inidicator to exit the slide show.
    
    Change-Id: I78b11f62d45d45bcf005e6f0a36f2d632b886900

diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
index 18f1691..d229c58 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
@@ -257,7 +257,9 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
 
         switch (aKeyCode) {
             case KeyEvent.KEYCODE_VOLUME_UP:
-                mCommunicationService.getTransmitter().performNextTransition();
+                if (!isLastSlideDisplayed()) {
+                    mCommunicationService.getTransmitter().performNextTransition();
+                }
                 return true;
 
             case KeyEvent.KEYCODE_VOLUME_DOWN:
@@ -275,6 +277,13 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
         return preferences.getBoolean(Preferences.Keys.VOLUME_KEYS_ACTIONS);
     }
 
+    private boolean isLastSlideDisplayed() {
+        int aCurrentSlideIndex = mCommunicationService.getSlideShow().getHumanCurrentSlideIndex();
+        int aSlidesCount = mCommunicationService.getSlideShow().getSlidesCount();
+
+        return aCurrentSlideIndex == aSlidesCount;
+    }
+
     @Override
     public boolean onKeyUp(int aKeyCode, KeyEvent aKeyEvent) {
         if (!areVolumeKeysActionsRequired()) {
commit 3c1c51020c07c748248d0c6e4ae33f3f37ce1390
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Thu Sep 5 11:59:27 2013 +0300

    Add the settings screen.
    
    It contains options that can confuse user:
    * changing transitions using volume keys;
    * keeping screenon while presenting.
    
    Change-Id: I1a9cb9afdf1409fc78e713b899d68ae045db5cb7

diff --git a/android/sdremote/AndroidManifest.xml b/android/sdremote/AndroidManifest.xml
index 109c1c2..7b80b66 100644
--- a/android/sdremote/AndroidManifest.xml
+++ b/android/sdremote/AndroidManifest.xml
@@ -54,6 +54,11 @@
         </activity>
 
         <activity
+            android:name=".activity.SettingsActivity"
+            android:label="@string/title_settings">
+        </activity>
+
+        <activity
             android:name=".activity.LicensesActivity"
             android:label="@string/title_licenses">
         </activity>
diff --git a/android/sdremote/res/menu/menu_action_bar_computers.xml b/android/sdremote/res/menu/menu_action_bar_computers.xml
index 7835fa9..f99df21 100644
--- a/android/sdremote/res/menu/menu_action_bar_computers.xml
+++ b/android/sdremote/res/menu/menu_action_bar_computers.xml
@@ -8,6 +8,11 @@
         android:showAsAction="always"/>
 
     <item
+        android:id="@+id/menu_settings"
+        android:title="@string/title_settings"
+        android:showAsAction="never"/>
+
+    <item
         android:id="@+id/menu_licenses"
         android:title="@string/menu_licenses"
         android:showAsAction="never"/>
diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 0aaa46f..f810f0e 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -7,12 +7,14 @@
     <string name="title_bluetooth" translatable="false">Bluetooth</string>
     <string name="title_wifi" translatable="false">WiFi</string>
     <string name="title_licenses">Open source licenses</string>
+    <string name="title_settings">Settings</string>
     <string name="title_connection">Connection</string>
     <string name="title_creation">Creation</string>
     <string name="title_slide_show">Slide Show</string>
     <string name="title_timer">Timer</string>
 
     <string name="menu_licenses">Open source licenses</string>
+    <string name="menu_settings">Settings</string>
     <string name="menu_reconnect">Reconnect</string>
     <string name="menu_add_computer">Add computer</string>
     <string name="menu_remove_computer">Remove</string>
@@ -48,4 +50,9 @@
     <string name="description_pager_slide">Slide preview</string>
     <string name="description_grid_slide">Slide preview</string>
 
+    <string name="preferences_volume_keys_actions_title">Volume keys actions</string>
+    <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>
+
 </resources>
diff --git a/android/sdremote/res/xml/preferences.xml b/android/sdremote/res/xml/preferences.xml
new file mode 100644
index 0000000..87b8450
--- /dev/null
+++ b/android/sdremote/res/xml/preferences.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <CheckBoxPreference
+        android:key="volume_keys_actions"
+        android:title="@string/preferences_volume_keys_actions_title"
+        android:summary="@string/preferences_volume_keys_actions_summary"/>
+
+    <CheckBoxPreference
+        android:key="keep_screen_on"
+        android:title="@string/preferences_keep_screen_on_title"
+        android:summary="@string/preferences_keep_screen_on_summary"/>
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
index 90003ef..da4652a 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
@@ -187,6 +187,10 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
     @Override
     public boolean onOptionsItemSelected(MenuItem aMenuItem) {
         switch (aMenuItem.getItemId()) {
+            case R.id.menu_settings:
+                callSettingsActivity();
+                return true;
+
             case R.id.menu_licenses:
                 callLicensesActivity();
                 return true;
@@ -196,6 +200,11 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
         }
     }
 
+    private void callSettingsActivity() {
+        Intent aIntent = Intents.buildSettingsIntent(this);
+        startActivity(aIntent);
+    }
+
     private void callLicensesActivity() {
         Intent aIntent = Intents.buildLicensesIntent(this);
         startActivity(aIntent);
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java
new file mode 100644
index 0000000..4309e8e
--- /dev/null
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java
@@ -0,0 +1,54 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.libreoffice.impressremote.activity;
+
+import android.os.Bundle;
+
+import com.actionbarsherlock.app.SherlockPreferenceActivity;
+import com.actionbarsherlock.view.MenuItem;
+import org.libreoffice.impressremote.R;
+
+public class SettingsActivity extends SherlockPreferenceActivity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        setUpHomeButton();
+        setUpPreferences();
+    }
+
+    private void setUpHomeButton() {
+        getSupportActionBar().setHomeButtonEnabled(true);
+    }
+
+    private void setUpPreferences() {
+        // This action is deprecated
+        // but we still need to target pre-Honeycomb devices
+
+        addPreferencesFromResource(R.xml.preferences);
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem aMenuItem) {
+        switch (aMenuItem.getItemId()) {
+            case android.R.id.home:
+                navigateUp();
+                return true;
+
+            default:
+                return super.onOptionsItemSelected(aMenuItem);
+        }
+    }
+
+    private void navigateUp() {
+        finish();
+    }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
index 791861c..18f1691 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
@@ -19,6 +19,7 @@ import android.os.IBinder;
 import android.support.v4.app.DialogFragment;
 import android.support.v4.app.Fragment;
 import android.support.v4.content.LocalBroadcastManager;
+import android.view.KeyEvent;
 
 import com.actionbarsherlock.app.ActionBar;
 import com.actionbarsherlock.app.SherlockFragmentActivity;
@@ -34,6 +35,7 @@ import org.libreoffice.impressremote.fragment.TimerEditingDialog;
 import org.libreoffice.impressremote.fragment.TimerSettingDialog;
 import org.libreoffice.impressremote.util.FragmentOperator;
 import org.libreoffice.impressremote.util.Intents;
+import org.libreoffice.impressremote.util.Preferences;
 
 public class SlideShowActivity extends SherlockFragmentActivity implements ServiceConnection {
     private static enum Mode {
@@ -53,6 +55,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
 
         setUpHomeButton();
         setUpFragment();
+        setUpKeepingScreenOn();
 
         bindService();
     }
@@ -86,6 +89,16 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
         }
     }
 
+    private void setUpKeepingScreenOn() {
+        findViewById(android.R.id.content).setKeepScreenOn(isKeepingScreenOnRequired());
+    }
+
+    private boolean isKeepingScreenOnRequired() {
+        Preferences preferences = Preferences.getSettingsInstance(this);
+
+        return preferences.getBoolean(Preferences.Keys.KEEP_SCREEN_ON);
+    }
+
     private void bindService() {
         Intent aIntent = Intents.buildCommunicationServiceIntent(this);
         bindService(aIntent, this, Context.BIND_AUTO_CREATE);
@@ -237,6 +250,50 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
     }
 
     @Override
+    public boolean onKeyDown(int aKeyCode, KeyEvent aKeyEvent) {
+        if (!areVolumeKeysActionsRequired()) {
+            return super.onKeyDown(aKeyCode, aKeyEvent);
+        }
+
+        switch (aKeyCode) {
+            case KeyEvent.KEYCODE_VOLUME_UP:
+                mCommunicationService.getTransmitter().performNextTransition();
+                return true;
+
+            case KeyEvent.KEYCODE_VOLUME_DOWN:
+                mCommunicationService.getTransmitter().performPreviousTransition();
+                return true;
+
+            default:
+                return super.onKeyDown(aKeyCode, aKeyEvent);
+        }
+    }
+
+    private boolean areVolumeKeysActionsRequired() {
+        Preferences preferences = Preferences.getSettingsInstance(this);
+
+        return preferences.getBoolean(Preferences.Keys.VOLUME_KEYS_ACTIONS);
+    }
+
+    @Override
+    public boolean onKeyUp(int aKeyCode, KeyEvent aKeyEvent) {
+        if (!areVolumeKeysActionsRequired()) {
+            return super.onKeyUp(aKeyCode, aKeyEvent);
+        }
+
+        // Suppress sound of volume changing
+
+        switch (aKeyCode) {
+            case KeyEvent.KEYCODE_VOLUME_UP:
+            case KeyEvent.KEYCODE_VOLUME_DOWN:
+                return true;
+
+            default:
+                return super.onKeyUp(aKeyCode, aKeyEvent);
+        }
+    }
+
+    @Override
     public boolean onCreateOptionsMenu(Menu aMenu) {
         getSupportMenuInflater().inflate(R.menu.menu_action_bar_slide_show, aMenu);
 
@@ -318,8 +375,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
 
         if (aTimer.isSet()) {
             callEditingTimer(aTimer);
-        }
-        else {
+        } else {
             callSettingTimer();
         }
     }
@@ -334,8 +390,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
     private DialogFragment buildTimerEditingDialog(Timer aTimer) {
         if (aTimer.isTimeUp()) {
             return TimerEditingDialog.newInstance(aTimer.getMinutesLength());
-        }
-        else {
+        } else {
             return TimerEditingDialog.newInstance(aTimer.getMinutesLeft());
         }
     }
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
index 0c22801..08b5cc2 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
@@ -21,6 +21,7 @@ import android.support.v4.view.PagerAdapter;
 import android.support.v4.view.ViewPager;
 import android.text.Html;
 import android.text.TextUtils;
+import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
index eb85418..cdcec9a 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
@@ -14,6 +14,7 @@ import android.content.Intent;
 import org.libreoffice.impressremote.activity.ComputerConnectionActivity;
 import org.libreoffice.impressremote.activity.ComputerCreationActivity;
 import org.libreoffice.impressremote.activity.LicensesActivity;
+import org.libreoffice.impressremote.activity.SettingsActivity;
 import org.libreoffice.impressremote.activity.SlideShowActivity;
 import org.libreoffice.impressremote.communication.CommunicationService;
 import org.libreoffice.impressremote.communication.Server;
@@ -139,6 +140,10 @@ public final class Intents {
         return new Intent(aContext, SlideShowActivity.class);
     }
 
+    public static Intent buildSettingsIntent(Context aContext) {
+        return new Intent(aContext, SettingsActivity.class);
+    }
+
     public static Intent buildLicensesIntent(Context aContext) {
         return new Intent(aContext, LicensesActivity.class);
     }
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
index 4b22c29..4ad2490 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
@@ -12,6 +12,7 @@ import java.util.Map;
 
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
 
 public final class Preferences {
     private static final class Locations {
@@ -28,6 +29,17 @@ public final class Preferences {
         }
 
         public static final String SELECTED_COMPUTERS_TAB_INDEX = "selected_computers_tab_index";
+        public static final String VOLUME_KEYS_ACTIONS = "volume_keys_actions";
+        public static final String KEEP_SCREEN_ON = "keep_screen_on";
+    }
+
+    private static final class Defaults {
+        private Defaults() {
+        }
+
+        public static final String STRING = null;
+        public static final int INT = 0;
+        public static final boolean BOOLEAN = false;
     }
 
     private final SharedPreferences mPreferences;
@@ -52,22 +64,34 @@ public final class Preferences {
         return new Preferences(aContext, Locations.APPLICATION_STATES);
     }
 
+    public static Preferences getSettingsInstance(Context context) {
+        return new Preferences(context);
+    }
+
+    private Preferences(Context context) {
+        mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+    }
+
     public Map<String, ?> getAll() {
         return mPreferences.getAll();
     }
 
     public String getString(String aKey) {
-        return mPreferences.getString(aKey, null);
+        return mPreferences.getString(aKey, Defaults.STRING);
     }
 
     public int getInt(String aKey) {
-        return mPreferences.getInt(aKey, 0);
+        return mPreferences.getInt(aKey, Defaults.INT);
     }
 
     public void setString(String aKey, String aValue) {
         mPreferences.edit().putString(aKey, aValue).commit();
     }
 
+    public boolean getBoolean(String aKey) {
+        return mPreferences.getBoolean(aKey, Defaults.BOOLEAN);
+    }
+
     public void setInt(String aKey, int aValue) {
         mPreferences.edit().putInt(aKey, aValue).commit();
     }


More information about the Libreoffice-commits mailing list