summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2013-02-13 00:34:49 +0200
committerTor Lillqvist <tml@iki.fi>2013-02-13 00:46:02 +0200
commit5e037cef389162fc75e3048a33d9175bf9e0bee5 (patch)
tree4eaeea32bfe6522943a9d7badbb59420869a9de5 /android
parent0d18ec16be3a0850a224492f049e6096ffedc96f (diff)
Simplify and fix management of the server lists
The existing code in refreshLists() was somewhat hard to understand, and it actually crashed (if uncommented-out). Now it simply empties the maps and view lists and then rebuilds them. The visible end result, at least for me, is that I no longer get duplicate servers in the list... Change-Id: I1543292e219e666e7dcbc68473f40a11e2eb3381
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java58
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothFinder.java5
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java10
3 files changed, 34 insertions, 39 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
index ac6012bbba00..207aef7613ec 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
@@ -9,8 +9,8 @@
package org.libreoffice.impressremote;
import java.text.MessageFormat;
-import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map.Entry;
import org.libreoffice.impressremote.communication.CommunicationService;
@@ -267,27 +267,18 @@ public class SelectorActivity extends SherlockActivity {
private void refreshLists() {
if (mCommunicationService != null) {
- Server[] aServers = mCommunicationService.getServers();
+ List<Server> aServers = mCommunicationService.getServers();
+
+ Log.i(Globals.TAG, "SelectorActivity.refreshLists: got " + aServers.size() + " servers");
+
+ // Simply replace the lists... first clear the old lists,
+ // Then add those currently found.
+
+ mNetworkServers.clear();
+ mBluetoothServers.clear();
+ mNetworkList.removeAllViews();
+ mBluetoothList.removeAllViews();
-/* TODO: this crashes currently - some concurrent modification on mBluetoothServers
- // Bluetooth -- Remove old
- for (Entry<Server, View> aEntry : mBluetoothServers.entrySet()) {
- if (!Arrays.asList(aServers).contains(aEntry.getKey())) {
- mBluetoothServers.remove(aEntry.getKey());
- mBluetoothList.removeView((View) aEntry.getValue()
- .getParent());
- }
- }
-*/
- // Network -- Remove old
- for (Entry<Server, View> aEntry : mNetworkServers.entrySet()) {
- if (!Arrays.asList(aServers).contains(aEntry.getKey())) {
- mNetworkServers.remove(aEntry.getKey());
- mNetworkList.removeView((View) aEntry.getValue()
- .getParent());
- }
- }
- // Add all new
for (Server aServer : aServers) {
boolean aIsBluetooth = (aServer.getProtocol() == Protocol.BLUETOOTH);
HashMap<Server, View> aMap = aIsBluetooth ? mBluetoothServers
@@ -295,22 +286,19 @@ public class SelectorActivity extends SherlockActivity {
LinearLayout aLayout = aIsBluetooth ? mBluetoothList
: mNetworkList;
- if (!aMap.containsKey(aServer)) {
- View aView = getLayoutInflater()
- .inflate(R.layout.activity_selector_sublayout_server,
- null);
+ View aView = getLayoutInflater()
+ .inflate(R.layout.activity_selector_sublayout_server,
+ null);
- TextView aText = (TextView) aView
- .findViewById(R.id.selector_sub_label);
- aText.setOnClickListener(mClickListener);
- aText.setText(aServer.getName());
- aLayout.addView(aView);
- aMap.put(aServer, aText);
-
- // registerForContextMenu(aView);
- registerForContextMenu(aText);
- }
+ TextView aText = (TextView) aView
+ .findViewById(R.id.selector_sub_label);
+ aText.setOnClickListener(mClickListener);
+ aText.setText(aServer.getName());
+ aLayout.addView(aView);
+ aMap.put(aServer, aText);
+ // registerForContextMenu(aView);
+ registerForContextMenu(aText);
}
}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothFinder.java
index 87535da2269f..b9c2cab545c8 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothFinder.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothFinder.java
@@ -34,10 +34,10 @@ public class BluetoothFinder {
public BluetoothFinder(Context aContext) {
mContext = aContext;
mAdapter = BluetoothAdapter.getDefaultAdapter();
-
}
public void startFinding() {
+ Log.i(Globals.TAG, "BluetoothFinder.startFinding(): mAdapter=" + mAdapter);
if (mAdapter == null) {
return; // No bluetooth adapter found (emulator, special devices)
}
@@ -49,6 +49,7 @@ public class BluetoothFinder {
}
public void stopFinding() {
+ Log.i(Globals.TAG, "BluetoothFinder.stopFinding(): mAdapter=" + mAdapter);
if (mAdapter == null) {
return; // No bluetooth adapter found (emulator, special devices)
}
@@ -57,6 +58,7 @@ public class BluetoothFinder {
mContext.unregisterReceiver(mReceiver);
} catch (IllegalArgumentException e) {
// The receiver wasn't registered
+ Log.i(Globals.TAG, "BluetoothFinder.stopFinding: " + e);
}
}
@@ -70,6 +72,7 @@ public class BluetoothFinder {
@Override
public void onReceive(Context context, Intent aIntent) {
+ Log.i(Globals.TAG, "BluetoothFinder: BroadcastReceiver.onReceive: aIntent=" + aIntent);
if (aIntent.getAction().equals(BluetoothDevice.ACTION_FOUND)) {
BluetoothDevice aDevice = (BluetoothDevice) aIntent.getExtras()
.get(BluetoothDevice.EXTRA_DEVICE);
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index b3af391a0942..5f8f8c6856b7 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -11,9 +11,11 @@ package org.libreoffice.impressremote.communication;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.libreoffice.impressremote.Globals;
import org.libreoffice.impressremote.communication.Server.Protocol;
import android.app.Service;
@@ -23,6 +25,7 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Binder;
import android.os.IBinder;
+import android.util.Log;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
@@ -126,6 +129,7 @@ public class CommunicationService extends Service implements Runnable {
private boolean mBluetoothPreviouslyEnabled;
public void startSearching() {
+ Log.i(Globals.TAG, "CommunicationService.startSearching()");
SharedPreferences aPref = PreferenceManager.getDefaultSharedPreferences(this);
boolean bEnableWifi = aPref.getBoolean("option_enablewifi", false);
if (bEnableWifi)
@@ -140,12 +144,12 @@ public class CommunicationService extends Service implements Runnable {
}
public void stopSearching() {
+ Log.i(Globals.TAG, "CommunicationService.stopSearching()");
mNetworkFinder.stopFinding();
mBluetoothFinder.stopFinding();
BluetoothAdapter aAdapter = BluetoothAdapter.getDefaultAdapter();
if (aAdapter != null) {
if (!mBluetoothPreviouslyEnabled) {
-
aAdapter.disable();
}
}
@@ -253,12 +257,12 @@ public class CommunicationService extends Service implements Runnable {
return mTransmitter;
}
- public Server[] getServers() {
+ public List<Server> getServers() {
ArrayList<Server> aServers = new ArrayList<Server>();
aServers.addAll(mNetworkFinder.getServerList());
aServers.addAll(mBluetoothFinder.getServerList());
aServers.addAll(mManualServers.values());
- return aServers.toArray(new Server[aServers.size()]);
+ return aServers;
}
public SlideShow getSlideShow() {