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

Artur Dryomov artur.dryomov at gmail.com
Sat Aug 3 09:02:50 PDT 2013


 android/sdremote/res/layout/activity_computer_creation.xml                                 |   46 ++++---
 android/sdremote/res/values/strings.xml                                                    |    2 
 android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java         |   24 +++
 android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java         |   61 ++++++----
 android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java         |    2 
 android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java |    8 -
 android/sdremote/src/org/libreoffice/impressremote/communication/MessagesReceiver.java     |    2 
 android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java      |   14 --
 android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java       |   19 +--
 android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java            |    8 -
 android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java        |   29 +++-
 android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java       |   60 +++++++--
 android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java                   |   52 +++++---
 13 files changed, 205 insertions(+), 122 deletions(-)

New commits:
commit 79f79ab077a008515e4235bdc6fcb9bf6f1af961
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sat Aug 3 16:58:59 2013 +0300

    Add saving the current tab between application launches.
    
    Mimic the Contacts app behaviour basically.
    
    Change-Id: Ib0579d26c105629cfe59620f996689a949bad073

diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
index 56b87e7..6249e22 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
@@ -25,6 +25,7 @@ import org.libreoffice.impressremote.util.BluetoothOperator;
 import org.libreoffice.impressremote.util.FragmentOperator;
 import org.libreoffice.impressremote.util.Intents;
 import org.libreoffice.impressremote.R;
