mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-03 17:02:13 +01:00
No functional changes, only run "Reformat code"
This commit is contained in:
parent
7f24ba8ffb
commit
5d6109a4fb
@ -100,6 +100,8 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
private static final long SCAN_DURATION = 30000; // 30s
|
private static final long SCAN_DURATION = 30000; // 30s
|
||||||
private final Handler handler = new Handler();
|
private final Handler handler = new Handler();
|
||||||
private final ArrayList<GBDeviceCandidate> deviceCandidates = new ArrayList<>();
|
private final ArrayList<GBDeviceCandidate> deviceCandidates = new ArrayList<>();
|
||||||
|
int CallbackType = android.bluetooth.le.ScanSettings.CALLBACK_TYPE_ALL_MATCHES;
|
||||||
|
int MatchMode = android.bluetooth.le.ScanSettings.MATCH_MODE_STICKY;
|
||||||
private ScanCallback newBLEScanCallback = null;
|
private ScanCallback newBLEScanCallback = null;
|
||||||
/**
|
/**
|
||||||
* If already bonded devices are to be ignored when scanning
|
* If already bonded devices are to be ignored when scanning
|
||||||
@ -115,8 +117,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
private Button startButton;
|
private Button startButton;
|
||||||
private boolean scanning;
|
private boolean scanning;
|
||||||
private long selectedUnsupportedDeviceKey = DebugActivity.SELECT_DEVICE;
|
private long selectedUnsupportedDeviceKey = DebugActivity.SELECT_DEVICE;
|
||||||
private Set<BTUUIDPair> foundCandidates = new HashSet<>();
|
|
||||||
|
|
||||||
private final Runnable stopRunnable = new Runnable() {
|
private final Runnable stopRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -124,6 +124,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
LOG.info("Discovery stopped by thread timeout.");
|
LOG.info("Discovery stopped by thread timeout.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private Set<BTUUIDPair> foundCandidates = new HashSet<>();
|
||||||
private final BroadcastReceiver bluetoothReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver bluetoothReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@ -168,8 +169,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
int CallbackType = android.bluetooth.le.ScanSettings.CALLBACK_TYPE_ALL_MATCHES;
|
|
||||||
int MatchMode = android.bluetooth.le.ScanSettings.MATCH_MODE_STICKY;
|
|
||||||
|
|
||||||
public void logMessageContent(byte[] value) {
|
public void logMessageContent(byte[] value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
@ -184,7 +183,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
BondingUtil.handleActivityResult(this, requestCode, resultCode, data);
|
BondingUtil.handleActivityResult(this, requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private GBDeviceCandidate getCandidateFromMAC(BluetoothDevice device) {
|
private GBDeviceCandidate getCandidateFromMAC(BluetoothDevice device) {
|
||||||
for (GBDeviceCandidate candidate : deviceCandidates) {
|
for (GBDeviceCandidate candidate : deviceCandidates) {
|
||||||
if (candidate.getMacAddress().equals(device.getAddress())) {
|
if (candidate.getMacAddress().equals(device.getAddress())) {
|
||||||
@ -280,7 +278,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
} else {
|
} else {
|
||||||
deviceCandidates.clear();
|
deviceCandidates.clear();
|
||||||
deviceCandidateAdapter.notifyDataSetChanged();
|
deviceCandidateAdapter.notifyDataSetChanged();
|
||||||
startDiscovery();
|
startDiscovery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +347,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
|
|
||||||
private void addToCandidateListIfNotAlreadyProcessed(BluetoothDevice device, short rssi, ParcelUuid[] uuids) {
|
private void addToCandidateListIfNotAlreadyProcessed(BluetoothDevice device, short rssi, ParcelUuid[] uuids) {
|
||||||
BTUUIDPair btuuidPair = new BTUUIDPair(device, uuids);
|
BTUUIDPair btuuidPair = new BTUUIDPair(device, uuids);
|
||||||
if(foundCandidates.contains(btuuidPair)) {
|
if (foundCandidates.contains(btuuidPair)) {
|
||||||
// LOG.info("candidate already processed, skipping");
|
// LOG.info("candidate already processed, skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -421,7 +419,18 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isScanning() {
|
private boolean isScanning() {
|
||||||
return scanning ;
|
return scanning;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScanning(boolean scanning) {
|
||||||
|
this.scanning = scanning;
|
||||||
|
if (scanning) {
|
||||||
|
startButton.setText(getString(R.string.discovery_stop_scanning));
|
||||||
|
} else {
|
||||||
|
startButton.setText(getString(R.string.discovery_start_scanning));
|
||||||
|
bluetoothProgress.setVisibility(View.GONE);
|
||||||
|
bluetoothLEProgress.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startBTLEDiscovery() {
|
private void startBTLEDiscovery() {
|
||||||
@ -465,7 +474,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a regular Bluetooth scan
|
* Starts a regular Bluetooth scan
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private void startBTDiscovery() {
|
private void startBTDiscovery() {
|
||||||
LOG.info("Starting BT discovery");
|
LOG.info("Starting BT discovery");
|
||||||
@ -492,17 +500,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScanning(boolean scanning) {
|
|
||||||
this.scanning = scanning;
|
|
||||||
if (scanning) {
|
|
||||||
startButton.setText(getString(R.string.discovery_stop_scanning));
|
|
||||||
} else {
|
|
||||||
startButton.setText(getString(R.string.discovery_start_scanning));
|
|
||||||
bluetoothProgress.setVisibility(View.GONE);
|
|
||||||
bluetoothLEProgress.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void bluetoothStateChanged(int newState) {
|
private void bluetoothStateChanged(int newState) {
|
||||||
if (newState == BluetoothAdapter.STATE_ON) {
|
if (newState == BluetoothAdapter.STATE_ON) {
|
||||||
this.adapter = BluetoothAdapter.getDefaultAdapter();
|
this.adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
@ -536,7 +533,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.adapter = adapter;
|
this.adapter = adapter;
|
||||||
if(GB.supportsBluetoothLE())
|
if (GB.supportsBluetoothLE())
|
||||||
this.bluetoothLeScanner = adapter.getBluetoothLeScanner();
|
this.bluetoothLeScanner = adapter.getBluetoothLeScanner();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -634,7 +631,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
LOG.error("Device candidate clicked, but item not found");
|
LOG.error("Device candidate clicked, but item not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!deviceCandidate.getDeviceType().isSupported()){
|
if (!deviceCandidate.getDeviceType().isSupported()) {
|
||||||
LOG.error("Unsupported device candidate");
|
LOG.error("Unsupported device candidate");
|
||||||
ArrayList deviceDetails = new ArrayList<>();
|
ArrayList deviceDetails = new ArrayList<>();
|
||||||
deviceDetails.add(deviceCandidate.getName());
|
deviceDetails.add(deviceCandidate.getName());
|
||||||
@ -662,7 +659,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(deviceCandidate.getMacAddress());
|
SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(deviceCandidate.getMacAddress());
|
||||||
|
|
||||||
String authKey = sharedPrefs.getString("authkey", null);
|
String authKey = sharedPrefs.getString("authkey", null);
|
||||||
if (authKey == null || authKey.isEmpty() ) {
|
if (authKey == null || authKey.isEmpty()) {
|
||||||
toast(DiscoveryActivity.this, getString(R.string.discovery_need_to_enter_authkey), Toast.LENGTH_LONG, GB.WARN);
|
toast(DiscoveryActivity.this, getString(R.string.discovery_need_to_enter_authkey), Toast.LENGTH_LONG, GB.WARN);
|
||||||
return;
|
return;
|
||||||
} else if (authKey.getBytes().length < 34 || !authKey.startsWith("0x")) {
|
} else if (authKey.getBytes().length < 34 || !authKey.startsWith("0x")) {
|
||||||
@ -678,7 +675,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
if (coordinator.getBondingStyle() == DeviceCoordinator.BONDING_STYLE_NONE ||
|
if (coordinator.getBondingStyle() == DeviceCoordinator.BONDING_STYLE_NONE ||
|
||||||
coordinator.getBondingStyle() == DeviceCoordinator.BONDING_STYLE_LAZY) {
|
coordinator.getBondingStyle() == DeviceCoordinator.BONDING_STYLE_LAZY) {
|
||||||
LOG.info("No bonding needed, according to coordinator, so connecting right away");
|
LOG.info("No bonding needed, according to coordinator, so connecting right away");
|
||||||
BondingUtil.connectThenComplete(this, deviceCandidate);
|
BondingUtil.connectThenComplete(this, deviceCandidate);
|
||||||
return;
|
return;
|
||||||
@ -771,20 +768,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
spinner.setOnItemSelectedListener(new CustomOnDeviceSelectedListener());
|
spinner.setOnItemSelectedListener(new CustomOnDeviceSelectedListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CustomOnDeviceSelectedListener implements AdapterView.OnItemSelectedListener {
|
|
||||||
|
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
|
||||||
SpinnerWithIconItem selectedItem = (SpinnerWithIconItem) parent.getItemAtPosition(pos);
|
|
||||||
selectedUnsupportedDeviceKey = selectedItem.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNothingSelected(AdapterView<?> arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBondingComplete(boolean success) {
|
public void onBondingComplete(boolean success) {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
@ -839,6 +822,20 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CustomOnDeviceSelectedListener implements AdapterView.OnItemSelectedListener {
|
||||||
|
|
||||||
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
||||||
|
SpinnerWithIconItem selectedItem = (SpinnerWithIconItem) parent.getItemAtPosition(pos);
|
||||||
|
selectedUnsupportedDeviceKey = selectedItem.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNothingSelected(AdapterView<?> arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private class BTUUIDPair {
|
private class BTUUIDPair {
|
||||||
private final BluetoothDevice bluetoothDevice;
|
private final BluetoothDevice bluetoothDevice;
|
||||||
private final ParcelUuid[] parcelUuid;
|
private final ParcelUuid[] parcelUuid;
|
||||||
@ -863,4 +860,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user