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

Artur Dryomov artur.dryomov at gmail.com
Sat Sep 21 15:36:09 PDT 2013


 android/sdremote/res/values/dimens.xml                                                     |    2 
 android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java         |   65 ++++++++++
 android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java |   31 ----
 android/sdremote/src/org/libreoffice/impressremote/communication/TcpServersFinder.java     |    7 -
 android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java             |   24 ---
 android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java                   |    1 
 6 files changed, 70 insertions(+), 60 deletions(-)

New commits:
commit 036cf17cac1d4e8843cb49b67d3c588362d190ca
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sun Sep 22 00:19:55 2013 +0300

    Change TCP servers search blocking delay.
    
    Change-Id: Ia25d064aa5ad030d08a4095e92c3a35fb9b2e68f

diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/TcpServersFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/TcpServersFinder.java
index ed0c4c3..40b7553 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/TcpServersFinder.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/TcpServersFinder.java
@@ -33,7 +33,7 @@ import org.libreoffice.impressremote.util.Intents;
 
 class TcpServersFinder implements ServersFinder, Runnable {
     private static final int SEARCH_DELAY_IN_SECONDS = 5;
-    private static final int BLOCKING_TIMEOUT_IN_SECONDS = 10;
+    private static final int BLOCKING_TIMEOUT_IN_SECONDS = 5;
 
     private static final int SEARCH_RESULT_BUFFER_SIZE = 1024;
 
commit 7d70990265ec18e01d59898d31d5eabca4a1f2f9
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sat Sep 21 23:55:46 2013 +0300

    Fix possible unexpected search stop.
    
    An executor stops working when a single task got an exception. This
    change prevents only one exception from being uncaught, if this will not
    help probably everything should be caught.
    
    Change-Id: I76a57fc0b1c759cb66bf13b5cdec7223c384bfa3

diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/TcpServersFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/TcpServersFinder.java
index a35c1d6..ed0c4c3 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/TcpServersFinder.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/TcpServersFinder.java
@@ -133,8 +133,7 @@ class TcpServersFinder implements ServersFinder, Runnable {
     private DatagramPacket buildSearchResultPacket() {
         byte[] aSearchResultBuffer = new byte[SEARCH_RESULT_BUFFER_SIZE];
 
-        return new DatagramPacket(
-            aSearchResultBuffer, aSearchResultBuffer.length);
+        return new DatagramPacket(aSearchResultBuffer, aSearchResultBuffer.length);
     }
 
     private String receiveSearchResult(DatagramPacket aSearchResultPacket) {
@@ -145,7 +144,7 @@ class TcpServersFinder implements ServersFinder, Runnable {
         } catch (SocketTimeoutException e) {
             return "";
         } catch (IOException e) {
-            throw new RuntimeException("Unable to receive search result.");
+            return "";
         }
     }
 
commit 13cf8f2599a9888f2a6f1b9dd8938978b4a0274f
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sat Sep 21 22:17:34 2013 +0300

    Change way of saving Bluetooth state one more time.
    
    Read a comment at the ComputersActivity.
    
    Change-Id: I4a933d262c28a08c1e2227a2eabec54ad2cfd16e

diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
index 7b085e7..7ccd18e 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
@@ -26,6 +26,7 @@ import org.libreoffice.impressremote.util.Fragments;
 import org.libreoffice.impressremote.util.Intents;
 import org.libreoffice.impressremote.R;
 import org.libreoffice.impressremote.util.Preferences;
+import org.libreoffice.impressremote.util.SavedStates;
 
 public class ComputersActivity extends SherlockFragmentActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
     private static final class TabsIndices {
@@ -36,14 +37,44 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
         public static final int WIFI = 1;
     }
 
+    private boolean mBluetoothWasEnabled;
+
     @Override
     protected void onCreate(Bundle aSavedInstanceState) {
         super.onCreate(aSavedInstanceState);
 
+        saveBluetoothState(aSavedInstanceState);
+        enableBluetooth();
+
         setUpTitle();
         setUpContent();
     }
 
+    private void saveBluetoothState(Bundle aSavedInstanceState) {
+        // In more ideal world this work should be done at the service.
+        // Unfortunately service cannot save or restore its state
+        // but enabling or disabling Bluetooth is quite a long operation,
+        // so we have more chances to manage state right at the activity.
+
+        if (!BluetoothOperator.isAvailable()) {
+            return;
+        }
+
+        mBluetoothWasEnabled = wasBluetoothEnabled(aSavedInstanceState);
+    }
+
+    private boolean wasBluetoothEnabled(Bundle aSavedInstanceState) {
+        if (aSavedInstanceState == null) {
+            return BluetoothOperator.getAdapter().isEnabled();
+        }
+
+        return aSavedInstanceState.getBoolean(SavedStates.Keys.BLUETOOTH_ENABLED);
+    }
+
+    private void enableBluetooth() {
+        BluetoothOperator.enable();
+    }
+
     private void setUpTitle() {
         // Looks hacky but it seems to be the best way to set activity’s title
         // different to application’s label. The other way is setting title
@@ -234,6 +265,40 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio
 
         aPreferences.setInt(Preferences.Keys.SELECTED_COMPUTERS_TAB_INDEX, aTabIndex);
     }
+
+    @Override
+    protected void onSaveInstanceState(Bundle aSavedInstanceState) {
+        super.onSaveInstanceState(aSavedInstanceState);
+
+        rememberBluetoothState(aSavedInstanceState);
+    }
+
+    private void rememberBluetoothState(Bundle aSavedInstanceState) {
+        aSavedInstanceState.putBoolean(SavedStates.Keys.BLUETOOTH_ENABLED, mBluetoothWasEnabled);
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+
+        restoreBluetoothState();
+    }
+
+    private void restoreBluetoothState() {
+        if (!BluetoothOperator.isAvailable()) {
+            return;
+        }
+
+        if (mBluetoothWasEnabled) {
+            return;
+        }
+
+        disableBluetooth();
+    }
+
+    private void disableBluetooth() {
+        BluetoothOperator.disable();
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index 0db8b41..a8aa85f 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -36,8 +36,6 @@ public class CommunicationService extends Service implements Runnable, MessagesL
 
     private ServersManager mServersManager;
 
-    private BluetoothOperator.State mBluetoothState;
-
     private Timer mTimer;
     private SlideShow mSlideShow;
 
@@ -53,21 +51,10 @@ public class CommunicationService extends Service implements Runnable, MessagesL
 
         mServersManager = new ServersManager(this);
 
-        saveBluetoothState();
-        enableBluetooth();
-
         mTimer = new Timer(this);
         mSlideShow = new SlideShow(mTimer);
     }
 
-    private void saveBluetoothState() {
-        mBluetoothState = BluetoothOperator.getState();
-    }
-
-    private void enableBluetooth() {
-        BluetoothOperator.enable();
-    }
-
     @Override
     public IBinder onBind(Intent aIntent) {
         return mBinder;
@@ -237,24 +224,6 @@ public class CommunicationService extends Service implements Runnable, MessagesL
     public void onDestroy() {
         stopServersSearch();
         disconnectServer();
-
-        restoreBluetoothState();
-    }
-
-    private void restoreBluetoothState() {
-        if (!BluetoothOperator.isStateValid(mBluetoothState)) {
-            return;
-        }
-
-        if (mBluetoothState.wasBluetoothEnabled()) {
-            return;
-        }
-
-        disableBluetooth();
-    }
-
-    private void disableBluetooth() {
-        BluetoothOperator.disable();
     }
 }
 
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java b/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
index 56b05aa..9522838 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
@@ -11,18 +11,6 @@ package org.libreoffice.impressremote.util;
 import android.bluetooth.BluetoothAdapter;
 
 public final class BluetoothOperator {
-    public static final class State {
-        private final boolean mWasBluetoothEnabled;
-
-        private State(boolean aIsBluetoothEnabled) {
-            mWasBluetoothEnabled = aIsBluetoothEnabled;
-        }
-
-        public boolean wasBluetoothEnabled() {
-            return mWasBluetoothEnabled;
-        }
-    }
-
     private BluetoothOperator() {
     }
 
@@ -38,18 +26,6 @@ public final class BluetoothOperator {
         return BluetoothAdapter.getDefaultAdapter();
     }
 
-    public static State getState() {
-        if (!isAvailable()) {
-            return null;
-        }
-
-        return new State(getAdapter().isEnabled());
-    }
-
-    public static boolean isStateValid(State aState) {
-        return aState != null;
-    }
-
     public static void enable() {
         if (!isAvailable()) {
             return;
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java b/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java
index 682632c..7bc5dad 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java
@@ -16,6 +16,7 @@ public final class SavedStates {
         private Keys() {
         }
 
+        public static final String BLUETOOTH_ENABLED ="BLUETOOTH_ENABLED";
         public static final String CURRENT_VIEW_ID = "CURRENT_VIEW_ID";
         public static final String ERROR_MESSAGE = "ERROR_MESSAGE";
         public static final String MODE = "MODE";
commit afa322020e0bcedd8d44b0ee0e231fc261bf04d3
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sat Sep 21 19:28:19 2013 +0300

    Change slide width a bit.
    
    Change-Id: I26bdddaf0e74e81ccb32992e70e27d0d123f7502

diff --git a/android/sdremote/res/values/dimens.xml b/android/sdremote/res/values/dimens.xml
index 9b1e885..7da8e69 100644
--- a/android/sdremote/res/values/dimens.xml
+++ b/android/sdremote/res/values/dimens.xml
@@ -31,7 +31,7 @@
     <dimen name="margin_slide">8dp</dimen>
 
     <dimen name="width_action_bar_divider">0.5dp</dimen>
-    <dimen name="width_slides_grid_column">90dp</dimen>
+    <dimen name="width_slides_grid_column">88dp</dimen>
 
     <dimen name="text_size_list_item">18sp</dimen>
     <dimen name="text_size_pin">35sp</dimen>


More information about the Libreoffice-commits mailing list