add more checks for possible NPE and simplify the UI
This commit is contained in:
parent
cc6b2736ce
commit
c399a17369
@ -17,7 +17,7 @@ public class BluetoothClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BluetoothConnection openConnection() throws IOException {
|
public BluetoothConnection openConnection() throws IOException {
|
||||||
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(BluetoothConstants.fdroidUuid());
|
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(BluetoothConstants.fdroidUuid());
|
||||||
BluetoothConnection connection = new BluetoothConnection(socket);
|
BluetoothConnection connection = new BluetoothConnection(socket);
|
||||||
connection.open();
|
connection.open();
|
||||||
return connection;
|
return connection;
|
||||||
|
@ -31,6 +31,7 @@ import org.fdroid.fdroid.localrepo.SwapManager;
|
|||||||
import org.fdroid.fdroid.net.BluetoothDownloader;
|
import org.fdroid.fdroid.net.BluetoothDownloader;
|
||||||
import org.fdroid.fdroid.net.bluetooth.BluetoothClient;
|
import org.fdroid.fdroid.net.bluetooth.BluetoothClient;
|
||||||
import org.fdroid.fdroid.net.bluetooth.BluetoothConnection;
|
import org.fdroid.fdroid.net.bluetooth.BluetoothConnection;
|
||||||
|
import org.fdroid.fdroid.net.bluetooth.BluetoothServer;
|
||||||
import org.fdroid.fdroid.views.fragments.ThemeableListFragment;
|
import org.fdroid.fdroid.views.fragments.ThemeableListFragment;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -134,13 +135,15 @@ public class BluetoothDeviceListView extends ListView implements
|
|||||||
|
|
||||||
final BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
|
final BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
|
||||||
final TextView deviceName = (TextView)headerView.findViewById(R.id.device_name);
|
final TextView deviceName = (TextView) headerView.findViewById(R.id.device_name);
|
||||||
deviceName.setText(bluetooth.getName());
|
deviceName.setText(bluetooth.getName());
|
||||||
|
|
||||||
final TextView address = (TextView)headerView.findViewById(R.id.device_address);
|
final TextView address = (TextView) headerView.findViewById(R.id.device_address);
|
||||||
address.setText(bluetooth.getAddress());
|
address.setText(bluetooth.getAddress());
|
||||||
|
|
||||||
populateBondedDevices();
|
initiateBluetoothScan();
|
||||||
|
|
||||||
|
// populateBondedDevices();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,8 +169,10 @@ public class BluetoothDeviceListView extends ListView implements
|
|||||||
{
|
{
|
||||||
Log.d(TAG, "Starting bluetooth scan...");
|
Log.d(TAG, "Starting bluetooth scan...");
|
||||||
|
|
||||||
cancelMenuItem.setVisible(true);
|
if (cancelMenuItem != null) {
|
||||||
scanMenuItem.setVisible(false);
|
cancelMenuItem.setVisible(true);
|
||||||
|
scanMenuItem.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
final ContentLoadingProgressBar loadingBar = getLoadingIndicator();
|
final ContentLoadingProgressBar loadingBar = getLoadingIndicator();
|
||||||
|
|
||||||
@ -181,17 +186,21 @@ public class BluetoothDeviceListView extends ListView implements
|
|||||||
if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
|
if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
|
||||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
Log.d(TAG, "Found bluetooth device: " + device.toString());
|
Log.d(TAG, "Found bluetooth device: " + device.toString());
|
||||||
boolean exists = false;
|
|
||||||
for (int i = 0; i < adapter.getCount(); i ++) {
|
|
||||||
if (adapter.getItem(i).getAddress().equals(device.getAddress())) {
|
|
||||||
exists = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!exists) {
|
if (device != null && device.getName() != null)
|
||||||
adapter.add(device);
|
if (device.getName().contains(BluetoothServer.BLUETOOTH_NAME_TAG)) {
|
||||||
}
|
boolean exists = false;
|
||||||
|
for (int i = 0; i < adapter.getCount(); i++) {
|
||||||
|
if (adapter.getItem(i).getAddress().equals(device.getAddress())) {
|
||||||
|
exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exists) {
|
||||||
|
adapter.add(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user