1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-26 02:14:22 +00:00

Fixed a bug where the bluetooth LE scanner would continue to scan even if the bluetooth selector window was closed

This commit is contained in:
hogliux 2017-02-09 17:43:15 +00:00
parent 376b83986a
commit ebbba641a4
3 changed files with 93 additions and 37 deletions

View file

@ -3,33 +3,6 @@
{
BluetoothManager()
{
ScanFilter.Builder scanFilterBuilder = new ScanFilter.Builder();
scanFilterBuilder.setServiceUuid (ParcelUuid.fromString (bluetoothLEMidiServiceUUID));
ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder();
scanSettingsBuilder.setCallbackType (ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.setScanMode (ScanSettings.SCAN_MODE_LOW_POWER)
.setScanMode (ScanSettings.MATCH_MODE_STICKY);
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null)
{
Log.d ("JUCE", "BluetoothManager error: could not get default Bluetooth adapter");
return;
}
BluetoothLeScanner bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
if (bluetoothLeScanner == null)
{
Log.d ("JUCE", "BluetoothManager error: could not get Bluetooth LE scanner");
return;
}
bluetoothLeScanner.startScan (Arrays.asList (scanFilterBuilder.build()),
scanSettingsBuilder.build(),
this);
}
public String[] getMidiBluetoothAddresses()
@ -48,6 +21,44 @@
return getAndroidMidiDeviceManager().isBluetoothDevicePaired (address);
}
public void startStopScan (boolean shouldStart)
{
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null)
{
Log.d ("JUCE", "BluetoothManager error: could not get default Bluetooth adapter");
return;
}
BluetoothLeScanner bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
if (bluetoothLeScanner == null)
{
Log.d ("JUCE", "BluetoothManager error: could not get Bluetooth LE scanner");
return;
}
if (shouldStart)
{
ScanFilter.Builder scanFilterBuilder = new ScanFilter.Builder();
scanFilterBuilder.setServiceUuid (ParcelUuid.fromString (bluetoothLEMidiServiceUUID));
ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder();
scanSettingsBuilder.setCallbackType (ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.setScanMode (ScanSettings.SCAN_MODE_LOW_POWER)
.setScanMode (ScanSettings.MATCH_MODE_STICKY);
bluetoothLeScanner.startScan (Arrays.asList (scanFilterBuilder.build()),
scanSettingsBuilder.build(),
this);
}
else
{
bluetoothLeScanner.stopScan (this);
}
}
public boolean pairBluetoothMidiDevice(String address)
{
BluetoothDevice btDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice (address);
@ -406,27 +417,42 @@
return info.getPorts();
}
public String getHumanReadableNameForPort (MidiDeviceInfo.PortInfo port, int portIndexToUseInName)
public String getHumanReadableNameForPort (MidiDeviceInfo.PortInfo port, int portIndexToUseInName, boolean addPortNumberToName)
{
String portName = port.getName();
if (addPortNumberToName)
{
String portName = port.getName();
if (portName.equals (""))
portName = ((port.getType() == MidiDeviceInfo.PortInfo.TYPE_OUTPUT) ? "Out " : "In ")
+ Integer.toString (portIndexToUseInName);
if (portName.equals(""))
portName = ((port.getType() == MidiDeviceInfo.PortInfo.TYPE_OUTPUT) ? "Out " : "In ")
+ Integer.toString(portIndexToUseInName);
return getHumanReadableDeviceName() + " " + portName;
return getHumanReadableDeviceName() + " " + portName;
}
return getHumanReadableDeviceName();
}
public String getHumanReadableNameForPort (int portType, int androidPortID, int portIndexToUseInName)
{
MidiDeviceInfo.PortInfo[] ports = info.getPorts();
int numTotalPorts = 0;
for (MidiDeviceInfo.PortInfo port : ports)
{
if (port.getType() == portType)
{
numTotalPorts++;
}
}
for (MidiDeviceInfo.PortInfo port : ports)
{
if (port.getType() == portType)
{
if (port.getPortNumber() == androidPortID)
return getHumanReadableNameForPort (port, portIndexToUseInName);
return getHumanReadableNameForPort (port, portIndexToUseInName, (numTotalPorts > 1));
}
}
@ -689,6 +715,15 @@
int portIdx = 0;
MidiDeviceInfo.PortInfo[] ports = physicalMidiDevice.getPorts();
int numberOfPorts = 0;
for (MidiDeviceInfo.PortInfo port : ports)
{
if (port.getType() == portType)
{
numberOfPorts++;
}
}
for (MidiDeviceInfo.PortInfo port : ports)
{
if (port.getType() == portType)
@ -700,7 +735,8 @@
listOfReturnedDevices.add (path);
deviceNames.add (physicalMidiDevice.getHumanReadableNameForPort (port,
path.portIndexToUseInName));
path.portIndexToUseInName,
(numberOfPorts > 1)));
}
}
}

View file

@ -21,6 +21,10 @@
return false;
}
public void startStopScan (boolean shouldStart)
{
}
public boolean pairBluetoothMidiDevice(String address)
{
return false;