Fixed styling of server finder.

Change-Id: I74186efe472f89463b597790d46be5523ce85b6f
This commit is contained in:
Andrzej J.R. Hunt
2012-08-03 14:15:37 +02:00
committed by Michael Meeks
parent b5d6989e8b
commit bbbfaf7b9e

View File

@@ -34,7 +34,9 @@ public class SelectorActivity extends Activity {
private CommunicationService mCommunicationService; private CommunicationService mCommunicationService;
private View mBluetoothContainer;
private LinearLayout mBluetoothList; private LinearLayout mBluetoothList;
private View mNetworkContainer;
private LinearLayout mNetworkList; private LinearLayout mNetworkList;
private TextView mNoServerLabel; private TextView mNoServerLabel;
@@ -49,7 +51,9 @@ public class SelectorActivity extends Activity {
LocalBroadcastManager.getInstance(this).registerReceiver(mListener, LocalBroadcastManager.getInstance(this).registerReceiver(mListener,
aFilter); aFilter);
mBluetoothContainer = findViewById(R.id.selector_container_bluetooth);
mBluetoothList = (LinearLayout) findViewById(R.id.selector_list_bluetooth); mBluetoothList = (LinearLayout) findViewById(R.id.selector_list_bluetooth);
mNetworkContainer = findViewById(R.id.selector_container_network);
mNetworkList = (LinearLayout) findViewById(R.id.selector_list_network); mNetworkList = (LinearLayout) findViewById(R.id.selector_list_network);
mNoServerLabel = (TextView) findViewById(R.id.selector_label_none); mNoServerLabel = (TextView) findViewById(R.id.selector_label_none);
@@ -109,53 +113,56 @@ public class SelectorActivity extends Activity {
private HashMap<Server, View> mNetworkServers = new HashMap<Server, View>(); private HashMap<Server, View> mNetworkServers = new HashMap<Server, View>();
private void refreshLists() { private void refreshLists() {
if (mCommunicationService == null) if (mCommunicationService != null) {
return;
Server[] aServers = mCommunicationService.getServers(); Server[] aServers = mCommunicationService.getServers();
// Bluetooth -- Remove old // Bluetooth -- Remove old
for (Entry<Server, View> aEntry : mBluetoothServers.entrySet()) { for (Entry<Server, View> aEntry : mBluetoothServers.entrySet()) {
if (!Arrays.asList(aServers).contains(aEntry.getKey())) { if (!Arrays.asList(aServers).contains(aEntry.getKey())) {
mBluetoothServers.remove(aEntry.getKey()); mBluetoothServers.remove(aEntry.getKey());
mBluetoothList.removeView(aEntry.getValue()); mBluetoothList.removeView(aEntry.getValue());
}
} }
} // Network -- Remove old
// Network -- Remove old for (Entry<Server, View> aEntry : mNetworkServers.entrySet()) {
for (Entry<Server, View> aEntry : mNetworkServers.entrySet()) { if (!Arrays.asList(aServers).contains(aEntry.getKey())) {
if (!Arrays.asList(aServers).contains(aEntry.getKey())) { mNetworkServers.remove(aEntry.getKey());
mNetworkServers.remove(aEntry.getKey()); mNetworkList.removeView(aEntry.getValue());
mNetworkList.removeView(aEntry.getValue()); }
} }
} // Add all new
// Add all new for (Server aServer : aServers) {
for (Server aServer : aServers) { boolean aIsBluetooth = (aServer.getProtocol() == Protocol.BLUETOOTH);
boolean aIsBluetooth = (aServer.getProtocol() == Protocol.BLUETOOTH); HashMap<Server, View> aMap = aIsBluetooth ? mBluetoothServers
HashMap<Server, View> aMap = aIsBluetooth ? mBluetoothServers : mNetworkServers;
: mNetworkServers; LinearLayout aLayout = aIsBluetooth ? mBluetoothList
LinearLayout aLayout = aIsBluetooth ? mBluetoothList : mNetworkList; : mNetworkList;
if (!aMap.containsValue(aServer)) {
View aView = getLayoutInflater()
.inflate(R.layout.activity_selector_sublayout_server,
aLayout);
TextView aText = (TextView) aView
.findViewById(R.id.selector_sub_label);
aText.setText(aServer.getName());
aMap.put(aServer, aView);
}
if (!aMap.containsValue(aServer)) {
View aView = getLayoutInflater().inflate(
R.layout.activity_selector_sublayout_server,
aLayout);
TextView aText = (TextView) aView
.findViewById(R.id.selector_sub_label);
aText.setText(aServer.getName());
aMap.put(aServer, aView);
} }
} }
// Hide as necessary // Hide as necessary
mBluetoothList.setVisibility((mBluetoothServers.size() != 0) ? View.VISIBLE mBluetoothContainer
: View.INVISIBLE); .setVisibility((mBluetoothServers.size() != 0) ? View.VISIBLE
mNetworkList.setVisibility((mNetworkServers.size() != 0) ? View.VISIBLE : View.GONE);
: View.INVISIBLE); mNetworkContainer
.setVisibility((mNetworkServers.size() != 0) ? View.VISIBLE
: View.GONE);
mNoServerLabel.setVisibility((mBluetoothServers.size() == 0) mNoServerLabel.setVisibility((mBluetoothServers.size() == 0)
&& (mNetworkServers.size() == 0) ? View.VISIBLE && (mNetworkServers.size() == 0) ? View.VISIBLE
: View.INVISIBLE); : View.GONE);
} }
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */