1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

BluetoothMidiDevicePairingDialogue: Improve formatting

This commit is contained in:
reuk 2025-04-01 20:31:42 +01:00
parent 2e5ecceea8
commit 71b1d001de
No known key found for this signature in database
2 changed files with 30 additions and 17 deletions

View file

@ -108,9 +108,9 @@ public class JuceMidiSupport
appContext = contextToUse; appContext = contextToUse;
} }
public String[] getMidiBluetoothAddresses () public List<String> getMidiBluetoothAddresses()
{ {
return bluetoothMidiDevices.toArray (new String[bluetoothMidiDevices.size ()]); return new ArrayList<String> (bluetoothMidiDevices);
} }
public String getHumanReadableStringForBluetoothAddress (String address) public String getHumanReadableStringForBluetoothAddress (String address)
@ -216,7 +216,7 @@ public class JuceMidiSupport
private BluetoothLeScanner scanner; private BluetoothLeScanner scanner;
private static final String bluetoothLEMidiServiceUUID = "03B80E5A-EDE8-4B33-A751-6CE34EC4C700"; private static final String bluetoothLEMidiServiceUUID = "03B80E5A-EDE8-4B33-A751-6CE34EC4C700";
private HashSet<String> bluetoothMidiDevices = new HashSet<String> (); private HashSet<String> bluetoothMidiDevices = new HashSet<>();
private Context appContext = null; private Context appContext = null;
} }

View file

@ -42,7 +42,7 @@ DECLARE_JNI_CLASS (AndroidJuceMidiSupport, "com/rmsl/juce/JuceMidiSupport")
#undef JNI_CLASS_MEMBERS #undef JNI_CLASS_MEMBERS
#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \ #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \
METHOD (getMidiBluetoothAddresses, "getMidiBluetoothAddresses", "()[Ljava/lang/String;") \ METHOD (getMidiBluetoothAddresses, "getMidiBluetoothAddresses", "()Ljava/util/List;") \
METHOD (pairBluetoothMidiDevice, "pairBluetoothMidiDevice", "(Ljava/lang/String;)Z") \ METHOD (pairBluetoothMidiDevice, "pairBluetoothMidiDevice", "(Ljava/lang/String;)Z") \
METHOD (unpairBluetoothMidiDevice, "unpairBluetoothMidiDevice", "(Ljava/lang/String;)V") \ METHOD (unpairBluetoothMidiDevice, "unpairBluetoothMidiDevice", "(Ljava/lang/String;)V") \
METHOD (getHumanReadableStringForBluetoothAddress, "getHumanReadableStringForBluetoothAddress", "(Ljava/lang/String;)Ljava/lang/String;") \ METHOD (getHumanReadableStringForBluetoothAddress, "getHumanReadableStringForBluetoothAddress", "(Ljava/lang/String;)Ljava/lang/String;") \
@ -58,7 +58,9 @@ struct AndroidBluetoothMidiInterface
static void startStopScan (bool startScanning) static void startStopScan (bool startScanning)
{ {
JNIEnv* env = getEnv(); JNIEnv* env = getEnv();
LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport,
AndroidJuceMidiSupport.getAndroidBluetoothManager,
getAppContext().get()));
if (btManager.get() != nullptr) if (btManager.get() != nullptr)
env->CallVoidMethod (btManager.get(), AndroidBluetoothManager.startStopScan, (jboolean) (startScanning ? 1 : 0)); env->CallVoidMethod (btManager.get(), AndroidBluetoothManager.startStopScan, (jboolean) (startScanning ? 1 : 0));
@ -70,21 +72,22 @@ struct AndroidBluetoothMidiInterface
JNIEnv* env = getEnv(); JNIEnv* env = getEnv();
LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport,
AndroidJuceMidiSupport.getAndroidBluetoothManager,
getAppContext().get()));
// if this is null then bluetooth is not enabled // if this is null then bluetooth is not enabled
if (btManager.get() == nullptr) if (btManager.get() == nullptr)
return {}; return {};
jobjectArray jDevices = (jobjectArray) env->CallObjectMethod (btManager.get(), LocalRef<jobject> jDevices { (jobjectArray) env->CallObjectMethod (btManager.get(),
AndroidBluetoothManager.getMidiBluetoothAddresses); AndroidBluetoothManager.getMidiBluetoothAddresses) };
LocalRef<jobjectArray> devices (jDevices);
const int count = env->GetArrayLength (devices.get()); const auto count = env->CallIntMethod (jDevices, JavaList.size);
for (int i = 0; i < count; ++i) for (auto i = (decltype (count)) 0; i < count; ++i)
{ {
LocalRef<jstring> string ((jstring) env->GetObjectArrayElement (devices.get(), i)); LocalRef<jstring> string { (jstring) env->CallObjectMethod (jDevices, JavaList.get, i) };
retval.add (juceString (string)); retval.add (juceString (string));
} }
@ -96,7 +99,9 @@ struct AndroidBluetoothMidiInterface
{ {
JNIEnv* env = getEnv(); JNIEnv* env = getEnv();
LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport,
AndroidJuceMidiSupport.getAndroidBluetoothManager,
getAppContext().get()));
if (btManager.get() == nullptr) if (btManager.get() == nullptr)
return false; return false;
@ -110,7 +115,9 @@ struct AndroidBluetoothMidiInterface
{ {
JNIEnv* env = getEnv(); JNIEnv* env = getEnv();
LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport,
AndroidJuceMidiSupport.getAndroidBluetoothManager,
getAppContext().get()));
if (btManager.get() != nullptr) if (btManager.get() != nullptr)
env->CallVoidMethod (btManager.get(), AndroidBluetoothManager.unpairBluetoothMidiDevice, env->CallVoidMethod (btManager.get(), AndroidBluetoothManager.unpairBluetoothMidiDevice,
@ -122,7 +129,9 @@ struct AndroidBluetoothMidiInterface
{ {
JNIEnv* env = getEnv(); JNIEnv* env = getEnv();
LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport,
AndroidJuceMidiSupport.getAndroidBluetoothManager,
getAppContext().get()));
if (btManager.get() == nullptr) if (btManager.get() == nullptr)
return address; return address;
@ -150,7 +159,9 @@ struct AndroidBluetoothMidiInterface
{ {
JNIEnv* env = getEnv(); JNIEnv* env = getEnv();
LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport,
AndroidJuceMidiSupport.getAndroidBluetoothManager,
getAppContext().get()));
if (btManager.get() == nullptr) if (btManager.get() == nullptr)
return unpaired; return unpaired;
@ -520,7 +531,9 @@ bool BluetoothMidiDevicePairingDialogue::isAvailable()
{ {
auto* env = getEnv(); auto* env = getEnv();
LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport, AndroidJuceMidiSupport.getAndroidBluetoothManager, getAppContext().get())); LocalRef<jobject> btManager (env->CallStaticObjectMethod (AndroidJuceMidiSupport,
AndroidJuceMidiSupport.getAndroidBluetoothManager,
getAppContext().get()));
return btManager != nullptr; return btManager != nullptr;
} }