diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2012-08-03 14:59:51 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2012-08-06 10:23:11 +0100 |
commit | c56b0a2fe8a54aef8229a7b32a8d62cc23bbd9e6 (patch) | |
tree | 158ca3adf290313923fb5a6ae713d4f03e2e88ac /android/sdremote | |
parent | ad72b47df44b6ac73a0b76b346d5e93811e6941f (diff) |
Added deletion of stale detected servers, UI fixed.
Change-Id: I I97a833b45e0c95a217004ae4a36e72a314d68d9f
Diffstat (limited to 'android/sdremote')
4 files changed, 48 insertions, 22 deletions
diff --git a/android/sdremote/res/layout/activity_selector.xml b/android/sdremote/res/layout/activity_selector.xml index 6f4cfa158cd8..c5c734b78daf 100644 --- a/android/sdremote/res/layout/activity_selector.xml +++ b/android/sdremote/res/layout/activity_selector.xml @@ -9,6 +9,13 @@ android:layout_margin="10dip" android:orientation="vertical" > + <TextView + android:id="@+id/selector_label_none" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/selector_noservers" + android:textAppearance="?android:attr/textAppearanceLarge" /> + <LinearLayout android:id="@+id/selector_container_bluetooth" android:layout_width="match_parent" @@ -16,13 +23,6 @@ android:orientation="vertical" > <TextView - android:id="@+id/selector_label_none" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/selector_noservers" - android:textAppearance="?android:attr/textAppearanceLarge" /> - - <TextView android:id="@+id/selector_label_bluetooth" android:layout_width="wrap_content" android:layout_height="wrap_content" diff --git a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java index 132b6e4eea28..201f41c4e846 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java @@ -70,6 +70,9 @@ public class SelectorActivity extends Activity { protected void onPause() { // TODO Auto-generated method stub super.onPause(); + if (mCommunicationService != null) { + mCommunicationService.stopFindingServers(); + } doUnbindService(); } @@ -89,6 +92,7 @@ public class SelectorActivity extends Activity { IBinder aService) { mCommunicationService = ((CommunicationService.CBinder) aService) .getService(); + mCommunicationService.startFindingServers(); } @Override @@ -160,9 +164,8 @@ public class SelectorActivity extends Activity { .setVisibility((mNetworkServers.size() != 0) ? View.VISIBLE : View.GONE); - mNoServerLabel.setVisibility((mBluetoothServers.size() == 0) - && (mNetworkServers.size() == 0) ? View.VISIBLE - : View.GONE); + mNoServerLabel.setVisibility(((mBluetoothServers.size() == 0) && (mNetworkServers + .size() == 0)) ? View.VISIBLE : View.GONE); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java index a278e9d9c6e6..879c962bb3b2 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java @@ -59,7 +59,6 @@ public class CommunicationService extends Service { @Override public void onCreate() { // TODO Create a notification (if configured). - mFinder.startFinding(); } @Override @@ -75,6 +74,14 @@ public class CommunicationService extends Service { return mFinder.getServerList(); } + public void startFindingServers() { + mFinder.startFinding(); + } + + public void stopFindingServers() { + mFinder.stopFinding(); + } + /** * Connect to a specific server. This method cannot be called on the main * activity thread. diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java index c47ce805e36a..5b1b33462925 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java @@ -21,6 +21,8 @@ public class ServerFinder { private static final int PORT = 1598; private static final String CHARSET = "UTF-8"; + private static final long SEARCH_INTERVAL = 1000 * 20; + private DatagramSocket mSocket = null; private Thread mListenerThread = null; @@ -40,9 +42,7 @@ public class ServerFinder { try { String aCommand = null; String aName = null; - System.out.println("SF:listening for packet\n"); mSocket.receive(aPacket); - System.out.println("SF:received packet\n"); int i; for (i = 0; i < aBuffer.length; i++) { if (aPacket.getData()[i] == '\n') { @@ -95,18 +95,34 @@ public class ServerFinder { mListenerThread = new Thread() { @Override public void run() { + long aTime = 0; try { mSocket = new DatagramSocket(); - String aString = "LOREMOTE_SEARCH\n"; - DatagramPacket aPacket = new DatagramPacket( - aString.getBytes(CHARSET), - aString.length(), - InetAddress.getByName("239.0.0.1"), - PORT); - mSocket.send(aPacket); - System.out.println("SF:sent packet\n"); mSocket.setSoTimeout(1000 * 10); while (!mFinishRequested) { + if (System.currentTimeMillis() - aTime > SEARCH_INTERVAL) { + String aString = "LOREMOTE_SEARCH\n"; + DatagramPacket aPacket = new DatagramPacket( + aString.getBytes(CHARSET), + aString.length(), + InetAddress.getByName("239.0.0.1"), + PORT); + mSocket.send(aPacket); + aTime = System.currentTimeMillis(); + for (Server aServer : mServerList.values()) { + if (System.currentTimeMillis() + - aServer.getTimeDiscovered() > 60 * 1000) { + mServerList.remove(aServer.getAddress()); + Intent aIntent = new Intent( + CommunicationService.MSG_SERVERLIST_CHANGED); + LocalBroadcastManager.getInstance( + mContext) + .sendBroadcast(aIntent); + + } + } + } + listenForServer(); } } catch (SocketException e) { @@ -135,6 +151,6 @@ public class ServerFinder { } public Server[] getServerList() { - return mServerList.entrySet().toArray(new Server[mServerList.size()]); + return mServerList.values().toArray(new Server[mServerList.size()]); } } |