+import org.libreoffice.impressremote.util.Preferences;
 
 public class ComputersActivity extends SherlockFragmentActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
     private static final class TabsIndices {
@@ -72,6 +73,8 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
 
         setUpTabs();
         setUpComputersPager();
+
+        setUpSavedTab();
     }
 
     private void setUpTabs() {
@@ -137,6 +140,14 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
     public void onPageScrollStateChanged(int aPosition) {
     }
 
+    private void setUpSavedTab() {
+        getSupportActionBar().setSelectedNavigationItem(loadTabIndex());
+    }
+
+    private int loadTabIndex() {
+        return Preferences.getApplicationStatesInstance(this).getInt("saved_tab");
+    }
+
     private void setUpComputersList() {
         Fragment aComputersFragment = ComputersFragment.newInstance(ComputersFragment.Type.WIFI);
 
@@ -189,6 +200,19 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
         Intent aIntent = Intents.buildLicensesIntent(this);
         startActivity(aIntent);
     }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+
+        saveTabIndex();
+    }
+
+    private void saveTabIndex() {
+        int aTabIndex = getSupportActionBar().getSelectedNavigationIndex();
+
+        Preferences.getApplicationStatesInstance(this).setInt("saved_tab", aTabIndex);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
index e81d3b7..f91fbf7 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
@@ -46,11 +46,11 @@ final class PairingProvider {
     }
 
     private String getSavedPin(Server aServer) {
-        return mAuthorizedServersPreferences.get(aServer.getAddress());
+        return mAuthorizedServersPreferences.getString(aServer.getAddress());
     }
 
     private void savePin(Server aServer, String aPin) {
-        mAuthorizedServersPreferences.set(aServer.getAddress(), aPin);
+        mAuthorizedServersPreferences.setString(aServer.getAddress(), aPin);
     }
 
     public static String getPairingDeviceName(Context aContext) {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
index 459f4e6..bb8ac0e 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
@@ -101,7 +101,7 @@ class ServersManager implements Comparator<Server> {
     }
 
     public void addTcpServer(String aAddress, String aName) {
-        mSavedServersPreferences.set(aAddress, aName);
+        mSavedServersPreferences.setString(aAddress, aName);
     }
 
     public void removeServer(Server aServer) {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
index 9c7c7f8..e39b31a 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
@@ -20,6 +20,7 @@ public final class Preferences {
 
         public static final String AUTHORIZED_SERVERS = "authorized_servers";
         public static final String SAVED_SERVERS = "saved_servers";
+        public static final String APPLICATION_STATES = "application_states";
     }
 
     private final SharedPreferences mPreferences;
@@ -40,18 +41,30 @@ public final class Preferences {
         return new Preferences(aContext, Locations.SAVED_SERVERS);
     }
 
+    public static Preferences getApplicationStatesInstance(Context aContext) {
+        return new Preferences(aContext, Locations.APPLICATION_STATES);
+    }
+
     public Map<String, ?> getAll() {
         return mPreferences.getAll();
     }
 
-    public String get(String aKey) {
+    public String getString(String aKey) {
         return mPreferences.getString(aKey, null);
     }
 
-    public void set(String aKey, String aValue) {
+    public int getInt(String aKey) {
+        return mPreferences.getInt(aKey, 0);
+    }
+
+    public void setString(String aKey, String aValue) {
         mPreferences.edit().putString(aKey, aValue).commit();
     }
 
+    public void setInt(String aKey, int aValue) {
+        mPreferences.edit().putInt(aKey, aValue).commit();
+    }
+
     public void remove(String aKey) {
         mPreferences.edit().remove(aKey).commit();
     }
commit 38a3eba78d3aa0fe34268a84e14a5af2823aa342
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sat Aug 3 16:39:25 2013 +0300

    Change the Preferences class.
    
    * Remove context dependency.
    * Modify the interface for easy usage.
    
    Change-Id: I9dfabbea1ec9ec9224dc8238a1884fdf695fc8db

diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
index 7329fd2..e81d3b7 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
@@ -15,10 +15,10 @@ import android.os.Build;
 import org.libreoffice.impressremote.util.Preferences;
 
 final class PairingProvider {
-    private final Context mContext;
+    private final Preferences mAuthorizedServersPreferences;
 
     private PairingProvider(Context aContext) {
-        mContext = aContext;
+        mAuthorizedServersPreferences = Preferences.getAuthorizedServersInstance(aContext);
     }
 
     public static boolean isPairingNecessary(Server aServer) {
@@ -46,17 +46,11 @@ final class PairingProvider {
     }
 
     private String getSavedPin(Server aServer) {
-        String aLocation = Preferences.Locations.AUTHORIZED_REMOTES;
-        String aServerAddress = aServer.getAddress();
-
-        return Preferences.getString(mContext, aLocation, aServerAddress);
+        return mAuthorizedServersPreferences.get(aServer.getAddress());
     }
 
     private void savePin(Server aServer, String aPin) {
-        String aLocation = Preferences.Locations.AUTHORIZED_REMOTES;
-        String aServerAddress = aServer.getAddress();
-
-        Preferences.set(mContext, aLocation, aServerAddress, aPin);
+        mAuthorizedServersPreferences.set(aServer.getAddress(), aPin);
     }
 
     public static String getPairingDeviceName(Context aContext) {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
index 337c05c..459f4e6 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
@@ -22,20 +22,18 @@ import android.content.Context;
 import org.libreoffice.impressremote.util.Preferences;
 
 class ServersManager implements Comparator<Server> {
-    private final Context mContext;
-
     private final ServersFinder mBluetoothServersFinder;
     private final ServersFinder mTcpServersFinder;
 
     private final Set<Server> mBlacklistedServers;
+    private final Preferences mSavedServersPreferences;
 
     public ServersManager(Context aContext) {
-        mContext = aContext;
-
-        mBluetoothServersFinder = new BluetoothServersFinder(mContext);
-        mTcpServersFinder = new TcpServersFinder(mContext);
+        mBluetoothServersFinder = new BluetoothServersFinder(aContext);
+        mTcpServersFinder = new TcpServersFinder(aContext);
 
         mBlacklistedServers = new HashSet<Server>();
+        mSavedServersPreferences = Preferences.getSavedServersInstance(aContext);
     }
 
     public void startServersSearch() {
@@ -63,8 +61,7 @@ class ServersManager implements Comparator<Server> {
     }
 
     private List<Server> getManualAddedTcpServers() {
-        Map<String, ?> aServersEntries = Preferences
-            .getAll(mContext, Preferences.Locations.STORED_SERVERS);
+        Map<String, ?> aServersEntries = mSavedServersPreferences.getAll();
 
         return buildTcpServers(aServersEntries);
     }
@@ -104,8 +101,7 @@ class ServersManager implements Comparator<Server> {
     }
 
     public void addTcpServer(String aAddress, String aName) {
-        Preferences.set(mContext, Preferences.Locations.STORED_SERVERS,
-            aAddress, aName);
+        mSavedServersPreferences.set(aAddress, aName);
     }
 
     public void removeServer(Server aServer) {
@@ -129,8 +125,7 @@ class ServersManager implements Comparator<Server> {
     }
 
     private void removeManualAddedServer(Server aServer) {
-        Preferences.remove(mContext, Preferences.Locations.STORED_SERVERS,
-            aServer.getAddress());
+        mSavedServersPreferences.remove(aServer.getAddress());
     }
 
     private void blacklistServer(Server aServer) {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
index 749d3ab..9c7c7f8 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
@@ -14,45 +14,46 @@ import android.content.Context;
 import android.content.SharedPreferences;
 
 public final class Preferences {
-    public static final class Locations {
+    private static final class Locations {
         private Locations() {
         }
 
-        public static final String AUTHORIZED_REMOTES = "sdremote_authorisedremotes";
-        public static final String STORED_SERVERS = "sdremote_storedServers";
+        public static final String AUTHORIZED_SERVERS = "authorized_servers";
+        public static final String SAVED_SERVERS = "saved_servers";
     }
 
-    private Preferences() {
-    }
+    private final SharedPreferences mPreferences;
 
-    private static SharedPreferences getPreferences(Context aContext, String aLocation) {
-        return aContext.getSharedPreferences(aLocation, Context.MODE_PRIVATE);
+    public static Preferences getAuthorizedServersInstance(Context aContext) {
+        return new Preferences(aContext, Locations.AUTHORIZED_SERVERS);
     }
 
-    public static Map<String, ?> getAll(Context aContext, String aLocation) {
-        return getPreferences(aContext, aLocation).getAll();
+    private Preferences(Context aContext, String aLocation) {
+        mPreferences = getPreferences(aContext, aLocation);
     }
 
-    public static String getString(Context aContext, String aLocation, String aKey) {
-        return getPreferences(aContext, aLocation).getString(aKey, null);
+    private SharedPreferences getPreferences(Context aContext, String aLocation) {
+        return aContext.getSharedPreferences(aLocation, Context.MODE_PRIVATE);
     }
 
-    public static void set(Context aContext, String aLocation, String aKey, String aValue) {
-        SharedPreferences.Editor aPreferencesEditor = getPreferences(aContext,
-            aLocation).edit();
-
-        aPreferencesEditor.putString(aKey, aValue);
+    public static Preferences getSavedServersInstance(Context aContext) {
+        return new Preferences(aContext, Locations.SAVED_SERVERS);
+    }
 
-        aPreferencesEditor.commit();
+    public Map<String, ?> getAll() {
+        return mPreferences.getAll();
     }
 
-    public static void remove(Context aContext, String aLocation, String aKey) {
-        SharedPreferences.Editor aPreferencesEditor = getPreferences(aContext,
-            aLocation).edit();
+    public String get(String aKey) {
+        return mPreferences.getString(aKey, null);
+    }
 
-        aPreferencesEditor.remove(aKey);
+    public void set(String aKey, String aValue) {
+        mPreferences.edit().putString(aKey, aValue).commit();
+    }
 
-        aPreferencesEditor.commit();
+    public void remove(String aKey) {
+        mPreferences.edit().remove(aKey).commit();
     }
 }
 
commit ef5342c677e2d28f46401dac02fc5a3d4c0c1bd0
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sat Aug 3 15:30:16 2013 +0300

    Fix updating of all slides even it is not necessary.
    
    Change-Id: I6f7937296915a7cff71d9d9ee491736a0c2c31be

diff --git a/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java b/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java
index 02097d2..be6f84f 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java
@@ -85,7 +85,7 @@ public class SlidesPagerAdapter extends PagerAdapter {
 
     @Override
     public int getItemPosition(Object aObject) {
-        // TODO: think about it, seems like a hack
+        // There seems no other way to update slides with notifyDataSetChanged.
 
         return POSITION_NONE;
     }
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
index 838245a..0c22801 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
@@ -200,7 +200,9 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn
             }
 
             if (Intents.Actions.SLIDE_PREVIEW.equals(aIntent.getAction())) {
-                mSlidesPagerFragment.refreshSlidesPager();
+                int aSlideIndex = aIntent.getIntExtra(Intents.Extras.SLIDE_INDEX, 0);
+
+                mSlidesPagerFragment.refreshSlide(aSlideIndex);
             }
         }
     }
@@ -221,6 +223,30 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn
         return LocalBroadcastManager.getInstance(aContext);
     }
 
+    private void refreshSlide(int aSlideIndex) {
+        // Refresh only loaded slides to avoid images blinking on large slides count.
+        // There is no way to invalidate only a certain slide.
+
+        int aCurrentSlideIndex = mCommunicationService.getSlideShow().getCurrentSlideIndex();
+
+        if (aSlideIndex == aCurrentSlideIndex) {
+            refreshSlidesPager();
+            return;
+        }
+
+        int aSlidesOffscreenCount = getSlidesPager().getOffscreenPageLimit();
+
+        if (aSlideIndex < aCurrentSlideIndex - aSlidesOffscreenCount) {
+            return;
+        }
+
+        if (aSlideIndex > aCurrentSlideIndex + aSlidesOffscreenCount) {
+            return;
+        }
+
+        refreshSlidesPager();
+    }
+
     private void refreshSlidesPager() {
         getSlidesPager().getAdapter().notifyDataSetChanged();
     }
commit 20a17af069891da72ae6024436fa39d365c5c654
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sat Aug 3 04:01:59 2013 +0300

    Move computer creation layout to scroll view.
    
    * Allows to use auto-focus.
    * Should probably be better on devices with small displays in landscape
      mode.
    
    Change-Id: I745ffbf1aef5f757b54155a9e79e99026c49dd86

diff --git a/android/sdremote/res/layout/activity_computer_creation.xml b/android/sdremote/res/layout/activity_computer_creation.xml
index 74751ea9..50fde03 100644
--- a/android/sdremote/res/layout/activity_computer_creation.xml
+++ b/android/sdremote/res/layout/activity_computer_creation.xml
@@ -1,25 +1,31 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              android:orientation="vertical"
-              android:padding="@dimen/padding_creation_layout"
-              android:layout_width="match_parent"
-              android:layout_height="match_parent">
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
 
-    <EditText
-        android:id="@+id/edit_ip_address"
-        android:singleLine="true"
-        android:inputType="phone"
-        android:hint="@string/hint_ip_address"
+    <LinearLayout
+        android:orientation="vertical"
+        android:padding="@dimen/padding_creation_layout"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"/>
+        android:layout_height="wrap_content">
 
-    <EditText
-        android:id="@+id/edit_name"
-        android:singleLine="true"
-        android:inputType="text|textCapSentences"
-        android:hint="@string/hint_name"
-        android:paddingTop="@dimen/padding_vertical_edit"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"/>
+        <EditText
+            android:id="@+id/edit_ip_address"
+            android:singleLine="true"
+            android:inputType="phone"
+            android:hint="@string/hint_ip_address"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"/>
+
+        <EditText
+            android:id="@+id/edit_name"
+            android:singleLine="true"
+            android:inputType="text|textCapSentences"
+            android:hint="@string/hint_name"
+            android:paddingTop="@dimen/padding_vertical_edit"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"/>
+
+    </LinearLayout>
 
-</LinearLayout>
\ No newline at end of file
+</ScrollView>
\ No newline at end of file
commit 53738414d34574d4c5fa06aba52b097f14b7dc17
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sat Aug 3 01:26:36 2013 +0300

    Fix possible negative time setting when time is up.
    
    Change-Id: Ic519480dd85075b0122d8ef8fcb32c1a68542ae3

diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
index 4cde89d..791861c 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
@@ -325,16 +325,19 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
     }
 
     private void callEditingTimer(Timer aTimer) {
-        int aTimerLength = aTimer.getMinutesLeft();
-
-        DialogFragment aFragment = TimerEditingDialog.newInstance(aTimerLength);
+        DialogFragment aFragment = buildTimerEditingDialog(aTimer);
         aFragment.show(getSupportFragmentManager(), TimerEditingDialog.TAG);
 
-        pauseTimer();
+        aTimer.pause();
     }
 
-    private void pauseTimer() {
-        mCommunicationService.getSlideShow().getTimer().pause();
+    private DialogFragment buildTimerEditingDialog(Timer aTimer) {
+        if (aTimer.isTimeUp()) {
+            return TimerEditingDialog.newInstance(aTimer.getMinutesLength());
+        }
+        else {
+            return TimerEditingDialog.newInstance(aTimer.getMinutesLeft());
+        }
     }
 
     private void callSettingTimer() {
commit 943a989139f8274b84ddbae41e27bf02433331d5
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sat Aug 3 01:25:44 2013 +0300

    Add more expression to the warning text.
    
    Change-Id: Ic535c4f744a1564f847e4ba4e9f312f82fc07e72

diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 92a2022..d6d4f3b 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -32,7 +32,7 @@
     <string name="message_impress_wifi_enabling">You should enable experimental features at “Tools → Options → LibreOffice → Advanced” as well.</string>
     <string name="message_impress_pairing_check">If you have Bluetooth pairing issues check instructions related to your desktop OS.</string>
     <string name="message_ip_address_validation">Type in a valid IP address.</string>
-    <string name="message_time_is_up">Time is up</string>
+    <string name="message_time_is_up">Time is up!</string>
 
     <string name="hint_ip_address">IP address</string>
     <string name="hint_name">Name (optional)</string>
commit b2e2f08837decc02e26fd9d3621794a111d6e91e
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sat Aug 3 00:03:51 2013 +0300

    Fix slide show orientation changes crashes.
    
    Change-Id: I6539d4b36fd858dd7eb609acc2e58c8851f3bfe4

diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
index fc0f7c6..4cde89d 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
@@ -385,7 +385,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
 
         stopTimer();
 
-        disconnectComputer();
+        // TODO: disconnect computer
 
         unbindService();
     }
@@ -394,10 +394,6 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
         mCommunicationService.getSlideShow().getTimer().stop();
     }
 
-    private void disconnectComputer() {
-        mCommunicationService.disconnect();
-    }
-
     private void unbindService() {
         unbindService(this);
     }
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index 51ca64c..e6dd88a 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -45,6 +45,7 @@ public class CommunicationService extends Service implements Runnable, MessagesL
 
     private boolean mBluetoothWasEnabled;
 
+    private Timer mTimer;
     private SlideShow mSlideShow;
 
     private Thread mThread;
@@ -62,7 +63,8 @@ public class CommunicationService extends Service implements Runnable, MessagesL
 
         mBluetoothWasEnabled = false;
 
-        mSlideShow = new SlideShow(new Timer(this));
+        mTimer = new Timer(this);
+        mSlideShow = new SlideShow(mTimer);
 
         mThread = new Thread(this);
         mThread.start();
@@ -247,7 +249,7 @@ public class CommunicationService extends Service implements Runnable, MessagesL
 
     @Override
     public void onSlideShowStart(int aSlidesCount, int aCurrentSlideIndex) {
-        mSlideShow.cleanUp();
+        mSlideShow = new SlideShow(mTimer);
         mSlideShow.setSlidesCount(aSlidesCount);
 
         Intent aIntent = Intents.buildSlideShowRunningIntent();
@@ -258,7 +260,7 @@ public class CommunicationService extends Service implements Runnable, MessagesL
 
     @Override
     public void onSlideShowFinish() {
-        mSlideShow.cleanUp();
+        mSlideShow = new SlideShow(mTimer);
 
         Intent aIntent = Intents.buildSlideShowStoppedIntent();
         LocalBroadcastManager.getInstance(this).sendBroadcast(aIntent);
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/MessagesReceiver.java b/android/sdremote/src/org/libreoffice/impressremote/communication/MessagesReceiver.java
index bb6de8f..4d226d8 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/MessagesReceiver.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/MessagesReceiver.java
@@ -14,12 +14,10 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import android.text.TextUtils;
 import android.util.Base64;
-import android.util.Log;
 
 class MessagesReceiver implements Runnable {
     private final BufferedReader mMessagesReader;
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java
index f6aa6dd..1996368 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java
@@ -75,14 +75,6 @@ public class SlideShow {
     public Timer getTimer() {
         return mTimer;
     }
-
-    public void cleanUp() {
-        mSlidesCount = 0;
-        mCurrentSlideIndex = 0;
-
-        mSlidePreviewsBytes.clear();
-        mSlideNotes.clear();
-    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java
index dcfd6ef..021a492 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java
@@ -24,6 +24,7 @@ import android.widget.AdapterView;
 import android.widget.GridView;
 
 import com.actionbarsherlock.app.SherlockFragment;
+import org.libreoffice.impressremote.communication.SlideShow;
 import org.libreoffice.impressremote.util.Intents;
 import org.libreoffice.impressremote.R;
 import org.libreoffice.impressremote.adapter.SlidesGridAdapter;
@@ -63,17 +64,31 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne
     }
 
     private void setUpSlidesGrid() {
-        SlidesGridAdapter aSlidesGridAdapter = new SlidesGridAdapter(getActivity(),
-            mCommunicationService.getSlideShow());
+        if (!isAdded()) {
+            return;
+        }
 
-        getSlidesGrid().setAdapter(aSlidesGridAdapter);
-        getSlidesGrid().setOnItemClickListener(this);
+        GridView aSlidesGrid = getSlidesGrid();
+
+        aSlidesGrid.setAdapter(buildSlidesAdapter());
+        aSlidesGrid.setOnItemClickListener(this);
     }
 
     private GridView getSlidesGrid() {
         return (GridView) getView().findViewById(R.id.grid_slides);
     }
 
+    private SlidesGridAdapter buildSlidesAdapter() {
+        SlideShow aSlideShow = mCommunicationService.getSlideShow();
+
+        return new SlidesGridAdapter(getActivity(), aSlideShow);
+    }
+
+    @Override
+    public void onItemClick(AdapterView<?> aAdapterView, View aView, int aPosition, long aId) {
+        mCommunicationService.getTransmitter().setCurrentSlide(aPosition);
+    }
+
     @Override
     public void onServiceDisconnected(ComponentName aComponentName) {
         mCommunicationService = null;
@@ -93,11 +108,6 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne
         getBroadcastManager().registerReceiver(mIntentsReceiver, aIntentFilter);
     }
 
-    @Override
-    public void onItemClick(AdapterView<?> aAdapterView, View aView, int aPosition, long aId) {
-        mCommunicationService.getTransmitter().setCurrentSlide(aPosition);
-    }
-
     private static final class IntentsReceiver extends BroadcastReceiver {
         private final SlidesGridFragment mSlidesGridFragment;
 
@@ -109,7 +119,6 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne
         public void onReceive(Context aContext, Intent aIntent) {
             if (Intents.Actions.SLIDE_SHOW_RUNNING.equals(aIntent.getAction())) {
                 mSlidesGridFragment.refreshSlidesGrid();
-
                 return;
             }
 
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
index 3092503..838245a 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java
@@ -21,8 +21,6 @@ import android.support.v4.view.PagerAdapter;
 import android.support.v4.view.ViewPager;
 import android.text.Html;
 import android.text.TextUtils;
-import android.util.DisplayMetrics;
-import android.util.TypedValue;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -70,10 +68,14 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn
     }
 
     private void setUpSlidesPager() {
+        if (!isAdded()) {
+            return;
+        }
+
         ViewPager aSlidesPager = getSlidesPager();
 
         aSlidesPager.setAdapter(buildSlidesAdapter());
-        aSlidesPager.setPageMargin(getSlidesMarginInPx());
+        aSlidesPager.setPageMargin(getSlidesMargin());
         aSlidesPager.setOnPageChangeListener(this);
 
         setUpCurrentSlide();
@@ -89,12 +91,8 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn
         return new SlidesPagerAdapter(getActivity(), aSlideShow);
     }
 
-    private int getSlidesMarginInPx() {
-        int aPxUnit = TypedValue.COMPLEX_UNIT_PX;
-        float aSlideMarginInDp = getResources().getDimension(R.dimen.margin_slide);
-        DisplayMetrics aDisplayMetrics = getResources().getDisplayMetrics();
-
-        return (int) TypedValue.applyDimension(aPxUnit, aSlideMarginInDp, aDisplayMetrics);
+    private int getSlidesMargin() {
+        return getResources().getDimensionPixelSize(R.dimen.margin_slide);
     }
 
     private void setUpCurrentSlide() {
@@ -186,21 +184,33 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn
 
         @Override
         public void onReceive(Context aContext, Intent aIntent) {
-            if (Intents.Actions.SLIDE_PREVIEW.equals(aIntent.getAction())) {
-                mSlidesPagerFragment.refreshSlidesPager();
+            if (Intents.Actions.SLIDE_SHOW_RUNNING.equals(aIntent.getAction())) {
+                mSlidesPagerFragment.setUpSlidesPager();
+                return;
+            }
+
+            if (Intents.Actions.SLIDE_SHOW_STOPPED.equals(aIntent.getAction())) {
+                mSlidesPagerFragment.setUpSlidesPager();
                 return;
             }
 
             if (Intents.Actions.SLIDE_CHANGED.equals(aIntent.getAction())) {
                 mSlidesPagerFragment.setUpCurrentSlide();
+                return;
+            }
+
+            if (Intents.Actions.SLIDE_PREVIEW.equals(aIntent.getAction())) {
+                mSlidesPagerFragment.refreshSlidesPager();
             }
         }
     }
 
     private IntentFilter buildIntentsReceiverFilter() {
         IntentFilter aIntentFilter = new IntentFilter();
-        aIntentFilter.addAction(Intents.Actions.SLIDE_PREVIEW);
+        aIntentFilter.addAction(Intents.Actions.SLIDE_SHOW_RUNNING);
+        aIntentFilter.addAction(Intents.Actions.SLIDE_SHOW_STOPPED);
         aIntentFilter.addAction(Intents.Actions.SLIDE_CHANGED);
+        aIntentFilter.addAction(Intents.Actions.SLIDE_PREVIEW);
 
         return aIntentFilter;
     }
commit d4b4c94aa185093927866818b81816452310c5f3
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Fri Aug 2 17:42:19 2013 +0300

    Add saving current mode when showing a slide show.
    
    Should be helpful on orientation changes.
    
    Change-Id: I0a00c980882decc3da3460f63b82c5d0bb308298

diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
index f739394..fc0f7c6 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
@@ -46,10 +46,10 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
     private IntentsReceiver mIntentsReceiver;
 
     @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
+    protected void onCreate(Bundle aSavedInstanceState) {
+        super.onCreate(aSavedInstanceState);
 
-        mMode = Mode.PAGER;
+        mMode = loadMode(aSavedInstanceState);
 
         setUpHomeButton();
         setUpFragment();
@@ -57,6 +57,14 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
         bindService();
     }
 
+    private Mode loadMode(Bundle aSavedInstanceState) {
+        if (aSavedInstanceState == null) {
+            return Mode.PAGER;
+        }
+
+        return (Mode) aSavedInstanceState.getSerializable("MODE");
+    }
+
     private void setUpHomeButton() {
         getSupportActionBar().setHomeButtonEnabled(true);
     }
@@ -131,6 +139,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
             if (Intents.Actions.TIMER_STARTED.equals(aIntent.getAction())) {
                 int aMinutesLength = aIntent.getIntExtra(Intents.Extras.MINUTES, 0);
                 mSlideShowActivity.startTimer(aMinutesLength);
+                mSlideShowActivity.setUpSlideShowInformation();
                 return;
             }
 
@@ -208,8 +217,6 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
 
         aTimer.setMinutesLength(aMinutesLength);
         aTimer.start();
-
-        setUpSlideShowInformation();
     }
 
     private void resumeTimer() {
@@ -358,9 +365,24 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
     }
 
     @Override
+    protected void onSaveInstanceState(Bundle aOutState) {
+        super.onSaveInstanceState(aOutState);
+
+        saveMode(aOutState);
+    }
+
+    private void saveMode(Bundle aOutState) {
+        aOutState.putSerializable("MODE", mMode);
+    }
+
+    @Override
     protected void onDestroy() {
         super.onDestroy();
 
+        if (!isServiceBound()) {
+            return;
+        }
+
         stopTimer();
 
         disconnectComputer();
@@ -373,18 +395,10 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
     }
 
     private void disconnectComputer() {
-        if (!isServiceBound()) {
-            return;
-        }
-
         mCommunicationService.disconnect();
     }
 
     private void unbindService() {
-        if (!isServiceBound()) {
-            return;
-        }
-
         unbindService(this);
     }
 


More information about the Libreoffice-commits mailing list