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

Artur Dryomov artur.dryomov at gmail.com
Thu Sep 19 14:23:55 PDT 2013


 android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java           |    9 ++-
 android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java |   19 ++++++
 android/sdremote/src/org/libreoffice/impressremote/communication/Server.java                 |   30 +++++++---
 android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java         |   26 ++++++++
 android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java          |   25 ++++++--
 android/sdremote/src/org/libreoffice/impressremote/util/Intents.java                         |   13 +++-
 6 files changed, 102 insertions(+), 20 deletions(-)

New commits:
commit 95e95e0a26694dd01412220eb6b44150dfead2bf
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Thu Sep 19 12:47:45 2013 +0300

    Add switching to the slides pager from the grid when selecting a slide.
    
    Change-Id: I029c298a90ff7f0cbaada25388e3a758dc4d583e

diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
index defd6a0..3c41ecc 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java
@@ -40,7 +40,7 @@ import org.libreoffice.impressremote.util.Preferences;
 import org.libreoffice.impressremote.util.SavedStates;
 
 public class SlideShowActivity extends SherlockFragmentActivity implements ServiceConnection {
-    private static enum Mode {
+    public static enum Mode {
         PAGER, GRID, EMPTY
     }
 
@@ -160,6 +160,12 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
 
         @Override
         public void onReceive(Context aContext, Intent aIntent) {
+            if (Intents.Actions.SLIDE_SHOW_MODE_CHANGED.equals(aIntent.getAction())) {
+                Mode aMode = (Mode) aIntent.getSerializableExtra(Intents.Extras.MODE);
+                mSlideShowActivity.changeMode(aMode);
+                return;
+            }
+
             if (Intents.Actions.SLIDE_CHANGED.equals(aIntent.getAction())) {
                 mSlideShowActivity.setUpSlideShowInformation();
                 return;
@@ -193,6 +199,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi
 
     private IntentFilter buildIntentsReceiverFilter() {
         IntentFilter aIntentFilter = new IntentFilter();
+        aIntentFilter.addAction(Intents.Actions.SLIDE_SHOW_MODE_CHANGED);
         aIntentFilter.addAction(Intents.Actions.SLIDE_CHANGED);
         aIntentFilter.addAction(Intents.Actions.TIMER_UPDATED);
         aIntentFilter.addAction(Intents.Actions.TIMER_STARTED);
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java
index 14e46e0..053648b 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.activity.SlideShowActivity;
 import org.libreoffice.impressremote.communication.SlideShow;
 import org.libreoffice.impressremote.util.Intents;
 import org.libreoffice.impressremote.R;
@@ -86,7 +87,23 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne
 
     @Override
     public void onItemClick(AdapterView<?> aAdapterView, View aView, int aPosition, long aId) {
-        mCommunicationService.getCommandsTransmitter().setCurrentSlide(aPosition);
+        changeCurrentSlide(aPosition);
+        changeSlideShowMode();
+    }
+
+    private void changeCurrentSlide(int aSlideIndex) {
+        mCommunicationService.getCommandsTransmitter().setCurrentSlide(aSlideIndex);
+    }
+
+    private void changeSlideShowMode() {
+        Intent aIntent = Intents.buildSlideShowModeChangedIntent(SlideShowActivity.Mode.PAGER);
+        getBroadcastManager().sendBroadcast(aIntent);
+    }
+
+    private LocalBroadcastManager getBroadcastManager() {
+        Context aContext = getActivity().getApplicationContext();
+
+        return LocalBroadcastManager.getInstance(aContext);
     }
 
     @Override
@@ -138,12 +155,6 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne
         return aIntentFilter;
     }
 
-    private LocalBroadcastManager getBroadcastManager() {
-        Context aContext = getActivity().getApplicationContext();
-
-        return LocalBroadcastManager.getInstance(aContext);
-    }
-
     private void refreshSlidesGrid() {
         getSlidesGrid().invalidateViews();
     }
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
index a6ade2d..beab7ae 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
@@ -38,6 +38,8 @@ public final class Intents {
         public static final String SLIDE_SHOW_RUNNING = "SLIDE_SHOW_RUNNING";
         public static final String SLIDE_SHOW_STOPPED = "SLIDE_SHOW_STOPPED";
 
+        public static final String SLIDE_SHOW_MODE_CHANGED = "SLIDE_SHOW_MODE_CHANGED";
+
         public static final String SLIDE_CHANGED = "SLIDE_CHANGED";
         public static final String SLIDE_PREVIEW = "SLIDE_PREVIEW";
         public static final String SLIDE_NOTES = "SLIDE_NOTES";
@@ -53,12 +55,12 @@ public final class Intents {
         }
 
         public static final String MINUTES = "MINUTES";
+        public static final String MODE = "MODE";
         public static final String PIN = "PIN";
-        public static final String SLIDE_INDEX = "SLIDE_INDEX";
-
         public static final String SERVER = "SERVER";
         public static final String SERVER_ADDRESS = "SERVER_ADDRESS";
         public static final String SERVER_NAME = "SERVER_NAME";
+        public static final String SLIDE_INDEX = "SLIDE_INDEX";
     }
 
     public static final class RequestCodes {
@@ -95,6 +97,13 @@ public final class Intents {
         return new Intent(Actions.SLIDE_SHOW_STOPPED);
     }
 
+    public static Intent buildSlideShowModeChangedIntent(SlideShowActivity.Mode aMode) {
+        Intent aIntent = new Intent(Actions.SLIDE_SHOW_MODE_CHANGED);
+        aIntent.putExtra(Extras.MODE, aMode);
+
+        return aIntent;
+    }
+
     public static Intent buildSlideChangedIntent(int aSlideIndex) {
         Intent aIntent = new Intent(Actions.SLIDE_CHANGED);
         aIntent.putExtra(Extras.SLIDE_INDEX, aSlideIndex);
commit 6d6017e353fe793d571d5d976d27ad0490c6f38a
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Tue Sep 17 17:33:11 2013 +0300

    Add additional comparison for servers in lists.
    
    Sort by class as well as by name. This change should help to show
    computers first, then phones and then other devices.
    
    Change-Id: I3a5dec6e5df33b766b70798ac1ad32a5d5db4a3f

diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
index 4d7619b..29e9b9c 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
@@ -15,6 +15,7 @@ import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothDevice;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -116,10 +117,26 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
     }
 
     private Server buildServer(BluetoothDevice aBluetoothDevice) {
+        Server.Type aServerType = buildServerType(aBluetoothDevice);
         String aServerAddress = aBluetoothDevice.getAddress();
         String aServerName = aBluetoothDevice.getName();
 
-        return Server.newBluetoothInstance(aServerAddress, aServerName);
+        return Server.newBluetoothInstance(aServerType, aServerAddress, aServerName);
+    }
+
+    private Server.Type buildServerType(BluetoothDevice aBluetoothDevice) {
+        int aBluetoothClass = aBluetoothDevice.getBluetoothClass().getMajorDeviceClass();
+
+        switch (aBluetoothClass) {
+            case BluetoothClass.Device.Major.COMPUTER:
+                return Server.Type.COMPUTER;
+
+            case BluetoothClass.Device.Major.PHONE:
+                return Server.Type.PHONE;
+
+            default:
+                return Server.Type.UNDEFINED;
+        }
     }
 
     private void callUpdatingServersList() {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Server.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Server.java
index de5c41d..4053c4f 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/Server.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Server.java
@@ -19,28 +19,38 @@ public class Server implements Parcelable {
         TCP, BLUETOOTH
     }
 
+    public static enum Type {
+        COMPUTER, PHONE, UNDEFINED
+    }
+
     private final Protocol mProtocol;
+    private final Type mType;
     private final String mAddress;
     private final String mName;
 
-    private Server(Protocol aProtocol, String aAddress, String aName) {
-        this.mProtocol = aProtocol;
-        this.mAddress = aAddress;
-        this.mName = aName;
+    private Server(Protocol aProtocol, Type aType, String aAddress, String aName) {
+        mProtocol = aProtocol;
+        mType = aType;
+        mAddress = aAddress;
+        mName = aName;
     }
 
     public static Server newTcpInstance(String aAddress, String aName) {
-        return new Server(Protocol.TCP, aAddress, aName);
+        return new Server(Protocol.TCP, Type.UNDEFINED, aAddress, aName);
     }
 
-    public static Server newBluetoothInstance(String aAddress, String aName) {
-        return new Server(Protocol.BLUETOOTH, aAddress, aName);
+    public static Server newBluetoothInstance(Type aClass, String aAddress, String aName) {
+        return new Server(Protocol.BLUETOOTH, aClass, aAddress, aName);
     }
 
     public Protocol getProtocol() {
         return mProtocol;
     }
 
+    public Type getType() {
+        return mType;
+    }
+
     public String getAddress() {
         return mAddress;
     }
@@ -64,9 +74,10 @@ public class Server implements Parcelable {
 
     @Override
     public void writeToParcel(Parcel aParcel, int aFlags) {
+        aParcel.writeString(mProtocol.name());
+        aParcel.writeString(mType.name());
         aParcel.writeString(mAddress);
         aParcel.writeString(mName);
-        aParcel.writeString(mProtocol.name());
     }
 
     public static final Parcelable.Creator<Server> CREATOR = new Parcelable.Creator<Server>() {
@@ -80,9 +91,10 @@ public class Server implements Parcelable {
     };
 
     private Server(Parcel aParcel) {
+        this.mProtocol = Protocol.valueOf(aParcel.readString());
+        this.mType = Type.valueOf(aParcel.readString());
         this.mAddress = aParcel.readString();
         this.mName = aParcel.readString();
-        this.mProtocol = Protocol.valueOf(aParcel.readString());
     }
 }
 
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
index bb8ac0e..eac2ec1 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
@@ -22,6 +22,13 @@ import android.content.Context;
 import org.libreoffice.impressremote.util.Preferences;
 
 class ServersManager implements Comparator<Server> {
+    private static final class CompareResult {
+        private CompareResult() {
+        }
+
+        public static final int EQUAL = 0;
+    }
+
     private final ServersFinder mBluetoothServersFinder;
     private final ServersFinder mTcpServersFinder;
 
@@ -94,6 +101,25 @@ class ServersManager implements Comparator<Server> {
 
     @Override
     public int compare(Server aFirstServer, Server aSecondServer) {
+        int aServersTypesComparison = compareServersTypes(aFirstServer, aSecondServer);
+        int aServersNamesComparison = compareServersNames(aFirstServer, aSecondServer);
+
+        if (aServersTypesComparison != CompareResult.EQUAL) {
+            return aServersTypesComparison;
+        }
+        else {
+            return aServersNamesComparison;
+        }
+    }
+
+    private int compareServersTypes(Server aFirstServer, Server aSecondServer) {
+        Server.Type aFirstServerType = aFirstServer.getType();
+        Server.Type aSecondServerType = aSecondServer.getType();
+
+        return aFirstServerType.compareTo(aSecondServerType);
+    }
+
+    private int compareServersNames(Server aFirstServer, Server aSecondServer) {
         String aFirstServerName = aFirstServer.getName();
         String aSecondServerName = aSecondServer.getName();
 


More information about the Libreoffice-commits mailing list