BluetoothDevicePreference -> kt

This commit is contained in:
Milos Kozak 2021-12-12 20:59:53 +01:00
parent bf5d0916ec
commit bfb556bb20

View file

@ -1,35 +1,22 @@
package info.nightscout.androidaps.danar; package info.nightscout.androidaps.danar
import android.bluetooth.*; import kotlin.jvm.JvmOverloads
import android.content.Context; import android.bluetooth.BluetoothAdapter
import androidx.preference.ListPreference; import android.bluetooth.BluetoothDevice
import android.util.AttributeSet; import android.bluetooth.BluetoothManager
import android.content.Context
import android.util.AttributeSet
import androidx.preference.ListPreference
import java.util.*
import java.util.Set; class BluetoothDevicePreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ListPreference(context, attrs) {
import java.util.Vector; init {
val entries = Vector<CharSequence>()
public class BluetoothDevicePreference extends ListPreference { (context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter?.let { bta ->
for (dev in bta.bondedDevices)
public BluetoothDevicePreference(Context context, AttributeSet attrs) { dev.name?.let { name -> entries.add(name) }
super(context, attrs);
BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
Vector<CharSequence> entries = new Vector<CharSequence>();
if (bta != null) {
Set<BluetoothDevice> pairedDevices = bta.getBondedDevices();
for (BluetoothDevice dev : pairedDevices) {
String name = dev.getName();
if(name != null) {
entries.add(name);
}
}
} }
setEntries(entries.toArray(new CharSequence[0])); setEntries(entries.toTypedArray())
setEntryValues(entries.toArray(new CharSequence[0])); entryValues = entries.toTypedArray()
} }
}
public BluetoothDevicePreference(Context context) {
this(context, null);
}
}