From bfb556bb20d836e2f82871556c6c9cc7cde05cfd Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 12 Dec 2021 20:59:53 +0100 Subject: [PATCH] BluetoothDevicePreference -> kt --- .../danar/BluetoothDevicePreference.kt | 49 +++++++------------ 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/BluetoothDevicePreference.kt b/danar/src/main/java/info/nightscout/androidaps/danar/BluetoothDevicePreference.kt index 794587c2ce..41b090bc72 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/BluetoothDevicePreference.kt +++ b/danar/src/main/java/info/nightscout/androidaps/danar/BluetoothDevicePreference.kt @@ -1,35 +1,22 @@ -package info.nightscout.androidaps.danar; +package info.nightscout.androidaps.danar -import android.bluetooth.*; -import android.content.Context; -import androidx.preference.ListPreference; -import android.util.AttributeSet; +import kotlin.jvm.JvmOverloads +import android.bluetooth.BluetoothAdapter +import android.bluetooth.BluetoothDevice +import android.bluetooth.BluetoothManager +import android.content.Context +import android.util.AttributeSet +import androidx.preference.ListPreference +import java.util.* -import java.util.Set; -import java.util.Vector; - -public class BluetoothDevicePreference extends ListPreference { - - public BluetoothDevicePreference(Context context, AttributeSet attrs) { - super(context, attrs); - - BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter(); - Vector entries = new Vector(); - if (bta != null) { - Set pairedDevices = bta.getBondedDevices(); - for (BluetoothDevice dev : pairedDevices) { - String name = dev.getName(); - if(name != null) { - entries.add(name); - } - } +class BluetoothDevicePreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ListPreference(context, attrs) { + init { + val entries = Vector() + (context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter?.let { bta -> + for (dev in bta.bondedDevices) + dev.name?.let { name -> entries.add(name) } } - setEntries(entries.toArray(new CharSequence[0])); - setEntryValues(entries.toArray(new CharSequence[0])); + setEntries(entries.toTypedArray()) + entryValues = entries.toTypedArray() } - - public BluetoothDevicePreference(Context context) { - this(context, null); - } - -} +} \ No newline at end of file